tz = { "ACDT" : { "fullname" : "Australian Central Daylight Time", "offset" : "+10:30" }, "ACST" : { "fullname" : "Australian Central Standard Time", "offset" : "+9:30" }, "ADT" : { "fullname" : "Atlantic Daylight Time", "offset" : "-3:00" }, "AEDT" : { "fullname" : "Australian Eastern Daylight Time", "offset" : "+11:00" }, "AEST" : { "fullname" : "Australian Eastern Standard Time", "offset" : "+10:00" }, "AKDT" : { "fullname" : "Alaska Daylight Time", "offset" : "-8:00" }, "AKST" : { "fullname" : "Alaska Standard Time", "offset" : "-9:00" }, "AST" : { "fullname" : "Atlantic Standard Time", "offset" : "-4:00" }, "AWDT" : { "fullname" : "Australian Western Daylight Time", "offset" : "+9:00" }, "AWST" : { "fullname" : "Australian Western Standard Time", "offset" : "+8:00" }, "BST" : { "fullname" : "British Summer Time", "offset" : "+1:00" }, "CAT" : { "fullname" : "Central Africa Time", "offset" : "+2:00" }, "CDT" : { "fullname" : "Central Daylight Time", "offset" : "-5:00" }, "CEDT" : { "fullname" : "Central European Daylight Time", "offset" : "+2:00" }, "CEST" : { "fullname" : "Central European Summer Time", "offset" : "+2:00" }, "CET" : { "fullname" : "Central European Time", "offset" : "+1:00" }, "CST" : { "fullname" : "Central Summer(Daylight) Time", "offset" : "+10:30" }, "CST" : { "fullname" : "Central Standard Time", "offset" : "+9:30" }, "CST" : { "fullname" : "Central Standard Time", "offset" : "-6:00" }, "CXT" : { "fullname" : "Christmas Island Time", "offset" : "+7:00" }, "EDT" : { "fullname" : "Eastern Daylight Time", "offset" : "-4:00" }, "EEDT" : { "fullname" : "Eastern European Daylight Time", "offset" : "+3:00" }, "EEST" : { "fullname" : "Eastern European Summer Time", "offset" : "+3:00" }, "EET" : { "fullname" : "Eastern European Time", "offset" : "+2:00" }, "EST" : { "fullname" : "Eastern Summer(Daylight) Time", "offset" : "+11:00" }, "EST" : { "fullname" : "Eastern Standard Time", "offset" : "+10:00" }, "EST" : { "fullname" : "Eastern Standard Time", "offset" : "-5:00" }, "GMT" : { "fullname" : "Greenwich Mean Time", "offset" : "+0:00" }, "HAA" : { "fullname" : "Heure AvancŽe de l'Atlantique", "offset" : "-3:00" }, "HAC" : { "fullname" : "Heure AvancŽe du Centre", "offset" : "-5:00" }, "HADT" : { "fullname" : "Hawaii-Aleutian Daylight Time", "offset" : "-9:00" }, "HAE" : { "fullname" : "Heure AvancŽe de l'Est", "offset" : "-4:00" }, "HAP" : { "fullname" : "Heure AvancŽe du Pacifique", "offset" : "-7:00" }, "HAR" : { "fullname" : "Heure AvancŽe des Rocheuses", "offset" : "-6:00" }, "HAST" : { "fullname" : "Hawaii-Aleutian Standard Time", "offset" : "-10:00" }, "HAT" : { "fullname" : "Heure AvancŽe de Terre-Neuve", "offset" : "-2:30" }, "HAY" : { "fullname" : "Heure AvancŽe du Yukon", "offset" : "-8:00" }, "HNA" : { "fullname" : "Heure Normale de l'Atlantique", "offset" : "-4:00" }, "HNC" : { "fullname" : "Heure Normale du Centre", "offset" : "-6:00" }, "HNE" : { "fullname" : "Heure Normale de l'Est", "offset" : "-5:00" }, "HNP" : { "fullname" : "Heure Normale du Pacifique", "offset" : "-8:00" }, "HNR" : { "fullname" : "Heure Normale des Rocheuses", "offset" : "-7:00" }, "HNT" : { "fullname" : "Heure Normale de Terre-Neuve", "offset" : "-3:30" }, "HNY" : { "fullname" : "Heure Normale du Yukon", "offset" : "-9:00" }, "IST" : { "fullname" : "Irish Summer Time", "offset" : "+1:00" }, "MDT" : { "fullname" : "Mountain Daylight Time", "offset" : "-6:00" }, "MESZ" : { "fullname" : "MitteleuropŠische Sommerzeit", "offset" : "+2:00" }, "MEZ" : { "fullname" : "MitteleuropŠische Zeit", "offset" : "+1:00" }, "MST" : { "fullname" : "Mountain Standard Time", "offset" : "-7:00" }, "NDT" : { "fullname" : "Newfoundland Daylight Time", "offset" : "-2:30" }, "NFT" : { "fullname" : "Norfolk (Island) Time", "offset" : "+11:30" }, "NST" : { "fullname" : "Newfoundland Standard Time", "offset" : "-3:30" }, "PDT" : { "fullname" : "Pacific Daylight Time", "offset" : "-7:00" }, "PST" : { "fullname" : "Pacific Standard Time", "offset" : "-8:00" }, "UTC" : { "fullname" : "Coordinated Universal Time", "offset" : "+0:00" }, "WEDT" : { "fullname" : "Western European Daylight Time", "offset" : "+1:00" }, "WEST" : { "fullname" : "Western European Summer Time", "offset" : "+1:00" }, "WET" : { "fullname" : "Western European Time", "offset" : "+0:00" }, "WST" : { "fullname" : "Western Summer(Daylight) Time", "offset" : "+9:00" }, "WST" : { "fullname" : "Western Standard Time", "offset" : "+8:00" } } function getEventDate(formDateField) { // I'm aware of Date.parse; my notes suggest that the Date object // cannot be trusted, so i'm parsing it myself. // Expected format: YYYY-MM-DDThh:mm:ss.zzz year = formDateField.substring(0,4); month = formDateField.substring(5,7) - 1; // Date objects assume January's the 0th month :-P day = formDateField.substring(8,10); hours = formDateField.substring(11,13); minutes = formDateField.substring(14,16); seconds = formDateField.substring(17,19); return new Date(year, month, day, hours, minutes, seconds); } function getTimeDifference(myTZ, eventTZ) { return tzOffsetToMsec(myTZ) - tzOffsetToMsec(eventTZ); } function tzOffsetToMsec(tz) { var offset_dir = (tz.charAt(0) == "-")? -1:1; var time = tz.substring(1,6).split(/:/) var hour = time[0]; var min = time[1]; var mins_in_hour = 60; var secs_in_min = 60; var ms_in_sec = 1000; return ( ( hour * mins_in_hour * secs_in_min * ms_in_sec ) + ( min * secs_in_min * ms_in_sec ) ) * offset_dir; // in msec } function adjustTime(startDate, endDate, myTZ, eventTZ, elementOnPage) { startDate = getEventDate(startDate).getTime(); // convert to msec endDate = getEventDate(endDate).getTime(); // convert to msec timeDifference = getTimeDifference(myTZ, tz[eventTZ].offset); adjustedStartEventDate = new Date( startDate + timeDifference ); adjustedEndEventDate = new Date( endDate + timeDifference ); $(elementOnPage).innerHTML = formatDate( adjustedStartEventDate, adjustedEndEventDate ); Element.show(elementOnPage); } function formatDate(startDateObj, endDateObj){ var month = new Array( "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ); if (startDateObj.getFullYear() == endDateObj.getFullYear() && startDateObj.getMonth() == endDateObj.getMonth() && startDateObj.getDate() == endDateObj.getDate()) { return new Array( month[startDateObj.getMonth()], " ", startDateObj.getDate(), ", ", startDateObj.getFullYear(), "
", sanitizeTime(startDateObj), " through ", sanitizeTime(endDateObj) ).join(''); } else { return new Array( month[startDateObj.getMonth()], " ", startDateObj.getDate(), ", ", startDateObj.getFullYear(), " at ", sanitizeTime(startDateObj), " through ", month[endDateObj.getMonth()], " ", endDateObj.getDate(), ", ", endDateObj.getFullYear(), " at ", sanitizeTime(endDateObj) ).join(''); } } function sanitizeTime(dateObj) { ampm = "AM" h = dateObj.getHours(); m = dateObj.getMinutes(); if ( h == 0 ) { h = 12; } else if ( h == 12 ) { ampm = "PM"; } else if ( h > 12 ) { ampm = "PM"; h = h - 12; } if ( m < 10 ) { m = "0" + m; } return h + ":" + m + " " + ampm; }