Day of the week: Difference between revisions

(Modula-3 (and I finally remembered to log in :)))
Line 298:
 
=={{header|Modula-3}}==
{{trans|FortranC}}
 
Modula-3 represents time using a (safe) wrapper around the C time interface.
Consequently, it suffers from the same problem as C.
 
<pre>
MODULE Yule EXPORTS Main;
 
IMPORT IO, Fmt, Date, Time;
 
VAR date: Date.T;
PROCEDURE DayOfWeek(d, m, y: INTEGER): INTEGER =
VAR j time:= y DIV 100Time.T;
k := y MOD 100;
BEGIN
RETURN (d + (m + 1) * 26 DIV 10 + k + k DIV 4 + j DIV 4 + 5 * j) MOD 7;
END DayOfWeek;
 
BEGIN
IO.Put("25th of December is a Sunday in ");
FOR year := 2008 TO 2121 DO
date.day := 25;
IF DayOfWeek(25, 12, year) = 1 THEN
date.month := Date.Month.Dec;
IO.Put(Fmt.Int(year) & " ");
date.year := year;
 
TRY
time := Date.ToTime(date);
EXCEPT
| Date.Error =>
IO.Put(Fmt.Int(year) & " is the last year we can specify\n");
EXIT;
END;
 
date := Date.FromTime(time);
 
IF date.weekDay = Date.WeekDay.Sun THEN
IO.Put("25th of December " & Fmt.Int(year) & " is Sunday\n");
END;
END;
IO.Put("\n");
END Yule.
</pre>
Line 324 ⟶ 336:
Output:
<pre>
25th of December 2011 is a Sunday in 2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118
IO.Put("25th of December 2016 is a Sunday in ");
25th of December 2022 is Sunday
25th of December 2033 is Sunday
2038 is the last year we can specify
</pre>
 
Anonymous user