Day of the week: Difference between revisions

From Rosetta Code
Content added Content deleted
m (#See_also)
(UNIX Shell)
Line 5: Line 5:


Using any standard date handling libraries of your programming language; compare the dates calculated with the output of other languages to discover any anomalies in the handling of dates which may be due to, for example, overflow in types used to represent dates/times similar to [[http://en.wikipedia.org/wiki/Y2k#See_also y2k]] problems.
Using any standard date handling libraries of your programming language; compare the dates calculated with the output of other languages to discover any anomalies in the handling of dates which may be due to, for example, overflow in types used to represent dates/times similar to [[http://en.wikipedia.org/wiki/Y2k#See_also y2k]] problems.


=={{header|UNIX Shell}}==

{{works with|bash}}

<pre>#! /bin/bash

for((i=2009; i <= 2099; i++))
do
date -d "$i-12-25" |egrep Sun
done

exit 0
</pre>

The first lines of output are

<pre>
Sun Dec 25 00:00:00 CET 2011
Sun Dec 25 00:00:00 CET 2016
Sun Dec 25 00:00:00 CET 2022
Sun Dec 25 00:00:00 CET 2033
date: invalid date `2038-12-25'
</pre>

I.e., starting from year 2038, the <tt>date</tt> command (which uses the glibc library, at least on GNU systems), is not able to recognise the date as a valid one!

Revision as of 14:29, 12 December 2008

Task
Day of the week
You are encouraged to solve this task according to the task description, using any language you may know.

A company decides that whenever Xmas falls on a Sunday that they will give their workers all extra paid holidays so that, together with any public holidays, workers will not have to work the following week (between the 25th of December and the first of January).

In what years between 2008 and 2099 will the 25th of December be a Sunday?

Using any standard date handling libraries of your programming language; compare the dates calculated with the output of other languages to discover any anomalies in the handling of dates which may be due to, for example, overflow in types used to represent dates/times similar to [y2k] problems.


UNIX Shell

Works with: bash
#! /bin/bash

for((i=2009; i <= 2099; i++))
do
 date -d "$i-12-25" |egrep Sun
done

exit 0

The first lines of output are

Sun Dec 25 00:00:00 CET 2011
Sun Dec 25 00:00:00 CET 2016
Sun Dec 25 00:00:00 CET 2022
Sun Dec 25 00:00:00 CET 2033
date: invalid date `2038-12-25'

I.e., starting from year 2038, the date command (which uses the glibc library, at least on GNU systems), is not able to recognise the date as a valid one!