Subject: Re: TZ and unix epoc
To: None <tech-kern@NetBSD.org>
From: George Georgalis <george@galis.org>
List: tech-kern
Date: 02/26/2006 18:10:16
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.


>> 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.

// George


-- 
George Georgalis, systems architect, administrator <IXOYE><
http://galis.org/ cell:646-331-2027 mailto:george@galis.org