BaH.DateTime: Constants Globals Functions Types Modinfo Source  

Date Time

This Blitzmax DateTime module utilizes the BOOST C++ library datetime functions to provide an extensive set of date and time features.

The module allows for control and maipulation of dates, times, periods, durations, time zones and the localization of month and weekday names (both for long and short formats).

Requirements

The DateTime module requires the BaH.Boost module, which should be available from the same place you found this.

Dates

Dates are based on the Gregorian calendar using a "proleptic" system, which extends dates back prior to the Gregorian Calendar's first adoption in 1582. The current implementation supports dates in the range 1400-Jan-01 to 9999-Dec-31. Many references will represent dates prior to 1582 using the Julian Calendar, so caution is in order if accurate calculations are required on historic dates.

Types for date processing include TDate, TPartialDate, TDatePeriod and the abstract TDateIterator (of which TDateDayIterator, TDateMonthIterator and TDateYearIterator are the implementations).

Examples of usage include :

ExampleDescription
Days Alive
Days Between New Years
Simple date arithmetic. Retrieve current day from clock.
Date Period CalculationsSee if a date is in a set of date periods (eg: is it a holiday/weekend)
Print a monthSmall utility which prints out all the days in a month from command line. Need to know if 1999-Jan-1 was a Friday or a Saturday? This program shows how to do it.
Print HolidaysUses date generators to convert abstract specification into concrete set of dates.

Times

The time system defines a non-adjusted time system with nano-second/micro-second resolution and stable calculation properties. This time system uses the Gregorian calendar to implement the date portion of the time representation.

Types for time processing include TTime, TTimeDuration and TTimePeriod.

Examples of usage include :

ExampleDescription
Time MathA few simple calculations using TTime and TTimeDurations.
Time PeriodsSome simple examples of intersection and display of time periods.

Localization

It is possible to localize the month and weekday names using a TDateFacet. This type provides a set of methods to enable the setting of both long and short versions of the texts. The default facet can be overridden by calling SetCurrentDateFacet, passing in the custom facet. Subsequently, all month/weekday output will reflect the new date facet.
To reset the current date facet, you can use the defaultDateFacet as a parameter to SetCurrentDateFacet.

In the locale folder included with the module, is a set of localized month/weekday names in 74 languages, using the .blf format as specified by the BaH.Locale module.
The example, locale_example.bmx shows one way to localize the datetime texts using that module.

Constants Summary

Apr , Aug , Dec , Feb , Fifth , First , Fourth , Friday , Jan , Jul , Jun , Mar , May , Monday , Nov , Oct , Saturday , Second , Sep , Sunday , Third , Thursday , Tuesday , Wednesday

Globals Summary

defaultDateFacet

Functions Summary

DaysBeforeWeekday Calculates the number of day from given date to previous given weekday.
DaysUntilWeekday Calculates the number of days from given date until given weekday.
EndOfMonthDay  
Month Get the month text for the specified month (1 - 12).
NextWeekday Generates a TDate object representing the date of the following weekday from the given date.
NumFractionalDigits Returns the number of fractional digits the time resolution has.
PreviousWeekday Generates a TDate object representing the date of the previous weekday from the given date.
SetCurrentDateFacet Sets the current date facet.
TDHours Convenience function for TTimeDuration.Hour().
TDMillisecs Convenience function for TTimeDuration.Millisecond().
TDMinutes Convenience function for TTimeDuration.Minute().
TDSeconds Convenience function for TTimeDuration.Second().
TicksPerSecond Return the number of ticks in a second.
WeekDay Get the weekday text for the specified weekday (0 - 6).

Types Summary

TDate The primary interface for date programming.
TDateDayIterator A TDateIterator for stepping over days.
TDateFacet The TDateFacet enables users to have significant control over the output of dates (and other gregorian objects).
TDateIterator Base type for date iterators.
TDateMonthIterator A TDateIterator for stepping over months.
TDatePeriod TDatePeriod provides direct representation for ranges between two dates.
TDateYearIterator A TDateIterator for stepping over years.
TFirstDayOfWeekAfter Date Generator for first day of the week after a date.
TFirstDayOfWeekBefore Date Generator for first day of the week before a date.
TFirstDayOfWeekInMonth Date Generator for first day of the week in month.
TLastDayOfWeekInMonth Date Generator for last day of the week in month.
TLocalDateTime A TLocalDateTime object is a point in time and an associated time zone.
TLocalTimePeriod TLocalTimePeriod provides direct representation for ranges between two local times.
TNthDayOfWeekInMonth Date Generator for nth day of the week in month.
TPartialDate Date Generator for a partial date.
TTime TTime is the primary interface for time point manipulation.
TTimeDuration Represents a length of time.
TTimePeriod TimePeriod provides direct representation for ranges between two times.
TTimeZone A posix TTimeZone is a set of data and rules that provide information about a time zone.
TTZDatabase The Time Zone Database (#TTZDatabase) is a store of time zone information.
TYearBasedGenerator Date Generator base type for TLastDayOfWeekInMonth, TFirstDayOfWeekInMonth, TNthDayOfWeekInMonth and TPartialDate.

Constants

Const Apr:Int
DescriptionMonth - April.

Const Aug:Int
DescriptionMonth - August.

Const Dec:Int
DescriptionMonth - December.

Const Feb:Int
DescriptionMonth - February.

Const Fifth:Int
DescriptionNth Day - Fifth.

Const First:Int
DescriptionNth Day - First.

Const Fourth:Int
DescriptionNth Day - Fourth.

Const Friday:Int
DescriptionWeek Day - Friday.

Const Jan:Int
DescriptionMonth - January.

Const Jul:Int
DescriptionMonth - July.

Const Jun:Int
DescriptionMonth - June.

Const Mar:Int
DescriptionMonth - March.

Const May:Int
DescriptionMonth - May.

Const Monday:Int
DescriptionWeek Day - Monday.

Const Nov:Int
DescriptionMonth - November.

Const Oct:Int
DescriptionMonth - October.

Const Saturday:Int
DescriptionWeek Day - Saturday.

Const Second:Int
DescriptionNth Day - Second.

Const Sep:Int
DescriptionMonth - September.

Const Sunday:Int
DescriptionWeek Day - Sunday.

Const Third:Int
DescriptionNth Day - Third.

Const Thursday:Int
DescriptionWeek Day - Thursday.

Const Tuesday:Int
DescriptionWeek Day - Tuesday.

Const Wednesday:Int
DescriptionWeek Day - Wednesday.

Globals

Global defaultDateFacet:TDateFacet
DescriptionThe default date facet.

Functions

Function DaysBeforeWeekday:Int(date:TDate, WeekDay:Int)
DescriptionCalculates the number of day from given date to previous given weekday.
InformationValid weekdays include Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday (0-6).

Function DaysUntilWeekday:Int(date:TDate, WeekDay:Int)
DescriptionCalculates the number of days from given date until given weekday.
InformationValid weekdays include Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday (0-6).

Function EndOfMonthDay:Int(year:Int, Month:Int)

Function Month:String(Month:Int)
DescriptionGet the month text for the specified month (1 - 12).
InformationThis is based on the current month format as specified by TDateFacet.

Function NextWeekday:TDate(date:TDate, WeekDay:Int)
DescriptionGenerates a TDate object representing the date of the following weekday from the given date.
InformationValid weekdays include Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday (0-6).

Function NumFractionalDigits:Int()
DescriptionReturns the number of fractional digits the time resolution has.
Information9 for nano, 6 for micro, etc.

Function PreviousWeekday:TDate(date:TDate, WeekDay:Int)
DescriptionGenerates a TDate object representing the date of the previous weekday from the given date.
InformationValid weekdays include Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday (0-6).

Function SetCurrentDateFacet(facet:TDateFacet)
DescriptionSets the current date facet.
InformationThis controls the appearance of date information.

Function TDHours:TTimeDuration(amount:Int)
DescriptionConvenience function for TTimeDuration.Hour().

Function TDMillisecs:TTimeDuration(amount:Int)
DescriptionConvenience function for TTimeDuration.Millisecond().

Function TDMinutes:TTimeDuration(amount:Int)
DescriptionConvenience function for TTimeDuration.Minute().

Function TDSeconds:TTimeDuration(amount:Int)
DescriptionConvenience function for TTimeDuration.Second().

Function TicksPerSecond:Int()
DescriptionReturn the number of ticks in a second.
InformationFor example, if the duration supports nanoseconds then the returned result will be 1,000,000,000 (1e+9).

Function WeekDay:String(WeekDay:Int)
DescriptionGet the weekday text for the specified weekday (0 - 6).
InformationThis is based on the current weekday format as specified by TDateFacet.
Valid weekdays include Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday (0-6).

Types

Type TDate
DescriptionThe primary interface for date programming.
InformationIn general, the date class is immutable once constructed although it does allow assignment from another date.
Methods Summary
add Return a TDate adding a day offset.
day Returns the day (of the month) part of the date.
dayIterator Returns a TDateDayIterator for this date.
dayOfWeek Get the day of the week.
dayOfYear Get the day of the year.
format Output the date in the specified format.
isAfter Returns true if the date is after when.
isBefore Returns true if the date is before when.
isEqual Returns true if the two dates are equal.
lastDayOfMonth Returns a TDate object set to the last day of the calling objects current month.
Month Returns the month part of the date.
monthIterator Returns a TDateMonthIterator for this date.
subtract Return a TDate by adding a day offset.
subtractDate Returns the number of days difference.
toISOExtendedString To YYYY-MM-DD where all components are integers.s.
toISOString To YYYYMMDD where all components are integers.
toSimpleString To YYYY-mmm-DD string where mmm 3 char month name.
toString To YYYY-mmm-DD string where mmm 3 char month name.
WeekDay Get the weekday as a string.
weekNumber Returns the ISO 8601 week number for the date.
year Returns the year part of the date.
yearIterator Returns a TDateYearIterator for this date.
ymd Populates year, month and day with the date parts.
Functions Summary
Create Creates a new TDate.
fromString From delimited date string where with order year-month-day eg: 2002-1-25.
fromUndelimitedString From iso type date string where with order year-month-day eg: 20020125.
localDay Creates a new TDate for the current local time.
universalDay Creates a new TDate for the current UCT time.
Method add:TDate(days:Int)
DescriptionReturn a TDate adding a day offset.
Information
SuperStrict

Framework BaH.DateTime Import BRL.StandardIO

Local d:TDate = TDate.localDay()

Print d.add(10).toString()

Example source
Method day:Int()
DescriptionReturns the day (of the month) part of the date.
Information
SuperStrict

Framework BaH.DateTime Import BRL.StandardIO

Local d:TDate = TDate.Create(2007, Jul, 17)

Print d.day()

Example source
Method dayIterator:TDateDayIterator(offset:Int = 1)
DescriptionReturns a TDateDayIterator for this date.
Informationoffset is the number of days moved in each forward/backward.
Method dayOfWeek:Int()
DescriptionGet the day of the week.
InformationSunday = 0, Monday = 1, etc.
SuperStrict

Framework BaH.DateTime Import BRL.StandardIO

Local d:TDate = TDate.localDay()

Print d.dayOfWeek()

Example source
Method dayOfYear:Int()
DescriptionGet the day of the year.
InformationNumber from 1 to 366.
SuperStrict

Framework BaH.DateTime Import BRL.StandardIO

Local d:TDate = TDate.localDay()

Print d.dayOfYear()

Example source
Method format:String(f:String)
DescriptionOutput the date in the specified format.
InformationFormatting characters are as follows :
Format SpecifierDescription
%aAbbreviated weekday name
%ALong weekday name
%bAbbreviated month name
%BFull month name
%cThe preferred date and time representation for the current locale.
%CThe century number (year/100) as a 2-digit integer.
%dDay of the month as decimal 01 to 31
%DEquivalent to m/%d/%y
%eLike d, the day of the month as a decimal number, but a leading zero is replaced by a space
%GThis has the same format and value as y, except that if the ISO week number belongs to the previous or next year, that year is used instead.
%gLike G, but without century.
%hEquivalent to b
%jDay of year as decimal from 001 to 366 for leap years, 001 - 365 for non-leap years.
%mMonth name as a decimal 01 to 12
%uThe day of the week as a decimal, range 1 to 7, Monday being 1.
%UThe week number of the current year as a decimal number, range 00 to 53, starting with the first Sunday as the first day of week 01. In 2005, Jan 1st falls on a Saturday, so therefore it falls within week 00 of 2005 (week 00 spans 2004-Dec-26 to 2005-Jan-01. This also happens to be week 53 of 2004).
%VThe ISO 8601:1988 week number of the current year as a decimal number, range 01 to 53, where week 1 is the first week that has at least 4 days in the current year, and with Monday as the first day of the week.
%wWeekday as decimal number 0 to 6
%WWeek number 00 to 53 where Monday is first day of week 1
%xImplementation defined date format from the locale.
%yTwo digit year
%YFour digit year
%Y-%b-%dDefault date format
%Y%m%dISO format
%Y-%m-%dISO extended format
SuperStrict

Framework BaH.DateTime Import BRL.StandardIO

Local d:TDate = TDate.localDay()

Print d.format("This is day d of month m, of the year G.")

Example source
Method isAfter:Int(when:TDate)
DescriptionReturns true if the date is after when.
Method isBefore:Int(when:TDate)
DescriptionReturns true if the date is before when.
Method isEqual:Int(when:TDate)
DescriptionReturns true if the two dates are equal.
Method lastDayOfMonth:TDate()
DescriptionReturns a TDate object set to the last day of the calling objects current month.
Information
SuperStrict

Framework BaH.DateTime Import BRL.StandardIO

Local d:TDate = TDate.localDay() Local lastDay:TDate = d.lastDayOfMonth()

Print lastDay.toString()

Example source
Method Month:Int()
DescriptionReturns the month part of the date.
Information
SuperStrict

Framework BaH.DateTime Import BRL.StandardIO

Local d:TDate = TDate.Create(2007, Jul, 17)

Print d.month()

Example source
Method monthIterator:TDateMonthIterator(offset:Int = 1)
DescriptionReturns a TDateMonthIterator for this date.
Informationoffset is the number of months moved in each forward/backward.
Method subtract:TDate(days:Int)
DescriptionReturn a TDate by adding a day offset.
Information
SuperStrict

Framework BaH.DateTime Import BRL.StandardIO

Local d:TDate = TDate.localDay()

Print d.subtract(14).toString()

Example source
Method subtractDate:Int(date:TDate)
DescriptionReturns the number of days difference.
Information
SuperStrict

Framework BaH.DateTime Import BRL.StandardIO

Local d1:TDate = TDate.Create(2000, Jan, 1) Local d2:TDate = TDate.localDay()

Print d2.subtractDate(d1)

Example source
Method toISOExtendedString:String()
DescriptionTo YYYY-MM-DD where all components are integers.s.
Method toISOString:String()
DescriptionTo YYYYMMDD where all components are integers.
Method toSimpleString:String()
DescriptionTo YYYY-mmm-DD string where mmm 3 char month name.
Method toString:String()
DescriptionTo YYYY-mmm-DD string where mmm 3 char month name.
Method WeekDay:String()
DescriptionGet the weekday as a string.
InformationThis is based on the current weekday format as specified by TDateFacet.
Method weekNumber:Int()
DescriptionReturns the ISO 8601 week number for the date.
Information
SuperStrict

Framework BaH.DateTime Import BRL.StandardIO

Local d:TDate = TDate.localDay()

Print d.weekNumber()

Example source
Method year:Int()
DescriptionReturns the year part of the date.
Information
SuperStrict

Framework BaH.DateTime Import BRL.StandardIO

Local d:TDate = TDate.Create(2007, Jul, 17)

Print d.year()

Example source
Method yearIterator:TDateYearIterator(offset:Int = 1)
DescriptionReturns a TDateYearIterator for this date.
Informationoffset is the number of years moved in each forward/backward.
Method ymd(year:Int Var, Month:Int Var, day:Int Var)
DescriptionPopulates year, month and day with the date parts.
Information
SuperStrict

Framework BaH.DateTime Import BRL.StandardIO

Local d:TDate = TDate.Create(2006, Dec, 24)

Local year:Int, month:Int, day:Int

d.ymd(year, month, day)

Print year Print month Print day

Example source
Function Create:TDate(year:Int, Month:Int, day:Int)
DescriptionCreates a new TDate.
Information
SuperStrict

Framework BaH.DateTime Import BRL.StandardIO

Local d:TDate = TDate.Create(1984, 4, 23)

Print d.toString()

Print TDate.Create(1990, Mar, 12).toString()

Example source
Function fromString:TDate(date:String)
ReturnsA TDate of the string entered, or Null if the date was invalid.
DescriptionFrom delimited date string where with order year-month-day eg: 2002-1-25.
Information
SuperStrict

Framework BaH.DateTime Import BRL.StandardIO

Local d:TDate = TDate.fromString("2004-09-25")

Print d.toString()

Example source
Function fromUndelimitedString:TDate(date:String)
DescriptionFrom iso type date string where with order year-month-day eg: 20020125.
Information
SuperStrict

Framework BaH.DateTime Import BRL.StandardIO

Local d:TDate = TDate.fromUndelimitedString("19760130")

Print d.toString()

Example source
Function localDay:TDate()
DescriptionCreates a new TDate for the current local time.
Information
SuperStrict

Framework BaH.DateTime Import BRL.StandardIO

Local d:TDate = TDate.localDay()

Print d.toString()

Example source
Function universalDay:TDate()
DescriptionCreates a new TDate for the current UCT time.

Type TDateDayIterator Extends TDateIterator
DescriptionA TDateIterator for stepping over days.
Functions Summary
CreateIterator Creates a new TDateDayIterator from date for the step size of offset days.
Function CreateIterator:TDateDayIterator(date:TDate, offset:Int = 1)
DescriptionCreates a new TDateDayIterator from date for the step size of offset days.

Type TDateFacet Extends TLocaleFacet
DescriptionThe TDateFacet enables users to have significant control over the output of dates (and other gregorian objects).
Methods Summary
format Set the format for dates.
monthFormat Set the format for months when they are output individually.
setISOExtendedFormat Sets the date format to ISO Extended.
setISOFormat Sets the date format to ISO.
setLongMonthNames Replace strings used when outputting long months.
setLongWeekdayNames Replace strings used when outputting long weekdays.
setShortMonthNames Replace strings used when outputting short months.
setShortWeekdayNames Replace strings used when outputting short weekdays.
weekdayFormat Set the format for weekdays when they are output individually.
Functions Summary
Create Creates a new TDateFacet.
Method format(fmt:String)
DescriptionSet the format for dates.
Method monthFormat(fmt:String)
DescriptionSet the format for months when they are output individually.
Method setISOExtendedFormat()
DescriptionSets the date format to ISO Extended.
Method setISOFormat()
DescriptionSets the date format to ISO.
Method setLongMonthNames(names:String[])
DescriptionReplace strings used when outputting long months.
InformationExpected to be non-Null and 12 months.
Method setLongWeekdayNames(names:String[])
DescriptionReplace strings used when outputting long weekdays.
InformationExpected to be non-Null and 7 days, with Sunday starting at 0.
Method setShortMonthNames(names:String[])
DescriptionReplace strings used when outputting short months.
InformationExpected to be non-Null and 12 months.
Method setShortWeekdayNames(names:String[])
DescriptionReplace strings used when outputting short weekdays.
InformationExpected to be non-Null and 7 days, with Sunday starting at 0.
Method weekdayFormat(fmt:String)
DescriptionSet the format for weekdays when they are output individually.
Function Create:TDateFacet()
DescriptionCreates a new TDateFacet.

Type TDateIterator Extends TDate Abstract
DescriptionBase type for date iterators.
InformationThe methods forward and backward will move along the time-line based on the size of the offset as defined when the iterator is created. See TDateDayIterator, TDateMonthIterator and TDateYearIterator for implementations.
Methods Summary
backward Move date backward one step.
forward Move date forward one step.
Method backward()
DescriptionMove date backward one step.
Method forward()
DescriptionMove date forward one step.

Type TDateMonthIterator Extends TDateIterator
DescriptionA TDateIterator for stepping over months.
Functions Summary
CreateIterator Creates a new TDateMonthIterator from date for the step size of offset months.
Function CreateIterator:TDateMonthIterator(date:TDate, offset:Int = 1)
DescriptionCreates a new TDateMonthIterator from date for the step size of offset months.

Type TDatePeriod
DescriptionTDatePeriod provides direct representation for ranges between two dates.
InformationThe range is from the begin date up to, but not including, the end date.
A period that is created with beginning and end points being equal, or with a duration of zero, is known as a zero length period. Zero length periods are considered invalid (it is perfectly legal to construct an invalid period). For these periods, the last point will always be one unit less that the begin point.
Methods Summary
begin Returns first day of period.
contains True if period is within this period.
containsDate True if date is within the period.
intersection Calculates the intersection of 2 periods.
intersects True if periods overlap.
isAdjacent Checks if two periods are adjacent, but not overlapping.
isAfter Determines if the period is after a given date.
isBefore Determines if the period is before a given date.
isEqual True if periods are the same.
isGreater True if begin greater than period.end.
isLess True if end is less than period.begin.
isNull True if period is not well formed.
last Returns the last date in the period.
length Returns the length (number of days) in the period.
merge Returns union of two periods.
periodEnd Returns one past the last in the period.
shift Add days to both begin and end.
span Combines two periods and any gap between them such that begin = min(begin, period.begin) and end = max(end , period.end)
toISOString  
toString To [YYYY-mmm-DD/YYYY-mmm-DD] string where mmm is 3 char month name.
Functions Summary
Create Create a period as [beginDate, endDate].
CreateWithDays Create a period as [beginDate, beginDate + length] where end point would be beginDate + length.
Method begin:TDate()
DescriptionReturns first day of period.
Information
SuperStrict

Framework BaH.DateTime Import BRL.StandardIO

Local startDate:TDate = TDate.localDay()

Local p:TDatePeriod = TDatePeriod.CreateWithDays(startDate, 100)

Print p.begin().toString()

Example source
Method contains:Int(period:TDatePeriod)
DescriptionTrue if period is within this period.
Information
SuperStrict

Framework BaH.DateTime Import BRL.StandardIO

Local p:TDatePeriod = TDatePeriod.Create(TDate.Create(2006, 1, 1), TDate.Create(2007, 1, 1))

Local pGood:TDatePeriod = TDatePeriod.Create(TDate.Create(2006, 4, 4), TDate.Create(2006, 5, 5)) Local pBad:TDatePeriod = TDatePeriod.Create(TDate.Create(2006, 10, 1), TDate.Create(2007, 2, 1))

Print p.contains(pGood) Print p.contains(pBad)

Example source
Method containsDate:Int(date:TDate)
DescriptionTrue if date is within the period.
InformationZero length periods cannot contain any points.
SuperStrict

Framework BaH.DateTime Import BRL.StandardIO

Local p:TDatePeriod = TDatePeriod.Create(TDate.Create(2006, 1, 1), TDate.Create(2007, 1, 1))

Local goodDate:TDate = TDate.Create(2006, 6, 1) Local badDate:TDate = TDate.create(2005, 1, 1)

Print p.containsDate(goodDate) Print p.containsDate(badDate)

Example source
Method intersection:TDatePeriod(period:TDatePeriod)
DescriptionCalculates the intersection of 2 periods.
InformationNull if no intersection.
SuperStrict

Framework BaH.DateTime Import BRL.StandardIO

Local p1:TDatePeriod = TDatePeriod.Create(TDate.Create(2006, 1, 1), TDate.Create(2007, 1, 1))

Local p2:TDatePeriod = TDatePeriod.Create(TDate.Create(2006, 10, 1), TDate.Create(2007, 2, 1))

Local intersection:TDatePeriod = p1.intersection(p2)

If intersection Then Print intersection.toString() End If

Example source
Method intersects:Int(period:TDatePeriod)
DescriptionTrue if periods overlap.
Information
SuperStrict

Framework BaH.DateTime Import BRL.StandardIO

Local p:TDatePeriod = TDatePeriod.Create(TDate.Create(2006, 1, 1), TDate.Create(2007, 1, 1))

Local pGood:TDatePeriod = TDatePeriod.Create(TDate.Create(2006, 10, 1), TDate.Create(2007, 2, 1)) Local pBad:TDatePeriod = TDatePeriod.Create(TDate.Create(2005, 1, 1), TDate.Create(2005, 12, 1))

Print p.intersects(pGood) Print p.intersects(pBad)

Example source
Method isAdjacent:Int(period:TDatePeriod)
DescriptionChecks if two periods are adjacent, but not overlapping.
Information
SuperStrict

Framework BaH.DateTime Import BRL.StandardIO

Local p1:TDatePeriod = TDatePeriod.Create(TDate.Create(2006, 10, 1), TDate.Create(2007, 1, 1)) Local p2:TDatePeriod = TDatePeriod.Create(TDate.Create(2006, 1, 1), TDate.Create(2006, 10, 1))

Local p3:TDatePeriod = TDatePeriod.Create(TDate.Create(2006, 1, 1), TDate.Create(2006, 9, 1)) ' a gap here!

Print p1.isAdjacent(p2) Print p1.isAdjacent(p3)

Example source
Method isAfter:Int(date:TDate)
DescriptionDetermines if the period is after a given date.
Information
SuperStrict

Framework BaH.DateTime Import BRL.StandardIO

Local p:TDatePeriod = TDatePeriod.Create(TDate.Create(2006, 10, 1), TDate.Create(2007, 1, 1))

Print p.isAfter(TDate.Create(2000, 1, 1)) Print p.isAfter(TDate.Create(2008, 1, 1))

Example source
Method isBefore:Int(date:TDate)
DescriptionDetermines if the period is before a given date.
Information
SuperStrict

Framework BaH.DateTime Import BRL.StandardIO

Local p:TDatePeriod = TDatePeriod.Create(TDate.Create(2006, 10, 1), TDate.Create(2007, 1, 1))

Print p.isBefore(TDate.Create(2000, 1, 1)) Print p.isBefore(TDate.Create(2008, 1, 1))

Example source
Method isEqual:Int(period:TDatePeriod)
DescriptionTrue if periods are the same.
Method isGreater:Int(period:TDatePeriod)
DescriptionTrue if begin greater than period.end.
Method isLess:Int(period:TDatePeriod)
DescriptionTrue if end is less than period.begin.
Method isNull:Int()
DescriptionTrue if period is not well formed.
Informationeg. end less than or equal to begin.
SuperStrict

Framework BaH.DateTime Import BRL.StandardIO

Local p1:TDatePeriod = TDatePeriod.Create(TDate.Create(2007, 2, 1), TDate.Create(2007, 3, 1)) Local p2:TDatePeriod = TDatePeriod.Create(TDate.Create(2007, 2, 1), TDate.Create(2007, 1, 1))

Print p1.isNull() Print p2.isNull()

Example source
Method last:TDate()
DescriptionReturns the last date in the period.
Information
SuperStrict

Framework BaH.DateTime Import BRL.StandardIO

Local startDate:TDate = TDate.localDay()

Local p:TDatePeriod = TDatePeriod.CreateWithDays(startDate, 100)

Print p.last().toString()

Example source
Method length:Int()
DescriptionReturns the length (number of days) in the period.
Information
SuperStrict

Framework BaH.DateTime Import BRL.StandardIO

Local startDate:TDate = TDate.localDay()

Local p:TDatePeriod = TDatePeriod.CreateWithDays(startDate, 100)

Print p.length()

Example source
Method merge:TDatePeriod(period:TDatePeriod)
DescriptionReturns union of two periods.
InformationNull if no intersection.
SuperStrict

Framework BaH.DateTime Import BRL.StandardIO

Local p1:TDatePeriod = TDatePeriod.Create(TDate.Create(2006, 10, 1), TDate.Create(2007, 1, 1)) Local p2:TDatePeriod = TDatePeriod.Create(TDate.Create(2006, 12, 1), TDate.Create(2007, 2, 1))

Local p3:TDatePeriod = TDatePeriod.Create(TDate.Create(2006, 1, 1), TDate.Create(2006, 5, 1)) ' doesn't overlap !

Local merged:TDatePeriod = p1.merge(p2)

If Not merged.isNull() Then Print merged.toString() End If

merged = p1.merge(p3)

If merged.isNull() Then Print p1.toString() + " and " + p3.toString() + " do NOT overlap!" End If

Example source
Method periodEnd:TDate()
DescriptionReturns one past the last in the period.
Information
SuperStrict

Framework BaH.DateTime Import BRL.StandardIO

Local startDate:TDate = TDate.localDay()

Local p:TDatePeriod = TDatePeriod.CreateWithDays(startDate, 100)

Print p.periodEnd().toString()

Example source
Method shift(days:Int)
DescriptionAdd days to both begin and end.
Information
SuperStrict

Framework BaH.DateTime Import BRL.StandardIO

Local startDate:TDate = TDate.Create(2007, Feb, 1) Local endDate:TDate = TDate.Create(2007, Mar, 1)

Local p:TDatePeriod = TDatePeriod.Create(startDate, endDate)

Print p.toString()

p.shift(15)

Print p.toString()

Example source
Method span:TDatePeriod(period:TDatePeriod)
DescriptionCombines two periods and any gap between them such that begin = min(begin, period.begin) and end = max(end , period.end)
Information
SuperStrict

Framework BaH.DateTime Import BRL.StandardIO

Local p1:TDatePeriod = TDatePeriod.Create(TDate.Create(2006, 1, 1), TDate.Create(2006, 10, 1)) Local p2:TDatePeriod = TDatePeriod.Create(TDate.Create(2006, 12, 1), TDate.Create(2007, 2, 1))

Local span:TDatePeriod = p1.span(p2)

If Not span.isNull() Then Print span.toString() End If

Example source
Method toISOString:String()
Method toString:String()
DescriptionTo [YYYY-mmm-DD/YYYY-mmm-DD] string where mmm is 3 char month name.
Function Create:TDatePeriod(beginDate:TDate, endDate:TDate)
DescriptionCreate a period as [beginDate, endDate].
InformationIf endDate is <= beginDate then the period will be invalid.
SuperStrict

Framework BaH.DateTime Import BRL.StandardIO

Local startDate:TDate = TDate.Create(2007, 1, 1) Local endDate:TDate = TDate.localDay()

Local p:TDatePeriod = TDatePeriod.Create(startDate, endDate)

Print p.toString()

Example source
Function CreateWithDays:TDatePeriod(beginDate:TDate, length:Int)
DescriptionCreate a period as [beginDate, beginDate + length] where end point would be beginDate + length.
InformationIf length is <= zero then the period will be defined as invalid.
SuperStrict

Framework BaH.DateTime Import BRL.StandardIO

Local startDate:TDate = TDate.localDay()

Local p:TDatePeriod = TDatePeriod.CreateWithDays(startDate, 150)

Print p.toString()

Example source

Type TDateYearIterator Extends TDateIterator
DescriptionA TDateIterator for stepping over years.
Functions Summary
CreateIterator Creates a new TDateYearIterator from date for the step size of offset years.
Function CreateIterator:TDateYearIterator(date:TDate, offset:Int = 1)
DescriptionCreates a new TDateYearIterator from date for the step size of offset years.

Type TFirstDayOfWeekAfter
DescriptionDate Generator for first day of the week after a date.
InformationCalculate something like First Sunday after Jan 1,2002.
Methods Summary
getDate Returns the date for the first day after the specified date.
Functions Summary
Create Creates a new TFirstDayOfWeekAfter for the given weekday.
Method getDate:TDate(date:TDate)
DescriptionReturns the date for the first day after the specified date.
Function Create:TFirstDayOfWeekAfter(WeekDay:Int)
DescriptionCreates a new TFirstDayOfWeekAfter for the given weekday.
InformationA weekday may be one of Sunday, Monday, Tuesday, Wednesday, Thursday, Friday or Saturday (0-6).

Type TFirstDayOfWeekBefore
DescriptionDate Generator for first day of the week before a date.
InformationCalculate something like First Monday before Feb 1,2002.
Methods Summary
getDate Returns the date for the first day before the specified date.
Functions Summary
Create Creates a new TFirstDayOfWeekBefore for the given weekday.
Method getDate:TDate(date:TDate)
DescriptionReturns the date for the first day before the specified date.
Function Create:TFirstDayOfWeekBefore(WeekDay:Int)
DescriptionCreates a new TFirstDayOfWeekBefore for the given weekday.
InformationA weekday may be one of Sunday, Monday, Tuesday, Wednesday, Thursday, Friday or Saturday (0-6).

Type TFirstDayOfWeekInMonth Extends TYearBasedGenerator
DescriptionDate Generator for first day of the week in month.
InformationSee TYearBasedGenerator.
Functions Summary
Create Creates a new TFirstDayOfWeekInMonth for the given weekday and month.
Function Create:TFirstDayOfWeekInMonth(WeekDay:Int, Month:Int)
DescriptionCreates a new TFirstDayOfWeekInMonth for the given weekday and month.
InformationA weekday may be one of Sunday, Monday, Tuesday, Wednesday, Thursday, Friday or Saturday.
Month may be one of Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov or Dec.

Type TLastDayOfWeekInMonth Extends TYearBasedGenerator
DescriptionDate Generator for last day of the week in month.
InformationSee TYearBasedGenerator.
Functions Summary
Create Creates a new TLastDayOfWeekInMonth for the given weekday and month.
Function Create:TLastDayOfWeekInMonth(WeekDay:Int, Month:Int)
DescriptionCreates a new TLastDayOfWeekInMonth for the given weekday and month.
InformationA weekday may be one of Sunday, Monday, Tuesday, Wednesday, Thursday, Friday or Saturday.
Month may be one of Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov or Dec.

Type TLocalDateTime
DescriptionA TLocalDateTime object is a point in time and an associated time zone.
InformationThe time is represented internally as UTC.
Methods Summary
addDays Adds days to local date time, returning a new TLocalDateTime.
addDuration Adds duration to the local date time, returning a new TLocalDateTime.
addMonths Adds months to local date time, returning a new TLocalDateTime.
addYears Adds years to local date time, returning a new TLocalDateTime.
isDST Determines if time value is in DST for associated zone.
isEqual True if the two local date times are equal.
isGreater True if this local date time is greater than the parameter.
isLess True if this local date time is less than the parameter.
localTime Returns the local time for this object (Wall-clock).
subtractDays Subtracts days from local date time, returning a new TLocalDateTime.
subtractDuration Subtracts duration from the local date time, returning a new TLocalDateTime.
subtractMonths Subtracts months from local date time, returning a new TLocalDateTime.
subtractYears Subtracts years from local date time, returning a new TLocalDateTime.
UTCTime Converts the local time value to a UTC value.
zone Returns associated TTimeZone object.
Functions Summary
CreateFromTime  
Method addDays:TLocalDateTime(days:Int)
DescriptionAdds days to local date time, returning a new TLocalDateTime.
Method addDuration:TLocalDateTime(duration:TTimeDuration)
DescriptionAdds duration to the local date time, returning a new TLocalDateTime.
Method addMonths:TLocalDateTime(months:Int)
DescriptionAdds months to local date time, returning a new TLocalDateTime.
Method addYears:TLocalDateTime(years:Int)
DescriptionAdds years to local date time, returning a new TLocalDateTime.
Method isDST:Int()
DescriptionDetermines if time value is in DST for associated zone.
Method isEqual:Int(ldt:TLocalDateTime)
DescriptionTrue if the two local date times are equal.
Method isGreater:Int(ldt:TLocalDateTime)
DescriptionTrue if this local date time is greater than the parameter.
Method isLess:Int(ldt:TLocalDateTime)
DescriptionTrue if this local date time is less than the parameter.
Method localTime:TTime()
DescriptionReturns the local time for this object (Wall-clock).
Information
SuperStrict

Framework BaH.DateTime Import BRL.StandardIO

Local pt:TTime = TTime.Create(TDate.Create(2004, Nov, 5), TDHours(10))

Local zone:TTimeZone = TTimeZone.Create("MST-07")

Local az:TLocalDateTime = TLocalDateTime.CreateFromTime(pt, zone)

Print az.UTCTime().toString() Print az.localTime().toString()

Example source
Method subtractDays:TLocalDateTime(days:Int)
DescriptionSubtracts days from local date time, returning a new TLocalDateTime.
Method subtractDuration:TLocalDateTime(duration:TTimeDuration)
DescriptionSubtracts duration from the local date time, returning a new TLocalDateTime.
Method subtractMonths:TLocalDateTime(months:Int)
DescriptionSubtracts months from local date time, returning a new TLocalDateTime.
Method subtractYears:TLocalDateTime(years:Int)
DescriptionSubtracts years from local date time, returning a new TLocalDateTime.
Method UTCTime:TTime()
DescriptionConverts the local time value to a UTC value.
Information
SuperStrict

Framework BaH.DateTime Import BRL.StandardIO

Local pt:TTime = TTime.Create(TDate.Create(2004, Nov, 5), TDHours(10))

Local zone:TTimeZone = TTimeZone.Create("MST-07")

Local az:TLocalDateTime = TLocalDateTime.CreateFromTime(pt, zone)

Print az.UTCTime().toString()

Example source
Method zone:TTimeZone()
DescriptionReturns associated TTimeZone object.
Function CreateFromTime:TLocalDateTime(time:TTime, zone:TTimeZone)

Type TLocalTimePeriod
DescriptionTLocalTimePeriod provides direct representation for ranges between two local times.
InformationPeriods provide the ability to simplify some types of calculations by simplifying the conditional logic of the program.
Methods Summary
begin Return first local date time of the period.
contains True if period is within the period.
containsTime True if time is within the period.
intersection Calculate the intersection of 2 periods.
intersects True if periods overlap.
isEqual True if the two local time periods are equal.
isGreater True if this local time period is greater than the parameter.
isLess True if this local time period is less than the parameter.
isNull True if period is not well formed.
last Return last local date time in the period.
length Return the length of the local time period.
merge Returns union of two periods.
periodEnd Return one past the last in period.
shift Add duration to both begin and end.
span Combines two periods and any gap between them such that begin = min(p1.begin, p2.begin) and end = max(p1.end , p2.end).
Functions Summary
Create Create a period as [begin, end).
CreateWithDuration Create a period as [begin, begin + duration) where end would be begin + duration.
Method begin:TLocalDateTime()
DescriptionReturn first local date time of the period.
Method contains:Int(period:TLocalTimePeriod)
DescriptionTrue if period is within the period.
Method containsTime:Int(time:TLocalDateTime)
DescriptionTrue if time is within the period.
InformationZero length periods cannot contain any points.
Method intersection:TLocalTimePeriod(period:TLocalTimePeriod)
DescriptionCalculate the intersection of 2 periods.
InformationNull if no intersection.
Method intersects:Int(period:TLocalTimePeriod)
DescriptionTrue if periods overlap.
Method isEqual:Int(period:TLocalTimePeriod)
DescriptionTrue if the two local time periods are equal.
InformationPeriods are equal if ltp1.begin = ltp2.begin and ltp1.last = ltp2.last.
Method isGreater:Int(period:TLocalTimePeriod)
DescriptionTrue if this local time period is greater than the parameter.
Method isLess:Int(period:TLocalTimePeriod)
DescriptionTrue if this local time period is less than the parameter.
Method isNull:Int()
DescriptionTrue if period is not well formed.
Informationeg. end less than or equal to begin.
Method last:TLocalDateTime()
DescriptionReturn last local date time in the period.
Method length:TTimeDuration()
DescriptionReturn the length of the local time period.
Method merge:TLocalTimePeriod(period:TLocalTimePeriod)
DescriptionReturns union of two periods.
InformationNull if no intersection.
Method periodEnd:TLocalDateTime()
DescriptionReturn one past the last in period.
Method shift(duration:TTimeDuration)
DescriptionAdd duration to both begin and end.
Method span:TLocalTimePeriod(period:TLocalTimePeriod)
DescriptionCombines two periods and any gap between them such that begin = min(p1.begin, p2.begin) and end = max(p1.end , p2.end).
Function Create:TLocalTimePeriod(beginTime:TLocalDateTime, endTime:TLocalDateTime)
DescriptionCreate a period as [begin, end).
InformationIf end is <= begin then the period will be defined as invalid.
Function CreateWithDuration:TLocalTimePeriod(beginTime:TLocalDateTime, duration:TTimeDuration)
DescriptionCreate a period as [begin, begin + duration) where end would be begin + duration.
InformationIf duration is <= zero then the period will be defined as invalid.

Type TNthDayOfWeekInMonth Extends TYearBasedGenerator
DescriptionDate Generator for nth day of the week in month.
InformationCalculate something like first Monday of January, second Tuesday of March, Third Sunday of December, etc.
See TYearBasedGenerator.
Functions Summary
Create Creates a new TNthDayOfWeekInMonth for the given nth, weekday and month.
Function Create:TNthDayOfWeekInMonth(nth:Int, WeekDay:Int, Month:Int)
DescriptionCreates a new TNthDayOfWeekInMonth for the given nth, weekday and month.
InformationNth may be one of First, Second, Third, Fourth, or Fifth (1-5). A weekday may be one of Sunday, Monday, Tuesday, Wednesday, Thursday, Friday or Saturday (0-6).
Month may be one of Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov or Dec (1-12).

Type TPartialDate Extends TYearBasedGenerator
DescriptionDate Generator for a partial date.
InformationSee TYearBasedGenerator.
Functions Summary
Create Creates a new TPartialDate for the given day and month.
Function Create:TPartialDate(day:Int, Month:Int)
DescriptionCreates a new TPartialDate for the given day and month.

Type TTime
DescriptionTTime is the primary interface for time point manipulation.
Methods Summary
addDays Adds days to time, returning a new TTime.
addDuration Adds duration to the time, returning a new TTime.
date Get the date part of a time.
isEqual True if the two times are equal.
isGreater True if this time is greater than the parameter.
isLess True if this time is less than the parameter.
subtract Subtracts time from the time, returning a TTimeDuration.
subtractDays Subtracts days from time, returning a new TTime.
subtractDuration Subtracts duration from the time, returning a new TTime.
timeOfDay Get the time offset in the day.
toISOExtendedString Convert to form YYYY-MM-DDTHH:MM:SS,fffffffff where T is the date-time separator.
toISOString Convert to form YYYYMMDDTHHMMSS,fffffffff where T is the date-time separator.
toString To YYYY-mmm-DD HH:MM:SS.fffffffff string where mmm 3 char month name.
Functions Summary
Create Constructs a new TTime from a date and offset.
CreateFromFileTime Converts a FileTime value to a TTime.
CreateFromTimeT Converts a time_t struct to a TTime.
CreateLocal Get the local time, second level resolution, based on the time zone settings of the computer.
CreateLocalMS Get the local time using a sub second resolution clock.
CreateUniversal Get the UTC time.
CreateUniversalMS Get the UTC time using a sub second resolution clock.
Method addDays:TTime(days:Int)
DescriptionAdds days to time, returning a new TTime.
Information
SuperStrict

Framework BaH.DateTime Import BRL.StandardIO

Local d:TDate = TDate.Create(2002, Jan, 1) Local t:TTime = TTime.Create(d, TDMinutes(5))

Local t2:TTime = t.addDays(1)

Print t.toString() Print t2.toString()

Example source
Method addDuration:TTime(duration:TTimeDuration)
DescriptionAdds duration to the time, returning a new TTime.
Information
SuperStrict

Framework BaH.DateTime Import BRL.StandardIO

Local d:TDate = TDate.Create(2002, Jan, 1) Local t:TTime = TTime.Create(d, TDMinutes(5))

Local t2:TTime = t.addDuration(TDHours(1).add(TDMinutes(2)))

Print t.toString() Print t2.toString()

Example source
Method date:TDate()
DescriptionGet the date part of a time.
Information
SuperStrict

Framework BaH.DateTime Import BRL.StandardIO

Local d:TDate = TDate.Create(2002, Jan, 10) Local t:TTime = TTime.Create(d, TDHours(1)) Print t.date().toString()

Example source
Method isEqual:Int(time:TTime)
DescriptionTrue if the two times are equal.
Method isGreater:Int(time:TTime)
DescriptionTrue if this time is greater than the parameter.
Method isLess:Int(time:TTime)
DescriptionTrue if this time is less than the parameter.
Method subtract:TTimeDuration(time:TTime)
DescriptionSubtracts time from the time, returning a TTimeDuration.
Information
SuperStrict

Framework BaH.DateTime Import BRL.StandardIO

Local d:TDate = TDate.Create(2002, Jan, 1) Local t1:TTime = TTime.Create(d, TDMinutes(5)) Local t2:TTime = TTime.Create(d, TDMinutes(2))

Print t2.subtract(t1).toString() ' negative result

Example source
Method subtractDays:TTime(days:Int)
DescriptionSubtracts days from time, returning a new TTime.
Information
SuperStrict

Framework BaH.DateTime Import BRL.StandardIO

Local d:TDate = TDate.Create(2002, Jan, 1) Local t:TTime = TTime.Create(d, TDMinutes(5))

Local t2:TTime = t.subtractDays(1)

Print t.toString() Print t2.toString()

Example source
Method subtractDuration:TTime(duration:TTimeDuration)
DescriptionSubtracts duration from the time, returning a new TTime.
Information
SuperStrict

Framework BaH.DateTime Import BRL.StandardIO

Local d:TDate = TDate.Create(2002, Jan, 1) Local t:TTime = TTime.Create(d, TDMinutes(5))

Local t2:TTime = t.subtractDuration(TDMinutes(2))

Print t.toString() Print t2.toString()

Example source
Method timeOfDay:TTimeDuration()
DescriptionGet the time offset in the day.
Information
SuperStrict

Framework BaH.DateTime Import BRL.StandardIO

Local d:TDate = TDate.Create(2002, Jan, 10) Local t:TTime = TTime.Create(d, TDHours(1)) Print t.timeOfDay().toString()

Example source
Method toISOExtendedString:String()
DescriptionConvert to form YYYY-MM-DDTHH:MM:SS,fffffffff where T is the date-time separator.
Method toISOString:String()
DescriptionConvert to form YYYYMMDDTHHMMSS,fffffffff where T is the date-time separator.
Method toString:String()
DescriptionTo YYYY-mmm-DD HH:MM:SS.fffffffff string where mmm 3 char month name.
InformationFractional seconds only included if non-zero.
Function Create:TTime(date:TDate, offset:TTimeDuration = Null)
DescriptionConstructs a new TTime from a date and offset.
Information
SuperStrict

Framework BaH.DateTime Import BRL.StandardIO

Local d:TDate = TDate.Create(2002, Jan, 1) Local t:TTime = TTime.Create(d, TDHours(14))

Print t.toString()

Example source
Function CreateFromFileTime:TTime(time:Int)
DescriptionConverts a FileTime value to a TTime.
InformationThis value is the number of seconds from 1-Jan-1970.
FileTime returns the time at UTC, so you will need to apply your local offset to get the correct local system time.
Function CreateFromTimeT:TTime(time:Byte Ptr)
DescriptionConverts a time_t struct to a TTime.
Function CreateLocal:TTime()
DescriptionGet the local time, second level resolution, based on the time zone settings of the computer.
Information
SuperStrict

Framework BaH.DateTime Import BRL.StandardIO

Local t:TTime = TTime.CreateLocal()

Print t.toString()

Example source
Function CreateLocalMS:TTime()
DescriptionGet the local time using a sub second resolution clock.
InformationOn Unix systems this is implemented using GetTimeOfDay. On most Win32 platforms it is implemented using ftime. Win32 systems often do not achieve microsecond resolution via this API. If higher resolution is critical to your application test your platform to see the achieved resolution.
Function CreateUniversal:TTime()
DescriptionGet the UTC time.
Information
SuperStrict

Framework BaH.DateTime Import BRL.StandardIO

Local t:TTime = TTime.CreateUniversal()

Print t.toString()

Example source
Function CreateUniversalMS:TTime()
DescriptionGet the UTC time using a sub second resolution clock.
InformationOn Unix systems this is implemented using GetTimeOfDay. On most Win32 platforms it is implemented using ftime. Win32 systems often do not achieve microsecond resolution via this API. If higher resolution is critical to your application test your platform to see the achieved resolution.

Type TTimeDuration
DescriptionRepresents a length of time.
Methods Summary
add Adds duration to this duration, returning the result in a new TTimeDuration.
divide Divides the length of the duration by value.
fractionalSeconds Get the number of fractional seconds.
hours Get the number of normalized hours.
invertSign Generate a new duration with the sign inverted.
isEqual True if the durations are equal.
isGreater True if this duration is greater than the parameter.
isLess True if this duration is less than the parameter.
isNegative True if duration is negative.
minutes Get the number of minutes normalized +/-(0..59).
multiply Multiplies the length of the duration by value.
seconds Get the normalized number of second +/-(0..59).
subtract Subtracts duration from this duration, returning the result in a new TTimeDuration.
toISOString Converts to a string in the form HHMMSS,fffffffff.
toString To HH:MM:SS.fffffffff where fff is fractional seconds that are only included if non-zero.
totalMilliseconds Get the total number of milliseconds truncating any remaining digits.
totalSeconds Get the total number of seconds truncating any fractional seconds.
Functions Summary
Create Creates a new TTimeDuration from the counts.
Hour Creates a new TTimeDuration for the number of hours.
Millisecond Creates a new TTimeDuration for the number of milliseconds.
Minute Creates a new TTimeDuration for the number of minutes.
Second Creates a new TTimeDuration for the number of seconds.
Method add:TTimeDuration(duration:TTimeDuration)
DescriptionAdds duration to this duration, returning the result in a new TTimeDuration.
Information
SuperStrict

Framework BaH.DateTime Import BRL.StandardIO

Local td:TTimeDuration = TDHours(12).add(TDMinutes(35)).add(TDSeconds(12))

Print td.toString()

Example source
Method divide:TTimeDuration(value:Int)
DescriptionDivides the length of the duration by value.
InformationDiscards any remainder.
SuperStrict

Framework BaH.DateTime Import BRL.StandardIO

Local td:TTimeDuration = TTimeDuration.Create(18, 30) ' 18 hours and 30 mins

Print td.divide(2).toString() ' 9 hours and 15 mins

Example source
Method fractionalSeconds:Int()
DescriptionGet the number of fractional seconds.
Method hours:Int()
DescriptionGet the number of normalized hours.
Method invertSign:TTimeDuration()
DescriptionGenerate a new duration with the sign inverted.
Information
SuperStrict

Framework BaH.DateTime Import BRL.StandardIO

Local td:TTimeDuration = TDHours(12)

Print td.toString() Print td.invertSign().toString()

Example source
Method isEqual:Int(duration:TTimeDuration)
DescriptionTrue if the durations are equal.
Method isGreater:Int(duration:TTimeDuration)
DescriptionTrue if this duration is greater than the parameter.
Method isLess:Int(duration:TTimeDuration)
DescriptionTrue if this duration is less than the parameter.
Method isNegative:Int()
DescriptionTrue if duration is negative.
Method minutes:Int()
DescriptionGet the number of minutes normalized +/-(0..59).
Method multiply:TTimeDuration(value:Int)
DescriptionMultiplies the length of the duration by value.
Information
SuperStrict

Framework BaH.DateTime Import BRL.StandardIO

Local td:TTimeDuration = TTimeDuration.Create(4, 10, 6)

Print td.multiply(3).toString()

Example source
Method seconds:Int()
DescriptionGet the normalized number of second +/-(0..59).
Method subtract:TTimeDuration(duration:TTimeDuration)
DescriptionSubtracts duration from this duration, returning the result in a new TTimeDuration.
Information
SuperStrict

Framework BaH.DateTime Import BRL.StandardIO

Local td1:TTimeDuration = TTimeDuration.Create(12, 30, 20) Local td2:TTimeDuration = TTimeDuration.Create(1, 30, 20)

Print td1.subtract(td2).toString()

Example source
Method toISOString:String()
DescriptionConverts to a string in the form HHMMSS,fffffffff.
Method toString:String()
DescriptionTo HH:MM:SS.fffffffff where fff is fractional seconds that are only included if non-zero.
Method totalMilliseconds:Int()
DescriptionGet the total number of milliseconds truncating any remaining digits.
Method totalSeconds:Int()
DescriptionGet the total number of seconds truncating any fractional seconds.
Function Create:TTimeDuration(hours:Int = 0, minutes:Int = 0, seconds:Int = 0, fractions:Int = 0)
DescriptionCreates a new TTimeDuration from the counts.
InformationThe fractions parameter is a number of units and is therefore affected by the resolution the application is compiled with. If the fractions argument exceeds the limit of the compiled precision, the excess value will be "carried over" into the seconds field.
Ths following is a technique using TicksPerSecond for creating a resolution independent fractions count :
Local numberOfTenths:Int = 5
' create a resolution independent count -- divide by 10 since there are 10 tenths in a second.
Local count:Int = numberOfTenths * (TicksPerSecond() / 10)

Local duration:TTimeDuration = TTimeDuration.Create(1, 2, 3, count) ' 01:02:03.5 - no matter the resolution settings

Function Hour:TTimeDuration(hours:Int)
DescriptionCreates a new TTimeDuration for the number of hours.
Information
SuperStrict

Framework BaH.DateTime Import BRL.StandardIO

Local td:TTimeDuration = TTimeDuration.Hour(10)

Print td.toString()

Example source
Function Millisecond:TTimeDuration(milliseconds:Int)
DescriptionCreates a new TTimeDuration for the number of milliseconds.
Information
SuperStrict

Framework BaH.DateTime Import BRL.StandardIO

Local td:TTimeDuration = TTimeDuration.Millisecond(180)

Print td.toString()

Example source
Function Minute:TTimeDuration(minutes:Int)
DescriptionCreates a new TTimeDuration for the number of minutes.
Information
SuperStrict

Framework BaH.DateTime Import BRL.StandardIO

Local td:TTimeDuration = TTimeDuration.Minute(7)

Print td.toString()

Example source
Function Second:TTimeDuration(seconds:Int)
DescriptionCreates a new TTimeDuration for the number of seconds.
Information
SuperStrict

Framework BaH.DateTime Import BRL.StandardIO

Local td:TTimeDuration = TTimeDuration.Second(45)

Print td.toString()

Example source

Type TTimePeriod
DescriptionTimePeriod provides direct representation for ranges between two times.
InformationPeriods provide the ability to simplify some types of calculations by simplifying the conditional logic of the program.
A period that is created with beginning and end points being equal, or with a duration of zero, is known as a zero length period. Zero length periods are considered invalid (it is perfectly legal to construct an invalid period). For these periods, the last point will always be one unit less that the begin point.
Methods Summary
begin Return first time of period.
contains True if time is within the period.
containsPeriod True if period is within the period.
intersection Calculate the intersection of 2 periods.
intersects True if periods overlap.
isEqual True if periods are the same.
isGreater True if begin greater than period.end.
isLess True if end is less than period.begin.
isNull True if period is not well formed.
last Return last time in the period.
length Return the length of the time period.
merge Returns union of two periods.
periodEnd Return one past the last in period.
shift Add duration to both begin and end.
span Combines two periods and any gap between them such that begin = min(p1.begin, p2.begin) and end = max(p1.end , p2.end).
toString To [YYYY-mmm-DD hh:mm:ss.fffffffff/YYYY-mmm-DD hh:mm:ss.fffffffff] string where mmm is 3 char month name.
Functions Summary
Create Create a period as [begin, end).
CreateWithDuration Create a period as [begin, begin + duration) where end would be begin + duration.
Method begin:TTime()
DescriptionReturn first time of period.
Method contains:Int(time:TTime)
DescriptionTrue if time is within the period.
InformationZero length periods cannot contain any points.
Method containsPeriod:Int(period:TTimePeriod)
DescriptionTrue if period is within the period.
Method intersection:TTimePeriod(period:TTimePeriod)
DescriptionCalculate the intersection of 2 periods.
InformationNull if no intersection.
Method intersects:Int(period:TTimePeriod)
DescriptionTrue if periods overlap.
Method isEqual:Int(period:TTimePeriod)
DescriptionTrue if periods are the same.
Method isGreater:Int(period:TTimePeriod)
DescriptionTrue if begin greater than period.end.
Method isLess:Int(period:TTimePeriod)
DescriptionTrue if end is less than period.begin.
Method isNull:Int()
DescriptionTrue if period is not well formed.
Informationeg. end is less than or equal to begin.
Method last:TTime()
DescriptionReturn last time in the period.
Method length:TTimeDuration()
DescriptionReturn the length of the time period.
Method merge:TTimePeriod(period:TTimePeriod)
DescriptionReturns union of two periods.
InformationNull if no intersection.
Method periodEnd:TTime()
DescriptionReturn one past the last in period.
Method shift(duration:TTimeDuration)
DescriptionAdd duration to both begin and end.
Method span:TTimePeriod(period:TTimePeriod)
DescriptionCombines two periods and any gap between them such that begin = min(p1.begin, p2.begin) and end = max(p1.end , p2.end).
Method toString:String()
DescriptionTo [YYYY-mmm-DD hh:mm:ss.fffffffff/YYYY-mmm-DD hh:mm:ss.fffffffff] string where mmm is 3 char month name.
Function Create:TTimePeriod(beginTime:TTime, endTime:TTime)
DescriptionCreate a period as [begin, end).
InformationIf end is <= begin then the period will be defined as invalid.
Function CreateWithDuration:TTimePeriod(beginTime:TTime, duration:TTimeDuration)
DescriptionCreate a period as [begin, begin + duration) where end would be begin + duration.
InformationIf duration is <= zero then the period will be defined as invalid.

Type TTimeZone
DescriptionA posix TTimeZone is a set of data and rules that provide information about a time zone.
InformationInformation includes the offset from UTC, its name and abbreviation, as well as daylight savings rules.

A posix time zone is unique in that the object is created from a Posix time zone string (IEEE Std 1003.1). A POSIX time zone string takes the form of:

    "std offset dst [offset],start[/time],end[/time]" (with no spaces).

'std' specifies the abbrev of the time zone. 'offset' is the offset from UTC. 'dst' specifies the abbrev of the time zone during daylight savings time. The second offset is how many hours changed during DST. 'start' and 'end' are the dates when DST goes into (and out of) effect. 'offset' takes the form of:

    [+|-]hh[:mm[:ss]] {h=0-23, m/s=0-59}

'time' and 'offset' take the same form. 'start' and 'end' can be one of three forms:

Mm.w.d {month=1-12, week=1-5 (5 is always last), day=0-6}
Jn {n=1-365 Feb29 is never counted}
n {n=0-365 Feb29 is counted in leap years}

Exceptions will be thrown under the following conditions:

  • An exception will be thrown for an invalid date spec (see date class).
  • A boost::local_time::bad_offset exception will be thrown for:
  • A DST start or end offset that is negative or more than 24 hours.
  • A UTC zone that is greater than +12 or less than -12 hours.
  • A boost::local_time::bad_adjustment exception will be thrown for a DST adjustment that is 24 hours or more (positive or negative)

As stated above, the 'offset' and '/time' portions of the string are not required. If they are not given they default to 01:00 for 'offset', and 02:00 for both occurrences of '/time'.

Some examples are:

"PST-8PDT01:00:00,M4.1.0/02:00:00,M10.1.0/02:00:00"
"PST-8PDT,M4.1.0,M10.1.0"

These two are actually the same specification (defaults were used in the second string). This zone lies eight hours west of GMT and makes a one hour shift forward during daylight savings time. Daylight savings for this zone starts on the first Sunday of April at 2am, and ends on the first Sunday of October at 2am.

    "MST-7"

This zone is as simple as it gets. This zone lies seven hours west of GMT and has no daylight savings.

    "EST10EDT,M10.5.0,M3.5.0/03"

This string describes the time zone for Sydney Australia. It lies ten hours east of GMT and makes a one hour shift forward during daylight savings. Being located in the southern hemisphere, daylight savings begins on the last Sunday in October at 2am and ends on the last Sunday in March at 3am.

"FST+3FDT02:00,J60/00,J304/02"

This specification describes a fictitious zone that lies three hours east of GMT. It makes a two hour shift forward for daylight savings which begins on March 1st at midnight, and ends on October 31st at 2am. The 'J' designation in the start/end specs signifies that counting starts at one and February 29th is never counted.

"FST+3FDT,59,304"

This specification is significant because of the '59'. The lack of 'J' for the start and end dates, indicates that the Julian day-count begins at zero and ends at 365. If you do the math, you'll see that allows for a total of 366 days. This is fine in leap years, but in non-leap years '59' (Feb-29) does not exist. This will construct a valid posix_time_zone object but an exception will be thrown if the date of '59' is accessed in a non-leap year. Ex:

posix_time_zone leap_day(std::string("FST+3FDT,59,304"));
leap_day.dst_local_start_time(2004); // ok
leap_day.dst_local_start_time(2003); // Exception thrown
Methods Summary
baseUTCOffset The amount of time offset from UTC (typically in hours).
DSTLocalEndTime The date and time daylight savings time ends in given year.
DSTLocalStartTime The date and time daylight savings time begins in given year.
DSTOffset The amount of time shifted during daylight savings.
DSTZoneAbbrev Returns the daylight savings abbreviation for the represented time zone.
DSTZoneName Returns the daylight savings name for the represented time zone.
hasDST Returns True if this time zone makes a daylight savings shift.
STDZoneAbbrev Returns the standard abbreviation for the represented time zone.
STDZoneName Returns the standard name for the represented time zone.
toString Returns a posix time zone string representation of this time zone object.
Functions Summary
Create  
Method baseUTCOffset:TTimeDuration()
DescriptionThe amount of time offset from UTC (typically in hours).
Method DSTLocalEndTime:TTime(year:Int)
DescriptionThe date and time daylight savings time ends in given year.
Method DSTLocalStartTime:TTime(year:Int)
DescriptionThe date and time daylight savings time begins in given year.
Method DSTOffset:TTimeDuration()
DescriptionThe amount of time shifted during daylight savings.
Method DSTZoneAbbrev:String()
DescriptionReturns the daylight savings abbreviation for the represented time zone.
Method DSTZoneName:String()
DescriptionReturns the daylight savings name for the represented time zone.
Method hasDST:Int()
DescriptionReturns True if this time zone makes a daylight savings shift.
Method STDZoneAbbrev:String()
DescriptionReturns the standard abbreviation for the represented time zone.
Method STDZoneName:String()
DescriptionReturns the standard name for the represented time zone.
Method toString:String()
DescriptionReturns a posix time zone string representation of this time zone object.
Function Create:TTimeZone(description:String)

Type TTZDatabase
DescriptionThe Time Zone Database (#TTZDatabase) is a store of time zone information.
InformationThe specifications for many time zones (377 at this time) are provided. These specifications are based on data found in the zoneinfo database. The specifications are stored in the file: data/date_time_zonespec.csv
Methods Summary
addRecord Adds a time zone, to the database.
timeZoneFromRegion Returns a time zone that matches the region listed in the data file.
Functions Summary
Create Creates an empty TTZDatabase.
LoadFromFile Creates and populates a TTZDatabase with time zone records found in the zone spec file.
Method addRecord(id:String, zone:TTimeZone)
DescriptionAdds a time zone, to the database.
Informationid is the region name for this zone (e.g. "America/Phoenix").
Method timeZoneFromRegion:TTimeZone(id:String)
Returnsa TTimeZone or Null if not found.
DescriptionReturns a time zone that matches the region listed in the data file.
Function Create:TTZDatabase()
DescriptionCreates an empty TTZDatabase.
Function LoadFromFile:TTZDatabase(filename:String)
DescriptionCreates and populates a TTZDatabase with time zone records found in the zone spec file.

Type TYearBasedGenerator Abstract
DescriptionDate Generator base type for TLastDayOfWeekInMonth, TFirstDayOfWeekInMonth, TNthDayOfWeekInMonth and TPartialDate.
Methods Summary
getDate Returns the date for the specified year.
Method getDate:TDate(year:Int) Abstract
DescriptionReturns the date for the specified year.

Module Information

Version1.00
LicenseBSD
CopyrightWrapper - 2007 Bruce A Henderson
ModserverBRL
History1.00
HistoryInitial Release.
CC_OPTS-fexceptions