Subject: Re: TZ and unix epoc
To: George Georgalis <george@galis.org>
From: Simon Burge <simonb@wasabisystems.com>
List: tech-kern
Date: 02/27/2006 11:52:48
"George Georgalis" wrote:

> On Sun, Feb 26, 2006 at 01:17:14PM -0600, Eric Haszlakiewicz wrote:
> >On Sun, Feb 26, 2006 at 12:30:09PM -0500, George Georgalis wrote:
> >> 
> >> I expected this command to return unix seconds of
> >> Thu Jan  1 00:00:00 GMT-2 1970; but it returns 0.
> >> 
> >>  env TZ='Etc/GMT-2' date -r 0 +%s
> >> 
> >> question 1, is this a bug?
> >
> >	You asked for 0 seconds from the Epoch.  You got 0 seconds from the Epoch.
> >That sounds about right to me.
> 
> 
> Right, but that's not what I meant to ask for. I meant, in a
> specified timezone (specifically -0200), what are the unix
> seconds at the start of the present day (second zero), in linux
> that would be "date -d 0" for any given TZ or print format you
> set.

As Eric said, this isn't a bug.  both "date -r" and strftime(3)'s
"%s" deal with seconds from the Epoch.  The local timezone doesn't
matter.

> >> question 2, how do I get the desired unix seconds?
> >
> >	I'm guessing you're trying to get the number of seconds between
> >two time zones.  That depends on what the date and time actually is, because
> >of things like some timezones having daylight savings time, and others don't.
> >You can get the offset for the _current_ (approximate) moment by comparing:
> >	env TZ='tz#1' date +%z
> >	env TZ='tz#2' date +%z
> >but of course you'll need to parse out the hours and minutes and calculate
> >the seconds yourself.
> 
> What I'm trying to do is generate Swatch internet beat time
> (the same numeral 000 through 999, everywhere in the world,
> cycling every 24 hours, synchronized from Biel, Switzerland),
> in netbsd ksh.
> 
> This works in Linux bash (tm):
> 
>  echo @$((10*(`TZ='GMT-1' date +%s`-`TZ='GMT-1' date -d 0 +%s`)/864))
> 
> that's integer math, ten times the difference of unix seconds in
> Biel, at the zero second, of today, there, divided by (mod) 864.
> 
> It's not clear how I may determine unix seconds for the zero
> second of the present day, in a given timezone, with netbsd.

Again, as Eric said - "you'll need to parse out the hours and minutes
and calculate the seconds yourself".

Something like:

	$ echo $(date +'%k 60 * %M + 60 * %S + p' | dc)
	42561

and doing the "*10/492" thing gives 

	$ echo $( date +'%k 60 * %M + 60 * %S + 10*864/p' | dc )
	492

which looks right as it approaches noon here.

Simon.
--
Simon Burge                            <simonb@wasabisystems.com>
NetBSD Support and Service:         http://www.wasabisystems.com/