-- DMSTime.Mesa
-- edited by Brotz, March 3, 1983 4:42 PM
-- edited by Levin, May 9, 1980 4:49 PM
DIRECTORY
Ascii USING [SP],
DMSTimeDefs USING [PackedTime, TimeFormat, UnpackedTime],
Inline USING [DIVMOD],
String USING [AppendChar, AppendString, AppendSubString, SubStringDescriptor],
TimeDefs USING [PackedTime, UnpackDT];
DMSTime: PROGRAM
IMPORTS Inline, String, TimeDefs
EXPORTS DMSTimeDefs =
BEGIN
OPEN DMSTimeDefs, String;
MapPackedTimeToTimeZoneString: PUBLIC PROCEDURE [pt: PackedTime, s: STRING,
format: TimeFormat ← timeHouse] =
BEGIN
upt: UnpackedTime = TimeDefs.UnpackDT[pt.lc];
dayNames: ARRAY [0 .. 7) OF STRING = ["Monday"L, "Tuesday"L, "Wednesday"L,
"Thursday"L, "Friday"L, "Saturday"L, "Sunday"L];
monthNames: ARRAY [0 .. 12) OF STRING = ["Jan."L, "Feb."L, "March"L, "April"L, "May"L,
"June"L, "July"L, "Aug."L, "Sept."L, "Oct."L, "Nov."L, "Dec."L];
AppendTwoDigitNumber: PROCEDURE [v: CARDINAL, suppressZeros: BOOLEAN] =
BEGIN
d1, d2: CARDINAL;
[d1, d2] ← Inline.DIVMOD[v, 10];
IF d1 ~= 0 OR ~suppressZeros THEN AppendChar[s, d1 + ’0];
AppendChar[s, d2 + ’0];
END; -- of AppendTwoDigitNumber --
AppendYear: PROCEDURE [useCentury: BOOLEAN] =
BEGIN
century, year: CARDINAL;
AppendChar[s, Ascii.SP];
[century, year] ← Inline.DIVMOD[upt.year, 100];
IF useCentury THEN AppendTwoDigitNumber[century, FALSE];
AppendTwoDigitNumber[year, FALSE];
END; -- of AppendYear --
AppendHumanTime: PROCEDURE =
BEGIN
aOrP: CHARACTER ← ’a;
AppendChar[s, Ascii.SP];
SELECT upt.hour FROM
< 1 => AppendTwoDigitNumber[12, TRUE];
< 12 => AppendTwoDigitNumber[upt.hour, TRUE];
= 12 => {aOrP ← ’p; AppendTwoDigitNumber[12, TRUE]};
ENDCASE => {aOrP ← ’p; AppendTwoDigitNumber[upt.hour-12, TRUE]};
AppendMinutes[];
AppendChar[s, Ascii.SP];
AppendChar[s, aOrP];
AppendChar[s, ’m];
END; -- of AppendHumanTime --
AppendMinutes: PROCEDURE =
BEGIN
AppendChar[s, ’:];
AppendTwoDigitNumber[upt.minute, FALSE];
END; -- of AppendMinutes --
AppendTimeZone: PROCEDURE =
BEGIN
KnownZones: TYPE = [5 .. 8];
zones: PACKED ARRAY KnownZones OF CHARACTER = [’E, ’C, ’M, ’P];
IF upt.zone IN KnownZones THEN
BEGIN
AppendChar[s, Ascii.SP];
AppendChar[s, zones[upt.zone]];
AppendChar[s, IF upt.dst THEN ’D ELSE ’S];
AppendChar[s, ’T];
END;
END; -- of AppendTimeZone --
s.length ← 0;
SELECT format FROM
timeHouse =>
BEGIN
AppendString[s, dayNames[upt.weekday]]; AppendChar[s, Ascii.SP];
AppendString[s, monthNames[upt.month]]; AppendChar[s, Ascii.SP];
AppendTwoDigitNumber[upt.day, TRUE];
AppendChar[s, ’,];
AppendYear[TRUE];
AppendHumanTime[];
AppendTimeZone[];
END;
-- laurelMsg =>
-- BEGIN
-- AppendTwoDigitNumber[upt.day, TRUE]; AppendChar[s, Ascii.SP];
-- AppendString[s, monthNames[upt.month]];
-- AppendYear[];
-- AppendHumanTime[];
-- AppendTimeZone[];
-- AppendString[s, " ("L]; AppendString[s, dayNames[upt.weekday]]; AppendChar[s, ’)];
-- END;
arpaMsg =>
BEGIN
ssd: SubStringDescriptor;
ssd ← [dayNames[upt.weekday], 0, 3];
AppendSubString[s, @ssd]; AppendChar[s, ’,]; AppendChar[s, Ascii.SP];
AppendTwoDigitNumber[upt.day, TRUE]; AppendChar[s, Ascii.SP];
ssd ← [monthNames[upt.month], 0, 3];
AppendSubString[s, @ssd];
AppendYear[FALSE]; AppendChar[s, Ascii.SP];
AppendTwoDigitNumber[upt.hour, FALSE];
AppendMinutes[];
AppendTimeZone[];
END;
ENDCASE;
END; -- of MapPackedTimeToTimeZoneString --
END. -- of DMSTime --