Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[Solved] Time zone code not recognized by date command
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
eduardt
n00b
n00b


Joined: 24 May 2011
Posts: 4

PostPosted: Tue May 24, 2011 6:46 pm    Post subject: [Solved] Time zone code not recognized by date command Reply with quote

Hi all,

I have no idea where to post this question or how to fully describe it so I think the easiest is to show you the command and the failure

Code:

date -d "Tue May 24 08:00:00 HKT 2011" +%s
date: invalid date `Tue May 24 08:00:00 HKT 2011'


I get that date from a file that was generated in a CentOS 5.4 machine. Not sure what time zone was selected.
What I need to do is get the date in local terms so the time zone info is important to me.

I have timezone-data-2009j

Any help is much appreciated.

Thanks

Ed


FIX: Multiple matching codes. Check output of command below.
Code:

find /usr/share/zoneinfo | xargs zdump | grep HKT


Last edited by eduardt on Tue May 24, 2011 9:20 pm; edited 1 time in total
Back to top
View user's profile Send private message
John R. Graham
Administrator
Administrator


Joined: 08 Mar 2005
Posts: 10590
Location: Somewhere over Atlanta, Georgia

PostPosted: Tue May 24, 2011 6:59 pm    Post subject: Reply with quote

HKT is Hongkong time, which is GMT-8. Looks like "date" doesn't handle arbitrary time zones in the time string, although the man page indicates that it should. Try substituting the GMT offset, like so
Code:
~ $ date -d "Wed May 25 02:53:40 -0800 2011" +%s
1306320820
Incidentally, your machine is really out of date. Current timezone-data is 2011e.

- John
_________________
I can confirm that I have received between 0 and 499 National Security Letters.
Back to top
View user's profile Send private message
eduardt
n00b
n00b


Joined: 24 May 2011
Posts: 4

PostPosted: Tue May 24, 2011 8:15 pm    Post subject: Reply with quote

Thanks for the reply John.

Yes my machine is really out of date. Production server, isolated network so updates have been frozen.

I have just updated
Code:

emerge -va timezone-data
[ebuild   R   ] sys-libs/timezone-data-2011e


But I still get the same error. Do I need to recompile glibc or coreutils? I would rather not as my profile is out of date and that would mean a lot of work.

With -0800 it works fine. It works well with other timezone codes, HKT gives it a hard time though
Code:

date -d "Tue May 24 08:00:00 -0800 2011" +%s
1306252800


Where can I get the timezone code to GMT offset pairings? (And yes, I know some of them are duplicates, see CET)

Thanks,

Ed

John R. Graham wrote:
HKT is Hongkong time, which is GMT-8. Looks like "date" doesn't handle arbitrary time zones in the time string, although the man page indicates that it should. Try substituting the GMT offset, like so
Code:
~ $ date -d "Wed May 25 02:53:40 -0800 2011" +%s
1306320820
Incidentally, your machine is really out of date. Current timezone-data is 2011e.

- John
Back to top
View user's profile Send private message
John R. Graham
Administrator
Administrator


Joined: 08 Mar 2005
Posts: 10590
Location: Somewhere over Atlanta, Georgia

PostPosted: Tue May 24, 2011 8:43 pm    Post subject: Reply with quote

I don't think you need to recompile anything else. And, I think I've gotten to the bottom of why "date" is refusing to play. Fact is, "HKT" is ambiguous. See the following:
Code:
~ $ find /usr/share/zoneinfo | xargs zdump | grep HKT
/usr/share/zoneinfo/Asia/Hong_Kong                          Wed May 25 04:40:00 2011 HKT
/usr/share/zoneinfo/posix/Asia/Hong_Kong                    Wed May 25 04:40:00 2011 HKT
/usr/share/zoneinfo/posix/Hongkong                          Wed May 25 04:40:00 2011 HKT
/usr/share/zoneinfo/right/Asia/Hong_Kong                    Wed May 25 04:39:36 2011 HKT
/usr/share/zoneinfo/right/Hongkong                          Wed May 25 04:39:36 2011 HKT
/usr/share/zoneinfo/Hongkong                                Wed May 25 04:40:00 2011 HKT
Not all HKT's are the same time! 8O

I'll bet that the ones that "date" is refusing to play nice with are all ambiguous. You'll probably need to research them manually and see which GMT offset needs to be substituted in each ambiguous case.

- John
_________________
I can confirm that I have received between 0 and 499 National Security Letters.
Back to top
View user's profile Send private message
Anon-E-moose
Watchman
Watchman


Joined: 23 May 2008
Posts: 6103
Location: Dallas area

PostPosted: Tue May 24, 2011 8:46 pm    Post subject: Reply with quote

John R. Graham wrote:
HKT is Hongkong time, which is GMT-8. Looks like "date" doesn't handle arbitrary time zones in the time string, although the man page indicates that it should. Try substituting the GMT offset, like so
Code:
~ $ date -d "Wed May 25 02:53:40 -0800 2011" +%s
1306320820
Incidentally, your machine is really out of date. Current timezone-data is 2011e.

- John


from the date info

Quote:
Time zone items other than `UTC' and `Z' are obsolescent and are not
recommended, because they are ambiguous; for example, `EST' has a
different meaning in Australia than in the United States. Instead,
it's better to use unambiguous numeric time zone corrections like
`-0500', as described in the previous section.

_________________
PRIME x570-pro, 3700x, 6.1 zen kernel
gcc 13, profile 17.0 (custom bare multilib), openrc, wayland
Back to top
View user's profile Send private message
John R. Graham
Administrator
Administrator


Joined: 08 Mar 2005
Posts: 10590
Location: Somewhere over Atlanta, Georgia

PostPosted: Tue May 24, 2011 8:52 pm    Post subject: Reply with quote

Doesn't help. He's got data containing those time zone strings that he needs to deal with.

- John
_________________
I can confirm that I have received between 0 and 499 National Security Letters.
Back to top
View user's profile Send private message
eduardt
n00b
n00b


Joined: 24 May 2011
Posts: 4

PostPosted: Tue May 24, 2011 8:53 pm    Post subject: Reply with quote

Thanks John,

I think that solves this issue. At least I know how I need to handle this. Also, if you notice, all are Honk Kong but slightly different interpretations/naming conventions, doh!
Sucks to be me right now.
Related question though, if I pick the first entry (head) from the list of possible matches, how can I get the offset (besides doing a calculation)

Ed

John R. Graham wrote:
I don't think you need to recompile anything else. And, I think I've gotten to the bottom of why "date" is refusing to play. Fact is, "HKT" is ambiguous. See the following:
Code:
~ $ find /usr/share/zoneinfo | xargs zdump | grep HKT
/usr/share/zoneinfo/Asia/Hong_Kong                          Wed May 25 04:40:00 2011 HKT
/usr/share/zoneinfo/posix/Asia/Hong_Kong                    Wed May 25 04:40:00 2011 HKT
/usr/share/zoneinfo/posix/Hongkong                          Wed May 25 04:40:00 2011 HKT
/usr/share/zoneinfo/right/Asia/Hong_Kong                    Wed May 25 04:39:36 2011 HKT
/usr/share/zoneinfo/right/Hongkong                          Wed May 25 04:39:36 2011 HKT
/usr/share/zoneinfo/Hongkong                                Wed May 25 04:40:00 2011 HKT
Not all HKT's are the same time! 8O

I'll bet that the ones that "date" is refusing to play nice with are all ambiguous. You'll probably need to research them manually and see which GMT offset needs to be substituted in each ambiguous case.

- John
Back to top
View user's profile Send private message
John R. Graham
Administrator
Administrator


Joined: 08 Mar 2005
Posts: 10590
Location: Somewhere over Atlanta, Georgia

PostPosted: Tue May 24, 2011 9:00 pm    Post subject: Reply with quote

Was unable to come up with a way to do this without some scripting work that implements the calculations you're no doubt thinking of at the moment. Left as an exercise for the student. :P

- John
_________________
I can confirm that I have received between 0 and 499 National Security Letters.
Back to top
View user's profile Send private message
eduardt
n00b
n00b


Joined: 24 May 2011
Posts: 4

PostPosted: Tue May 24, 2011 9:01 pm    Post subject: Reply with quote

Thanks :)

You can mark this solved. I would do it but I don't know how.

Ed
Back to top
View user's profile Send private message
John R. Graham
Administrator
Administrator


Joined: 08 Mar 2005
Posts: 10590
Location: Somewhere over Atlanta, Georgia

PostPosted: Tue May 24, 2011 9:06 pm    Post subject: Reply with quote

You're welcome. Just edit your original post, prefix the subject with [Solved], and save it. :)

- John
_________________
I can confirm that I have received between 0 and 499 National Security Letters.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum