package yocaml

  1. Overview
  2. Docs

Describes a date associated with a time. The "default" date format is yyyy-mm-dd HH:mm-ss. In addition to describing data as injectable or readable, the module provides a naive date processing API that seems to be useful for describing a blog.

Types

Types used to describe a date.

type month =
  1. | Jan
  2. | Feb
  3. | Mar
  4. | Apr
  5. | May
  6. | Jun
  7. | Jul
  8. | Aug
  9. | Sep
  10. | Oct
  11. | Nov
  12. | Dec

Type describing a month

type year = private int

Type describing a year (positive int, Because let's face it, we're not going to publish blogs during antiquity, are we?).

type day = private int

Type describing a day. A number from 1 to 31 (depending on the month).

type hour = private int

Type describing an hour. A number from 0 to 23.

type min = private int

Type describing a minut. A number from 0 to 59.

type sec = private int

Type describing a second. A number from 0 to 59.

type t = {
  1. year : year;
  2. month : month;
  3. day : day;
  4. hour : hour;
  5. min : min;
  6. sec : sec;
}

Describes a complete date. As all potentially different values are private, the type must not be abstract (or private), as it must go through validation phases.

Building date

val make : ?time:(int * int * int) -> year:int -> month:int -> day:int -> unit -> t Data.Validation.validated_value

make ?time ~year ~month ~day () Builds a date when all data and validates all data.

validate data try to read a date from a generic representation.

Dealing with date as metadata

val normalize : t -> Data.t

normalize datetime render data generically (with additional fields). Here is the list of fields:

  • year: int the year value
  • month: int the month value
  • day: int the day value
  • hour: int the hour value
  • min: int the min value
  • sec: int the sec value
  • has_time: bool true if time is different than 0,0,0, false otherwise
  • day_of_week: int a number that represent the day of week (0: Monday, 6: Sunday)
  • repr: record some representation of the date

Representation of a date (field repr) :

  • repr.month: string a three-letters ident for the month
  • repr.day_of_week: string a three-letters ident for the day of the week
  • repr.datetime: string a string representation of the date YYYY-mm-dd HH:mm:ss
  • repr.date: string a string representation of the date YYYY-mm-dd
  • repr.time: string a string representation of the date HH:mm:ss

Generating so much data may seem strange, but it allows the user to decide precisely, in his template, how to use/represent a date, which, in my opinion, is a good thing. No ?

Infix operators

module Infix : sig ... end

A collection of infix operators for comparing dates.

val (=) : t -> t -> bool

a = b returns true if a equal b, false otherwise.

val (<>) : t -> t -> bool

a <> b returns true if a is not equal to b, false otherwise.

val (>) : t -> t -> bool

a > b returns true if a is greater than b, false otherwise.

val (>=) : t -> t -> bool

a > b returns true if a is greater or equal to b, false otherwise.

val (<) : t -> t -> bool

a > b returns true if a is smaller than b, false otherwise.

val (<=) : t -> t -> bool

a > b returns true if a is smaller or equal to b, false otherwise.

Util

val compare : t -> t -> int

Comparison between datetimes.

val equal : t -> t -> bool

Equality between datetime.

val min : t -> t -> t

min a b returns the smallest a or b.

val max : t -> t -> t

max a b returns the greatest a or b.

val pp : Format.formatter -> t -> unit

Pretty printer for date.

val pp_rfc822 : ?tz:string -> unit -> Format.formatter -> t -> unit

Pretty printer according to the RFC822 specification.

val pp_rfc3339 : ?tz:string -> unit -> Format.formatter -> t -> unit

Pretty printer according to the RFC822 specification.

val dummy : t

A dummy datetime.

OCaml

Innovation. Community. Security.