PermaLinkLotusScript to convert date to ISO 8601 format
posted Friday 2nd, January 2004
 



One of the main problems encountered with RSS feeds is dates that do not conform to the ISO 8601 specification. Here is some very simple LotusScript to convert a date to this format:
Dim dtLocal As NotesDateTime
Dim dtGMT As NotesDateTime
Dim strRSSDate As String
Set dtLocal = New NotesDateTime( Now )
Set dtGMT = New NotesDateTime( Left$(dtLocal.GMTTime, 22) )
strRSSDate = Format$(dtGMT.LSLocalTime, "yyyy-mm-ddThh:nn:ssZ")

Here's an explanation:
  1. The NotesDateTime value dtLocal is set to some valid date/time. For purposes of illustration here, I'm setting it to the current time Now.

  2. Then I cheat a little. I get the left-most 22 characters of the GMTTime property. The GMTTime property returns a string representing the date/time converted to Greenwich Mean Time (more and more frequently now being referred to as "Universal Time" - here are details about GMT and Universal Time). For example, at the time of this writing, the dtLocal field was set to a NotesDateTime object with a value of "01/02/2004 05:56:46 PM PST". The GMTTime property of dtLocal was "01/03/2004 01:56:46 AM GMT", so dtGMT received a value of "01/03/2004 01:56:46 AM" (the left-most 22 characters of the GMTTime property.

  3. By then getting the LSLocalTime value for that 22-character string, I could pass this new dateTime to the string Format$ method with a mask that results in a text representation of a date, compliant with the ISO 8601 specification. In this case, the final date respresentation is "2004-01-03T01:56:46Z". The "T" in the string designates where the time component is starting, and the "Z" indicates that we are representing this time value as GMT, so we therefore do not need to include a value to indicate a time zone offset.
OK, so what's the practical application? Well, on my blog, each RSS feed is served up from a Domino page element that includes an embedded view. The column formula builds the hmtl for each post or comment, and included many lines of formula to compute the needed date fields for the RSS feed. I've now converted my blog so that the embedded views reference a field on each document. That field is populated when the document is saved, so the view does not have to incur that overhead. For the initial conversion of existing documents, I wrote this agent and ran it from the main view within the Notes client interface to my blog. If you get my RSS feed, this change has been incorporated.

My plan is to also write routines for this date conversion using JavaScript, Java, and maybe @Formula.
Comments :
 
 

No documents found