Linux "date" command ignores leap-seconds?
Walter Dnes
waltdnes-SLHPyeZ9y/tg9hUCZPvPmw at public.gmane.org
Thu Jan 17 02:42:22 UTC 2013
On Wed, Jan 16, 2013 at 02:59:08PM -0500, D. Hugh Redelmeier wrote
> Clearly all leap years before the Epoch don't count, but ones after do.
> Years that are multiples of 4 are leap years (UNLESS they are multiples
> of 100 (UNLESS they are multiples of 400)). A leap year delays the
> start of subsequent years by one day.
> 1969 is the year after the last multiple of 4 before the epoch.
> 1901 is the year after the last multiple of 100 before the epoch.
> 1601 is the year after the last multiple of 400 before the epoch
My quick-n-dirty leap-year algorithm uses bash integer division.
Here's pseudocode
* LEAPYR = FALSE
* if ( YYYY mod 100 = 0 ) then YYYY = ( YYYY / 100 )
* if ( YYYY mod 4 = 0 ) then LEAPYR = TRUE
Note that the 2nd line converts 1700 to 17, 1800 to 18, 1900 to 19,
and 2000 to 20. Then it is safe to blindly prceed with the test for
whole-number-multiple-of-4.
Here's bash code...
zyear=${xyear}
scratch=$(( ${xyear} / 100 ))
if [ $(( ${scratch} * 100 )) -eq ${zyear} ]; then
zyear=${scratch}
fi
leap_year=0
scratch=$(( ${zyear} / 4 ))
if [ $(( ${scratch} * 4 )) -eq ${zyear} ]; then
leap_year=1
fi
--
Walter Dnes <waltdnes-SLHPyeZ9y/tg9hUCZPvPmw at public.gmane.org>
I don't run "desktop environments"; I run useful applications
--
The Toronto Linux Users Group. Meetings: http://gtalug.org/
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://gtalug.org/wiki/Mailing_lists
More information about the Legacy
mailing list