Jeff Godfrey <
jeffgo...@gmail.com> wrote:
> On Friday, July 17, 2015 at 1:22:56 PM UTC-5, Rich wrote:
> > Jeff Godfrey wrote:
> >
> > Note, why do you believe this webpage is correct, but feel Tcl's clock
> > is wrong? What evidence do you have that the webpage is more likely to
> > be correct?
> Because the webpage provides a break down like this:
> 197 days, 14 hours, 26 minutes and 25 seconds
> ...in addition to other formats...
> Which is 1) easy to verify that it's the correct local time (2:26 pm), 2) is easy to manually calculate the necessary results from, and 3) those manually calculated results match the results presented by the website - but are 60 minutes different than the values returned by Tcl.
> >
> > > I thought that [clock seconds] return a value based on GMT, so it
> > > made since that I needed to shift my comparison date into GMT also,
> > > but so far, no luck.
> >
> > No, you have to manually "undo" your timezone offset for summer time
> > from your clock scan.
> >
> > This produces the correct value from Tcl that matches the value from
> > the webpage (which provides evidence that both are likely correct)
> > (note, I'm in EDT now, so I had to apply the EDT offset to the scan).
> >
> > expr {([clock seconds] - [clock scan "2015-01-01 00:00:00" -format "%Y-%m-%d %H:%M:%S" -timezone -0400]) / 60}
> OK, but how would I do this generically - from any local system clock
> anywhere in the world (always ignoring DST offsets)?
By asking [clock]:
% clock format [clock seconds] -format %z
-0400
This bit from the clock manpage describes what is going on:
If a format string lacks a %z or %Z format group, it is possible for
the time to be ambiguous because it appears twice in the same day,
once without and once with Daylight Saving Time. If this situation
occurs, the first occurrence of the time is chosen. (For this
reason, it is wise to have the input string contain the time zone
when converting local times. This caveat does not apply to UTC
times.)
> Again, it's simple in concept. I just want to know the total number
> of minutes from the beginning of the year - according to the time
> presented by the local system clock. Nothing more.
Rolling the above together it works:
expr {([clock seconds] - [clock scan "2015-01-01 00:00:00" \
-format "%Y-%m-%d %H:%M:%S" \
-timezone [clock format [clock seconds] -format %z]]) / 60}