A function to convert an ISO 8601 date to a NotesDateTime


Function ISO8601toNotesDateTime(DateIn As String) As NotesDateTime
    'ISO 8601 Date
    '2022-08-08T12:14:00+00:00
    
    Dim dateTime As New NotesDateTime("Today 06:00am") 'Time and Date in this case just to initialize ndt, they will be updated
    Dim intYear As Integer
    Dim intMonth As Integer
    Dim intDay As Integer
    Dim intHours As Integer
    Dim intMinutes As Integer
    Dim intSeconds As Integer
    Dim TimeZonePlusMinus As String
    Dim intTimeZoneHours As Integer
    Dim intTimeZoneMinutes As Integer
    Dim IntTZPlusMinus As Integer
    Dim TimeZoneDiff As Integer
    
    intYear = CInt(Mid(DateIn, 1,4))
    intMonth = CInt(Mid(DateIn, 6,2))
    intDay = CInt(Mid(DateIn, 9,2))
    intHours = CInt(Mid(DateIn, 12,2))
    intMinutes= CInt(Mid(DateIn, 15,2))
    intSeconds= CInt(Mid(DateIn, 18,2))
    TimeZonePlusMinus = Mid(DateIn, 20,1)
    intTimeZoneHours = CInt(Mid(DateIn, 21,2))
    intTimeZoneMinutes = CInt(Mid(DateIn, 24,2))
    
    'Will time adjustment be up or down to get correct GMT
    If TimeZonePlusMinus = "+" Then
        IntTZPlusMinus = -1
    Else
        IntTZPlusMinus = 1
    End If

    'construct the notesdatetime
    dateTime.LocalTime = ( DateNumber ( intYear  ,intMonth , intDay ) +TimeNumber ( intHours , intMinutes , intSeconds))
    
    TimeZoneDiff = dateTime.Timezone + dateTime.Isdst
    
    datetime.Adjusthour((TimeZoneDiff * -1) + (intTZPlusMinus * intTimeZoneHours))
    'For some reason Lotusscript converttoZone only supports integers, but there are some 
    ' timezones like India which can be half hour, so we need to take that into account when adjusting the time
    datetime.Adjustminute(intTZPlusMinus * intTimeZoneMinutes)

    Set ISO8601toNotesDateTime = datetime

End Function
All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.
No comments yetLogin first to comment...