'API Set Notes Time: Option Public Option Explicit %REM This agent will synchronize the Notes time with the OS time using an unsupported API function called OSSetCurrentDateTime. When a Notes client or server starts up initially, it gets the OS time and uses that as its own time. However, if Notes is open for a long period of time (like a server that is up for several weeks or months), the OS time and the Notes time can get out of sync. You can always restart Notes to reset the Notes time, but for a high-availability server this can sometimes be problematic. Please be careful using this method to sync the times, because you could have unexpected results if you happen to make a significant change to the Notes server time while a server process is running. It's safest to run this in the off-hours, when no tasks are running. To test this, just open up your Notes client and (with the client still open) set your operating system time back an hour. When you run this agent, it should display an hour difference between the OS time and the Notes time initially, and it should then display the same time for both after the OSSetCurrentDateTime function has been called. Interestingly, if you set the OS time ahead instead of back, Notes will sometimes display the new OS time as the API time without having to call OSSetCurrentDateTime. I have no idea why this happens. version 1.0 Julian Robichaux http://www.nsftools.com %END REM '** special data type used by Notes for time/date handline with the API Type TIMEDATE innards(0 To 1) As Long End Type '** Notes API function for getting the current time/date (that is, the time/date '** that Notes is using, which could be out of sync with the time/date that the '** operating system is using) Declare Sub OSCurrentTIMEDATE Lib "nnotes.dll" (retTimeDate As TIMEDATE) '** Notes API function that converts a TIMEDATE structure to a time/date string. '** The IntlFormat and TimeFormat are technically special data types, but it works '** much better just to pass these as Integer zeros, which makes Notes use its '** default settings Declare Function ConvertTIMEDATEToText Lib "nnotes.dll" (Byval IntlFormat As Integer, _ Byval TimeFormat As Integer, InputTime As TIMEDATE, Byval retTextBuffer As String, _ Byval TextBufferLength As Integer, retTextLength As Integer) As Integer '** undocumented and unsupported API function that sets the Notes time Declare Sub OSSetCurrentDateTime Lib "nnotes.dll" (retTimeDate As TIMEDATE) Sub Initialize Dim apiTime As TIMEDATE Dim apiTimeString As String Dim osTime As Variant Dim formulaTime As Variant '** first, show the user what the currently reported times are Call OSCurrentTIMEDATE(apiTime) apiTimeString = ApiTimeDateToText(apiTime) osTime = Now Print "[BEFORE] OS Time = " & osTime & "; API Time = " & apiTimeString '** then, get the current OS time as a TIMEDATE value and set the Notes '** time using the undocumented OSSetCurrentDateTime function formulaTime = Evaluate( |@Text(@Now; "*")| ) apiTime.Innards(0) = Val("&H" & Strright(formulaTime(0), ":") & "L") apiTime.Innards(1) = Val("&H" & Strleft(formulaTime(0), ":") & "L") Call OSSetCurrentDateTime(apiTime) '** finally, show the user what the times are again, so they can see any change Call OSCurrentTIMEDATE(apiTime) apiTimeString = ApiTimeDateToText(apiTime) osTime = Now Print "[AFTER] OS Time = " & osTime & "; API Time = " & apiTimeString End Sub Function ApiTimeDateToText (theTime As TIMEDATE) As String '** a small wrapper around the API function that converts an API TIMEDATE '** structure to a text string Dim returnString As String*256 Dim lengthReturned As Integer Dim ret As Integer Dim retStringConverted As String ret = ConvertTIMEDATEToText(0, 0, theTime, returnString, Len(returnString) - 1, lengthReturned) retStringConverted = Left$(returnString, Instr(returnString, Chr(0)) - 1) ApiTimeDateToText = retStringConverted End Function
This LotusScript was converted to HTML using the ls2html routine,
provided by Julian Robichaux at nsftools.com.