package yocaml

  1. Overview
  2. Docs

Module Archetype.DatetimeSource

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.

Sourcetype 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

Sourcetype 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?).

Sourcetype day = private int

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

Sourcetype hour = private int

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

Sourcetype min = private int

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

Sourcetype sec = private int

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

Sourcetype 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

Sourceval 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

Sourceval 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

Sourcemodule Infix : sig ... end

A collection of infix operators for comparing dates.

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

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

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

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

Sourceval (>) : t -> t -> bool

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

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

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

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

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

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

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

Util

Sourceval compare : t -> t -> int

Comparison between datetimes.

Sourceval equal : t -> t -> bool

Equality between datetime.

Sourceval min : t -> t -> t

min a b returns the smallest a or b.

Sourceval max : t -> t -> t

max a b returns the greatest a or b.

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

Pretty printer for date.

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

Pretty printer according to the RFC822 specification.

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

Pretty printer according to the RFC822 specification.

Sourceval dummy : t

A dummy datetime.