package http-date

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

HTTP timestamp decoders and encoders complaint to RFC 9110 (HTTP Semantics).

The current supported formats for decoding/encoding are as follows:

  • IMF(Internet Message Format) date, eg "Sun, 06 Nov 1994 08:49:37 GMT"
  • RFC 850 date, eg "Sunday, 06-Nov-94 08:49:37 GMT" Obsolete
  • asctime date, eg "Sun Nov 6 08:49:37 1994" Obsolete

HTTP timestamps are always in GMT/UTC

References

type encoding =
  1. | IMF
    (*

    Internet Message Format fixdate, eg "Sun, 06 Nov 1994 08:49:37 GMT"

    *)
  2. | RFC850
    (*

    RFC 850 date, eg "Sunday, 06-Nov-94 08:49:37 GMT" Obsolete

    *)
  3. | ASCTIME
    (*

    asctime date, eg "Sun Nov 6 08:49:37 1994" Obsolete

    *)

Encoding format specification for encode.

Note:

RFC850 and ASCTIME are both considered obsolete. It is not advised for usage in new applications. They are both included here for compliance of RFC 9110 and for backwards compatibility. IMF is the recommended format for usage.

val decode : ?century:int -> string -> Ptime.t

decode s is ptime if s contains a valid textual representation of formats defined in encoding.

century An integer value representing century component of a year. This is used to decode the correct year component of ptime, if s contains RFC 850 encoded date value, e.g. year 96 is decoded as 1996 if century = 19. If century is not given, then the decoded year component is used as is, i.e. 96.

decoding string in IMF fix date format:

Http_date.decode "Sun, 06 Nov 1994 08:49:37 GMT"
  • raises Invalid_argument

    if s contains date format not supported by encoding.

Encode HTTP timestamps

val encode : ?encoding:encoding -> Ptime.t -> string

encode ?encoding ptime encodes ptime into a given encoding textual representation. The default value of encoding is IMF.

Pretty Printing timestamps

val pp : ?encoding:encoding -> Stdlib.Format.formatter -> Ptime.t -> unit

pp ?encoding fmt ptime is like encode ?encoding ptime except it prints out to fmt instead of a string.

OCaml

Innovation. Community. Security.