Module CalendarLib.Printer

Pretty printing and parsing from string. In the following, an "event" is either a date or a time or a calendar.

This module implements different printers: one for each kind of events. The three printers have the same signature: they mainly implement a fprint : string -> formatter -> t -> unit function and a from_fstring : string -> string -> t function. The first one prints an event according to a format string (see below for a description of such a format). The second one converts a string to an event according to a format string.

A format string follows the unix utility 'date' (with few modifications). It is a string which contains two types of objects: plain characters and conversion specifiers. Those specifiers are introduced by a % character and their meanings are:

By default, date pads numeric fields with zeroes. Two special modifiers between `%' and a numeric directive are recognized:

@example a possible output of %D is 01/06/03 @example a possible output of the date is %B, the %-dth is the date is January, the 6th is matched by ; @example a possible output of %c is Thu Sep 18 14:10:51 2003.

Internationalization

You can manage the string representations of days and months. By default, the English names are used but you can change their by setting the references day_name and month_name.

@example day_name := function Date.Mon -> "lundi" | Date.Tue -> "mardi" | Date.Wed -> "mercredi" | Date.Thu -> "jeudi" | Date.Fri -> "vendredi" | Date.Sat -> "samedi" | Date.Sun -> "dimanche" sets the names of the days to the French names.

val day_name : ( Date.day -> string ) Stdlib.ref

String representation of a day.

val name_of_day : Date.day -> string

name_of_day d is equivalent to !day_name d. Used by the specifier %A.

val short_name_of_day : Date.day -> string

short_name_of_day d returns the 3 first characters of name_of_day d. Used by the specifier %a.

val month_name : ( Date.month -> string ) Stdlib.ref

String representation of a month.

val name_of_month : Date.month -> string

name_of_month m is equivalent to !day_month m. Used by the specifier %B.

val short_name_of_month : Date.month -> string

short_name_of_month d returns the 3 first characters of name_of_month d. Used by the specifier %b.

val set_word_regexp : Re.Str.regexp -> unit

Set the regular expression used to recognize words in from_fstring. Default is [a-zA-Z]*.

  • since 1.10

Printers (including parsers from string)

Printers also contain parsers which allow to build events from strings.

module type S = sig ... end

Generic signature of a printer-parser.

module Date : S with type t = Date.t

Date printer. Specifiers which use time functionalities are not available on this printer. Default format is %i.

module DatePrinter : S with type t = Date.t
module Time : S with type t = Time.t

Time printer. Specifiers which use date functionalities are not available on this printer. Default format is %T.

module TimePrinter : S with type t = Time.t
module Ftime : S with type t = Ftime.t

Ftime printer. Seconds are rounded to integers before pretty printing. Specifiers which use date functionalities are not available on this printer. Default format is %T.

module Precise_Calendar : S with type t = Calendar.Precise.t

Precise Calendar printer. Default format is %i %T.

module Calendar : S with type t = Calendar.t

Calendar printer. Default format is %i %T.

module CalendarPrinter : S with type t = Calendar.t

Precise Fcalendar printer. Seconds are rounded to integers before pretty printing. Default format is %i %T.

module Fcalendar : S with type t = Fcalendar.t

Fcalendar printer. Seconds are rounded to integers before pretty printing. Default format is %i %T.