/* Written by Nathan Wilkes, Saraden Studios All rights reserved Copyright (c) 2002 nathan@saraden.co.nz */ function UpdateTimes() { //if (document.layers) return 0; if (clockTID) clearTimeout (clockTID); theStr = FormatUTCDate(CalcTime (12, 9, 1, 2, 3)) if (document.all) // IE specific code { document.getElementById("timeblock").innerHTML = theStr; tdate = new Date(); tdate2 = new Date(); tdate2.setMinutes (tdate2.getMinutes()+1, 0, 0); theOffset = Date.parse (tdate2.toString()) - Date.parse (tdate.toString()); clockTID = setTimeout ("UpdateTimes();", theOffset); } else if (document.getElementById) { // DOM code document.write(theStr); } else if (document.layers) // legacy code { document.write(theStr); } } clockTID = false; ////////////////////////////////////////////////////////////////////////////////////////////////////////////// var ServerTime = 1219940254 var TempDate = new Date(); var LocalTime = Date.UTC(TempDate.getUTCFullYear(), TempDate.getUTCMonth(), TempDate.getUTCDate(), TempDate.getUTCHours(), TempDate.getUTCMinutes(), TempDate.getUTCSeconds(), 0)/1000; var TimeOffset = LocalTime-ServerTime; //Finds the date of a given "day" in a target month //TargetCount = 1 for 1st occurance, 2 for 2nd etc // Set to 0 for last occurance in month //Dates (should) be UTC //Returns 0 if no match found function DateOfDay (TargetMonth, TargetYear, TargetDay, TargetCount) { var TestDate = new Date(0); var utcDay, utcCount; TestDate.setUTCFullYear (TargetYear); TestDate.setUTCMonth (TargetMonth); TestDate.setUTCDate (1); utcDay = 0; utcCount = 0; while (TestDate.getUTCMonth() == TargetMonth) { if (TestDate.getUTCDay() == TargetDay) { utcDay = TestDate.getUTCDate(); if (++utcCount == TargetCount) break; } TestDate.setUTCDate (TestDate.getUTCDate()+1); } return utcDay; } function CalcTime (GMTOffset, DSTStartMonth, DSTStartOcc, DSTEndMonth, DSTEndOcc) { //Result is a timezone-adjusted date stored in the UTC portion of the date object //LOCALIZATION FUNCTIONS WILL NOT WORK ON THESE RESULTS var fDST = false; var UTCDate = new Date(); // fDST = CheckDST (GMTOffset, DSTStartMonth, DSTStartOcc, DSTEndMonth, DSTEndOcc); UTCDate.setUTCSeconds(UTCDate.getUTCSeconds()-TimeOffset); //Adjust local time to server time UTCDate.setUTCHours(UTCDate.getUTCHours()+GMTOffset); //Add GMT offset if (fDST) UTCDate.setUTCHours(UTCDate.getUTCHours()+1); //If DST flag is set, increase time by 1 hour return UTCDate; } function CheckDST (GMTOffset, DSTStartMonth, DSTStartOcc, DSTEndMonth, DSTEndOcc) { //NZST = +12 (GMTOffset = 12) //DST Start: First Sunday in October (DSTStartMonth = 9, DSTStartOcc = 1) //DST End: Third Sunday in March (DSTEndMonth = 2, DSTEndOcc = 3) //AUS EST = +10 (GMTOffset = 10) //DST Start: Last Sunday in October (DSTStartMonth = 9, DSTStartOcc = 0) //DST End: Last Sunday in March (DSTEndMonth = 2, DSTEndOcc = 0) //US EST = -5 //US CST = -6 //US PST = -8 //DST Start: First Sunday in April //DST End: Last Sunday in October //Europe //Start: Last Sunday in March at 1 am. //End: Last Sunday in October at 1 am var fDST = false; var UTCDate = new Date(); var utcMonth, utcDay; UTCDate.setUTCSeconds(UTCDate.getUTCSeconds()-TimeOffset); //Adjust local time to server time UTCDate.setUTCHours(UTCDate.getUTCHours()+GMTOffset); //If we're in range exclusive, it's DST utcMonth = UTCDate.getUTCMonth(); if (DSTStartMonth > DSTEndMonth) {if ((utcMonth > DSTStartMonth) || (utcMonth < DSTEndMonth)) fDST = true;} else {if ((utcMonth > DSTStartMonth) && (utcMonth < DSTEndMonth)) fDST = true;} //In first month - locate occurance of sunday if (utcMonth == DSTStartMonth) { utcDay = DateOfDay (DSTStartMonth, UTCDate.getUTCFullYear(), 0, DSTStartOcc); if (UTCDate.getUTCDate() >= utcDay) fDST = true; } //In last month - locate occurance of sunday if (utcMonth == DSTEndMonth) { utcDay = DateOfDay (DSTEndMonth, UTCDate.getUTCFullYear(), 0, DSTEndOcc); if (UTCDate.getUTCDate() < utcDay) fDST = true; } return fDST; } function FormatUTCDate (DateObj) //Uses UTC portion of date object - assumes this has been adjusted to appropriate timezone for display //Example would be to use this to convert a CalcTime result into a display string { var dDay, dMonth, dYear, dHour, dMinute, dSec, dSign var padMonth, padYear, padMinute, padSec; var aMonthName = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"); dDay = DateObj.getUTCDate(); dMonth = DateObj.getUTCMonth()+1; dYear = DateObj.getUTCFullYear(); dHour = DateObj.getUTCHours(); dMinute = DateObj.getUTCMinutes(); dSec = DateObj.getUTCSeconds(); dSign = "am"; if (dHour > 12) {dHour-=12; dSign="pm";} padMonth = ""; if (dMonth < 10) padMonth = "0"; padYear = ""; if (dYear < 10) padYear = "0"; padMinute = ""; if (dMinute < 10) padMinute = "0"; padSec = ""; if (dSec < 10) padSec = "0"; retval=dDay+" "+aMonthName[dMonth-1]+" "+dYear+"
"+dHour+":"+padMinute+dMinute+dSign; return retval }