Saturday, 01 January, 2005

Date and time format finalized

I spent a little more time on the date and time parsing code that I discussed on December 17.  I have created a .NET structure, called W3CDateTime, which maintains the time and UTC offset.  The class can parse RFC822 format dates as well as W3C date time values.  The structure interface mimics the interface for System.DateTime, including the ability to subtract dates to get a TimeSpan value, to add TimeSpan values to dates, and to compare the date values.  It includes all of the System.DateTime functionality except the internationalization options for input and output and some of the date format conversions (OLE Automation and File Date Time).

Creating the structure was an interesting study in the use of regular expressions and interface design.  It also took a whole lot more code than I expected, mostly because I had to implement a whole lot of simple properties and small methods that take three lines of syntactic sugar for a single line of functionality.

I discussed the development and implementation of the structure, complete with source code in C# and Visual Basic in my .NET Reference Guide column.  The full article is here.