|
From: | Andreas Fischlin |
Subject: | Re: [Gm2] Re: ISO & SysClock.def ? |
Date: | Mon, 19 Jan 2009 19:50:45 +0100 |
User-agent: | Thunderbird 2.0.0.19 (Macintosh/20081209) |
Implementation typically very platform dependent. :-( Here an implementation that works for Macintosh from P1 Modula-2 (I guess no one is interested in Classic variants, which I could also provide): DEF: ------ DEFINITION MODULE SysClock; (* Facilities for accessing a system clock that records the date and time of day *) CONST maxSecondParts = 0; TYPE Month = [1 .. 12]; Day = [1 .. 31]; Hour = [0 .. 23]; Min = [0 .. 59]; Sec = [0 .. 59]; Fraction = [0 .. maxSecondParts]; UTCDiff = [-780 .. 720]; DateTime = RECORD year: CARDINAL; month: Month; day: Day; hour: Hour; minute: Min; second: Sec; fractions: Fraction; (* parts of a second *) zone: UTCDiff; (* Time zone differential factor which is the number of minutes to add to local time to obtain UTC. *) summerTimeFlag: BOOLEAN; (* Interpretation of flag depends on local usage. *) END; PROCEDURE CanGetClock (): BOOLEAN; (* Returns TRUE if a system clock can be read; FALSE otherwise *) PROCEDURE CanSetClock (): BOOLEAN; (* Returns TRUE if a system clock can be set; FALSE otherwise *) PROCEDURE IsValidDateTime (userData: DateTime): BOOLEAN; (* Returns TRUE if the value of userData represents a valid date and time; FALSE otherwise *) PROCEDURE GetClock (VAR userData: DateTime); (* If possible, assigns system date and time of day to userData *) PROCEDURE SetClock (userData: DateTime); (* If possible, sets the system clock to the values of userData *) END SysClock. MOD: -------- (**************************************** * * * MODULA-2 Library * * ===================== * * * * Macintosh Implementation * * * * Version 8.1 * * * * © 1997-2005 p1 GmbH * * * * The p1 Library is free for * * non-profit use. For-profit * * use and / or distribution of * * the p1 Library requires a * * licence from p1 GmbH. * * * * p1 Gesellschaft für Informatik * * Hogenbergstraße 22 * * D-80686 München * * * ****************************************) IMPLEMENTATION MODULE SysClock; (* Access to system date and time of day clock *) FROM BasicTime IMPORT TimeRec, TimeRecPtr, time, localtime; FROM SYSTEM IMPORT INT32, ADR; PROCEDURE CanGetClock (): BOOLEAN; (* Tests if a clock can be read *) BEGIN RETURN TRUE; END CanGetClock; PROCEDURE CanSetClock (): BOOLEAN; (* Tests if a clock can be set *) BEGIN RETURN FALSE; (*8.0*) END CanSetClock; PROCEDURE IsValidDateTime (userData: DateTime): BOOLEAN; (* Tests if the value of userData is a valid date and time representation *) PROCEDURE LeapYear (year: CARDINAL): BOOLEAN; BEGIN RETURN (year MOD 4 = 0) AND (year MOD 400 <> 0) END LeapYear; BEGIN WITH userData DO RETURN (day <> 0) AND ( (month IN BITSET {1, 3, 5, 7, 8, 10, 12}) AND (day <= 31) OR (month IN BITSET {4, 6, 9, 11}) AND (day <= 30) OR (month =2) AND NOT LeapYear (year) AND (day <= 28) OR (month =2) AND LeapYear (year) AND (day <= 29) ); END(*WITH*); END IsValidDateTime; PROCEDURE GetClock (VAR userData: DateTime); (* Assigns local date and time of day to userData *) VAR sysTime: TimeRecPtr; t: INT32; BEGIN t := time (NIL); sysTime := localtime (ADR (t)); WITH sysTime^ DO userData := DateTime {tm_year + 1900, tm_mon + 1, tm_mday, tm_hour, tm_min, tm_sec, 0, tm_gmtoff / 60, tm_isdst <> 0}; END(*WITH*); END GetClock; PROCEDURE SetClock (userData: DateTime); (* Sets the system clock to the given local date and time *) (* * VAR * sysTime: DateTimeRec; * BEGIN * WITH userData DO * IF IsValidDateTime (userData) AND * (hour <= 23) AND (minute <= 59) AND (second <= 59) * THEN * sysTime := DateTimeRec {year, month, day, hour, minute, second, 0}; * SetTime (sysTime); * END(*IF*); * END(*WITH*); *) END SetClock; END SysClock. Regards, Andreas Gaius Mulley wrote: Iztok Kobal <address@hidden> writes:Contents of SysClock.def reveals that something is really wrong: ...snip... CONST maxSecondParts = <implementation-defined integral value>; ...snap... What to do ?Hi Iztok, ahh yes this module has not been implemented yet. Currently the completed iso modules are: ChanConsts CharClass ClientSocket ConvTypes EXCEPTIONS IOChan IOConsts IOLink M2EXCEPTION M2RTS ProgramArgs RawIO RealConv RealMath RndFile RTdata RTentity RTfio RTgen RTgenif RTio SimpleCipher SeqFile StdChans Storage StreamFile Strings STextIO SYSTEM TERMINATION TextIO WholeConv WholeIO WholeStr. There is a known problem with REAL input/output at present - which I'm working on. The list of finished iso modules is held in gm2/gm2-libs-iso/README.texi regards, Gaius _______________________________________________ gm2 mailing list address@hidden http://lists.nongnu.org/mailman/listinfo/gm2 --
________________________________________________________________________ ETH Zurich Prof. Dr. Andreas Fischlin Systems Ecology - Institute of Integrative Biology CHN E 21.1 Universitaetstrasse 16 8092 Zurich SWITZERLAND address@hidden www.sysecol.ethz.ch +41 44 633-6090 phone +41 44 633-1136 fax Make it as simple as possible, but distrust it! ________________________________________________________________________ |
andreas_fischlin.vcf
Description: Vcard
[Prev in Thread] | Current Thread | [Next in Thread] |