Determine if given date is in DST


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Determine if given date is in DST
# 1  
Old 07-13-2009
Determine if given date is in DST

Is there a way to figure out if given date is in DST or in EST? So imagine a shell script is_date_dst.sh

sh is_date_dst.sh 2009-03-02 would return 0 and
sh is_date_dst.sh 2009-03-22 would return 1

This script should not assume the timezone of the machine it runs on, but only the date passed in as a param.

Thanks
# 2  
Old 07-13-2009
Quote:
Originally Posted by asriva
Is there a way to figure out if given date is in DST or in EST? So imagine a shell script is_date_dst.sh

sh is_date_dst.sh 2009-03-02 would return 0 and
sh is_date_dst.sh 2009-03-22 would return 1

This script should not assume the timezone of the machine it runs on, but only the date passed in as a param.

Thanks
In the examples above how did you arrive at either 0 or 1?
In general, how can you determine the TZ by looking at a date only?
# 3  
Old 07-14-2009
If the date is in DST (ie between 2nd Sunday of Mar and 1 sunday of November, both inclusive) then the function should return 1, else 0.
# 4  
Old 07-14-2009
something to start with:
Code:
#!/bin/ksh
#set -x

d='2009-03-02'

year="${d%%-*}"

#echo "year->[${year}]"

dd="$(echo "${d}"|sed 's/-//g')"

march=$(printf "%d%02d%02d" "${year}" '3' $(cal 3 "${year}" | nawk 'FNR==4 {print $NF}'))
nov=$(printf "%d%02d%02d" "${year}" '11' $(cal 11 "${year}" | nawk 'FNR==3 {print $NF}'))

#echo "march->[${march}]"
#echo "nov->[${nov}]"

if [ ${dd} -gt ${march} -a ${dd} -le ${nov} ]; then
   echo 1
else
   echo 0
fi

# 5  
Old 07-14-2009
Thanks alot for your help. This is pretty close, but I think this gets tricky if you select fields based on rows/fields (which is what you are doing). Here you are picking 2nd Saturday of Mar and 1 Saturday of Nov.
How do we then get the 2nd Sunday of Mar and 1 Sunday of Nov?

I think the most correct logic is:
for Mar: get the last day of Feb, then get the first Sunday after that date. Then add 7 to it.
for Nov: get the last day of Oct, then get the first Sunday after that date.

I dont know how this can be done in shell/AWK/sed though

Thanks.

Last edited by asriva; 07-14-2009 at 07:45 PM..
# 6  
Old 07-15-2009
i don't know what's DST and EST dates, but if i have to do it
I would just check the date today, check if its DST put a flag file, if it reaches EST delete the flag file. then just do whatever you want to the time subtract 1 or something.
# 7  
Old 07-15-2009
GNU date can give you the timezone for a date...
Code:
date -d '2009-03-02' '+%Z'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Detect DST from a date entered by user in bash

I am trying to write a bash script that takes in a users input of a specific date in a format such as MM/DD/YYYY and returns whether or not that specific date was during daylight savings time or not. Is there a specific function that checks this? Does the date command have a way to do this? I am... (1 Reply)
Discussion started by: conman1985
1 Replies

2. Shell Programming and Scripting

Script to determine Date,TotalFile,total size of file based on date

I have file listed like below -rw-r--r--+ 1 test test 17M Nov 26 14:43 test1.gz -rw-r--r--+ 1 test test 0 Nov 26 14:44 test2.gz -rw-r--r--+ 1 test test 0 Nov 27 10:41 test3.gz -rw-r--r--+ 1 test test 244K Nov 27 10:41 test4.gz -rw-r--r--+ 1 test test 17M Nov 27 10:41 test5.gz I... (5 Replies)
Discussion started by: krish2014
5 Replies

3. AIX

Australia NSW DST

Hello. Our application is running on AIX box located in NSW , Australia. As DST starts on Oct 28th - Do you know IF AIX boxes have auto updates of day light saving times? IF not , how to do it? IF yes, where can I verify it? Thank you! (3 Replies)
Discussion started by: panchpan
3 Replies

4. Shell Programming and Scripting

DST Change For Australia

Hello , We are investigating an issue from a customer from Western Australia related to DST change on 25 th March. The customer in Australia has the below settings for Time Zone. The System is Solaris 9. TZ=Australia/NSW CMASK=022 We are trying to reproduce the problem in our local... (1 Reply)
Discussion started by: Mohammed
1 Replies

5. Solaris

DST Patch

How to update DST patch. Whatat are the necessary steps that have to be taken on the servers to update this patch?. (1 Reply)
Discussion started by: sandeepkv
1 Replies

6. AIX

AIX and DST

Just a quick last minute thing here. AIX 5.1. I ran the perl script referenced in the tutorials and found the AIX box is triggering DST on the 14th instead of the 11th. The 5.2 boxes come back with the right answers. The DST patches have been applied (or I'd have Apr 1st instead of the 14th). ... (0 Replies)
Discussion started by: BOFH
0 Replies

7. SCO

Dst - V 3.6.3

Hello, Anyone know where I can find the DST updates for SCO Xdesktop 3.6.3? Thanks (0 Replies)
Discussion started by: ddzc
0 Replies

8. SCO

DST script for 5.0.0

I checked SCO's site for DST fix for SCO 5.0.0 and there iis not one available. Can I run a script in the cron to read in and change the time? TiA (2 Replies)
Discussion started by: tbgeek
2 Replies

9. Solaris

DST on Solaris 2.6/7

I have several servers that are outside the country and are running Solaris 6 mainly with a few Solaris 7 boxes here and there. Because of that, we need to schedule time to change the time on March 11th and again in April, October and November. At least until the customer decides it's time to... (3 Replies)
Discussion started by: BOFH
3 Replies

10. Shell Programming and Scripting

Determine date and time the file was created through shell scripts

Can I determine when the particular file was created, in korn-shell. Can please someone help me. If possible please mail the solution to me. my mail id: bharat.surana@gmail.com (1 Reply)
Discussion started by: BharatSurana
1 Replies
Login or Register to Ask a Question