[tz] Adapting localtime.c
guy at alum.mit.edu
Sun Oct 9 18:03:25 UTC 2016
On Oct 8, 2016, at 12:46 PM, Carsten Larsen <cs at innolan.dk> wrote:
> AmigaOS uses an Epoch of January 1, 1978, 00:00:00 instead of January 1, 1970, 00:00:00 UTC. Time zone is not specified.
> The Epoch difference is easy to calculate.
As "January 1, 1978, 00:00:00" is, as per your private response, January 1, 1978, 00:00:00 *local* time, then if you want to implement a UNIX-compatible version of time(), you need to convert the AmigaOS time to UTC, and then add 252460800 to the result.
localtime(), in all implementations for UN*X, expects a UN*X-style time value to be passed to it; the tz implementation was originally an implementation for UN*X, so that's what it expects.
So if you want to implement a time() that produces a result that can be passed to the tzcode implementation of localtime(), you need to implement a UN*X-compatible time().
> The actual time is is number of seconds since 1.1.1978 and possibly a
> GMT offset (if the user have bothered to set it. The system does not take it into consideration). There is no concept of daylight saving rules and no concept of UTC.
> I guess I need to determine the exact point of January 1, 1970, 00:00:00 *UTC* on my (AmigaOS) timeline in order to use the time.h functions in tz,
> and I assume the TZ variable and tz code can help me to do so.
The tz code was originally written for UN*X, so the conversions it's primarily oriented to implementing are:
1) convert a seconds-since-a-UTC-epoch value to year/month/day/hour/minute/second in local time (localtime());
2) convert year/month/day/hour/minute/second in local time to a seconds-since-a-UTC-Epoch value (mtkime()).
As such, the code doesn't directly help an attempt to convert a seconds-since-a-local-time-Epoch value to a seconds-since-a-UTC-epoch value. You could, I guess, convert the AmigaOS time to year/month/day/hour/minute/second in local time, and then hand it to mtkime().
More information about the tz