Class Time

Superclasses :
util::Error
lang::Object
Package :
util

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
Source

Class summary
Methods inherited from util::Error
error(a) get_reason()
Variables inherited from util::Error
reason
Methods inherited from lang::Object
clone(seen) get_class() get_class_name() get_id() hash_code(depth, seen) is_instance(name)
Methods defined in this class
after(d) before(d) compute_broken_down_fields() compute_seconds() equals(d) format(p) format_int(n, w) format_month(w) format_weekday(w) format_year(w) get_cum_days(y, m) get_days(y, m) get_hour() get_int() get_mday() get_min() get_month() get_sec() get_seconds() get_year() get_zone() initially() match_literal() parse(s, p) parse_ampm() parse_int(w) parse_month(w) parse_timezone() parse_weekday() parse_year(w) set_current_time(z) set_fields(year, month, mday, hour, min, sec, zone) set_hour(n) set_mday(n) set_min(n) set_month(n) set_month_truncate(n) set_sec(n) set_seconds(n, zone) set_year(n) set_zone(z) simple_parse(s) to_clock() to_date() to_date_clock() to_dateline() to_letter_string() to_rfc822() to_short_string() to_string() week_day() year_day()
Variables defined in this class
hour mday min month ppos psub sec seconds year zone

Method detail

after(d)

Succeed if date is after d
Source

before(d)

Succeed if date is before d
Source

compute_broken_down_fields()

Compute broken down fields based on seconds past base date
Source

compute_seconds()

Compute seconds past base date based on broken down fields.
Source

equals(d)

Overrides equals(other, seen) in lang::Object
Succeed if date is equal to d. Overrides Object.equals()
Source

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
Source

format_int(n, w)

Private method, not intended for client invocation

format_month(w)

Private method, not intended for client invocation

format_weekday(w)

Private method, not intended for client invocation

format_year(w)

Private method, not intended for client invocation

get_cum_days(y, m)

Private method, not intended for client invocation

get_days(y, m)

Private method, not intended for client invocation

get_hour()

Get the hour.
Source

get_int()

Private method, not intended for client invocation

get_mday()

Get the mday.
Source

get_min()

Get the min.
Source

get_month()

Get the month.
Source

get_sec()

Get the seconds past the hour.
Source

get_seconds()

Get the seconds past the base date
Source

get_year()

Get the year.
Source

get_zone()

Get the time zone
Source

initially()


match_literal()

Private method, not intended for client invocation

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).

Source

parse_ampm()

Private method, not intended for client invocation

parse_int(w)

Private method, not intended for client invocation

parse_month(w)

Private method, not intended for client invocation

parse_timezone()

Private method, not intended for client invocation

parse_weekday()

Private method, not intended for client invocation

parse_year(w)

Private method, not intended for client invocation

set_current_time(z)

Set to the current time
Parameters :
z - an optional Timezone. If omitted, the system timezone is used.
Source

set_fields(year, month, mday, hour, min, sec, zone)

Set the fields
Source

set_hour(n)

Set hour; recompute seconds past the base date.
Source

set_mday(n)

Set mday; recompute seconds past the base date.
Source

set_min(n)

Set min; recompute seconds past the base date.
Source

set_month(n)

Set month; recompute seconds past the base date.
Source

set_month_truncate(n)

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

set_sec(n)

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

set_seconds(n, zone)

Set seconds and zone field; re-compute broken down fields
Parameters :
n - the seconds past the base point
z - the zone, as a Timezone object, or &null, in which chase the system timezone is used.
Source

set_year(n)

Set year; recompute seconds past the base date.
Source

set_zone(z)

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

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.
Source

to_clock()

Convert to icon &clock format
Source

to_date()

Private method, not intended for client invocation

to_date_clock()

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

to_dateline()

Convert to a string in icon &dateline format
Source

to_letter_string()

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

to_rfc822()

Convert to string in accordance with RFC 822.
Source

to_short_string()

Convert to string in format d-MMM-yy
Source

to_string()

Overrides to_string(depth, seen) in lang::Object
Convert to a string
Source

week_day()

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

year_day()

Compute year day. January 1st = 1 etc
Source

Variable detail

hour


mday


min


month


ppos


psub


sec


seconds


year


zone