Class Time |
This class is used to represent a date/time. The representation may be retrieved from the class either as the constituent parts of a date, or as the number of seconds since a base date, which is 1/1/1600. The "seconds" viewpoint is always in UTC, whilst the "broken down" viewpoint is always in the local timezone. The timezone is specified as a timezone object. If not specified as a parameter the timezone defaults to a value extracted from the system, if possible. @example @ t := Time() # t is uninitialized @ t.set_current_time(Timezone(-18000)) # t now represents the current time; # time zone GMT-5hrs @ t.parse("1990/12/2 11:22:03 -0500") # the given date @ t.set_fields(1990, 12, 2, 11, 22, 03, Timezone(-18000)) # the same date @ t.set_seconds(n, z) # n seconds past the base date in GMT, +/-z mins
Details |
Constructor |
Methods: |
Succeed if date is after d
Succeed if date is before d
Compute broken down fields based on seconds past base date
Compute seconds past base date based on broken down fields.
Succeed if date is equal to d. Overrides {Object.equals()}
Format the instance using the given pattern string. The pattern consists of pattern chars and other chars. The "width" of a field is the number of successive equal pattern chars. For example in the pattern yyyy/MMM/dd the widths are 4, 3 and 2 respectively. The possible pattern chars are :- E - The weekday. A width < 4 gives the first three chars (eg Mon), otherwise the full day is given (eg Monday) y - The year. If the width is 2, the year will be the least significant 2 digits (eg "99"), otherwise it is the full year padded to the width. d - The day of the month padded to the width. H - The hour in the day using the 24 hour clock padded to the width. h - The hour in the day using the 12 hour clock padded to the width. M - The month of the year. If the width is less than 3 then the numeric value is used, padded to the width. If the width is 3, then the abbreviated month is used (eg "Jul"); otherwise the full month is used (eg "July"). m - The minute in the hour padded to the width. s - The second in the minute padded to the width. a - am or pm. The width is ignored. A - AM or PM The width is ignored. z - the timezone id (eg UTC or +0400). The width is ignored. Literal strings (which can include the above chars) can be included using single quotes. Two single quotes maps to an actual single quote. @example @ @ yyyy MM dd HH mm ss -> 1999 12 17 23 30 01 @ yyyy MM dd HH 'o''clock' mm ss -> 1999 12 17 23 o'clock 30 01 @ yyyy/M/d HH:mm:ss zzz -> 1999/2/7 23:30:01 PST @ E MMM dd HH:mm:ss zzz yyyy -> Mon Feb 07 23:30:01 PST 1999 @ yy MM dd HH mm ss -> 99 12 17 23 30 01
Format the given int using the given width @p
Format a month (Jan, Feb etc) given a width @p
Format a weekday (Mon, Tue etc) given a width. @p
Format a year given the width @p
Return the difference in seconds between the current system time and the time represented by this object.
Utility procedure - return cumulative days upto month m in year y @p
Utility procedure - return in month m for year y @p
Get the hour.
Get the mday.
Get the min.
Get the month.
Get the seconds past the hour.
Get the seconds past the base date
Get the year.
Get the time zone
Match a literal, which begins with a ', and ends with the next ', except that two ' together means a single ' in the result. @p
Parse the instance using the given pattern string. The pattern consists of pattern chars and other chars. The "width" of a field is the number of successive equal pattern chars. For example in the pattern yyyy/MMM/dd the widths are 4, 3 and 2 respectively. Except for the month (see below), the only use of the width is to separate adjacent fields, eg yyyyMMdd with input "19991201". The possible pattern chars are :- E - The weekday (eg Mon) - this is just a sequence of upper and lower case chars and is otherwise ignored. y - The year. If the year is less than 70 it is taken to be 20xx; if it is less than 100 it is taken to be 19xx, otherwise it is as given. d - The day of the month H/h - The hour in the day M - The month of the year. If the width is less than 3 then the numeric value is expected, otherwise the textual value is expected. m - The minute in the hour s - The second in the minute a/A - am or pm. Case is ignored. If pm, then the hour is adjusted accordingly in the result. z - The timezone (eg UTC or +0400).
Get the next parsed am/pm @p
Get the next parsed int @p
Get the next parsed month @p
Get the next parsed timezone @p
Get the next parsed weekday @p
Get the next parsed month @p
Set to the current time @param z an optional {Timezone}. If omitted, the system timezone is used.
set_fields(year, month, mday, hour, min, sec, zone)
Set the fields
Set hour; recompute seconds past the base date.
Set mday; recompute seconds past the base date.
Set min; recompute seconds past the base date.
Set month; recompute seconds past the base date.
As above, but if mday is out of bounds for new month, truncate to end of month
Set seconds past the hour; recompute seconds past the base date.
Set seconds and zone field; re-compute broken down fields @param n the seconds past the base point @param z the zone, as a {Timezone} object, or &null, in which chase @ the system timezone is used.
Set year; recompute seconds past the base date.
Set the time zone offset. The zone is a Timezone object.
An alternative more liberal form of parsing. The numeric fields are taken as successive ints in the input: all else is ignored. The year, month and day are mandatory, but hours, mins, secs are optional. Finally, an optional timezone is allowed.
Convert to icon &clock format
# Convert to icon &date format @p
Convert to a string in icon &date format followed by Icon &clock format followed by the timezone.
Convert to a string in icon &dateline format
Convert to string in a format suitable for use in a letter
Convert to string in accordance with RFC 822.
Convert to string in format d-MMM-yy
Convert to a string
Compute day of week. 0 = Sunday etc. Add 6 because 1/1/Time_data_base_year is always a Saturday
Compute year day. January 1st = 1 etc
Fields: |