rfc3339-old:   RFC 3339 Timestamps
1 Introduction
2 Record Type
make-rfc3339-record
rfc3339-record?
rfc3339-record:  year
rfc3339-record:  month
rfc3339-record:  mday
rfc3339-record:  hour
rfc3339-record:  minute
rfc3339-record:  second
rfc3339-record:  secfrac
rfc3339-record:  offsetmin
rfc3339-record:  set-year!
rfc3339-record:  set-month!
rfc3339-record:  set-mday!
rfc3339-record:  set-hour!
rfc3339-record:  set-minute!
rfc3339-record:  set-second!
rfc3339-record:  set-secfrac!
rfc3339-record:  set-offsetmin!
rfc3339-record->list
3 Parsing
parse-rfc3339-string
string->rfc3339-record
rfc3339-string->list
rfc3339-string->vector
4 Formatting
write-rfc3339
rfc3339-record->string
5 Validation
check-rfc3339-record-date
check-rfc3339-record-time
check-rfc3339-record-offset
check-rfc3339-record-full
valid-full-rfc3339-record?
6 SRFI-19 Interoperability
rfc3339-string->srfi19-date/  constructor
7 History
8 Legal
2:0

rfc3339-old: RFC 3339 Timestamps🔗ℹ

Neil Van Dyke

1 Introduction🔗ℹ

The rfc3339-old package implements parsing, formatting, and simple validation of RFC 3339 date and time format, which is a subset of ISO 8601, intended for use in Internet protocols. This is an old Scheme library, for those programs that still need it.
Note that full Scheme support of ISO 8601 and various time-related computation is a very different project of the author, and not at all the intention of rfc3339-old.
Historically, rfc3339-old required R5RS, SRFI-6, SRFI-9, and two particular regular expression functions. This version of ths package has been reworked to not need srfi-lib, while maintaining the same external interface.

2 Record Type🔗ℹ

rfc3339-record is an abstract data type for the information in an RFC 3339 format time and date. (“rfc3339-string” is used in identifiers to denote the RFC 3339 format as a Scheme string.)

procedure

(make-rfc3339-record year    
  month    
  mday    
  hour    
  minute    
  second    
  secfrac    
  offsetmin)  rfc3339-record?
  year : (or/c #f nonnegative-integer?)
  month : (or/c #f nonnegative-integer?)
  mday : (or/c #f nonnegative-integer?)
  hour : (or/c #f nonnegative-integer?)
  minute : (or/c #f nonnegative-integer?)
  second : (or/c #f nonnegative-integer?)
  secfrac : (or/c #f real?)
  offsetmin : (or/c #f nonnegative-integer?)
Construct an rfc3339-record with the given field values. Each of year, month, mday, hour, minute, and second is #f or a nonnegative integer. secfrac is #f or a real number that is greater than or equal to 0.0 and less than 1.0. offsetmin is #f or a nonnegative integer. Note that offsetmin represents both the hour and minute components of an RFC 3339 string.

procedure

(rfc3339-record? x)  boolean?

  x : any/c
Predicate for rfc3339-record.

procedure

(rfc3339-record:year rec)  (or/c #f nonnegative-integer?)

  rec : rfc3339-record?
(rfc3339-record:month rec)  (or/c #f nonnegative-integer?)
  rec : rfc3339-record?
(rfc3339-record:mday rec)  (or/c #f nonnegative-integer?)
  rec : rfc3339-record?
(rfc3339-record:hour rec)  (or/c #f nonnegative-integer?)
  rec : rfc3339-record?
(rfc3339-record:minute rec)  (or/c #f nonnegative-integer?)
  rec : rfc3339-record?
(rfc3339-record:second rec)  (or/c #f nonnegative-integer?)
  rec : rfc3339-record?
(rfc3339-record:secfrac rec)  (or/c #f nonnegative-integer?)
  rec : rfc3339-record?
(rfc3339-record:offsetmin rec)  (or/c #f nonnegative-integer?)
  rec : rfc3339-record?
Get the respective field value of rfc3339-record rec.

procedure

(rfc3339-record:set-year! rec val)  void?

  rec : rfc3339-record?
  val : (or/c #f nonnegative-integer?)
(rfc3339-record:set-month! rec val)  void?
  rec : rfc3339-record?
  val : (or/c #f nonnegative-integer?)
(rfc3339-record:set-mday! rec val)  void?
  rec : rfc3339-record?
  val : (or/c #f nonnegative-integer?)
(rfc3339-record:set-hour! rec val)  void?
  rec : rfc3339-record?
  val : (or/c #f nonnegative-integer?)
(rfc3339-record:set-minute! rec val)  void?
  rec : rfc3339-record?
  val : (or/c #f nonnegative-integer?)
(rfc3339-record:set-second! rec val)  void?
  rec : rfc3339-record?
  val : (or/c #f nonnegative-integer?)
(rfc3339-record:set-secfrac! rec frac)  void?
  rec : rfc3339-record?
  frac : (or/c #f real?)
(rfc3339-record:set-offsetmin! rec val)  void?
  rec : rfc3339-record?
  val : (or/c #f nonnegative-integer?)
Set the respective field value of rfc3339-record rec to val.

procedure

(rfc3339-record->list rec)

  
(list/c (or/c #f nonnegative-integer?)
        (or/c #f nonnegative-integer?)
        (or/c #f nonnegative-integer?)
        (or/c #f nonnegative-integer?)
        (or/c #f nonnegative-integer?)
        (or/c #f nonnegative-integer?)
        (or/c #f real?)
        (or/c #f nonnegative-integer?))
  rec : rfc3339-record?
Yields a list of the rfc3339-record rec fields,corresponding to the arguments of the make-rfc3339-record procedure.
> (rfc3339-record->list (make-rfc3339-record 1985 4 12 23 20 50 0.52 0))
  (1985 4 12 23 20 50 0.52 0)

3 Parsing🔗ℹ

The parsing procedures are for constructing rfc3339-records, lists, and vectors from RFC 3339 strings. The underlying parser can also apply a user-supplied closure directly.

procedure

(parse-rfc3339-string str constructor)  any

  str : string
  constructor : procedure?
Parses RFC 3339 string str and applies procedure constructor with the parsed values. The arguments of constructor are the same as those of make-rfc3339-record.

procedure

(string->rfc3339-record str)  rfc3339-record?

  str : string?
Yields an rfc3339-record from RFC 3339 string str.

procedure

(rfc3339-string->list str)  list?

  str : string?
(rfc3339-string->vector str)  vector?
  str : string?
Yields a list or vector (respectively) from the parsed values of RFC 3339 string str. The list and vector elements correspond to the arguments of make-rfc3339-record.
> (rfc3339-string->list   "1985-04-12T23:20:69.52+5:0")
  (1985 4 12 23 20 69 0.52 300)
> (rfc3339-string->vector "1985-04-12T23:20:69.52+5:0")
  #(1985 4 12 23 20 69 0.52 300)

4 Formatting🔗ℹ

An RFC 3339 string format can be obtained from an rfc3339-record.

procedure

(write-rfc3339 rec port)  void?

  rec : rfc3339-record?
  port : output-port?
Write an RFC 3339 string format of rfc3339-record rec to output port port.

procedure

(rfc3339-record->string rec)  string?

  rec : rfc3339-record?
Yield an RFC 3339 string format of rfc3339-record rec as a Scheme string.

5 Validation🔗ℹ

A few procedures are provided for validating rfc3339-records.

procedure

(check-rfc3339-record-date rec explain?)  (or/c #f list?)

  rec : rfc3339-record?
  explain? : boolean?
(check-rfc3339-record-time rec explain?)  (or/c #f list?)
  rec : rfc3339-record?
  explain? : boolean?
(check-rfc3339-record-offset rec explain?)  (or/c #f list?)
  rec : rfc3339-record?
  explain? : boolean?
Check the respective component of rfc3339-record rec for completeness and correctness, yielding #f iff no problems were detected. If explain? is true, then true values of these procedures are lists that “explain” the error detected. For example:
> (check-rfc3339-record-date
   (string->rfc3339-record "1999-02")    #t)
  (missing mday)
> (check-rfc3339-record-date
   (string->rfc3339-record "1999-02-29") #t)
  (invalid mday 29 (and (integer? mday) (<= 1 mday (month-days year month))))
> (check-rfc3339-record-date
   (string->rfc3339-record "2000-02-29") #t)
  #f
Leap years are calculated correctly. Leap seconds (61st seconds in minutes) are tolerated in any date and time.

procedure

(check-rfc3339-record-full rec explain?)  (or/c #f list?)

  rec : rfc3339-record?
  explain? : boolean?
Checks all three components. See check-rfc3339-record-date et al.

procedure

(valid-full-rfc3339-record? rec)  boolean?

  rec : rfc3339-record?
Yields a true value iff check-rfc3339-record-full yields a false value.

6 SRFI-19 Interoperability🔗ℹ

This package has no dependency on SRFI-19, but a procedure is provided for constructing a SRFI-19 date. This is for historical reasons, given this package’s origin as a Scheme library; with Racket, you normally want to use Racket standard libraries, rather than SRFIs.

procedure

(rfc3339-string->srfi19-date/constructor str    
  make-date)  any
  str : string
  make-date : procedure?
Contruct a SRFI-19 date from an RFC 3339 string, where str is the string, and make-date is the SRFI-19 date constructor. Applications using SRFI-19 may wish to define an rfc3339-string->date procedure:
(define (rfc3339-string->date str)
  (rfc3339-string->srfi19-date/constructor str make-date))

7 History🔗ℹ

8 Legal🔗ℹ

Copyright 2005, 2009, 2016 Neil Van Dyke. This program is Free Software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. See http://www.gnu.org/licenses/ for details. For other licenses and consulting, please contact the author.