UXTimeImpl.mesa
Copyright Ó 1989, 1991 by Xerox Corporation. All rights reserved.
Bill Jackson (bj) June 18, 1989 6:03:49 pm PDT
DIRECTORY
BasicTime USING [ GMT, Now ],
UXTime USING [ UXTIME ];
UXTimeImpl: CEDAR PROGRAM
IMPORTS BasicTime
EXPORTS UXTime ~ {
OPEN UXTime;
OutOfRange: PUBLIC ERROR ~ CODE;
TimeNotKnown: PUBLIC ERROR ~ CODE;
Concrete Representation Operations
DOWN: PUBLIC PROC [ time: UXTIME ] RETURNS [ secs: CARD32 ] ~ {
secs ¬ LOOPHOLE[time];
};
UP: PUBLIC PROC [ secs: CARD32 ] RETURNS [ time: UXTIME ] ~ {
time ¬ LOOPHOLE[secs];
};
Now: PUBLIC PROC RETURNS [ time: UXTIME ] ~ {
now: BasicTime.GMT ~ BasicTime.Now[];
time ¬ FromGMT[now];
};
Period: PUBLIC PROC [ from, to: UXTIME ] RETURNS [ delta: INT32 ] ~ {
delta ¬ DOWN[from] - DOWN[to];
};
Update: PUBLIC PROC [ base: UXTIME, period: INT32 ] RETURNS [ time: UXTIME ] ~ {
time ¬ UP[DOWN[base] + period];
};
GMT details
gmtBaseYear: NAT ~ 1968; -- really should come from BasicTime, but it's not exported
gmtCorrection: CARD32 ~ 63158400;
( ((unixBaseYear-gmtBaseYear)*365+1) * 24*60*60 ); - 1968 was a leap year
GMTDOWN: PUBLIC PROC [ gmt: BasicTime.GMT ] RETURNS [ secs: CARD32 ] ~ {
secs ¬ LOOPHOLE[gmt];
};
GMTUP: PUBLIC PROC [ secs: CARD32 ] RETURNS [ gmt: BasicTime.GMT ] ~ {
gmt ¬ LOOPHOLE[secs];
};
ToGMT: PUBLIC PROC [ time: UXTIME ] RETURNS [ gmt: BasicTime.GMT ] ~ {
gmt ¬ GMTUP[DOWN[time] + gmtCorrection];
};
FromGMT: PUBLIC PROC [ gmt: BasicTime.GMT ] RETURNS [ time: UXTIME ] ~ {
time ¬ UP[GMTDOWN[gmt] - gmtCorrection];
};
}.