Code Based On Time Of Day
Someone recently wanted some help with an application. They had an application where one button would call one of two agents based on the time of the day. If it was first shift (9 AM to 5 PM for the support people) one agent would be called. Second and third shift would call another agent. The tricky part was that the users of the application were spread across multiple time zones. The application needed to call the right agent based on a specific time zone. How would this be handled in a Notes client application? Fortunately, the users of the application were all on Notes 6. Notes 6 introduced a new field type called Time Zone that really helps out here. It allows the Notes 6 client to adjust times to the time zone of the support people (U.S. Eastern Time) so the button would know if it's between 9 AM and 5 PM on a weekday.
First, I had the developer create a hidden computed for display (CFD) Time Zone field. The field is called EasternTimeZone. The formula for the field computed the correct time zone:
"Z=5$DO=1$DL=4 1 1 10 -1 1"
Obviously, this needs some further explanation. I got all the information from the Notes Designer Help. Z=5 is the time zone (GMT minus 5 hours). DO=1 says that Daylight Saving Time (DST) is observed in this time zone. When DST is observed, then you need to tell the client when DST starts and ends. That's what DL does. The value says that it starts in April (month 4), on the first (the first "1" is the week number) Sunday (the second "1" is the day of the week). DST ends in October (month 10), on the last ("-1") Sunday ("1").
Now that we have a Time Zone field, we add another hidden CFD field. This field is text and is called CurrentEasternTime. The field computes the current time in the Eastern time zone and gives the value in a text format. The formula is:
@TimeToTextInZone(@Now; EasternTimeZone; "T1S1")
This formula is new to Notes 6. It is similar to @Text, but adds the second parameter of the time zone.
The reason the value is stored in text is so we know that Notes won't convert things back to the end user's time zone without our knowledge. The plain text is just a time value with no time zone associated, so looking at this value later on (in the next field), it won't matter what time zone the Notes client will use.
Finally, a third CFD text field called AgentToRun computes what agent to run based on the time of day (in the Eastern time zone) and the day of the week:
@If(@Weekday(@Now) = 1; "(Off Shift)"; @Weekday(@Now) = 7; "(Off Shift)"; @Hour(@TextToTime(CurrentEasternTime)) < 9; "(Off Shift)"; @Hour(@TextToTime(CurrentEasternTime)) >= 17; "(Off Shift)"; "(On Shift)")
This formula first checks for Sunday and Saturday. On those days, no matter what time, the "Off Shift" agent will run. For Monday through Friday, if the hour is less than 9 (before 9 AM), the "Off Shift" agent will run. If the hour is greater than or equal to 17 (5 PM), then the "Off Shift" agent will run. If all those other checks fail, then it is between 9 AM and 5 PM on a weekday, and the "On Shift" agent will run.