<%@ Language=JavaScript %> <%/* ============================================================================= DateTimeClient.asp VERSIONINFO Version: __PUT_PHAROS_VERSION_HERE__ Copyright: Copyright © 2004 Pharos Systems Inc Description: Date and time functions for client browsers Notes: The majority of the functionality is directly imported from DateTime.asp Warning: This software is property of Pharos Systems New Zealand Ltd. Unauthorized use or duplication of this software is strictly prohibited. Authorized users are subject to the following restrictions: * Neither the author, their corporation, nor Pharos Systems New Zealand Ltd. is responsible for any consequences of the use of this software. * The origin of this software must not be misrepresented either by explicit claim or by omission. * Altered versions of this software must be plainly marked as such. * This notice may not be removed or altered. ================================================================================ */%> <% // This file uses JavaScript reflection to reuse the functions from DateTime.asp. // Modifying the functions in DateTime.asp will also modify the functions in this file, however // if any new functions or arrays are added they need to be explictly referenced here. // Using SCRIPT LANGUAGE=JScript RUNAT=Server src="DateTime.asp" // Worked fine for IIS 5.0 but did not work for IIS 4.0. %> <% if ( "undefined" == typeof( CurrentServerTime ) ) { CurrentServerTime = new Date(); } // Converts a server-side array to a client-side array function GetClientSideArray( ArrayName, Array ) { var ArrayText = "var " + ArrayName + " = [ "; var IsText = false; var i; // See if the array contains text items for ( i = 0; i < Array.length; ++i ) { if ( isNaN( Array[ i ] ) ) { IsText = true; break; } } for ( i = 0; i < Array.length; ++i ) { if ( IsText ) { ArrayText += "\""; } ArrayText += Array[ i ].replace( "\"", "\\\"" ); if ( IsText ) { ArrayText += "\""; } if ( Array.length - 1 != i ) { ArrayText += ", "; } } ArrayText += " ];\n"; return ArrayText; } Response.Write( GetClientSideArray( "DayNames", DayNames ) ); Response.Write( GetClientSideArray( "ShortDayNames", ShortDayNames ) ); Response.Write( GetClientSideArray( "MonthNames", MonthNames ) ); Response.Write( GetClientSideArray( "ShortMonthNames", ShortMonthNames ) ); Response.Write( CompareDateOnly ); Response.Write( CompareTimeOnly ); Response.Write( FormatEstimatedTime ); Response.Write( FormatBasicTime ); Response.Write( FormatDateTime ); Response.Write( GetDisplayDate ); Response.Write( GetDisplayTimeCommon ); Response.Write( GetDisplayTime ); Response.Write( GetDisplayTimeWithSeconds ); %> // Client-side only functions // ------------------------------------------------------------------------------------- function DisplayClock( TimeStr ) { if ( document.layers ) // Netscape. // Date object methods do not work on Netscape 4.05, so use locale Date time string { var NewHTML = ""; NewHTML += GetCorrectedDate().toLocaleString() + ""; document.layers.txtClock.document.write( NewHTML ); document.layers.txtClock.document.close(); } else if ( document.getElementById ) // Document Object Model (IE 5+, NS 6+) { document.getElementById( "txtClock" ).innerHTML = TimeStr; } else // IE4 { document.all.txtClock.innerHTML = TimeStr; } } var ServerDate = new Date( <% = CurrentServerTime.valueOf() %> ); var ClientDate = new Date(); var ServerTimeZoneOffset = <% = CurrentServerTime.getTimezoneOffset() %>; // If the time zone is different on the client machine we adjust the time // so it will be the same as the on the iis server machine. var TimeZoneOffsetCorrection = ( ClientDate.getTimezoneOffset() - ServerTimeZoneOffset ) * 60000; var TimeOffsetCorrection = ServerDate - ClientDate; var TimeCorrection = TimeZoneOffsetCorrection + TimeOffsetCorrection; function ShowClock() { // This function actually displays the time. var TimeStr = ""; if ( GetCorrectedDate().toLocaleString ) { TimeStr = GetCorrectedDate().toLocaleString(); } else { TimeStr = FormatDateTime( GetCorrectedDate() ); } DisplayClock( TimeStr ); } function ShowBasicClock() { var TimeStr = FormatBasicTime( GetCorrectedDate() ); DisplayClock( TimeStr ); } function GetCorrectedDate() { var Today = new Date(); Today = new Date( Today.valueOf() + TimeCorrection ); return Today; }