I was recently asked to create a time tracking application. One of the issues I ran into was determining what week number of the year it was when creating the timesheet.
There is no @Week in formula language and no Week function in LotusScript. There were a couple ideas in JavaScript, but wanted to put it into LotusScript.
So, I came up with the idea of passing a date, formatted as a string, and finding which week it fell in.
Here is the function:
Function atWeek(weekDate As String) As Integer
Dim checkDate As NotesDateTime
Dim firstADate As NotesDateTime
Dim beginWeek As NotesDateTime
Dim endWeek As NotesDateTime
Dim message As String
Dim currentYear As String
Dim firstDay As String
Dim dayOfWeek As Integer
Dim addDays As Integer
Dim x As Integer
Dim dayCounter As Integer
Dim monthCounter As Integer
'Set the globals...
Const months = 12
Const weeks = 53 '365 Days / 7 Days a week = 52.14
Const weekdays = 7
Const dayOne = "01/01/"
currentYear = Year(Today)
firstDay = dayOne & currentYear
'Set the dates...
Set checkDate = New NotesDateTime(weekDate)
Set firstDate = New NotesDateTime(firstDay)
'Get the first week...
dayOfWeek = Weekday(firstDay)
addDays = weekdays - dayOfWeek
'Set the begin/end dates...
Set beginWeek = New NotesDateTime(firstDate.DateOnly)
'Increase the date...
firstDate.AdjustDay(addDays)
Set endWeek = New NotesDateTime(firstDate.DateOnly)
'Let's see if the date falls between first week...
If beginWeek.LSLocalTime <= checkDate.LSLocalTime Then If endWeek.LSLocalTime => checkDate.LSLocalTime Then
'We have a winner...
atWeek = 1
Exit Function
End If
End If
'We have the first week, let's get the next...
'Start with the second week, since we have the first week...
For x = 2 To weeks
'Increase the dates...
endWeek.AdjustDay(1)
Set beginWeek = New NotesDateTime(endWeek.DateOnly)
endWeek.AdjustDay(6)
Set endWeek = New NotesDateTime(endWeek.DateOnly)
'Let's see if the date falls between...
If beginWeek.LSLocalTime <= checkDate.LSLocalTime Then If endWeek.LSLocalTime => checkDate.LSLocalTime Then
'We have a winner...
atWeek = x
Exit Function
End If
End If
Next
End Function
Yes, I know I have 53 as the total weeks, but to do this based on a calendar year, there are 53 weeks. If you run 12/31/2009 through this function, 53 is returned.
It's a good little function, hopefully it will help you.
Tuesday, February 17, 2009
Tuesday, September 16, 2008
Finding and flagging "orphan" documents
A recent project that I was on had an issue with a user who happened to copy documents and paste them back into the database and then delete the original --- as quoted, the user said "the database was slow, so I was trying to shake things up."
Well, little did this user know that these were documents that had children/response documents associated with them. Now that the parent/child relationship was broken, the users were not too happy about this.
First, I had to find all the orphan docs before I associated them. So I wrote this little function which worked out pretty well:
Function IsOrphan(docResponse As NotesDocument) As Integer
Dim s As New NotesSession
Dim db As NotesDatabase
Dim docParent As NotesDocument
Dim docUNID As String
Dim parentUNID As String
Dim parentUNIDLength As Integer
Set db = s.CurrentDatabase
IsOrphan = False
'Check to see if this doc is really a response...
If docResponse.IsResponse Then
Else
Exit Function
End If
parentUNID = docResponse.ParentDocumentUNID
parentUNIDLength = Len(parentUNID)
Select Case parentUNIDLength
Case 32
Set docParent = db.GetDocumentByUNID(parentUNID)
If docParent Is Nothing Then
IsOrphan = True
Else
'Is the doc valid?
If docParent.IsValid = True Then
'See if this doc is a deletion stub...
If docParent.IsDeleted = True Then
IsOrphan = True
Else
docUNID = docParent.UniversalID
'Check to see if they are the same... [idiot check]...
If docUNID = parentUNID Then
Else
IsOrphan = True
End If
End If
Else
'Not valid...
IsOrphan = True
End If
End If
Case 1 To 31
'Parent UNID is not a UNID...
IsOrphan = True
Case 0
'Response, but no Parent UNID...
IsOrphan = True
End Select
End Function
Thought I would share this...
Well, little did this user know that these were documents that had children/response documents associated with them. Now that the parent/child relationship was broken, the users were not too happy about this.
First, I had to find all the orphan docs before I associated them. So I wrote this little function which worked out pretty well:
Function IsOrphan(docResponse As NotesDocument) As Integer
Dim s As New NotesSession
Dim db As NotesDatabase
Dim docParent As NotesDocument
Dim docUNID As String
Dim parentUNID As String
Dim parentUNIDLength As Integer
Set db = s.CurrentDatabase
IsOrphan = False
'Check to see if this doc is really a response...
If docResponse.IsResponse Then
Else
Exit Function
End If
parentUNID = docResponse.ParentDocumentUNID
parentUNIDLength = Len(parentUNID)
Select Case parentUNIDLength
Case 32
Set docParent = db.GetDocumentByUNID(parentUNID)
If docParent Is Nothing Then
IsOrphan = True
Else
'Is the doc valid?
If docParent.IsValid = True Then
'See if this doc is a deletion stub...
If docParent.IsDeleted = True Then
IsOrphan = True
Else
docUNID = docParent.UniversalID
'Check to see if they are the same... [idiot check]...
If docUNID = parentUNID Then
Else
IsOrphan = True
End If
End If
Else
'Not valid...
IsOrphan = True
End If
End If
Case 1 To 31
'Parent UNID is not a UNID...
IsOrphan = True
Case 0
'Response, but no Parent UNID...
IsOrphan = True
End Select
End Function
Thought I would share this...
Subscribe to:
Posts (Atom)