Prestupna sekunda (Drive: Prestupny rok)
Alexandr Malusek
malusek na hroch.ujf.cas.cz
Středa Únor 25 16:41:34 CET 1998
mj na atrey.karlin.mff.cuni.cz (Martin Mares) writes:
> > Pokud vim, tak Unixove OS na tyto sekundove posuny neberou ohled.
>
> Jestli mne ma pamet neklame, alespon GNU libc na ne ohled bere
> (ve zdrojacich je kompletni tabulka vsech historickych prestupnych
> sekund, ktera se pri gmtime() a spol. pouziva).
Skutecne to tam je, ale zatim mi neni jasne, do jake miry se to
vyuziva. Mimo jine je v souboru mktime.c napsano:
Posix.1 prohibits leap seconds, but some hosts have them anyway.
Prestupna sekunda byla napr. v roce 1995:
(Prevzato z http://www.ast.cam.ac.uk/RGO/leaflets/special/leap.html)
The successive times each second at the end of 1995 were
1995 December 31 23h 59m 59s
1995 December 31 23h 59m 60s
1996 January 1 00h 00m 00s
Ze zajmu jsem si spustil nasledujici program:
#include <stdio.h>
#include <time.h>
struct tm tm1 = {59, 59, 23, 31, 11, 95, 0, 364, 0};
struct tm tm2 = { 1, 0, 0, 1, 0, 96, 1, 0, 0};
int
main()
{
printf("1. cas = %s", asctime(&tm1));
printf("2. cas = %s", asctime(&tm2));
printf("Rozdil = %e s\n\n", difftime(mktime(&tm2), mktime(&tm1)));
return 0;
}
Ten vypsal:
1. cas = Sun Dec 31 23:59:59 1995
2. cas = Mon Jan 1 00:00:01 1996
Rozdil = 2.000000e+00 s
Pokud by system pracoval s prestupnymi sekundami, pak by tento
rozdil mel byt 3s, nikoliv 2s. Spoustel jsem to na RH4.2, RH5.0 a
Solarisu 2.5.1 vsude se stejnym vysledkem.
--
A. Malusek (malusek na ujf.cas.cz)
UJF AV CR
Další informace o konferenci Linux