Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 8a3bc4f354f8e7761f8021d5c812c16813552e25c9e540623795bfc4897033dc
Ticket: f2b5f89c0d8520ea86b929daa19ec13fc3a24d2d
clock scan of leapsecond: wrong result in 8.6 and 9.0
User & Date: sebres on 2024-11-14 22:53:42
Changes

  1. icomment:
    Neither it is reasonable (see the output of conversion by scan and format back, last command from my example), nor it is OK in 8.7... Or rather it's "OK" only because 8.7 uses -valid 0 by default, with -valid 1 it'd behave in the same way as 9.0 (produce an error "invalid time" too).
    
    As for possible later fix of "imperfections/limitations", regardless the complexity it'd also introduce deviation from several systems, e. g. on linux (or  POSIX/GNU/langs/whatever):
    <code><pre style="padding-left:20pt">
    $ TZ=GMT date -d @1483228800 '+%Y-%m-%d %H:%M:%S'
    2017-01-01 00:00:00
    $ tclsh <<<'puts [clock format 1483228800 -f {%Y-%m-%d %H:%M:%S} -gmt 1]'
    2017-01-01 00:00:00
    $ python -c 'from datetime import datetime; print(datetime.utcfromtimestamp(1483228800).strftime("%Y-%m-%d %H:%M:%S"))'
    2017-01-01 00:00:00
    </pre></code>
    
    also scanning of time like `23:59:60` is completely not supported (basically nowhere):
    <code><pre style="padding-left:20pt">
    $ TZ=GMT date -d '2017-01-01 00:00:00' '+%s'
    <b style="color:green;">1483228800</b>
    $ TZ=GMT date -d '2016-12-31 23:59:60' '+%s'
    <b style="color:red;">date: invalid date ‘2016-12-31 23:59:60’</b><br/>
    $ python -c 'from datetime import datetime; print(datetime.fromisoformat("2017-01-01 00:00:00+00:00").timestamp())'
    <b style="color:green;">1483228800.0</b>
    $ python -c 'from datetime import datetime; print(datetime.fromisoformat("2016-12-31 23:59:60+00:00").timestamp())'
    <b style="color:red;">ValueError: second must be in 0..59</b>
    </pre></code>
    
    Why tcl must do the things (especially in the wrong way), that also basically not accepted by any tool or programming language?
    
    Again, handling of leap seconds not supported by unix time (and POSIX) at all, and introducing them would:
    
    - allow values that are not allowed everywhere else and not a standard;
    - deviate from any other tools and programming languages by its values (e. g. value of seconds since POSIX shall be then larger by +27 seconds) or behavior.
    
    Also see [stackoverflow: Unix time and leap seconds](https://stackoverflow.com/a/16539483/7161854):
    
    <i><blockquote>The number of seconds per day are fixed with Unix timestamps.
    
    <blockquote>The Unix time number is zero at the Unix epoch, and increases by exactly 86400 per day since the epoch.</blockquote>
    
    So it cannot represent leap seconds. The OS will slow down the clock to accommodate for this. The leap seconds is simply not existent as far a Unix timestamps are concerned.</blockquote></i>
    
    So it will be not just wrong, but different to any other clock/date/timestamp handling.
    
    Just consider the leap second like everyone else - it is just a small clock-slowdown (or a short time-jump), so the same timestamp will be used for two real-world seconds (one real and another leap second).<br/>
    And if someone really needs to parse the textual form "23:56:60" (e. g. in the way you trying to do that), it'd be possible either using own pre-processor or just with a `clock scan "23:56:60" -valid 0`. That's it.<br/>
    It is anyway needed only in really special cases or for real-time near programming (but then one mostly uses monotonic time, with micro- or nanosecond precision, and/or completely different facilities).
    
    The same is valid for other artificial forms, for instance sometimes used by the banks, like `32 Jan` or `30 Feb` (value dates in the electronic bank statement). Nobody else will really accept them.
    
  2. login: "sebres"
  3. mimetype: "text/x-markdown"