View previous topic :: View next topic |
Author |
Message |
eduardt n00b
Joined: 24 May 2011 Posts: 4
|
Posted: Tue May 24, 2011 6:46 pm Post subject: [Solved] Time zone code not recognized by date command |
|
|
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 |
|
|
John R. Graham Administrator
Joined: 08 Mar 2005 Posts: 10590 Location: Somewhere over Atlanta, Georgia
|
Posted: Tue May 24, 2011 6:59 pm Post subject: |
|
|
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 |
|
|
eduardt n00b
Joined: 24 May 2011 Posts: 4
|
Posted: Tue May 24, 2011 8:15 pm Post subject: |
|
|
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 |
|
|
John R. Graham Administrator
Joined: 08 Mar 2005 Posts: 10590 Location: Somewhere over Atlanta, Georgia
|
Posted: Tue May 24, 2011 8:43 pm Post subject: |
|
|
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!
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 |
|
|
Anon-E-moose Watchman
Joined: 23 May 2008 Posts: 6103 Location: Dallas area
|
Posted: Tue May 24, 2011 8:46 pm Post subject: |
|
|
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 |
|
|
John R. Graham Administrator
Joined: 08 Mar 2005 Posts: 10590 Location: Somewhere over Atlanta, Georgia
|
Posted: Tue May 24, 2011 8:52 pm Post subject: |
|
|
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 |
|
|
eduardt n00b
Joined: 24 May 2011 Posts: 4
|
Posted: Tue May 24, 2011 8:53 pm Post subject: |
|
|
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!
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 |
|
|
John R. Graham Administrator
Joined: 08 Mar 2005 Posts: 10590 Location: Somewhere over Atlanta, Georgia
|
Posted: Tue May 24, 2011 9:00 pm Post subject: |
|
|
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.
- John _________________ I can confirm that I have received between 0 and 499 National Security Letters. |
|
Back to top |
|
|
eduardt n00b
Joined: 24 May 2011 Posts: 4
|
Posted: Tue May 24, 2011 9:01 pm Post subject: |
|
|
Thanks
You can mark this solved. I would do it but I don't know how.
Ed |
|
Back to top |
|
|
John R. Graham Administrator
Joined: 08 Mar 2005 Posts: 10590 Location: Somewhere over Atlanta, Georgia
|
Posted: Tue May 24, 2011 9:06 pm Post subject: |
|
|
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 |
|
|
|