Time zone issues in UNIX flavors


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Time zone issues in UNIX flavors
# 1  
Old 12-20-2012
Time zone issues in UNIX flavors

Hello All,

I am in process of migrating all my scripts from AIX box to Linux box. In one of my script I calculate my last week date with the below command

Code:
$ TZ=EDT+172 date +%F
2012-12-13

$ uname -a
AIX 1 7 000B29AAD400

Now when I tried running the same in Linux, it gives a false output

Code:
$ uname -a
Linux 2.6.18-308.11.1.el5 x86_64 x86_64 x86_64 GNU/Linux

$ TZ=EDT+172 date +%F
2012-12-19

I know in Linux we can use
Code:
date -d

command to obtain the desired date, since my code contains huge number of these, I don't like to get it changed.

Can some one please help on how to get the Timezone concept work in Linux in the similar fashion as in AIX, thanks in advance.
# 2  
Old 12-20-2012
The offset in TZ for GNU date (or libc?) seemed can't be bigger than 24. You need to convert the day part into -d argument as you said. Either override your date command with a function:
Code:
function date
{
  local t="${TZ%%[-0-9+]*}"
  local n="${TZ#$t}"
  [ -z "$t" ] && { command date "$@"; return; }
  #TZ=$t$((n%24)) /bin/date -d "$((-n/24)) days" "$@"
  TZ=$t$((n%24)) command date -d "$((-n/24)) days" "$@"
}

or convert all your scripts with:
Code:
awk '{
  if (match($0, /TZ=[A-Z]+[-+0-9 ]+date/)) {
    n = s = substr($0, RSTART, RLENGTH)
    gsub(/[^-+0-9]/, "", n)
    sub(n, sprintf("%+d", n%24), s)
    x = sprintf("%+d days", -int(n/24))
    $0 = substr($0,1,RSTART-1) s " -d \"" x "\"" substr($0,RSTART+RLENGTH)
  }
  print
}'


Last edited by binlib; 12-20-2012 at 02:51 PM..
This User Gave Thanks to binlib For This Post:
# 3  
Old 12-21-2012
I don't have permissions to touch my date function. I will get my script amended with
Code:
date -d

Smilie

Thanks for your time
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert UTC time into current UNIX sever time zone

Hi guys thanks for the help for my previous posts.Now i have a requirement that i download a XMl file which has UTC time stamp.I need to convert UTC time into Unix server timezone. For ex if the time zone of unix server is CDT then i need to convert into CDT.whatever may be the system time... (5 Replies)
Discussion started by: mohanalakshmi
5 Replies

2. UNIX for Dummies Questions & Answers

How to change the time zone in UNIX??

hi, my system date and time zone is PDT. whenever i append date time stamp to a file it appends the system date thats PDT date time zone. i want to append GMT time zone. is there a mechanism or option which can append the date time stamp according to GMT. (4 Replies)
Discussion started by: Little
4 Replies

3. Solaris

showing 2 different time zones in global zone and nonglobal zone

can some one help me out as it is showing 2 different time zones in global zone and nonglobal zone .In global zone it is showing in GMT while in nonglobal zone i it showing as PDT. System in running with solaris 10 (3 Replies)
Discussion started by: ravijanjanam12
3 Replies

4. Solaris

modifying date and time and time zone on solaris 5.10 with (redundant server) veritas

I have a cluster of two Solaris server (veritas cluster). one working and the other is standby I am going to change the date on them , and am looking for a secure solution as it is giving an important service. my opinion is that the active one doesn't need to be restarted (if I don't change the... (1 Reply)
Discussion started by: barry1946
1 Replies

5. UNIX for Dummies Questions & Answers

Unix flavors that run on x86, x86_64 bit processors?

Hello everyone. This is an awesome forum. Glad to have joined! :) I use Linux mostly, even for Desktop usage. I just love everything about it, all the way down to how the font looks while browsing. Its just so sleek and sexy. But I also boot Windows for those programs I just need that only... (23 Replies)
Discussion started by: insomnia
23 Replies

6. Shell Programming and Scripting

Get all types of shell supported on any unix flavors.

Hello - Is there a command/way we can find out, what shells are supported on a Unix machine? Please let me know. Thanks, Manju (3 Replies)
Discussion started by: manju--
3 Replies

7. Solaris

Solaris zone issues

Hi, Configuring a new zone in Solaris 10, even though used svcadm to enable the service telnet, it give the following state always enabled uninitialized svc:/network/telnet:default Also noticed the same is happening while enabling other services too. Any ideas. Thanks for your help. (5 Replies)
Discussion started by: uxadmin007
5 Replies

8. Shell Programming and Scripting

One Script on all the Unix flavors

Hi , I need to run a script on different flavors, namely 1) Linux 2) AIX 3) Solaris 4) HP-UX Almost the entire script is the same except at a few places where commands specific to that OS are to be run. Is it possible to have a single script that runs on all the platforms? Sth... (5 Replies)
Discussion started by: tcsprak
5 Replies

9. UNIX for Dummies Questions & Answers

What exactly is a Unix Flavors means??

could anybody tell me what is a unix flavor? (4 Replies)
Discussion started by: human
4 Replies

10. UNIX Desktop Questions & Answers

UNIX flavors

Are there any flavors of UNIX which are better suited for implementation in the field of 3d animation, if so what are they? (3 Replies)
Discussion started by: aloysius1001
3 Replies
Login or Register to Ask a Question