8.25. File tom/Date

class tom.Date

The Date class implements absolute times using doubles to represent the number of seconds passed since a certain reference date. Internally the time at which the Date class was initialized is used as reference. As absolute reference the first instant of January 1, 2001 is used. All gregorian calculation functions use an absolute date which is the number of days since the Gregorian date December 31, 1 BC.

inherits

State supers: State

variables

const EPSILON = 1e-06;

For two dates to be considered equal they should be no further apart than EPSILON.

const OFFSET_DISTANT_FUTURE = 1e+100;

const OFFSET_DISTANT_PAST = -OFFSET_DISTANT_FUTURE;

const SECONDS_PER_DAY = 86400.0;

const ABSOLUTE_REFDATE = 730486;

The number of days from the imaginary Gregorian date Sunday, 31 december 1 BC to our reference date (January 1 2001).

static public double relative_offset;

Some offset from the reference date relative to which all Date instances maintain their notion of time. This is set in load, ensuring a high accuracy of dates near the moment in time during which this program is running.

static public Date distant_future;

A date in the very far future and a date in the very far past.

static public Date distant_past;

methods


double (now)
  relativeTimeIntervalSinceNow
post
  now > 0.0;

Return the number of seconds after relative_offset it is now.


double
  timeIntervalSinceReferenceDate;

Return the number of seconds after the absolute reference date it is now. This number is negative for dates before the first instant of January 1, 2001.


(int, double)
  absoluteAndSecondsOfTimeInterval double ti;

Return the absolute date and the seconds passed in that day for a time interval since the reference date.


int
  absoluteFromGregorian (int, int, int) (year, month, day);

The number of days elapsed between the Gregorian date 12/31/1 BC and (year, month, day). The Gregorian date Sunday, December 31, 1 BC is imaginary.


int
  absoluteFromIso (int, int, int) (year, week, day);

The number of days elapsed between the Gregorian date 1 BC December 31 and DATE. The `ISO year' corresponds approximately to the Gregorian year, but weeks start on Monday and end on Sunday. The first week of the ISO year is the first such week in which at least 4 days are in a year. The ISO commercial DATE has the form (year, week, day) in which week is in the range 1..52 and day is in the range 0..6 (1 == Monday, 2 == Tuesday, ..., 0 == Sunday). The Gregorian date Sunday, December 31, 1 BC is imaginary.


int
  dayNameOnOrBefore (int, int) (day_name, absolute);

Returns the absolute date of the day_name on or before absolute. day_name==0 means Sunday, day_name==1 means Monday, and so on.

Note: Applying this function to absolute+6 gives us the day_name on or after an absolute day d. Similarly, applying it to absolute+3 gives the day_name nearest to absolute, applying it to absolute-1 gives the day_name previous to absolute, and applying it to absolute+7 gives the day_name following absolute.


int
  dayNumber (int, int, int) (year, month, day);

Return the day number within the year of the date (year, month, day). For example, dayNumber (1, 1, 1987) returns the value 1, while dayNumber (12, 31, 1980) returns 366.


int
  dayOfWeekOfAbsolute int absolute;

Return the Gregorian day of the week for absolute where 0==Sunday, 1==Monday, ..., 6==Saturday.


(int, int, int)
  gregorianFromAbsolute int date;

Compute the list (month, day, year) corresponding to the absolute DATE. The absolute date is the number of days elapsed since the (imaginary) Gregorian date Sunday, December 31, 1 BC.


boolean
  isLeapYear int year;

Return TRUE iff year is a Gregorian leap year.


(int, int, int)
  isoFromAbsolute int absolute;

Compute the `ISO commercial date' corresponding to the absolute. The ISO year corresponds approximately to the Gregorian year, but weeks start on Monday and end on Sunday. The first week of the ISO year is the first such week in which at least 4 days are in a year. The ISO commercial date has the form (year week day) in which week is in the range 1..52 and day is in the range 0..6 (1 = Monday, 2 = Tuesday, ..., 0 = Sunday). The absolute date is the number of days elapsed since the (imaginary) Gregorian date Sunday, December 31, 1 BC.


int
  lastDayOfMonth int month
            year int year;

Return the last day of the month month of the year year.


void
  load MutableArray arguments;

Perform class initialization.


Date
  now;

Return a date instance representing this moment.


protected double
  relativeTimeIntervalOfAbsoluteAndSeconds (int, double) (absolute, seconds);

Return the absolute date and the seconds passed in that day for a time interval since the reference date.


double
  timeIntervalOfAbsoluteAndSeconds (int, double) (absolute, seconds);

Return the absolute date and the seconds passed in that day for a time interval since the reference date.

instance tom.Date

variables

double relative_ti;

methods


int
  compare id other;

Returns -1 if the receiver is earlier than other 0 if the difference is smaller that EPSILON and 1 if the receiver is after other.


id
  dateWithOffset double ti;

Return a new instance initialized at ti seconds after the receiver.


Date
  earlierDate Date other;

Return other if it is earlier than the receiver, return the receiver otherwise.


boolean
  equals id d;

Return TRUE iff the receiver is within EPSILON seconds of d.


protected id
  init double d;

Designated initializer.


id
  init;

Initialize with the current time.


id
  initWithTimeIntervalSinceNow double ti;

Initialize with ti seconds after the current time.


id
  initWithTimeIntervalSinceReferenceDate double ti;

Initialize with ti seconds after the absolute reference date January 1, 2001.


Date
  laterDate Date other;

Return other iff it is later than the receiver, return the receiver otherwise.


protected double
  relativeTimeInterval;

Return the number of seconds after relative_offset


double
  timeIntervalSinceDate Date d;

Return the number of seconds passed since d. This number is negative if the receiver is earlier than d.


double
  timeIntervalSinceNow;

Return the number of seconds passed since now. This number is negative for dates before now.


double
  timeIntervalSinceReferenceDate;

Return the number of seconds passed since the absolute reference date. This number is negative for all dates before the first instant of January 1 2001.


OutputStream
  write OutputStream s;

Print this date in a human readable format, relative to GMT.


void
  encodeUsingCoder Encoder coder;

Undocumented.


void
  initWithCoder Decoder coder;

Undocumented.