Modula-2 Reloaded

A Modern Typesafe & Literate Programming Notation

Site Menu

Project

Specification

Implementation

Recommendations

Reference

Needs Updating

Work in Progress

Wastebasket

Wiki Manual

edit SideBar

Spec TZ

TZ

DEFINITION MODULE TZ [ZTYPE];

(* Time Zone Offsets *)


FROM FileIO IMPORT File; (* required for IO *)


(* TZ type *)

TYPE
    TZ = OPAQUE RECORD
        value : OCTET; (* 8 bits *)
    END; (* TZ *)


CONST interval = 15;
(* All TZ values must be divisible by 15. *)

CONST [TMIN] minValue = -720;
(* Smallest value of type TZ.
   This value is bound to TMIN for type TZ. *) 

CONST [TMAX] maxValue = 720;
(* Largest value of type TZ.
   This value is bound to TMAX for type TZ. *) 


(* Literal assignment *)

PROCEDURE [:=] assign ( VAR assignTo : TZ; literal : ARRAY OF CHAR );
(* Converts string literal to a TZ value and assigns it to assignTo.
   This procedure is bound to the := operator for literal assignment. *)


(* Type conversions *)

PROCEDURE [::] toCARD  ( n : TZ ) : CARDINAL;
(* Converts TZ value n to a CARDINAL value and returns it. This
   function is bound to the :: operator for TZ to CARDINAL conversion. *)

PROCEDURE [::] toINT ( n : TZ ) : INTEGER; 
(* Converts TZ value n to an INTEGER value and returns it. This
   function is bound to the :: operator for TZ to INTEGER conversion. *)

PROCEDURE [::] fromCARD  ( n : CARDINAL ) : TZ;
(* Converts CARDINAL value n to a TZ value and returns it. This function
   is bound to the :: operator for CARDINAL to TZ conversion. *)

PROCEDURE [::] fromINT  ( n : INTEGER ) : TZ;
(* Converts INTEGER value n to a TZ value and returns it. This function
   is bound to the :: operator for INTEGER to TZ conversion. *)


(* Monadic arithmetic operations *) 

PROCEDURE [ABS] abs ( n : TZ ) : TZ;
(* Returns the absolute value of TZ value n.
   This function is bound to pervasive function ABS for type TZ. *)

PROCEDURE [NEG] neg ( n : TZ ) : TZ;
(* Returns the sign reversed value of TZ value n.
   This function is bound to the unary minus operator for type TZ. *)

PROCEDURE [ODD] odd ( n : TZ ) : BOOLEAN;
(* Returns TRUE if TZ value n is odd, otherwise FALSE.
   This function is bound to pervasive function ODD for type TZ. *)


(* Dyadic arithmetic operations *) 

PROCEDURE [+] add ( n1, n2 : TZ ) : TZ;
(* Adds TZ values n1 and n2 and returns the result.
   This function is bound to the + operator for type TZ. *)

PROCEDURE [-] sub ( n1, n2 : TZ ) : TZ;
(* Subtracts TZ value n2 from n1 and returns the result.
   This function is bound to the - operator for type TZ. *)


(* Relational operations *) 

PROCEDURE [=] isEqual ( n1, n2 : TZ ) : BOOLEAN;
(* Returns TRUE if TZ values n1 and n2 are equal, otherwise FALSE.
   This function is bound to operators = and # for type TZ. *)

PROCEDURE [<] isLess ( n1, n2 : TZ ) : BOOLEAN;
(* Returns TRUE if TZ value n1 is less than n2, otherwise FASLE.
   This function is bound to operators < and >= for type TZ. *)

PROCEDURE [>] isGreater ( n1, n2 : TZ ) : BOOLEAN;
(* Returns TRUE if TZ value n1 is greater than n2, otherwise FALSE.
   This function is bound to operators > and <= for type TZ. *)


(* Scalar conversion primitives *)

CONST digitCapacity = 3; (* maximum digits in native format *)

PROCEDURE [TO] toSXF ( n : TZ; VAR s : ARRAY OF CHAR );
(* Converts TZ value n to a string in scalar exchange format.
   This procedure is used to synthesise conversions to other scalar types
   when no direct conversion path exists. *)

PROCEDURE [FROM] fromSXF ( VAR n : TZ; CONST s : ARRAY OF CHAR );
(* Converts a string in scalar exchange format to a TZ value.
   This procedure is used to synthesise conversions from other scalar types
   when no direct conversion path exists. *)


(* Common Time Zone Identifiers *)

CONST
    UTC  = 0;      (* Universal Time Coordinated, UTC *)
    GMT  = 0;      (* Greenwich Mean Time, UTC+0000 *)
    WET  = 0;      (* Western European Time, UTC+0000 *)

    CET  = 60;     (* Central European Time, UTC+0100 *)
    MET  = 60;     (* Middle European Time, UTC+0100 *)
    WAT  = 60;     (* West African Time, UTC+0100 *)
    EET  = 120;    (* Eastern European Time, UTC+0200 *)
    USZ1 = 120;    (* Russia Zone 1 Time, UTC+0200 *)
    CAT  = 120;    (* Central African Time, UTC+0200 *)
    SAST = 120;    (* South African Standard Time, UTC+0200 *)
    TST  = 180;    (* Turkish Standard Time, UTC+0300 *)
    AST  = 180;    (* Arabian Standard Time, UTC+0300 *)
    EAT  = 180;    (* East African Time, UTC+0300 *)
    MSK  = 180;    (* Moscow Time, UTC+0300 *)
    USZ2 = 180;    (* Russia Zone 2 Time, UTC+0300 *)
    IRT  = 210;    (* Iran Time, UTC+0330 *)
    USZ3 = 240;    (* Russia Zone 3 Time, UTC+0400 *)
    AZT  = 240;    (* Azerbaijan Time, UTC+0400 *)
    RET  = 240;    (* Reunion Time, UTC+0400 *)
    MUT  = 240;    (* Mauritius Time, UTC+0400 *)
    AFT  = 270;    (* Afghanistan Time, UTC+0430 *)
    USZ4 = 300;    (* Russia Zone 4 Time, UTC+0500 *)
    KGT  = 300;    (* Kyrgyzstan Time, UTC+0500 *)
    TMT  = 300;    (* Turkmenistan Time, UTC+0500 *)
    TJT  = 300;    (* Tajikistan Time, UTC+0500 *)
    UZT  = 300;    (* Uzbekistan Time, UTC+0500 *)
    PKT  = 300;    (* Pakistan Time, UTC+0500 *)
    MVT  = 300;    (* Maldives Time, UTC+0500 *)
    IST  = 330;    (* Indian Standard Time, UTC+0530 *)
    NPT  = 345;    (* Nepal Time, UTC+0545 *)
    LKT  = 360;    (* Lanka Time, UTC+0600 *)
    BTT  = 360;    (* Bhutan Time, UTC+0600 *)
    BDT  = 360;    (* Bangladesh Time, UTC+0600 *)
    USZ5 = 360;    (* Russia Zone 5 Time, UTC+0600 *)
    NSUT = 390;    (* North Sumatra Time, UTC+0630 *)
    MMT  = 390;    (* Myanmar/Burma Time, UTC+0630 *)
    USZ6 = 420;    (* Russia Zone 6 Time, UTC+0700 *)
    THA  = 420;    (* Thailand Standard Time, UTC+0700 *)
    ICT  = 420;    (* Indochina Time, UTC+0700 *)
    JAVT = 420;    (* Java Time, UTC+0700 *)
    MYT  = 480;    (* Malaysia Time, UTC+0800 *)
    SGT  = 480;    (* Singapore Time, UTC+0800 *)
    BNT  = 480;    (* Brunei Time, UTC+0800 *)
    CCT  = 480;    (* China Coastal Time, UTC+0800 *)
    HKT  = 480;    (* Hong Kong Time, UTC+0800 *)
    PHT  = 480;    (* Philippine Time, UTC+0800 *)
    USZ7 = 480;    (* Russia Zone 7 Time, UTC+0800 *)
    ULAT = 480;    (* Ulaan Bataar Time *)
    WST  = 480;    (* Australian Western Standard Time, UTC+0800 *)
    USZ8 = 540;    (* Russia Zone 8 Time, UTC+0900 *)
    KST  = 540;    (* Korean Standard Time, UTC+0900 *)
    JST  = 540;    (* Japanese Standard Time, UTC+0900 *)
    ACST = 570;    (* Australian Central Standard Time, UTC+0930 *)
    PGT  = 600;    (* Papua New Guinea Time, UTC+1000 *)
    USZ9 = 600;    (* Russia Zone 9 Time, UTC+1000 *)
    AEST = 600;    (* Australian Eastern Standard Time, UTC+1000 *)
    UZ10 = 660;    (* Russia Zone 10 Time, UTC+1100 *)
    NCT  = 660;    (* New Caledonia Time, UTC+1100 *)
    VUT  = 660;    (* Vanuatu Time, UTC+1100 *)
    FJT  = 720;    (* Fiji Time, UTC+1200 *)
    TVT  = 720;    (* Tuvalu Time, UTC+1200 *)
    NZT  = 720;    (* New Zealand Time, UTC+1200 *)
    NZST = 720;    (* New Zealand Standard Time, UTC+1200 *)
    IDLE = 720;    (* International Date Line East, UTC+1200 *)

    AZOT = -60;    (* Azores Time, UTC-0100 *)
    CVT  = -60;    (* Cape Verde Time, UTC-0100 *)
    VTZ  = -120;   (* Greenland Eastern Standard Time, UTC-0200 *)
    BRA  = -180;   (* Brazil Standard Time, UTC-0300 *)
    ART  = -180;   (* Argentina Time, UTC-0300 *)
    UYT  = -180;   (* Uruguay Time, UTC-0300 *)
    SRT  = -180;   (* Suriname Time, UTC-0300 *)
    GFT  = -180;   (* French Guyana Time, UTC-0300 *)
    UTZ  = -180;   (* Greenland Western Standard Time, UTC-0300 *)
    CLT  = -240;   (* Chile Time, UTC-0400 *)
    BOT  = -240;   (* Bolivia Time, UTC-0400 *)
    GYT  = -240;   (* Guyana Time, UTC-0400 *)
    PYT  = -240;   (* Paraguay Time, UTC-0400 *)
    FKT  = -240;   (* Falkland Island Time, UTC-0400 *)
    EST  = -300;   (* US Eastern Standard Time, UTC-0500 *)
    COT  = -300;   (* Colombia Time, UTC-0500 *)
    PET  = -300;   (* Peru Time, UTC-0500 *)
    CST  = -360;   (* US Central Standard Time, UTC-0600 *)
    MEX  = -360;   (* Mexico Time, UTC-0600 *)
    MST  = -420;   (* US Mountain Standard Time, UTC-0700 *)
    PST  = -480;   (* US Pacific Standard Time, UTC-0800 *)
    AKST = -540;   (* US Alaska Standard Time, UTC-0900 *)
    YST  = -540;   (* US Yukon Standard Time, UTC-0900 *)
    HST  = -600;   (* US Hawaiian Standard Time, UTC-1000 *)
    HAST = -600;   (* US Hawaii-Aleutian Standard Time, UTC-1000 *)
    THAT = -600;   (* Thahiti Time, UTC-1000 *)
    BET  = -660;   (* Bering Standard Time, UTC-1100 *)
    IDLW = -720;   (* International Date Line West, UTC-1200 *)


(* IO operations *)

PROCEDURE Read( infile : File; VAR n : TZ );
(* Reads the textual representation of a TZ value from stream infile
   - any leading whitespace is skipped
   - any remaining characters that are part of the numeral being read are
     removed from infile
   - the numeric value of the numeral string read is assigned to the variable
     passed in for n
   - the file status is set to any of:
     success, outOfRange, wrongFormat, endOfLine, or endOfInput. This
   procedure is substituted for invocations of READ with a TZ argument. *)

PROCEDURE Write( outfile : File; n : TZ );
(* Writes the textual representation of value n to stream outfile. This
   procedure is substituted for invocations of WRITE with a TZ argument.*)

PROCEDURE WriteF ( outfile      : File;
                   CONST fmtStr : ARRAY OF CHAR;
                   items        : VARIADIC OF TZ );
(* Writes a formatted textual representation of one or more TZ values to
   output stream outfile. The output format is determined by fmtStr. This
   procedure is substituted for invocations of WRITEF with one or more
   TZ arguments. *)

END TZ.