'CAPI_TIMEDATE:
Option Declare
Use "CommonDeclare"
' --- Notes C API declares and constants (translated from the header files)
Public Type TIMEDATE
Innards(1) As Long
End Type
Public Const TIMEDATE_MINIMUM = 0
Public Const TIMEDATE_MAXIMUM = 1
Public Const TIMEDATE_WILDCARD = 2
Public Const MAXALPHATIMEDATE = 80
Dim session As NotesSession
Dim Platform As Integer
Declare Sub W32TimeConstant Lib "nnotes" Alias "TimeConstant"(Byval TimeConstantType As Integer, td As TIMEDATE)
Declare Sub Os2TimeConstant Lib "inotes" Alias "TimeConstant"(Byval TimeConstantType As Integer, td As TIMEDATE)
Declare Sub LnxTimeConstant Lib "libnotes.so" Alias "TimeConstant"(Byval TimeConstantType As Integer, td As TIMEDATE)
Declare Sub W32OSCurrentTIMEDATE Lib "nnotes" Alias "OSCurrentTIMEDATE"(retTimeDate As TIMEDATE)
Declare Sub Os2OSCurrentTIMEDATE Lib "inotes" Alias "OSCurrentTIMEDATE"(retTimeDate As TIMEDATE)
Declare Sub LnxOSCurrentTIMEDATE Lib "libnotes.so" Alias "OSCurrentTIMEDATE"(retTimeDate As TIMEDATE)
Declare Function W32ConvertTIMEDATEToText Lib "nnotes" Alias "ConvertTIMEDATEToText"(Byval intFormat&, Byval TextFormat&, InputTime As TIMEDATE, Byval retTextBuffer$, Byval TextBufferLength%, retTextLength%) As Integer
Declare Function Os2ConvertTIMEDATEToText Lib "inotes" Alias "ConvertTIMEDATEToText"(Byval intFormat&, Byval TextFormat&, InputTime As TIMEDATE, Byval retTextBuffer$, Byval TextBufferLength%, retTextLength%) As Integer
Declare Function LnxConvertTIMEDATEToText Lib "libnotes.so" Alias "ConvertTIMEDATEToText"(Byval intFormat&, Byval TextFormat&, InputTime As TIMEDATE, Byval retTextBuffer$, Byval TextBufferLength%, retTextLength%) As Integer
Declare Function W32TimeDateDifference Lib "nnotes" Alias "TimeDateDifference"(t1 As TIMEDATE, t2 As TIMEDATE) As Long
Declare Function Os2TimeDateDifference Lib "inotes" Alias "TimeDateDifference"(t1 As TIMEDATE, t2 As TIMEDATE) As Long
Declare Function LnxTimeDateDifference Lib "libnotes.so" Alias "TimeDateDifference"(t1 As TIMEDATE, t2 As TIMEDATE) As Long
%REM
Declare Function W32NSFItemGetTime Lib "nnotes" Alias "NSFItemGetTime"(Byval handle As Long, Byval ItemName As String, td As TIMEDATE) As Integer
Declare Function Os2NSFItemGetTime Lib "inotes" Alias "NSFItemGetTime"(Byval handle As Long, Byval ItemName As String, td As TIMEDATE) As Integer
Declare Function LnxNSFItemGetTime Lib "libnotes.so" Alias "NSFItemGetTime"(Byval handle As Long, Byval ItemName As String, td As TIMEDATE) As Integer
%END REM
Declare Function W32TimeDateAdjust Lib "nnotes" Alias "TimeDateAdjust"(Tim As TIMEDATE, _
Byval secs As Integer, Byval mins As Integer, Byval hours As Integer,_
Byval days As Integer, Byval months As Integer, Byval years As Integer) As Integer
Declare Function Os2TimeDateAdjust Lib "inotes" Alias "TimeDateAdjust"(Tim As TIMEDATE, _
Byval secs As Integer, Byval mins As Integer, Byval hours As Integer,_
Byval days As Integer, Byval months As Integer, Byval years As Integer) As Integer
Declare Function LnxTimeDateAdjust Lib "libnotes.so" Alias "TimeDateAdjust"(Tim As TIMEDATE, _
Byval secs As Integer, Byval mins As Integer, Byval hours As Integer,_
Byval days As Integer, Byval months As Integer, Byval years As Integer) As Integer
Sub Initialize
Set session = New NotesSession
Select Case session.Platform
Case "Windows/32"
Platform = 1
Case "OS/2v2"
Platform = 2
Case "Windows/16"
Platform = 3
Case "Linux"
Platform = 4
End Select
End Sub
Public Sub TimeConstant(Byval TimeConstantType As Integer, td As TIMEDATE)
Select Case Platform
Case 1
Call W32TimeConstant(TimeConstantType, td)
Case 2
Call Os2TimeConstant(TimeConstantType, td)
Case 4
Call LnxTimeConstant(TimeConstantType, td)
End Select
End Sub
Public Sub OSCurrentTIMEDATE(retTimeDate As TIMEDATE)
Select Case Platform
Case 1
Call W32OSCurrentTIMEDATE(retTimeDate)
Case 2
Call Os2OSCurrentTIMEDATE(retTimeDate)
Case 4
Call LnxOSCurrentTIMEDATE(retTimeDate)
End Select
End Sub
Public Sub ConvTIMEDATEtoDateTime(td As TIMEDATE, nt As Variant)
Dim buf As String
Dim rc As Integer, rlen As Integer
On Error Goto ErrH
buf = Space$(32)
rc = ConvertTIMEDATEToText(0&,0&, td, buf, Len(buf)-1, rlen)
If rc<>0 Then Error 7000,"ConvTIMEDATEtoDateTime: ConvertTIMEDATEToText rc="& Cstr(rc)
Select Case Datatype(nt)
Case V_PRODOBJ
Set nt = New NotesDateTime(Trim$(buf))
Case Else
nt = Cdat(Trim$(buf))
End Select
Eos: Exit Sub
ErrH:
On Error Goto 0
Error Err, "ConvTIMEDATEtoDateTime("& Cstr(Erl) &"): "& Error$
Resume Eos
End Sub
Public Sub ConvDateTimeToTIMEDATE(nt As Variant, td As TIMEDATE)
Dim nTime As NotesDateTime
Dim Intr As NotesInternational
Dim bits As String
On Error Goto ErrH
Select Case Datatype(nt)
Case V_DATE
Set nTime = session.CreateDateTime(Cstr(nt))
Case V_PRODOBJ
Set nTime = nt
End Select
Set Intr = session.International
td.Innards(0) = ((Hour(nTime.LSGMTTime)*60+Minute(nTime.LSGMTTime))*60+Second(nTime.LSGMTTime))*100
bits = "&B"
If Intr.IsDST Then
bits = bits &"1"
Else
bits = bits &"0"
End If
If Intr.TimeZone<0 Then 'East?
bits = bits &"1"
Else
bits = bits &"0"
End If
bits = bits & Right$("0"& Bin$(Cint(Abs(Intr.TimeZone)\100)\15), 2) & Right$("000"& Bin$(Abs(Intr.TimeZone) Mod 100), 4)
bits = bits & Right$(String(23,"0") & Bin$(Clng(Cdbl(nTime.LSLocalTime))+2415018), 24) 'дни от сотворения Мира
td.Innards(1)= Val(bits &"&")
Eos: Exit Sub
ErrH:
On Error Goto 0
Error Err, "ConvDateTimeToTIMEDATE("& Cstr(Erl) &"): "& Error$
Resume Eos
End Sub
Sub GetNow(nt As Variant, dt As TIMEDATE)
'Возвращает кореллированные времена текущего сервера
Dim tdoc As NotesDocument
Dim db As NotesDatabase
On Error Goto ErrH
Set db = session.CurrentDatabase
Set tdoc = New NotesDocument(db)
Dim t1 As New NotesDateTime(Cstr(tdoc.Created))
dt.Innards(1) = Val("&H"& Mid$(tdoc.UniversalID,17,8) &"&")
dt.Innards(0) = Val("&H"& Mid$(tdoc.UniversalID,25,8) &"&")
If Isempty(nt) Or Datatype(nt)=V_DATE Then
nt = t1.LSLocalTime
Elseif Datatype(nt)=V_PRODOBJ Then
On Error Goto 0
If nt Isa "NotesDateTime" Then Set nt = t1 Else Error 7000, "Invalid parameter type"
Else
On Error Goto 0
Error 7000, "Invalid parameter type"
End If
Eos: Exit Sub
ErrH:
On Error Goto 0
Error Err, "GetNow("& Cstr(Erl) &"): "& Error$
Resume Eos
End Sub
Public Function TimeDateDifference(t1 As TIMEDATE, t2 As TIMEDATE) As Long
Select Case Platform
Case 1
TimeDateDifference = W32TimeDateDifference(t1, t2)
Case 2
TimeDateDifference = Os2TimeDateDifference(t1, t2)
Case 4
TimeDateDifference = LnxTimeDateDifference(t1, t2)
End Select
End Function
Public Function TimeDateAdjust(Tim As TIMEDATE,_
Byval secs As Integer, Byval mins As Integer, Byval hours As Integer,_
Byval days As Integer, Byval months As Integer, Byval years As Integer) As Integer
Select Case Platform
Case 1
TimeDateAdjust = W32TimeDateAdjust(Tim, secs, mins, hours, days, months, years)
Case 2
TimeDateAdjust = Os2TimeDateAdjust(Tim, secs, mins, hours, days, months, years)
Case 4
TimeDateAdjust = LnxTimeDateAdjust(Tim, secs, mins, hours, days, months, years)
End Select
End Function
Public Function ConvertTIMEDATEToText(Byval intFormat&, Byval TextFormat&, InputTime As TIMEDATE, retTextBuffer$, Byval TextBufferLength%, retTextLength%) As Integer
Select Case Platform
Case 1
ConvertTIMEDATEToText = W32ConvertTIMEDATEToText(intFormat, TextFormat, InputTime, retTextBuffer, TextBufferLength, retTextLength)
Case 2
ConvertTIMEDATEToText = Os2ConvertTIMEDATEToText(intFormat, TextFormat, InputTime, retTextBuffer, TextBufferLength, retTextLength)
Case 4
ConvertTIMEDATEToText = LnxConvertTIMEDATEToText(intFormat, TextFormat, InputTime, retTextBuffer, TextBufferLength, retTextLength)
End Select
End Function