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..
Yup, (almost) no ambiguity at all. Almost because a timezone identifier might also map to several abbreviations depending on daylight savings and political changes. In PHP, you can do that with either
DateTimeZone::listAbbreviations()
(but this one isn't very reliable since it shows all the abbreviations used since the dawn of tzdb) orDateTimeZone::getTransitions()
- this one is better since if you traverse the array backwards and return the first transitionabbr
that isn't observing DST.There is no one-to-one mapping between timezone abbreviations, timezone offsets and timezone expansions. For example,
CDT
stands forCentral Daylight Time
which maps to bothUTC+10:30
(Australia) andUTC-5
(North America). It has the same abbreviation, but maps to different continents and time offsets.Similarly,
CST
isCentral Standard Time
andCentral Summer Time
and maps onto the following 3 offsets:UTC+9:30
,UTC-6
andUTC+10:30
IST
, which you refer to above, is alsoIrish Summer Time
and maps toUTC+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.
Maye you should look this php function timezone_name_from_abbr()
You general, you can't do it because it's ambiguous -- the same abbreviation is used for differente timezones.
Example:
Even IST is not unique:
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.