Anonymous
Domino 2.0 Rich Internet Applications with IBM Lotus Notes/Domino
You are here: Today » Makig a calendar in LotusScript
« Domino Workspace: Rich text editor beta
Domino Workspace: first beta of the Blog room »

Makig a calendar in LotusScript

The calendar is inspired (again) by Jake Howlett's Notes Butter. First I started to make some helper functions:

Getting the first day of the month

Function firstDate(theDate As NotesDateTime) As NotesDateTime
    Dim dDay As NotesDateTime
    Set dDay=New NotesDateTime(theDate.DateOnly)
    dDay.AdjustDay(-Day(dDay.DateOnly)+1)
    Set firstDate=dDay
End Function

The number of days in a month

I didn't need this for the calendar, but in case you need it, this is a very nifty way of getting the number of days in a given month:

Function monthDays(theDate As NotesDateTime) As Integer
    Dim dDay As NotesDateTime
    Set dDay=New NotesDateTime(theDate.DateOnly)
    dDay.AdjustDay(-Day(dDay.DateOnly)+1)
    dDay.AdjustMonth(1)
    dDay.AdjustDay(-1)
    monthDays=Day(dDay.DateOnly)
End Function

The name of a month

Function monthName(theDate As NotesDateTime)As String
    Dim mNames As Variant
    mNames=Split("January February March April May June July August September October November December", " ")
    monthName=mNames(Month(theDate.DateOnly)-1)
End Function

The calendar

The CSS

.calendar{width:100%;border:0;border-collapse:collapse}
.calendar td{text-align:right;padding-right:3px;border-bottom:solid 1px #999}
.blur{color:#ccc}
.today{background:#fc0}
.we{background:#ddd}

The LotusScript

Sub blogCalendar(theDate As Notesdatetime)
    On Error Goto catch
    Dim dDay As NotesDateTime, todayDate As New NotesDateTime("Today")
    Dim fills As Integer, i As Integer, rowClosed As Boolean
    Dim cssClass As String
    
    Set dDay=firstDate(theDate)
    ws.body |<div class="box">|
    ws.body |<b class="bt">| & monthName(dDay) & | | & Year(dDay.DateOnly) & |</b>|
    ws.body |<table class="calendar">|
    ws.body |<tr><td>mo</td><td>tu</td><td>we</td><td>th</td>
<td>fr</td><td>sa</td><td>su</td></tr>|

    ws.body |<tr>|
    fills=6
    If Weekday(dDay.DateOnly)>1 Then
        fills = Weekday(dDay.DateOnly)-2
    End If
    Call dDay.AdjustDay(0-fills)
    For i =1 To fills
        ws.body |<td class="blur">| & Day(dDay.DateOnly) & |</td>|
        dDay.AdjustDay 1
    Next
    rowclosed=False
    Do
        If rowclosed Then
            ws.body |<tr>|
            rowclosed=False
        End If
        cssClass=||
        If dDay.DateOnly=todayDate.DateOnly Then
            cssClass=| class="today"|
        Elseif Weekday(dDay.DateOnly)=1 Or Weekday(dDay.DateOnly)=7 Then
            cssClass=| class="we"|
        End If
        ws.body |<td| & cssClass & |>| & Day(dDay.DateOnly) & |</td>|
        If (Weekday(dDay.DateOnly)=1) Then
            ws.body |</tr>|
            rowclosed=True
        End If
        dDay.AdjustDay 1
    Loop Until Day(dDay.DateOnly)=1
    If Not Weekday(dDay.dateonly)=2 Then
        fills=8-Weekday(dDay.DateOnly)
        For i=0 To fills
            ws.body |<td class="blur">| & Day(dDay.DateOnly) & |</td>|
            Call dDay.AdjustDay(1)
        Next
        ws.body |</tr>|
    End If
    ws.body |</table>|
    ws.body |</div>|
    
    Goto finally
catch:
    Error Err, Error & " in " & Getthreadinfo(1) & ", line " & Erl
    Resume finally
finally:
End Sub

Next steps

I've also fixed a bug in the Code to HTML script so that |...| is highlighted corectly now. For my calendar, I still need to get the links to the blog entries for each day.

Star rating

0%

Comments

  1. 03/14/2008 04:23:10 PM, prasad duvvuri

    is there a way i can look at your calendar screen shot ?? Thanks.

  2. 15/03/2008 08:18:07, Michel Van der Meiren

    It is the calendar you see on this page on your right.

To add a comment, log in or register as new user. It's free and safe.