rip747 / TimeZone-CFC

A component that will take a timestamp from a timezone and convert it to and from utc. It will also a utc timestamp and convert it to the local time in a timezone. All this while taking Daylight Savings time into account. This is all done using the java.util.TimeZone class.
17 stars 7 forks source link

fixed some issues so it would work in Railo #3

Open aqlong opened 14 years ago

aqlong commented 14 years ago

Here's the updated code:

``` ---> var timezone=tzObj.getTimeZone(arguments.tz); var tYear=javacast("int",Year(arguments.thisDate)); var tMonth=javacast("int",month(arguments.thisDate)-1); //java months are 0 based var tDay=javacast("int",Day(thisDate)); var tDOW=javacast("int",DayOfWeek(thisDate)); //day of week var tMS=javacast("int",((Hour(thisDate)*3600000)+Minute(thisDate)*60000+Second(thisDate)*1000)); //milliseconds in the day var tmptz = variables.tzObj.getTimeZone(arguments.tz); var stThisTZ = structnew(); stThisTZ.id = arguments.tz; // Get the display name stThisTZ.shortName = tmptz.getDisplayName(tmptz.inDaylightTime(arguments.today), variables.tzObj.SHORT); stThisTZ.longName = tmptz.getDisplayName(tmptz.inDaylightTime(arguments.today), variables.tzObj.LONG); stThisTZ.readableName = tmptz.getDisplayName(); // Get the number of hours from GMT stThisTZ.rawOffset = tmptz.getRawOffset(); stThisTZ.offset = getTZOffset(arguments.today, arguments.tz); stThisTZ.offsetMinutes = abs(getTZOffset(arguments.today, arguments.tz)) /3600000 % 60; // Does the time zone have a daylight savings time period? stThisTZ.hasDST = tmptz.useDaylightTime(); // Is the time zone currently in a daylight savings time? stThisTZ.inDST = tmptz.inDaylightTime(arguments.today); return variables.defaultTimeZoneId; var tmptz = variables.tzObj.getTZ(aTzId); return tmptz.getDisplayName(tmptz.inDaylightTime(aDate), variables.tzObj.SHORT); var tmptz = variables.tzObj.getTZ(aTzId); return convertTZ(now(), variables.defaultTimeZoneId, aTzId); return variables.standardTimeZones.List; if (structKeyExists(variables.standardTimeZones.Entry, aTzId)) return variables.standardTimeZones.Entry[aTzId].Description; else return "Unknown TimeZone"; var vsTZ = structNew(); vsTZ.Entry = structNew(); vsTZ.List = ""; vsTZ.BadList = ""; addStandardTimeZone(vsTZ, "Etc/GMT+12", "GMT -12:00 Dateline"); addStandardTimeZone(vsTZ, "Etc/GMT+11", "GMT -11:00"); addStandardTimeZone(vsTZ, "Pacific/Honolulu", "GMT -10:00 Hawaii"); addStandardTimeZone(vsTZ, "Etc/GMT+10", "GMT -10:00"); addStandardTimeZone(vsTZ, "Pacific/Marquesas", "GMT -09:30 Marquesas"); addStandardTimeZone(vsTZ, "America/Anchorage", "GMT -09:00 Alaska"); addStandardTimeZone(vsTZ, "Etc/GMT+9", "GMT -09:00"); addStandardTimeZone(vsTZ, "Pacific/Pitcairn", "GMT -08:30 Pitcarn"); addStandardTimeZone(vsTZ, "Etc/GMT+8", "GMT -08:00"); addStandardTimeZone(vsTZ, "America/Los_Angeles", "GMT -08:00 US/Canada Pacific"); addStandardTimeZone(vsTZ, "Etc/GMT+7", "GMT -07:00"); addStandardTimeZone(vsTZ, "America/Denver", "GMT -07:00 US/Canada Mountain"); addStandardTimeZone(vsTZ, "America/Phoenix", "GMT -07:00 U.S. Mountain Time (Arizona)"); addStandardTimeZone(vsTZ, "America/Mexico_City", "GMT -06:00 Mexico"); addStandardTimeZone(vsTZ, "Etc/GMT+6", "GMT -06:00"); addStandardTimeZone(vsTZ, "America/Chicago", "GMT -06:00 US/Canada Central"); addStandardTimeZone(vsTZ, "America/Bogota", "GMT -05:00 Columbia"); addStandardTimeZone(vsTZ, "America/Lima", "GMT -05:00 Peru"); addStandardTimeZone(vsTZ, "America/New_York", "GMT -05:00 US/Canada Eastern"); addStandardTimeZone(vsTZ, "Etc/GMT+5", "GMT -05:00"); addStandardTimeZone(vsTZ, "America/Halifax", "GMT -04:00 Canada Atlantic"); addStandardTimeZone(vsTZ, "Etc/GMT+4", "GMT -04:00"); addStandardTimeZone(vsTZ, "America/Santiago", "GMT -04:00 Pacific South America"); addStandardTimeZone(vsTZ, "America/St_Johns", "GMT -03:30 Newfoundland"); addStandardTimeZone(vsTZ, "America/Buenos_Aires", "GMT -03:00 Argentina"); addStandardTimeZone(vsTZ, "Etc/GMT+3", "GMT -03:00"); addStandardTimeZone(vsTZ, "America/Sao_Paulo", "GMT -03:00 Eastern South America"); addStandardTimeZone(vsTZ, "Etc/GMT+2", "GMT -02:00 Mid-Atlantic"); addStandardTimeZone(vsTZ, "Etc/GMT+1", "GMT -01:00"); addStandardTimeZone(vsTZ, "Atlantic/Azores", "GMT -01:00 Azores"); addStandardTimeZone(vsTZ, "Etc/GMT", "GMT +00:00"); addStandardTimeZone(vsTZ, "Europe/London", "GMT +00:00 GMT Britain, Ireland, Portugal"); addStandardTimeZone(vsTZ, "Etc/GMT-1", "GMT +01:00"); addStandardTimeZone(vsTZ, "Europe/Paris", "GMT +01:00 Western Europe"); addStandardTimeZone(vsTZ, "Africa/Windhoek", "GMT +01:00 Namibia"); addStandardTimeZone(vsTZ, "Etc/GMT-2", "GMT +02:00 Eastern Europe"); addStandardTimeZone(vsTZ, "Asia/Amman", "GMT +02:00 Jordan"); addStandardTimeZone(vsTZ, "Europe/Athens", "GMT +02:00 Athens, Beirut, Bucharest, Istanbul, Minsk"); addStandardTimeZone(vsTZ, "Africa/Cairo", "GMT +02:00 Egypt"); addStandardTimeZone(vsTZ, "Asia/Damascus", "GMT +02:00 Damascus"); addStandardTimeZone(vsTZ, "Asia/Gaza", "GMT +02:00 Gaza"); addStandardTimeZone(vsTZ, "Asia/Jerusalem", "GMT +02:00 Jerusalem"); addStandardTimeZone(vsTZ, "Etc/GMT-3", "GMT +03:00 Saudia Arabia"); addStandardTimeZone(vsTZ, "Asia/Baghdad", "GMT +03:00 Iraq"); addStandardTimeZone(vsTZ, "Europe/Moscow", "GMT +03:00 Moscow, St. Petersburg, Volgograd"); addStandardTimeZone(vsTZ, "Asia/Tehran", "GMT +03:30 Tehran"); addStandardTimeZone(vsTZ, "Etc/GMT-4", "GMT +04:00 Arabian"); addStandardTimeZone(vsTZ, "Asia/Kabul", "GMT +04:30 Kabul"); addStandardTimeZone(vsTZ, "Etc/GMT-5", "GMT +05:00 Pakistan, West Asia"); addStandardTimeZone(vsTZ, "Asia/Yekaterinburg", "GMT +05:00 Yekaterinburg"); addStandardTimeZone(vsTZ, "Asia/Calcutta", "GMT +05:30 Chennai, Kolkata, Mumbai, New Delhi"); addStandardTimeZone(vsTZ, "Asia/Katmandu", "GMT +05:45 Kathmandu"); addStandardTimeZone(vsTZ, "Etc/GMT-6", "GMT +06:00 Bangladesh, Central Asia"); addStandardTimeZone(vsTZ, "Asia/Novosibirsk", "GMT +06:00 Almaty, Novosibirsk"); addStandardTimeZone(vsTZ, "Asia/Rangoon", "GMT +06:30 Rangoon"); addStandardTimeZone(vsTZ, "Asia/Bangkok", "GMT +07:00 Bangkok, Hanoi, Jakarta"); addStandardTimeZone(vsTZ, "Etc/GMT-7", "GMT +07:00"); addStandardTimeZone(vsTZ, "Asia/Krasnoyarsk", "GMT +07:00 Krasnoyarsk"); addStandardTimeZone(vsTZ, "Asia/Shanghai", "GMT +08:00 China, Taiwan"); addStandardTimeZone(vsTZ, "Asia/Singapore", "GMT +08:00 Singapore"); addStandardTimeZone(vsTZ, "Etc/GMT-8", "GMT +08:00 Australia (WT)"); addStandardTimeZone(vsTZ, "Asia/Irkutsk", "GMT +08:00 Irkutsk, Ulaan Bataar"); addStandardTimeZone(vsTZ, "Asia/Seoul", "GMT +09:00 Korea"); addStandardTimeZone(vsTZ, "Asia/Tokyo", "GMT +09:00 Japan"); addStandardTimeZone(vsTZ, "Etc/GMT-9", "GMT +09:00"); addStandardTimeZone(vsTZ, "Asia/Yakutsk", "GMT +09:00 Yakutsk"); addStandardTimeZone(vsTZ, "Australia/Adelaide", "GMT +09:30 Adelaide (CT)"); addStandardTimeZone(vsTZ, "Australia/Darwin", "GMT +09:30 Darwin"); addStandardTimeZone(vsTZ, "Etc/GMT-10", "GMT +10:00"); addStandardTimeZone(vsTZ, "Asia/Vladivostok", "GMT +10:00 Vladivostok"); addStandardTimeZone(vsTZ, "Australia/Melbourne", "GMT +10:00 Melbourne (ET)"); addStandardTimeZone(vsTZ, "Australia/Hobart", "GMT +10:00 Hobart"); addStandardTimeZone(vsTZ, "Australia/Lord_Howe", "GMT +10:30 Australia (Lord Howe)"); addStandardTimeZone(vsTZ, "Etc/GMT-11", "GMT +11:00"); addStandardTimeZone(vsTZ, "Asia/Magadan", "GMT +11:00 Magadan, Solomon Is., New Caledonia"); addStandardTimeZone(vsTZ, "Pacific/Norfolk", "GMT +11:30 Norfolk Islands"); addStandardTimeZone(vsTZ, "Etc/GMT-12", "GMT +12:00"); addStandardTimeZone(vsTZ, "Pacific/Auckland", "GMT +12:00 Fiji, New Zealand"); addStandardTimeZone(vsTZ, "Etc/GMT-13", "GMT +13:00"); addStandardTimeZone(vsTZ, "Etc/GMT-14", "GMT +14:00"); return duplicate(vsTZ); aTZStruct.Entry[aTZ] = structNew(); aTZStruct.Entry[aTZ].Description = aTZDesc; aTZStruct.List = ListAppend(aTZStruct.List, aTZ); if (isValidTZ(aTZ)) { aTZStruct.Entry[aTZ].Detail = getTZ(aTZ); } else { throw("Timezone Id '#aTZ#' invalid;", 100010); } ```
rip747 commented 14 years ago

thank you very much for helping out. would it be possible to get the updates from a pull request or in patch form? if not, i understand and i can just copy over the existing file. i would though like your name attached to the commit so you can get proper credit for your work.

aqlong commented 14 years ago

I'm sorry. I don't have Git, so if you wouldn't mind doing a diff and/or just copying over... thanks,

rip747 commented 14 years ago

sorry it took me so long to get back to you on this. would you happen to remember the revision that this code was based off of? i can then apply it and merge.

aqlong commented 14 years ago

I don't know what revision, but it was whatever revision state it was in on September 24, 2010

mlncn commented 11 years ago

Fix made in this fork - https://github.com/activore/TimeZone-CFC And pull request posted.

Thanks rip747 and aqlong!