Accessing Time Data
Developing TACL Programs
2–22
107365 Tandem Computers Incorporated
Computing the Day of the Week
Use the macro in Figure 2-9,
dayofweek
, to calculate the day of the week, as follows:
16> dayofweek
Tuesday
17>
Figure 2-9. Computing the Current Day
?SECTION dayofweek MACRO
== Calculates the day of the week from the three word
== TIMESTAMP, which starts at 00:00 31 December 1974
== (a Wednesday).
#FRAME
[#PUSH
day^of^week
elapsed^days
elapsed^weeks
]
== There are 8640000 hundredths of a second in a day.
== Determine how many days have elapsed since
== midnight, December 31st, 1974 (starting timestamp).
#SET elapsed^days [#COMPUTE [#TIMESTAMP]/8640000]
== Determine how many whole weeks have elapsed.
#SET elapsed^weeks [#COMPUTE [elapsed^days]/7]
== The day of the week is the total elapsed days minus the
== number of days in the elapsed whole weeks.
#SET day^of^week [#COMPUTE [elapsed^days] -
([elapsed^weeks]*7)]
== Output the day
[#CASE [day^of^week]
|0| #OUTPUT Tuesday
|1| #OUTPUT Wednesday
|2| #OUTPUT Thursday
|3| #OUTPUT Friday
|4| #OUTPUT Saturday
|5| #OUTPUT Sunday
|6| #OUTPUT Monday
|OTHERWISE|
#OUTPUT Error: Day of week must be 0-6 inclusive
]
#UNFRAME