Day of the week

From Rosetta Code
Revision as of 14:29, 12 December 2008 by rosettacode>ShinTakezou (UNIX Shell)
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!