In article <o8a8nl$msd$
1...@news-1.m-online.net>,
Janis Papanagnou <
janis_pa...@hotmail.com> wrote:
>On 18.02.2017 18:17, Kenny McCormack wrote:
>>> [...]
>>
>> I've written an extension library for this. You can find it at the usual
>> URL (at the usual PORT) - the filename is "mktime_ex.zip".
>
>I'll have a look at it. (Provided that I'll find the "usual" URL/port.)
>Thanks!
Good to hear. The URL/PORT were published earlier in various other threads
in this newsgroup. I just don't like to write any more often than I have
to, because of the 'bots.
>>> It also seems that the GNU awk time functions (systime() and mktime()) are
>>> defined inconsistently WRT UTC/local time.
>>
>> I'm not sure what you mean here. Could you clarify?
>
>I just meant that mktime() returns seconds given _local time_ (DST optional),
>while systime() returns seconds given _UTC_.
The thing you have to understand is that both of these functions are just
thin wrappers (almost pass-throughs) to various underlying C (POSIX) library
time functions. So, basically, they are the way they are because that's
the way the underlying library functions are. I.e., "Don't blame the GAWK
developers".
For example, the GAWK "mktime" function is a thin wrapper around the C
library function of the same name. Now, it turns out that the C library
also has a function called "timegm" - that is identical to "mktime" except
that the input data is assumed to be in UTC rather than in local time
(i.e., local time as indicated by the setting of the TZ env var - or the
equivalent, since TZ is sort of obsolete/deprecated in today's Linux/Unix
(I.e., POSIX) world).
One of the things my extension library does is give you direct access to
"timegm", and this should solve your underlying issue.
That all said, I must emphasize that there is only one "Epoch time" number.
It is (modulo the issue of so-called "leap seconds") the number of seconds
elapsed since 4 PM, December 31st, 1969 (Los Angeles time). That's what
systime() returns. It is also what mktime() returns - based on
interpreting the string you pass relative to your local timezone. To
re-iterate, if GAWK gave you native access to timegm(), then you could pass
in a string that would be interpreted relative to UTC rather than one
relative to your local timezone. And if GAWK gave you a meaningful way to
change the value of TZ on the fly, you could get "Epoch time" from a string
expressed in any timezone that you wanted.
>The function call interface does not support UTC in case of mktime() (and
>no "local time seconds" - whether that makes sense or not - with
>systime(). This is one inconsistency; seconds are Epoch seconds but
>there's no possibilities to specify the arguments to be interpreted as
>UTC. Generally I think that UTC should always be supported in one way or
>another. And I cannot understand why it's not supported given that there
>is a UTC flag in gawk's strftime(). The set of time functions is defined
>inconsistently from user's (or at least from my) perspective.
As I've tried to make clear above, it just hasn't come up until now.
As of the current writing, GAWK does not give you access to "timegm"; it
only gives you access to "mktime". Nor does it give you any meaningful way
to change the environment (i.e., the content of the running process's
environment variables) once your script is running. My various extension
libs address all of these problems (and more). The so-called "master"
branch of GAWK (which will someday be released as GAWK 4.2) addresses the
later issue (though not as well - in the context of this particular issue -
as mine does).
>(I also try to avoid side effects in functions, like my shell workaround with
>TZ=UTC, or by explicitly setting ENVIRON["TC"]="UTC"[*] with the current gawk
>respository version. That should be directly controllable using a function
>parameter, not by a global variable. Specifically if it's a clean extension
>[with an additional, optional function argument] that does not even break any
>existing code.)
I agree totally with this paragraph.
>The whole point is that there should be a way to specify _what time_ it is
>that is presented as argument, given the insight that there is not only "one
>time" existing. The internal representation should be consistent (say, Unix
>Epoch seconds UTC) and the user interface should allow specifying any "real"
>time to convert from/to internal mtime. UTC, as the standard, is outstanding
>here, but other TZs (as supported with your extension) is valuable as well.
I agree totally with this paragraph as well.
>[*] We should be aware that using ENVIRON["TZ"] to adjust function behaviour
>is bulky, and conceptually reflects very old Fortran programming paradigms,
>i.e. technology used in the 1960's.
I agree totally with this paragraph as well.
--
b w r w g y b r y b