Oberon || Library || Module Index || Search Engine || Definition || Module


Ulm's Oberon Library:
Timezones


NAME

Timezones - abstraction for time zones

SYNOPSIS

TYPE Name = ARRAY 12 OF CHAR;
TYPE Offset = Scales.Value;
TYPE Timezone = POINTER TO TimezoneRec;
TYPE TimezoneRec =
   RECORD
      (PersistentDisciplines.ObjectRec)
      baseName:   Name;
   END;
TYPE Glimpse = POINTER TO GlimpseRec;
TYPE GlimpseRec =
   RECORD
      (Objects.ObjectRec)
      name:       Name;
      offset:     Offset;
      isDst:      BOOLEAN;
      lastChange,
      nextChange: Times.Time;
   END;
VAR utc: Timezone;
VAR local: Timezone;


TYPE LookupProc = PROCEDURE (tz: Timezone; at: Times.Time; VAR glimpse: GlimpseRec); TYPE Interface = POINTER TO InterfaceRec; TYPE InterfaceRec = RECORD (Objects.ObjectRec) unsteady: BOOLEAN; lookup: LookupProc; stdGlimpse: Glimpse; END; TYPE InitProc = PROCEDURE (tz: Timezone) : Interface; TYPE FindProc = PROCEDURE (name: ARRAY OF CHAR; VAR tz: Timezone; VAR glimpse: GlimpseRec) : BOOLEAN;

PROCEDURE GetOffset(tz: Timezone; at: Times.Time) : Scales.Value; PROCEDURE Unsteady(tz: Timezone) : BOOLEAN; PROCEDURE Lookup(tz: Timezone; at: Times.Time; VAR glimpse: GlimpseRec); PROCEDURE FindOffset(name: ARRAY OF CHAR; VAR offset: Offset) : BOOLEAN; PROCEDURE Find(name: ARRAY OF CHAR; VAR tz: Timezone; VAR glimpse: GlimpseRec) : BOOLEAN;

PROCEDURE Init(tz: Timezone; if: Interface); PROCEDURE DelayInit(tz: Timezone; init: InitProc); PROCEDURE Declare(find: FindProc);

DESCRIPTION

A time zone is a persistent object that can tell how a local time differs from universal time (aka Greenwich mean time). We want to keep time values uniform around the globe; location dependent, however, their interpretation.

Throughout this module, offset values are given in seconds relative to GMT. Timezones can be either steady, in which case each access to them will yield the same result, or unsteady. A look at a time zone at a certain time is called a glimpse.

Unsteady tells if tz is unsteady.

GetOffset returns the offset defined by tz for the given time at, or some basic offset in case at is NIL.

Lookup stores a complete timezone status (glimpse) of tz at a given time at in glimpse. at may be NIL to get a glimpse containing the basic offset. Note that glimpse.lastChange or glimpse.nextChange might be NIL if these times do not exist or can not be determined.

FindOffset searches among the time zones known to the system for a glimpse named name. If such a glimpse could be found, the corresponding offset is stored in offset and TRUE is returned, otherwise FALSE.

FindTimezone searches among the time zones known to the system for a glimpse named name. If such a glimpse and time zone could be found they are stored in tz resp. glimpse and TRUE is returned, otherwise FALSE.

The variable utc contains a time zone representing universal time itself.

local contains a local time zone which is normally defined by the system, to be most likely appropriate at the system's location, but may be reset any time.

New time zones must be initialized either with Init or DelayInit. The interface if must contain either lookup if if.unsteady is TRUE, or stdGlimpse otherwise. stdGlimpse can also be provided in the former case if lookup should not be called with at = NIL. If DelayInit is used, init will be called when tz is first accessed to supply a valid interface. This is intended mostly for the benefit of implementations of default time zones, like local, that might be expensive to initialize, but can guarantee to work, switching to an alternative in case of problems rather than reporting an error during initialization.

Declare arranges for find to be called when time zones are searched for. The last declared function will be called first.

Time zones are persistent. Thus, PersistentObjects.Read and PersistentObjects.Write are valid operations on time zones. If a Read operation causes a projection onto type Timezone to take place (due to foreign modules that can't be loaded), the time zone will be mapped to universal time (utc).

DIAGNOSTICS

Invalid time zone implementations can lead to failed assertions:

SEE ALSO

Dates
date and time conversions
PersistentObjects
abstraction for persistent objects
Times
reference scale for time measurement systems
UnixTimezones
implementation of timezones known by the system

AUTHOR

Martin Hasch, University of Ulm
some minor revisions are due to Andreas Borchert, University of Ulm
Edited by: borchert, last change: 1996/09/16, revision: 1.3, converted to HTML: 1997/04/28

Oberon || Library || Module Index || Search Engine || Definition || Module