cl-date-time-parser

https://github.com/tkych/cl-date-time-parser.git

git clone 'https://github.com/tkych/cl-date-time-parser.git'

(ql:quickload :cl-date-time-parser)
7

Last modified: 2014-05-18 14:39:27 tkych

version 0.1.03 (beta)

CL-Date-Time-Parser

In general, an implementation should be conservative in its sending behavior, and liberal in its receiving behavior. RFC791: Internet Protocol

There are a lot of formats to specify the date and time on the Web. For example:

The goal of cl-date-time-parser is to hide the difference between date-time formats, and enable to manage date and time as the one date-time format (Universal Time).

Function parse-date-time parses date-time-string, and return universal-time and fraction. Parsable date-time formats are:

In addition, parse-date-time can liberally parse the above formats with little broken.

Depends-on

Installation

cl-test-grid results:

Auto:
  1. CL-REPL> (ql:quickload :cl-date-time-parser)
Manual:
  1. SHELL$ git clone https://github.com/tkych/cl-date-time-parser
  2. CL-REPL> (push #p"/path-to-cl-date-time-parser/cl-date-time-parser/" asdf:*central-registry*)
  3. CL-REPL> (ql:quickload :cl-date-time-parser) or (asdf:load-system :cl-date-time-parser)

Examples

(parse-date-time "Thu, 23 Jul 2013 19:42:23 GMT") ;RFC 1123
=> 3583597343, 0

(parse-date-time "Thu Jul 23 19:42:23 2013") ;asctime
=> 3583597343, 0

(parse-date-time "Thursday, 23-Jul-13 19:42:23 GMT") ;RFC 1036
=> 3583597343, 0

(parse-date-time "2013-07-23T19:42:23Z") ;RFC 3339
=> 3583597343, 0

(parse-date-time "20130723T194223Z") ;ISO 8601
=> 3583597343, 0

(parse-date-time "Thu, 23 Jul 2013 19:42:23 JST")
=> 3583564943, 0

(parse-date-time "2013-07-23T19:42:23+09:00")
=> 3583564943, 0

(parse-date-time "23 Jul 13 19:42:23 +0900")
=> 3583564943, 0

(parse-date-time "Thu Jul 23 19:42:23 JST 2013")
=> 3583564943, 0

(parse-date-time "2013-07-23T19:42:23.45Z")
=> 3583597343, 0.45

(parse-date-time "2013-01-01")
=> 3565987200, 0

(parse-date-time "2013")
=> 3565987200, 0

(parse-date-time "1 Jan 13")
=> 3565987200, 0

(parse-date-time "2003-12-31T25:14:55Z") ;broken hours
=> 3281908495, 0
(parse-date-time "2004-01-01T01:14:55Z")
=> 3281908495, 0

(parse-date-time "2003-12-31T10:61:55Z") ;broken minuits
=> 3281857315, 0
(parse-date-time "2003-12-31T11:01:55Z")
=> 3281857315, 0

(parse-date-time "2003-12-31T10:14:61Z") ;broken seconds
=> 3281854501, 0
(parse-date-time "2003-12-31T10:15:01Z")
=> 3281854501, 0

(parse-date-time ";3-12-31T10:15:01Z") ;broken two-digit-years c.f. rfc3339, 3.
=> 3597473701, 0
(parse-date-time "2013-12-31T10:15:01Z")
=> 3597473701, 0

For further examples, please see Eval-Test in date-time-parser.lisp

Manual

[Function] PARSE-DATE-TIME date-time-stringuniversal-time, fraction

Parse date-time-string, and return universal-time and fraction. date-time-string must represent the date-time after 1900-01-01T00:00:00Z.

Parsable Formats:

Reference

Author, License, Copyright