att / ast

AST - AT&T Software Technology
Eclipse Public License 1.0
556 stars 152 forks source link

date: wrong timezone for 1970 -> 1971 in British timezone #17

Open stephane-chazelas opened 8 years ago

stephane-chazelas commented 8 years ago

https://en.wikipedia.org/wiki/British_Summer_Time#Periods_of_deviation

Between 27 October 1968 and 31 October 1971, there was no daylight saving time in mainland Britain. It was GMT+1 all year round. On both GNU and Solaris system, the system's strftime/localtime is correct:

$ TZ=Europe/London perl -MPOSIX -le 'print strftime "%F %T %Z %z", localtime 0'
1970-01-01 01:00:00 BST +0100

(BST being then British Standard Time, not Summer this time).

But ksh93's "printf %T" or the ast date utility seem to get it wrong:

$ ksh93 -c 'printf "%(%F %T %Z %z)T\n" "#0"'
1970-01-01 00:00:00 GMT -0000

(ksh93u on Solaris 10)

$ arch/linux.i386-64/bin/date -d "#0"
Thu Jan  1 00:00:00 GMT 1970

(from the beta branch on Debian).

krader1961 commented 6 years ago

This issue is the poster child for why ksh93 should use the equivalent OS provided functionality rather than that of the AST libraries. There will never be enough people who care about AST locale and timezone functions to fix bugs like this in a timely manner. If we want ksh93 to remain relevant we must update it to rely more on the functionality provided by the OS. Possibly providing fallback implementations when necessary but with the understanding that those fallback functions will always be best effort and likely to have shortcomings. Basic features like support for timezones and locales should not be the responsibility of this project.

krader1961 commented 6 years ago

This is a reminder that we need to remove the ksh dependency on the AST time code. We've managed to remove the dependency on the AST vmalloc and AST locale subsystems (not 100% in the latter case but close enough). I recently removed a couple of AST time functions that were unused. It should be possible to replace the ksh dependency on the AST tm code with standard functions like timelocal() instead of the AST tmlocal(). And localtime() instead of tmlocaltime(). Etcetera.

There are several Coverity Scan issues involving the AST time subsystem. Rather than fix those problems it would be preferable to just remove the problematic code.

krader1961 commented 6 years ago

Who knows about the TM_OPTIONS env var? From src/lib/libast/tm/tminit.c:

stropt(getenv("TM_OPTIONS"), options, sizeof(*options), tmopt, NULL);

I'm betting there is no one outside the community of people which has examined the ksh source.

krader1961 commented 5 years ago

Note that src/lib/libast/man/tm.3 does, sort of, document TM_OPTIONS. But I'm willing to bet real money that 99.999999% of ksh users are wholly unaware of this env var. And I say "sort of" documented because that man page does not actually document its valid values. It only hints at the behavior that can be altered by setting that env var.