Re: Universal time in 4DOS?



Luchezar Georgiev wrote:
| Steve Fabian пишет:
|| BTW, on my current system, under historical data, I found
|| TIMEZONE.BAT dated 1996-08-09...
|
| What does this file do?

Here is the whole file:

@set tz=EST5EDT

(all of 1 line, conforms to MSC 6.0)
|
||| I don't know if you know but I've always been for the KISS (Keep It
||| Simple & Stupid) principle rather than the MICC (Make It Complex &
||| Complicated :)
||
|| Adding dependence on variable TZ for UT vs. local time conversion is
|| not MICC. However, putting it into a plugin-like option should be
|| acceptable to all.
|
| To do a TSR for this is even more complex than to add it built-in.
| Anyway, parsing the TZ variable to find out the actual hour offset is
| a nightmare. If there was no "summer time" (DST), it wouldn't be, but
| with it, it is :(

Yes, the modern definition of TZ is "all-encompassing". IIRC the ISDST.BTM
program below does parse it.

@echo off
*setlocal
*unalias *

alias qtm=`set _isdst=-1 %+ echo Could not determine DST status for %t_date
at %t_time %+ endlocal tz _isdst %+ quit -1`
alias qt=`if %_isdst eq -1 qtm %+ echo On %t_date at %t_time DST was
%@if[%_isdst EQ 0,not,] in effect %+ endlocal tz _isdst %+ quit %_isdst`

iff %# gt 0 then
do f in /l %*
switch %f
case /? .or. /h .or. -? .or. -h .or. --help
goto USAGE
endswitch
enddo
endiff
on error goto USAGE
set clock_dst=c:\ISDST.dat

switch %#
case 0
set t_date=%_date
set t_time=%_time
case 1
set t_date=%1
set t_time=%_time
default
set t_date=%1
set t_time=%2
endswitch

:: Test for TZ variable with DST rules defined in Mm.n.d format
:: and set the default one hour clock correction

iff not defined tz then
echo Assuming USA Eastern Time

switch %@year[%t_date]
case 1974
set _rule=M1.1.0/2,M10.5.0/2
case 1975
set _rule=M2.5.0/2,M10.5.0/2
default
iff %yr LE 1986 then
set _rule=M4.5.0/2,M10.5.0/2
elseiff %yr GE 2007 then
set _rule=%M3.2.0/2,M11.1.0/2
else
set _rule=%M4.1.0/2,M10.5.0/2
endiff
endswitch
set tz=EST5EDT4,%_rule
endiff

set start_dst=%@word[1,%tz] %+ set end_dst=%@word[2,%tz]
if %start_dst lt "" %=
set _isdst=%@index[%@word[0,%tz],%@strip[-+0123456789,%@word[0,%tz]]]
qt
if %@index[%start_dst,M] ne 0 .or. %@index[%end_dst,M] ne 0 qtm
set dst_correct=01:00:00

:: Rotate months DST end and current relative to DST start
set s_month=%@strip[M,%@field[".",0,%start_dst]]
set e_month=%@strip[M,%@field[".",0,%end_dst]]
set e_month=%@eval[%e_month-%s_month]
if %e_month lt 0 set e_month=%@eval[%e_month+12]
set month_now=%@eval[%@month[%t_date]-%s_month]
if %month_now lt 0 set month_now=%@eval[%month_now+12]

iff %month_now ge 0 .and. %month_now le %e_month then
iff %month_now eq 0 then
set start_end=%start_dst
gosub is_dst_yet
elseiff %month_now eq %e_month then
set start_end=%end_dst
gosub is_dst_yet
:: _isdst n/a (-1) in the hour before and after the end of DST
iff %se_day eq 1 then
set diff=%@eval[%se_time-%@time[%t_time]]
iff %diff gt 0 .and. %diff le %@time[%dst_correct] then
:: if checking current time use record of system clock
:: DST setting if available from file %clock_dst
iff %& le "" then
set _isdst=%@line[%clock_dst,0]
if %_isdst ne 1 .and. %_isdst ne 0 set _isdst=-1
qt
endiff
qtm
endiff
endiff
:: end DST returns is start of Standard Time
%@if[%_isdst eq 1,set _isdst=0,set _isdst=1]
else %+ set _isdst=1
endiff
else %+ set _isdst=0
endiff
qt

:is_dst_yet
set se_week=%@field[".",1,%start_end]
set se_day=%@field["./",2,%start_end]
set se_time=%@time[%@field["./",3,%start_end]]
:: set day of month test for nth occurrence of day
set se_week=%@field[%@dec[%se_week],0,7,14,21,24]
:: rotate 4dos @dowi so that day of occurrence is 1
set se_day=%@eval[%@dowi[%t_date]-%se_day]
if %se_day le 0 set se_day=%@eval[%se_day+7]
iff %@eval[%@day[%t_date]-%se_day] ge %se_week .and. not %=
(%se_day eq 1 .and. %@time[%t_time] lt %se_time) then %+ set _isdst=1
else %+ set _isdst=0
endiff
unset /q se_week
return

:USAGE
echo.
echos Invocation: %_batchanme
text
[date [time]]

where both DATE and TIME default to the current value

Exit codes:
-----------

-1 information about DST not available
0 standard time in effect
1 daylight saving time in effect

Originally published:
December 9, 2004 - Gary Welles

Notes:

ST is used below to denote local standard time
DST is used below to denote local daylight saving time

The default one hour clock correction (%dst_correct) is
used when -1 (n/a) is returned during the last hour of
DST / first hour of ST. However, if we are checking
system time (ISDST with no paramenters) and a file
(%clock_dst) containing the DST status of the clock is
present, a correct DST flag will be returned, regardless
of whether or not the clock has been corrected.

ISDST requires a complete time zone environment variable
(tz) with DST rules, if applicable. Zones without DST
(i.e. GMT0 or EST+5) will always return standard time (0).
TZ variables with DST such as EST5EDT or EST5EDT4, but
without stated rules will return -1 (n/a). Also rules
not in Mm.n.d format (i.e. Julian (Jn or n) formats),
will return -1 (n/a). The rule is copied from:

<http://www.cs.vu.nl/pub/minix/2.0.2/wwwman/man5/TZ.5.html>

SYNOPSIS

TZ=stz[-]offset[dstz[offset][,start[/time],end[/time]]]

stzzone A three or more letter name for the time zone in normal (winter)
time.

[-]offset
A signed time telling the offset of the time zone westwards from
Greenwich. The time has the form hh[:mm[:ss]] with a one of two
digit hour, and optional two digit minutes and seconds.

dst The name of the time zone when daylight saving is in effect. It may
be followed by an offset telling how big the clock correction is
other than the default of 1 hour.

start/time,end/time
Specifies the start and end of the daylight saving period. The
start and end fields indicate on what day the changeover occurs.
They must be in the following format:

Mm.n.d
This indicates
month m (1 <= m <= 12),
the n-th ( 1 <= n <= 5 ) occurrence of
day d ( 0 <= d <= 6, 0=Sunday).

The 5-th occurrence means the last occurrence of that day in a
month. So M4.1.0 is the first Sunday in April, M9.5.0 is the last
Sunday in September.

The time field indicates the time the changeover occurs on the given
day.

EXAMPLES

Greenwich Mean Time:

TZ=GMT0

Central European Time, 1 hour east from Greenwich, daylight saving starts
on the last Sunday in March at 2 AM and ends on the last Sunday in
October at 3 AM:

TZ=CET-1CEST,M3.5.0/2,M10.5.0/3

British time, daylight saving starts and ends at the same moment as CET,
but in an earlier time zone:

TZ=GMT0BST,M3.5.0/1,M10.5.0/2

The eastern European time zones also have the changeovers at the same
absolute time as British time and CET.

U.S. Eastern Standard Time, 5 hours west from Greenwich, daylight saving
starts on the first Sunday in April at 2 AM and ends on the last Sunday
in October at 2 AM:

TZ=EST5EDT,M4.1.0/2,M10.5.0/2

Time change rules for US:

1967..1973, 1976..1986 M4.5.0/2,M10.5.0/2
1974 M1.1.0/2,M10.5.0/2
1975 M2.5.0/2,M10.5.0/2
1987..2006 M4.1.0/2,M10.5.0/2
2007.. M3.2.0/2,M11.1.0/2

It shouldn't surprise you that daylight saving in New Zealand is observed
in the months opposite from the previous examples. It starts on the
first Sunday in October at 2 AM and ends on the third Sunday in March at
3 AM:

TZ=NZST-12NZDT,M10.1.0/2,M3.3.0/3

CAVEAT

You may have noticed that many fields are optional. Do no omit them,
because the defaults are bogus. If you need daylight saving then fully
specify the changeovers.

West is negative, east is positive, ask any sailor.

Next year's time zone and daylight saving time are determined by
politicians.

endtext
set _isdst=-1
endlocal _isdst
quit -1
--
Steve

.



Relevant Pages

  • Re: Round to nearest Multiple? NumericUpDown Question.
    ... no instrument no spam DOT com> wrote: ... I love how I've had to become something of an expert on all this time zone ... So somewhere along the line one of my devices thinks we're out of DST. ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Help with check time function
    ... using the UTC functions. ... The chage to/from DST normally occurs ... The clock for my mobile phone message system is in the same timezone ... Rather than daylight saving in summer, ...
    (comp.lang.javascript)
  • Re: Round to nearest Multiple? NumericUpDown Question.
    ... Double-check the version of the framework. ... only reads the current time zone information on startup. ... My Windows time is set to Mountain Time with automatically ... adjust dst clicked. ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: What time is it?
    ... I had to 'fool' my time zone in order to work. ... system does not think you are on DST. ... Open MCE and run through the Program Guide Setup again (Settings, TV, ... "helpless in the east" <helpless in the ...
    (microsoft.public.windows.mediacenter)
  • Re: Round to nearest Multiple? NumericUpDown Question.
    ... There are OS updates that have to be applied to make everything work. ... I love how I've had to become something of an expert on all this time zone ... It's definitely a DST error. ... I'm using the windows mobile 6.0 emulator within visual studio. ...
    (microsoft.public.dotnet.framework.compactframework)