Wednesday, July 9, 2014

Allegro CL - Tech Corner - Universal date/time parser facility

New universal date/time parser facility

A new universal date/time parser facility was added by a recent patch. It defines the new functions string-to-universal-time and universal-time-to-string. The first function takes a string specifying a date and time in any of a variety of standard formats and returns the corresponding universal time. The second function converts a universal time to one of those formats. For example,
(string-to-universal-time "20031231" :format :iso8601)
  => 3281846400 :iso8601 :time-zone-not-specified
(universal-time-to-string 3281846400 :format :iso8601)
  => "2003-12-31T00:00:00"
(string-to-universal-time "20031231")
  => 3281846400 :iso8601 :time-zone-not-specified
(universal-time-to-string 3281846400)
  => "2003-12-31T00:00:00"
(string-to-universal-time "20031231" :format :iso8601 :native t)
  => # nil nil

(string-to-universal-time "20031231" :format :iso8601)
  => 3281846400 :iso8601 :time-zone-not-specified
(universal-time-to-string 3281846400 :format :iso8601)
  => "2003-12-31T00:00:00"
(string-to-universal-time "20031231")
  => 3281846400 :iso8601 :time-zone-not-specified
(universal-time-to-string 3281846400)
  => "2003-12-31T00:00:00"
(string-to-universal-time "20031231" :format :iso8601 :native t)
  => # nil nil
This new facility is separate from the existing date-time module but, as the last example indicates, integrated with it. The date-time module is described in date-time.htm The new universal date time parser is described here.

No comments:

Post a Comment