[Toybox] Stat %Z - What are valid values?
David Seikel
onefang at gmail.com
Wed Jan 25 15:33:59 PST 2017
On Wed, 25 Jan 2017 17:15:37 -0600 Rob Landley <rob at landley.net> wrote:
> On 01/24/2017 06:10 PM, Rich Felker wrote:
> >>> strptime with %s? I suspect there are some nasty underspecified
> >>> issues with how it interacts with timezones.
> >>
> >> I thought unix time was always UTS and the timezone just affected
> >> how it was displayed?
> >
> > The problem is that strptime produces a struct tm. When the fields
> > it's parsing to produce this struct tm are "broken down time"
> > fields, strptime does not need to know/care whether the caller is
> > going to interpret the struct tm as UTC or local time; it's just a
> > bunch of numbers. But when strptime is going to take a unix time
> > value (seconds since epoch) and convert it to struct tm, it matters
> > whether the caller is supposed to treat that struct tm as UTC or
> > local.
>
> According to man 2 time:
>
> time() returns the time as the number of seconds since the
> Epoch, 1970-01-01 00:00:00 +0000 (UTC).
>
> I.E. the definition of unix time is UTC. So %s _not_ being UTC is
> silly.
>
> My use case (and presumably most people's) is turning a time string
> into a struct timespec. What the actual struct tm fields are is
> irrelevant to that as long as mktime() translates the result back to
> the right number. The struct tm has a timezone field in it. As long
> as strptime sets the timezone when it adjusts the hours so mktime()
> can adjust it _back_, the result is the same number you fed into %s.
> Which is the point of the exercise.
>
> (Remember when Linux systems used to have a "store system clock in GMT
> instead of localtime" option during config, and the config option went
> away because nobody ever _didn't_ do that? Yeah, that.)
Storing the system clock as local time is done all the time, on systems
that also boot into OSes that don't know how to handle a GMT system
clock. Like dual boot Linux / Windows systems for instance. When I
setup such a dual boot system late last year, I recall I had to "fix"
the Linux side to use local time for the system clock, coz it
defaulted to GMT.
Much ado about nothing, I have no plans to move that computer to a
different time zone. This time zone doesn't even do daylight saving.
On systems that don't have to share clock hardware with silly OSes,
then sure I leave the system clock at GMT. Just don't ask me what my
Mac does, I have no idea, and no plans to dual boot it.
--
A big old stinking pile of genius that no one wants
coz there are too many silver coated monkeys in the world.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20170126/4aedebba/attachment-0002.sig>
More information about the Toybox
mailing list