Class Time

Summary


 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

Superclasses:
Error, Object

Package:
util
File:
time.icn
Methods:
after, before, compute_broken_down_fields, compute_seconds, equals, format, format_int, format_month, format_weekday, format_year, get_age, get_cum_days, get_days, get_hour, get_mday, get_min, get_month, get_sec, get_seconds, get_year, get_zone, match_literal, parse, parse_ampm, parse_int, parse_month, parse_timezone, parse_weekday, parse_year, set_current_time, set_fields, set_hour, set_mday, set_min, set_month, set_month_truncate, set_sec, set_seconds, set_year, set_zone, simple_parse, to_clock, to_date, to_date_clock, to_dateline, to_letter_string, to_rfc822, to_short_string, to_string, week_day, year_day

Methods inherited from Error:
error, get_reason

Methods inherited from Object:
Type, className, clone, fieldNames, genMethods, getField, get_class, get_class_name, get_id, hasField, hasMethod, hash_code, instanceOf, invoke, is_instance, setField

Fields:
hour, mday, min, month, ppos, psub, sec, seconds, year, zone

Source code.

Details
Constructor

Time(a)

Methods:

after(d)


 Succeed if date is after d


before(d)


 Succeed if date is before d


compute_broken_down_fields()


 Compute broken down fields based on seconds past base date


compute_seconds()


 Compute seconds past base date based on broken down fields.


equals(d)


 Succeed if date is equal to d.  Overrides {Object.equals()}

This method overrides equals in class Object

format(p)


 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_int(n, w)


 Format the given int using the given width
 @p


format_month(w)


 Format a month (Jan, Feb etc) given a width
 @p


format_weekday(w)


 Format a weekday (Mon, Tue etc) given a width.
 @p


format_year(w)


 Format a year given the width
 @p


get_age()


 Return the difference in seconds between the current system time and the
 time represented by this object.


get_cum_days(y, m)


 Utility procedure - return cumulative days upto month m in year y

 @p


get_days(y, m)


 Utility procedure - return in month m for year y

 @p


get_hour()


 Get the hour.


get_mday()


 Get the mday.


get_min()


 Get the min.


get_month()


 Get the month.


get_sec()


 Get the seconds past the hour.


get_seconds()


 Get the seconds past the base date


get_year()


 Get the year.


get_zone()


 Get the time zone


match_literal()


 Match a literal, which begins with a ', and ends with the next ', except
 that two ' together means a single ' in the result.
 @p


parse(s, 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).


parse_ampm()


 Get the next parsed am/pm
 @p


parse_int(w)


 Get the next parsed int
 @p


parse_month(w)


 Get the next parsed month
 @p


parse_timezone()


 Get the next parsed timezone
 @p


parse_weekday()


 Get the next parsed weekday
 @p


parse_year(w)


 Get the next parsed month
 @p


set_current_time(z)


 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(n)


 Set hour; recompute seconds past the base date.


set_mday(n)


 Set mday; recompute seconds past the base date.


set_min(n)


 Set min; recompute seconds past the base date.


set_month(n)


 Set month; recompute seconds past the base date.


set_month_truncate(n)


 As above,  but if mday is out of bounds for new month,
 truncate to end of month


set_sec(n)


 Set seconds past the hour; recompute seconds past the base date.


set_seconds(n, zone)


 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(n)


 Set year; recompute seconds past the base date.


set_zone(z)


 Set the time zone offset.  The zone is a Timezone object.


simple_parse(s)


 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.


to_clock()


 Convert to icon &clock format


to_date()

#
 Convert to icon &date format

 @p


to_date_clock()


 Convert to a string in icon &date format followed by Icon &clock format
 followed by the timezone.


to_dateline()


 Convert to a string in icon &dateline format


to_letter_string()


 Convert to string in a format suitable for use in a letter


to_rfc822()


 Convert to string in accordance with RFC 822.


to_short_string()


 Convert to string in format d-MMM-yy


to_string()


 Convert to a string

This method overrides to_string in class Object

week_day()


 Compute day of week.  0 = Sunday etc.  Add 6 because
 1/1/Time_data_base_year is always a Saturday


year_day()


 Compute year day. January 1st = 1 etc


Fields:
hour

mday

min

month

ppos

psub

sec

seconds

year

zone


This page produced by UniDoc on 2021/04/15 @ 23:59:54.