Consistent date format

The following class presents a developer with an interface that gives a uniform interface to handle date formats in Lotus.

If you have ever faced the dreadful way Lotus handles date formats, then you know you need a way to handle them uniformly. The following class presents a developer with an interface that gives a uniform interface to handle this.

Usage:
Include the following class in a script library.

Then to use it:

  1. Include "scriptlib name" in declaration section.
  2. Dim cd as ConsDate
To return a text string with following format:
YYYYDDMM call cd.getCommonNow

If you need other formats you could look at the getCommonNow property and play with it to fit your needs.

' Declarations
           Private n_sess As NotesSession
           Private n_datNow As NotesDateTime
           Private n_intWork As NotesInternational
           Private intDateType As Integer                                         ' NotesDate Type
           Private strDate As String                                                 ' Date to use
           Private strYear As String                                                 ' Year
           Private strMonth As String                                              ' Month
           Private strDay As String                                                  ' Day
           Private strTime As String                                                 ' Time to use
           Private strDateSep As String                                            ' Date Separator
           Private strTimeSep As String                                           ' Time Separator
           Private strAm As String                                                    ' AM identifyer
           Private strPm As String                                                    ' PM Identifyer
' END Declarations
'***************************************************************************************
' Constructor and destructor
'***************************************************************************************
           Sub New
                      Set n_sess = New NotesSession
                      Set n_datNow = New NotesDateTime(Now)
                      Me.strDate = n_datNow.DateOnly
                      Me.strTime = n_datNow.TimeOnly
                      Set n_intWork = n_sess.International
                      Me.strDateSep = Me.n_intWork.DateSep
                      Me.strTimeSep = Me.n_intWork.TimeSep
                      Me.strAm = Me.n_intWork.AMString
                      Me.strPm = Me.n_intWork.PMString

                      If Me.n_intWork.IsDateDMY Then Me.intDateType = 1
                      If Me.n_intWork.IsDateMDY Then Me.intDateType = 2
                      If Me.n_intWork.IsDateYMD Then Me.intDateType = 3
                      Call Me.InitializeDate
                      Call Me.InitializeTime
           End Sub

           Sub Delete
                      Set n_intWork = Nothing
                      Set n_sess = Nothing
                      Set n_datNow = Nothing
           End Sub

'***************************************************************************************
' Set properties
'***************************************************************************************
           Public Property Set setAmString(Byval v_strAm As String)
                      ' Changing the AM string identifyer
                      Me.strAm = v_strAm
           End Property

           Public Property Set setPmString(Byval v_strPm As String)
                      ' Changing the PM string identifyer
                      Me.strPm = v_strPm
           End Property 

           Public Property Set setTimeSep(Byval v_strTimeSep As String)
                      ' Changing the time separator used
                      Me.strTimeSep = v_strTimeSep
           End Property 

           Public Property Set setDateSep(Byval v_strDateSep As String)
                      ' Changing the date separator used
                      Me.strDateSep = v_strDateSep
           End Property

           Public Property Set setDate(Byval v_strDate As String)
                      ' Changing the date used
                      Me.strDate = v_strDate
           End Property

           Public Property Set setTime(Byval v_strTime As String)
                      ' Changing the time used
                      Me.strTime = v_strTime
           End Property

'***************************************************************************************
' Get properties
'***************************************************************************************
           Public Property Get getCommonNow As String
                      ' This is the ISO date format
                      getCommonNow = Me.strYear + "-" + Me.strMonth + "-" + Me.strDay
           End Property

           Public Property Get getTime As String
                      getTime = Me.strTime
           End Property

           Public Property Get getConvertedTime(Byval v_strTime As String) As String
                      ' Changing the time used
                      Me.strTime = v_strTime
                      Call Me.InitializeTime
                      getConvertedTime = Me.strTime
           End Property
'***************************************************************************************
' Private functions and subs
'***************************************************************************************
           Private Sub InitializeTime
                      Dim strResult As String                                            ' Result string
                      Dim intLenResult As Integer                           ' Length of result
                      Dim intLoopCounter As Integer                      ' Loop counter
                      Dim intLenFrom As Integer                            ' Length of strFrom

                      strResult = Me.strTime
                      ' We only do this if TimeSep is different from what we want
                      If Me.strTimeSep <> ":" Then
                                 intLoopCounter = 0
                                 intLenFrom = Len(Me.strTimeSep)
                                 Do While(intLoopCounter < Len(strResult))
                                            intLoopCounter = intLoopCounter + 1
                                            If Mid$(strResult, intLoopCounter, intLenFrom ) = 
Me.strTimeSep Then intLenResult=Len(strResult) strResult=Left$(strResult, (intLoopCounter-1)) + ":"
+_ Right$(strResult, intLenResult - ( (intLoopCounter-
1) + ( intLenFrom ) ) ) End If Loop End If ' initializes the time object If Instr(1,strResult,Me.strAm) <> 0 Then ' This is AM Me.strTime = Trim$(Left$(strResult,Len(strResult) -
Len(Me.strAm))) Elseif Instr(1,strResult,Me.strPm) <> 0 Then ' This Is Pm Dim intTime As Integer Dim strTemp As String strTemp = Left$(strResult,(Instr(1,strResult,":",5)-1)) strResult = Mid$(strResult,Len(strTemp) + 1) intTime = Cint(strTemp) + 12 If intTime = 24 Then intTime = 0 strResult = Cstr(intTime) + strResult Me.strTime = Trim$(Left$(strResult,Len(strResult) -
Len(Me.strPm))) Else ' This is 24H Me.strTime = strResult End If End Sub Private Sub InitializeDate ' Initialises the date object Dim intIndex As Integer intIndex = Instr(1,Me.strDate,Me.strDateSep,5) Select Case Me.intDateType Case 1 Me.strDay = Left$(Me.strDate,intIndex-1) Me.strDate = Mid$(Me.strDate,intIndex+1) intIndex = Instr(1,Me.strDate,Me.strDateSep,5) Me.strMonth = Left$(Me.strDate,intIndex-1) Me.strYear = Mid$(Me.strDate,intIndex+1) Case 2 Me.strMonth = Left$(Me.strDate,intIndex-1) Me.strDate = Mid$(Me.strDate,intIndex+1) intIndex = Instr(1,strDate,Me.strDateSep,5) Me.strDay = Left$(Me.strDate,intIndex-1) Me.strYear = Mid$(Me.strDate,intIndex+1) Case 3 Me.strYear = Left$(Me.strDate,intIndex-1) Me.strDate = Mid$(Me.strDate,intIndex+1) intIndex = Instr(1,Me.strDate,Me.strDateSep,5) Me.strMonth = Left$(Me.strDate,intIndex-1) Me.strDay = Mid$(Me.strDate,intIndex+1) End Select End Sub End Class


Do you have comments on this tip? Let us know.

This was first published in July 2003

Dig deeper on LotusScript

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchWindowsServer

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchEnterpriseLinux

SearchDataCenter

SearchExchange

SearchContentManagement

Close