tags:

views:

39

answers:

2

I am working on a php (codeigniter) project. I have been doing a lot of work in timezones to convert times between different timezones and the server timezone.

I know how to convert a php timezone identifier to its abbreviation (like Asia/Calcutta to IST). But now, I need the expansion of this abbreviation (Indian Standard Time).

Is there any way to do this in php code, or any webservice to convert it? This is my last step in complete mastery in timezone programming! :)

Edit: As one person who answered pointed out, abbreviations can be ambiguous.. But timezone identifiers aren't. So can I directly convert "Asia/Calcutta" to "Indian Standard Time"? There is no ambiguity in that..

+1  A: 

You general, you can't do it because it's ambiguous -- the same abbreviation is used for differente timezones.

Example:

  • CDT: Central Daylight Time (America/Cancun, America/Chicago, ...)
  • CDT: Mexico Central Daylight Time (America)
  • CDT: Cuba Central Daylight Time (America)
  • CDT: Canada Central Daylight Time (America)

Even IST is not unique:

  • IST: Irish Summer Time (Europe)
  • IST: Indian Standard Time (Asia)
  • IST: Israel Standard Time (not in zic)

There are, however, several heuristics. For instance, PostgreSQL comes with several timezone sets that you can swap depending on the continent of your target audience.

Artefacto
Ahh... I didn't know about this. If that is the case, do you know how to convert a timezone identifier like Asia/Calcutta to Indian standard time? No ambiguity there..
Munim
@Munim I don't know if you can do it just with PHP. There seems to be no way to format a date so as to get a timezone abbreviation (the closest thing is the "tz" formatter, but that will give the full timezone if possible).
Artefacto
@Artefacto If the data is not there in any php functions, I am willing to use a web service.
Munim
A: 

There is no one-to-one mapping between timezone abbreviations, timezone offsets and timezone expansions. For example, CDT stands for Central Daylight Time which maps to both UTC+10:30 (Australia) and UTC-5 (North America). It has the same abbreviation, but maps to different continents and time offsets.

Similarly, CST is Central Standard Time and Central Summer Time and maps onto the following 3 offsets: UTC+9:30, UTC-6 and UTC+10:30

IST, which you refer to above, is also Irish Summer Time and maps to UTC+1

So, to answer your question, nope, you can't do it. If you really want to achieve mastery in timezone programming, read up on the ISO specifications for the same.

bluesmoon
Read my latest edit. I have changed the question. I am still looking for a solution to convert a timezone identifier(which is unique) to the expansion directly. No ambiguity there..
Munim
There's still a problem in that expansions aren't standard, but you can get most of what you want just by looking up the tzdatabase. Here's a link: http://code.google.com/p/tzdata/
bluesmoon