Module Date


module Date: Libs.ExtNetdate.Netdate
Support for dates, including parsing and formating.
Author(s): Gerg Stolpmann (OCamlNet module), David Teller


Note
Several functions of this module are defined with respect to a base date called the epoch. While the definition of epoch may be system-dependent, most systems take as epoch 00:00:00 UTC, January 1, 1970.

type t = {
   year : int; (*the complete year*)
   month : int; (*a month, between 1 and 12*)
   day : int; (*a day, between 1 and 31*)
   hour : int; (*the number of hours since midnight, between 0 and 23*)
   minute : int; (*the number of minutes since the beginning of the hour, between 0 and 59*)
   second : int; (*the number of seconds since the begining of the minute, between 0 and 59*)
   zone : int; (*the local zone offset, in minutes of advance wrt UTC. For instance, 60 = UTC+0100.*)
   week_day : int; (*the number of days since sunday, between 0 and 6 Note As a special exception, week_day may be -1, if the day of the week is unknown*)
}
The representation of a date in time.
val now : unit -> t
now () returns the current date, as expressed in the local zone.
val localzone : int
The offset in minutes for the local time zone from the UTC
val create : ?zone:int -> float -> t
Convert the time (seconds since the epoch) to a date/time record
val parse : string -> t
Parse a string and return a date/time record
val since_epoch : t -> float
Convert a date/time record into the time (seconds since the epoch)
val parse_epoch : string -> float
Parse a string and return the time (seconds since the epoch
val format_to : 'a Extlib.InnerIO.output -> ?fmt:string -> t -> unit
Format a date/time record according to the format string and outputs the resulting string to the channel.

The format string consists of zero or more conversion specifications and ordinary characters. All ordinary characters are output directly to the channel. A conversion specification consists of the '%' character and one other character.

fmt : An optional format stating how the date/time should be displayed. If unspecified, this will use the same format as Date.mk_mail_date.

The conversion specifications are:

val format : ?fmt:string -> t -> string
Format a date/time record as a string
fmt : An optional format stating how the date/time should be displayed. If unspecified, this will use the same format as Date.mk_mail_date.
val mk_mail_date : ?zone:int -> float -> string
Convert the time (seconds since the epoch) to a date string that conforms to RFC 1123 (which updates RFC 822).

Example: "Sun, 06 Nov 1994 08:49:37 -0500".

val mk_usenet_date : ?zone:int -> float -> string
Convert the time (seconds since the epoch) to a date string that conforms to RFC 1036 (which obsoletes RFC 850).

Example: "Sunday, 06-Nov-94 08:49:37 -0500".

Note that this format has only two digits for the year.


Boilerplate code


S-Expressions

val t_of_sexp : Sexplib.Sexp.t -> t
val sexp_of_t : t -> Sexplib.Sexp.t

Printing

val print : 'a Extlib.InnerIO.output -> t -> unit
Print a date with a default format.

The default format used is the same as Date.mk_mail_date