the timedate type
Definition: |
include builtins\timedate.e
timedate identifier -- or -- bool bIsTime = timedate(object x) |
Description: | This serves to define the timedate type. With some caution you can also call it like an ordinary function to determine whether an object is or perhaps rather is not a timedate. |
pwa/p2js: | Supported, with similar constraints to sequence, though of course in this case the type function is automatically transpiled rather than being previously hand-crafted in p2js.js. |
Comments: |
A timedate can hold the result from date() and a successful call to
parse_date_string(). It can be modified using adjust_timedate(), set_timezone(), and change_timezone(). The DT_XXX constants as defined in the date() documentation can be used to examine the contents of a timedate. If d is a (sequence) result from dir(), then each d[i][D_YEAR..D_SECOND(or $)] is also a valid timedate, however the D_XXX constants are not suitable for use with timedate variables (unless you subtract 3 from them, ie D_YEAR-1, which makes the D_XXX constants match the DT_XXX constants ![]() Internally, a timedate is a sequence of between 8 and 10 integers, depending on whether it has a timezone. The result from date() is a valid timedate, without a timezone, as is {0,0,0,0,0,0,0,0}. Note that attempts to parse say "3:15pm" must clearly leave day/month/year as zero, so any validation cannot be too fussy. It will however trigger a typecheck failure if the month, day, hour, minute, second, dayofweek, dayofyear, timezone are outside 0..12, 31, 23, 59, 59, 7, 366, length(timezones) respectively. When invoked as a function, returns 1 if x is (probably/possibly) a timedate otherwise returns 0. See adjust_timedate() for normalising nonsensical dates. To quietly catch errors from parse_date_string(), store the result in a sequence variable and either use the timedate function to test it or check that the length() is not 3 before attempting to use it as a timedate. |
Example: |
include builtins\timedate.e timedate td = parse_date_string("1/1/2001",{"D/M/YYYY"}) ?format_timedate(td,"Dddd, Mmmm dth, yyyy") -- displays "Monday, January 1st, 2001" |
See Also: | date, length, parse_date_string, adjust_timedate, set_timezone, change_timezone, format_timedate |