TIP: Click on subject to list as thread! ANSI
echo: 4dos
to: JOHN HENTSCH
from: TED MENKS
date: 1998-05-14 00:11:00
subject: DST-calculation revised

Hi John,
As you may have noticed in my last posting before this, I've played my 
%@dowi[]
trick on you again... You'll now see that it wasn't the last trick in my 
book... :))
I told you in an earlier message that checking the hour seemed to me like a 
dreary job that only mattered for a meager four hours each year.
Your routine supplied me with the proof: it was too much work for so little 
gain, although you made an elegant job of it, adding some different ECHO's 
for each of the test-outcomes ;-)
But now the dime dropped, and the mechanism started working...
Take an expression like ToDay=%@doy[%_date].%@right[2,0%_hour]
The part before the decimal dot would represent the current day of the year, 
the part after the dot would be:
00 between midnight and 01:00
01 between 01:00 and 02:00
02 between 02:00 and 03:00
..
..
23 between 23:00 and midnight
After midnight, the hour returns to 00, but the day-of-the-year will be 
incremented by one, giving a higher result again...
That's all the result of %@right[2,0%_hour]
If we now simply add .02 to Daytmdate and Stdtmdate, we would then be able to 
test for DST with ONE single iff-then-else-endiff, like in the following 
batch:
:: ******************* third version ***********************
:setGTZ, third version by (TM)
:: Check for day light savings time date/time range -
set tStr=%@eval[8-%@dowi[4-7-%_year]]
:: The following line gets the extra .02 added
set Daytmdate=%@doy[4-%tStr-%_year].02
gosub setGTZ1
echo Daylight Time JumpForward Date: Sunday, April %tStr, %_year.
set tStr=%@eval[32-%@dowi[10-31-%_year]]
:: The following line also gets the extra .02 added
set Stdtmdate=%@doy[10-%tStr-%_year].02
gosub setGTZ1
echo Standard Time FallBack Date:    Sunday, October %tStr, %_year.
echo.
:: the following line gets the current hour (%_hour) added as a fraction.
set toDay=%@doy[%_date].%@right[2,0%_hour]
iff %toDay ge %Daytmdate .and. %toDay lt %Stdtmdate then
  echo ...It's Daylight Savings time!
  set GTZ=UTC+7
else
  echo ...It's Standard time!
  set GTZ=UTC+8
endiff
echo.
unset toDay Daytmdate Stdtmdate tStr
return
:setGTZ1
iff %@index[ 1 2 3 , %@instr[0,-1,0%tStr]] eq -1 then
  set tStr=%tStr%th
elseiff %@instr[1,-1,0%tStr] eq 1 then
  set tStr=%tStr%th
else
  set tStr=%tStr%%@word[%@instr[0,-1,0%tStr],nul st nd rd]
endiff
return
:: *********** END *** third version *** END ***************
Well, you see the result, huh? It's much shorter now. Only 887 bytes for the 
whole job.
If we now strip the screen-output, we get a routine that's almost back to the 
size of my initial proposal, but with the added precision of checking the 
hour.
Here's the example:
:: ******************* fourth version **********************
:setGTZ, fourth version by (TM)
set Daytm=%@doy[4-%@eval[8-%@dowi[4-7-%_year]]-4-%_year].02
set Stdtm=%@doy[10-%@eval[32-%@dowi[10-31-%_year]]-%_year].02
set toDay=%@doy[%_date].%@right[2,0%_hour]
iff %toDay ge %Daytm .and. %toDay lt %Stdtm then
  set GTZ=UTC+7
else
  set GTZ=UTC+8
endiff
unset toDay Daytm Stdtm
return
:: *********** END *** fourth version *** END **************
How 'bout that, pardner ? The truth, the whole truth and nothing but the 
truth in only 308 bytes ;-)
Another two cents worth from me...
See you in the next message,
  Ted Menks  2:2449/236.51 / 2:284/412.51  PGPkey: 2048/1B2ACCED (by RRQ)
... If at first you don't succeed, have somebody else do it for you!
--- 4Dos v6.01a ---
(2:2449/236.51)
---------------
* Origin: It's the 4Dos way! (Teddy's Land +49-5971-14966

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.