January - Month of the date-errors
I learned something these days: date-functions are not only a good idea, you should also use them! Why? Because otherwise, you run into a whole lot of trouble, like scripts aborting without a reason, monthly log-data getting added to the wrong month, etc.
Take Perl for example. Paul Programmer does not want to reinvent the wheel and therefore uses Date::Calc for his date-related calculations. To get the number of days in a month he uses
$days = Days_in_Month($year,$month);
Nice, isn’t it? Unfortunately, the caffeine supply was temporarily suspended and so this code sprang into life to calculate last months number of days:
$days = Days_in_Month($year,$month-1);
Do you know what happened in January? Exactly, a run-time error. Bad! After the caffein supply was restored, Paul Programmer quickly fixed the bug with this:
my($lastyear,$lastmonth,$lastday) = Add_Delta_YM($year,$month, 1, 0, -1);
$days = Days_in_Month($lastyear,$lastmonth);
A lot nicer, isn’t it?
The same is true in Notes-Programming. If Nora Notesprogrammer wants to adjust a DateTime value, she uses the corresponding functions:
Dim dtToday As NotesDateTime
Dim dtLastMonth As NotesDateTime
Set dtToday = New NotesDateTime( "Today" )
Set dtlastMonth = dtToday
Call dtLastMonth.AdjustMonth( -1 )
Messagebox( "Today: " & dtToday.LocalTime )
Messagebox( "LastMonth: " & dtLastMonth.LocalTime )
Oh, and PLEASE do use functions/methods like „LocalTime” to get a string representation of the Date. Usually the give back the date formated (order of date and month, etc.) according to the local preferences.