├── index.cfm ├── readme.txt └── timezone.cfc /index.cfm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |

TimeZone class is now loaded

6 |
7 | 8 | 9 | 10 | 11 | t = now(); 12 | //today=createdateTime(2007,11,14,16,10,0); 13 | today=createdateTime(year(t),month(t),day(t),hour(t),minute(t),second(t)); 14 | timeZones=application.tz.getAvailableTZ(); 15 | if (structKeyExists(form,"thisTZ")){ 16 | inDST=application.tz.isDST(today,form.thisTZ); 17 | thisRawOffset=application.tz.getRawOffset(form.thisTZ); 18 | thisOffset=application.tz.getTZOffset(today,form.thisTZ); 19 | dstSavings=application.tz.getDST(form.thisTZ); 20 | hasDST=application.tz.usesDST(form.thisTZ); 21 | theseTZ=application.tz.getTZbyOffset(thisRawOffset); 22 | utcDate=application.tz.castToUTC(today,form.thisTZ); 23 | castDate=application.tz.castFromUTC(utcDate,form.thisTZ); 24 | serverDate=application.tz.castToServer(today,form.thisTZ); 25 | fromServer=application.tz.castFromServer(today,form.thisTZ); 26 | serverTZ=application.tz.getServerTZ(); 27 | } 28 | 29 | 30 | 31 | 32 | 33 | 34 | timeZone.cfc testbed 35 | 40 | 41 | 42 | 43 | 44 |
45 | timezone: 46 |   47 | 54 |   55 |   56 | 57 |
58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 |
server datetime :: #dateformat(today)#  #timeformat(today)#
server timezone :: #serverTZ#
selected timezone :: #form.thisTZ#
raw offset :: #numberFormat(thisRawOffset,"+__.__")# hrs
offset :: #numberFormat(thisOffset,"+__.__")# hrs
DST savings :: #numberFormat(dstSavings,"+__.__")# hrs
uses DST :: #hasDST#
in DST :: #inDST#
cast to UTC :: #dateFormat(UTCdate)#  #timeFormat(UTCdate)#
cast from UTC :: #dateFormat(castDate)#  #timeFormat(castDate)#
cast to server :: #dateFormat(serverDate)#  #timeFormat(serverDate)#
cast from server :: #dateFormat(fromServer)#  #timeFormat(fromServer)#
74 |
75 |
76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 |
Other timezones with #numberFormat(thisRawOffset,"+__.__")# hrs raw offset.
#theseTZ[i]#
None found.
93 |
94 | 95 | 96 | -------------------------------------------------------------------------------- /readme.txt: -------------------------------------------------------------------------------- 1 | LICENSE 2 | Copyright 2007 Paul Hastings 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | === 17 | Included in this archive are three versions of the timezone.CFC to handle various timezone functions: 18 | 19 | timezone.cfc: based on core java 20 | icu4jTZ.cfc: based on ICU4J lib's com.ibm.icu.util.TimeZone for installs that have the ICU4J jar file on the server's classpath. requires ICU4J library. 21 | REMOTEicu4jTZ.cfc: based on ICU4J lib's com.ibm.icu.util.TimeZone for installs that do not have the ICU4J jar file on the server's classpath. requires ICU4J library & mark mandel's javaLoader CFC http://javaloader.riaforge.org/. 22 | 23 | note: The two ICU4J based CFCs require an init (mainly to keep the syntax for both CFCs the same). For the remote classpath CFC, you can pass in the location of the ICU4J jar file. 24 | 25 | public methods in the CFCs: 26 | - isDST determines if a given date & timezone are in DST. if no date or timezone is passed 27 | the method defaults to current date/time and server timezone. PUBLIC. 28 | - getAvailableTZ returns an array of available timezones on this server (ie according to server's ICU4J version). 29 | - getTZByOffset returns an array of available timezones on this server (ie according to server's ICU4J version) with the same UTC offset. 30 | - isValidTZ determines if a given timezone is valid according to getAvailableTZ. 31 | - usesDST determines if a given timezone uses DST. 32 | - getRawOffset returns the raw (as opposed to DST) offset in hours for a given timezone. 33 | - getTZOffset returns offset in hours for a given date/time & timezone, uses DST if timezone uses and is currently in DST. 34 | - getDST returns DST savings for given timezone. 35 | - castToUTC return UTC from given datetime in given timezone. required argument thisDate, optional argument thisTZ valid timezone ID, defaults to server timezone. 36 | - castfromUTC return date in given timezone from UTC datetime. required argument thisDate, optional argument thisTZ valid timezone ID, defaults to server timezone. 37 | - castToServer returns server datetime from given datetime in given timezone. required argument thisDate valid datetime, optional argument thisTZ valid timezone ID, defaults to server timezone. 38 | - castfromServer return datetime in given timezone from server datetime. required argument thisDate valid datetime, optional argument thisTZ valid timezone ID, defaults to server timezone. 39 | - getServerTZ returns server timezone. 40 | - getServerTZShort returns "short" name for the server's timezone. 41 | - getServerId returns ID for the server's timezone (timezone.CFC ONLY) 42 | 43 | 44 | The ICU4J-based CFCs also include: 45 | - getTZByCountry returns an array of available timezones on this server (ie according to 46 | server's ICU4J version) within a given country. 47 | - init, initializes the CFC. for non-classpath installs, pass in location to ICU4J jar file. for classpath installs, use a null init. 48 | 49 | classpath: 50 | 51 | tz=createObject("component","icu4jTZ").init(); 52 | timezones=tz.getTZByCountry("AU"); 53 | 54 | 55 | non-classpath: 56 | 57 | tz=createObject("component","REMOTEicu4jJTZ").init("c:\resources\icu4j.jar"); 58 | timezones=tz.getTZByCountry("AU"); 59 | 60 | 61 | 62 | If you like, you can find my wishlist at 63 | http://www.amazon.com/gp/registry/wishlist/35SOQPL36CP87/104-4400936-8795966 64 | -------------------------------------------------------------------------------- /timezone.cfc: -------------------------------------------------------------------------------- 1 | 2 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 118 | 119 | 120 | 121 | 122 | 123 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 152 | 154 | 155 | 156 | 162 | 163 | 164 | 165 | 166 | 167 | ---> 168 | 169 | 170 | 171 | 172 | 175 | 176 | 177 | 178 | 179 | var timezone=tzObj.getTimeZone(arguments.tz); 180 | var tYear=javacast("int",Year(arguments.thisDate)); 181 | var tMonth=javacast("int",month(arguments.thisDate)-1); //java months are 0 based 182 | var tDay=javacast("int",Day(thisDate)); 183 | var tDOW=javacast("int",DayOfWeek(thisDate)); //day of week 184 | var tMS=javacast("int",((Hour(thisDate)*3600000)+Minute(thisDate)*60000+Second(thisDate)*1000)); //milliseconds in the day 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 204 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 219 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 250 | 251 | 252 | 253 | 254 | 255 | 257 | 258 | 259 | 260 | 261 | 262 | 264 | 265 | 266 | 267 | 268 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 280 | 281 | 282 | 283 | 284 | var tmptz = variables.tzObj.getTimeZone(arguments.tz); 285 | var stThisTZ = structnew(); 286 | 287 | stThisTZ.id = arguments.tz; 288 | 289 | // Get the display name 290 | 291 | stThisTZ.shortName = tmptz.getDisplayName(tmptz.inDaylightTime(arguments.today), variables.tzObj.SHORT); 292 | stThisTZ.longName = tmptz.getDisplayName(tmptz.inDaylightTime(arguments.today), variables.tzObj.LONG); 293 | stThisTZ.readableName = tmptz.getDisplayName(); 294 | 295 | 296 | // Get the number of hours from GMT 297 | 298 | stThisTZ.rawOffset = tmptz.getRawOffset(); 299 | stThisTZ.offset = getTZOffset(arguments.today, arguments.tz); 300 | stThisTZ.offsetMinutes = abs(getTZOffset(arguments.today, arguments.tz)) /3600000 % 60; 301 | 302 | 303 | // Does the time zone have a daylight savings time period? 304 | 305 | stThisTZ.hasDST = tmptz.useDaylightTime(); 306 | 307 | 308 | // Is the time zone currently in a daylight savings time? 309 | 310 | stThisTZ.inDST = tmptz.inDaylightTime(arguments.today); 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 320 | 321 | return variables.defaultTimeZoneId; 322 | 323 | 324 | 325 | 326 | 328 | 329 | 330 | 331 | var tmptz = variables.tzObj.getTimeZone(aTzId); 332 | 333 | return tmptz.getDisplayName(tmptz.inDaylightTime(aDate), variables.tzObj.SHORT); 334 | 335 | 336 | 337 | 338 | 339 | 341 | 342 | 343 | var tmptz = variables.tzObj.getTimeZone(aTzId); 344 | 345 | return convertTZ(now(), variables.defaultTimeZoneId, aTzId); 346 | 347 | 348 | 349 | 350 | 351 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 361 | 362 | return variables.standardTimeZones.List; 363 | 364 | 365 | 366 | 367 | 368 | 370 | 371 | 372 | if (structKeyExists(variables.standardTimeZones.Entry, aTzId)) 373 | return variables.standardTimeZones.Entry[aTzId].Description; 374 | else 375 | return "Unknown TimeZone"; 376 | 377 | 378 | 379 | 380 | 381 | 382 | var vsTZ = structNew(); 383 | vsTZ.Entry = structNew(); 384 | vsTZ.List = ""; 385 | vsTZ.BadList = ""; 386 | 387 | addStandardTimeZone(vsTZ, "Etc/GMT+12", "GMT -12:00 Dateline"); 388 | addStandardTimeZone(vsTZ, "Etc/GMT+11", "GMT -11:00"); 389 | addStandardTimeZone(vsTZ, "Pacific/Honolulu", "GMT -10:00 Hawaii"); 390 | addStandardTimeZone(vsTZ, "Etc/GMT+10", "GMT -10:00"); 391 | addStandardTimeZone(vsTZ, "Pacific/Marquesas", "GMT -09:30 Marquesas"); 392 | addStandardTimeZone(vsTZ, "America/Anchorage", "GMT -09:00 Alaska"); 393 | addStandardTimeZone(vsTZ, "Etc/GMT+9", "GMT -09:00"); 394 | addStandardTimeZone(vsTZ, "Pacific/Pitcairn", "GMT -08:30 Pitcarn"); 395 | addStandardTimeZone(vsTZ, "Etc/GMT+8", "GMT -08:00"); 396 | addStandardTimeZone(vsTZ, "America/Los_Angeles", "GMT -08:00 US/Canada Pacific"); 397 | addStandardTimeZone(vsTZ, "Etc/GMT+7", "GMT -07:00"); 398 | addStandardTimeZone(vsTZ, "America/Denver", "GMT -07:00 US/Canada Mountain"); 399 | addStandardTimeZone(vsTZ, "America/Phoenix", "GMT -07:00 U.S. Mountain Time (Arizona)"); 400 | addStandardTimeZone(vsTZ, "America/Mexico_City", "GMT -06:00 Mexico"); 401 | addStandardTimeZone(vsTZ, "Etc/GMT+6", "GMT -06:00"); 402 | addStandardTimeZone(vsTZ, "America/Chicago", "GMT -06:00 US/Canada Central"); 403 | addStandardTimeZone(vsTZ, "America/Bogota", "GMT -05:00 Columbia"); 404 | addStandardTimeZone(vsTZ, "America/Lima", "GMT -05:00 Peru"); 405 | addStandardTimeZone(vsTZ, "America/New_York", "GMT -05:00 US/Canada Eastern"); 406 | addStandardTimeZone(vsTZ, "Etc/GMT+5", "GMT -05:00"); 407 | addStandardTimeZone(vsTZ, "America/Halifax", "GMT -04:00 Canada Atlantic"); 408 | addStandardTimeZone(vsTZ, "Etc/GMT+4", "GMT -04:00"); 409 | addStandardTimeZone(vsTZ, "America/Santiago", "GMT -04:00 Pacific South America"); 410 | addStandardTimeZone(vsTZ, "America/St_Johns", "GMT -03:30 Newfoundland"); 411 | addStandardTimeZone(vsTZ, "America/Buenos_Aires", "GMT -03:00 Argentina"); 412 | addStandardTimeZone(vsTZ, "Etc/GMT+3", "GMT -03:00"); 413 | addStandardTimeZone(vsTZ, "America/Sao_Paulo", "GMT -03:00 Eastern South America"); 414 | addStandardTimeZone(vsTZ, "Etc/GMT+2", "GMT -02:00 Mid-Atlantic"); 415 | addStandardTimeZone(vsTZ, "Etc/GMT+1", "GMT -01:00"); 416 | addStandardTimeZone(vsTZ, "Atlantic/Azores", "GMT -01:00 Azores"); 417 | addStandardTimeZone(vsTZ, "Etc/GMT", "GMT +00:00"); 418 | addStandardTimeZone(vsTZ, "Europe/London", "GMT +00:00 GMT Britain, Ireland, Portugal"); 419 | addStandardTimeZone(vsTZ, "Etc/GMT-1", "GMT +01:00"); 420 | addStandardTimeZone(vsTZ, "Europe/Paris", "GMT +01:00 Western Europe"); 421 | addStandardTimeZone(vsTZ, "Africa/Windhoek", "GMT +01:00 Namibia"); 422 | addStandardTimeZone(vsTZ, "Etc/GMT-2", "GMT +02:00 Eastern Europe"); 423 | addStandardTimeZone(vsTZ, "Asia/Amman", "GMT +02:00 Jordan"); 424 | addStandardTimeZone(vsTZ, "Europe/Athens", "GMT +02:00 Athens, Beirut, Bucharest, Istanbul, Minsk"); 425 | addStandardTimeZone(vsTZ, "Africa/Cairo", "GMT +02:00 Egypt"); 426 | addStandardTimeZone(vsTZ, "Asia/Damascus", "GMT +02:00 Damascus"); 427 | addStandardTimeZone(vsTZ, "Asia/Gaza", "GMT +02:00 Gaza"); 428 | addStandardTimeZone(vsTZ, "Asia/Jerusalem", "GMT +02:00 Jerusalem"); 429 | addStandardTimeZone(vsTZ, "Etc/GMT-3", "GMT +03:00 Saudia Arabia"); 430 | addStandardTimeZone(vsTZ, "Asia/Baghdad", "GMT +03:00 Iraq"); 431 | addStandardTimeZone(vsTZ, "Europe/Moscow", "GMT +03:00 Moscow, St. Petersburg, Volgograd"); 432 | addStandardTimeZone(vsTZ, "Asia/Tehran", "GMT +03:30 Tehran"); 433 | addStandardTimeZone(vsTZ, "Etc/GMT-4", "GMT +04:00 Arabian"); 434 | addStandardTimeZone(vsTZ, "Asia/Kabul", "GMT +04:30 Kabul"); 435 | addStandardTimeZone(vsTZ, "Etc/GMT-5", "GMT +05:00 Pakistan, West Asia"); 436 | addStandardTimeZone(vsTZ, "Asia/Yekaterinburg", "GMT +05:00 Yekaterinburg"); 437 | addStandardTimeZone(vsTZ, "Asia/Calcutta", "GMT +05:30 Chennai, Kolkata, Mumbai, New Delhi"); 438 | addStandardTimeZone(vsTZ, "Asia/Katmandu", "GMT +05:45 Kathmandu"); 439 | addStandardTimeZone(vsTZ, "Etc/GMT-6", "GMT +06:00 Bangladesh, Central Asia"); 440 | addStandardTimeZone(vsTZ, "Asia/Novosibirsk", "GMT +06:00 Almaty, Novosibirsk"); 441 | addStandardTimeZone(vsTZ, "Asia/Rangoon", "GMT +06:30 Rangoon"); 442 | addStandardTimeZone(vsTZ, "Asia/Bangkok", "GMT +07:00 Bangkok, Hanoi, Jakarta"); 443 | addStandardTimeZone(vsTZ, "Etc/GMT-7", "GMT +07:00"); 444 | addStandardTimeZone(vsTZ, "Asia/Krasnoyarsk", "GMT +07:00 Krasnoyarsk"); 445 | addStandardTimeZone(vsTZ, "Asia/Shanghai", "GMT +08:00 China, Taiwan"); 446 | addStandardTimeZone(vsTZ, "Asia/Singapore", "GMT +08:00 Singapore"); 447 | addStandardTimeZone(vsTZ, "Etc/GMT-8", "GMT +08:00 Australia (WT)"); 448 | addStandardTimeZone(vsTZ, "Asia/Irkutsk", "GMT +08:00 Irkutsk, Ulaan Bataar"); 449 | addStandardTimeZone(vsTZ, "Asia/Seoul", "GMT +09:00 Korea"); 450 | addStandardTimeZone(vsTZ, "Asia/Tokyo", "GMT +09:00 Japan"); 451 | addStandardTimeZone(vsTZ, "Etc/GMT-9", "GMT +09:00"); 452 | addStandardTimeZone(vsTZ, "Asia/Yakutsk", "GMT +09:00 Yakutsk"); 453 | addStandardTimeZone(vsTZ, "Australia/Adelaide", "GMT +09:30 Adelaide (CT)"); 454 | addStandardTimeZone(vsTZ, "Australia/Darwin", "GMT +09:30 Darwin"); 455 | addStandardTimeZone(vsTZ, "Etc/GMT-10", "GMT +10:00"); 456 | addStandardTimeZone(vsTZ, "Asia/Vladivostok", "GMT +10:00 Vladivostok"); 457 | addStandardTimeZone(vsTZ, "Australia/Melbourne", "GMT +10:00 Melbourne (ET)"); 458 | addStandardTimeZone(vsTZ, "Australia/Hobart", "GMT +10:00 Hobart"); 459 | addStandardTimeZone(vsTZ, "Australia/Lord_Howe", "GMT +10:30 Australia (Lord Howe)"); 460 | addStandardTimeZone(vsTZ, "Etc/GMT-11", "GMT +11:00"); 461 | addStandardTimeZone(vsTZ, "Asia/Magadan", "GMT +11:00 Magadan, Solomon Is., New Caledonia"); 462 | addStandardTimeZone(vsTZ, "Pacific/Norfolk", "GMT +11:30 Norfolk Islands"); 463 | addStandardTimeZone(vsTZ, "Etc/GMT-12", "GMT +12:00"); 464 | addStandardTimeZone(vsTZ, "Pacific/Auckland", "GMT +12:00 Fiji, New Zealand"); 465 | addStandardTimeZone(vsTZ, "Etc/GMT-13", "GMT +13:00"); 466 | addStandardTimeZone(vsTZ, "Etc/GMT-14", "GMT +14:00"); 467 | 468 | return duplicate(vsTZ); 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | aTZStruct.Entry[aTZ] = structNew(); 479 | aTZStruct.Entry[aTZ].Description = aTZDesc; 480 | 481 | aTZStruct.List = ListAppend(aTZStruct.List, aTZ); 482 | 483 | if (isValidTZ(aTZ)) 484 | { 485 | aTZStruct.Entry[aTZ].Detail = getTimeZone(aTZ); 486 | } 487 | else 488 | { 489 | application.functions.general.throw("Timezone Id '#aTZ#' invalid;", 100010); 490 | } 491 | 492 | 493 | 494 | --------------------------------------------------------------------------------