caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Pierre Weis <pierre.weis@inria.fr>
To: alan.schmitt@polytechnique.org (Alan Schmitt)
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] date manipulation library
Date: Wed, 17 Sep 2003 09:57:16 +0200 (MET DST)	[thread overview]
Message-ID: <200309170757.JAA18757@pauillac.inria.fr> (raw)
In-Reply-To: <20030915143708.GK2354@alan-schm1p> from Alan Schmitt at "Sep 15, 103 10:37:08 am"

Hi Alan,

> I am writing an application that needs to manipulate dates. More 
> precisely, it needs a function that, given a date and a duration (12 
> days, 2 weeks, 3 months ...) returns the date at the end of the 
> duration. Is there a library providing such a thing ? (I have looked at 
> NetDate in ocamlnet, but I cannot find a way to do it that is not a hack 
> (convert the date to float, add the number of seconds corresponding to 
> the duration (tricky in the case of months), and convert back to date 
> format)).
> 
> Alan Schmitt
> 
> -- 
> The hacker: someone who figured things out and made something cool happen.
> 
> -------------------
> To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
> Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners

As part of the bazar-ocaml, the ``htmlc'' template files compiler for
HTML is distributed for years now.
As part of htmlc, a complete (i.e. fairly rich) date manipulation
library is distributed.
It has been used for years in various contexts, is properly
documented, and has no known bugs.

If this library approximately satisfies your needs, let me know if
something is missing, or if you want to add more functionalities: we
can share the development!

To give you an idea, here is the interface for the (auxilliary) date module:

-------------------------------------------------------------------------
(* Getting the time of day. *)

val local_date_of_day : Lang.t -> string;;
 (* Return the current date as a string according to the [lang] argument.
    Assumes the local time zone. *)

val date_of_day : Lang.t -> string;;
 (* Return the current date as a string according to the [lang] argument.
    Assumes Greenwich meridian time zone, also known as UTC. *)

val date_uk_of_day : unit -> string;;
val date_fr_of_day : unit -> string;;
 (* The string representation of the current time of day, respectively
    in english and french. Assumes the local time zone. *)

val date : unit -> string;;
 (* Synomym for [date_of_day Uk]. *)

val local_date : unit -> string;;
 (* Synomym for [local_date_of_day Uk]. *)

val time_of_day : unit -> tm;;
 (* Return the time of day as a Unix time. Assumes Greenwich meridian
    time zone, also known as UTC. *)

val string_of_time : Lang.t -> tm -> string;;
 (* Translate a Unix time to a string according to the [lang]
    argument. *)

 (* Last modification time of a file. *)
val last_modification_time_of_file : string -> tm;;
val last_modification_date_of_file : Lang.t -> string -> string;;
 (* Assumes Greenwich meridian time zone. *)
-------------------------------------------------------------------------

And now, the interface file for lib_date library:

-------------------------------------------------------------------------
val year_is_leap : int -> bool;;
 (* Checks if the int argument represents a leap year. *)
val last_day_of_month : int -> int -> int;;
 (* [last_day_of_month month year] returns the number of the last day
    of the month for the given year. *)
val date_is_valid : int -> int -> int -> bool;;
 (* [date_is_valid month_day month year] checks if the given arguments
    represent a valid date. *)
val compare_date : (int * int * int) -> (int * int * int) -> int;;
 (* Compares two dates represented as triple of integers [(month_day,
    month, year)], with the same convention as the polymorphic
    comparison [compare]. [compare_date (d1, m1, y1) (d2, m2, y2)]
    returns respectively [0], [1], or [-1], if date [(d1, m1, y1)] is
    respectively equal to, greater than, or lower than
    the date [(d2, m2, y2)]. *)
val week_day_of_date : int -> int -> int -> int;;
 (* [week_day_of_date month_day month year] return the number of the
    day in the week that corresponds to the date
    [month_day, month, year].
    (Week days are numbered from [0] for sunday to [6] for saturday.) *)

(* Translation from integer representation to day and month names. *)

val string_of_month : Lang.t -> int -> string;;
val string_of_week_day : Lang.t -> int -> string;;
 (* Mapping from days and months, represented as theirs numbers, to
    their usual character string names.
    The numbering starts from 0: thus Sunday and January have number 0.
    These functions raise [Invalid_argument] if their arguments are out of
    the proper range ([0..6] for day numbers and [0..11] for month
    numbers), or if the language is not supported. *)
val string_of_date : Lang.t ->
    int -> int -> int ->
    string * string * string * string;;
 (* [string_of_date lang d m y] calculates the week day associated
    with the date [d, m, y], and returns the string representations of
    the tuple [(week_day, d, m, y)].
    For instance [string_of_date Uk (21, 3, 2000)] is
    [("Tuesday", "21", "March", "2000")]. *)

val string_of_full_date : Lang.t ->
    int -> int -> int -> int ->
    string * string * string * string;;
 (* [string_of_full_date lang w d m y] returns a string representation
    of the tuple [(w, d, m, y)], supposed to be a date [d, m, y] with
    week day [w]. *)

val string_of_mois : int -> string;;
val string_of_jour : int -> string;;
 (* Same as above for french days and months. *)

val week_day_of_string : Lang.t -> string -> int;;
val month_of_string : Lang.t -> string -> int;;
 (* Map a day  (resp. a month) represented as a string for the language
    [lang] to the corresponding number. Recognition of valid strings is
    case unsensitive and usual abbreviations are accepted.
    Raise [Invalid_argument "unknown language"], if the language is
    not supported. *)

val format_date : Lang.t -> int -> int -> int -> int -> string;;
 (* [format_date lang month_day month week_day year] returns a string
    representation of a date according to the language [lang]. The
    date is represented by 4 integers: [week_day] and
    [month] are the numbers encoding the names of the day and
    the name of the month. Their should be in a range suitable for calling
    [string_of_month] and [string_of_week_day].
    The [month_day] and [year] arguments are the number of the day in
    the month and the number of the year. If the year number is lesser
    than 1000, then 1900 is added to it.
    There is no verification that the date is valid.
    For instance,
    [format_date Uk 31 12 5 00] is ["Friday, December 31, 1900"],
    [format_date Uk 31 12 5 101] is ["Friday, December 31, 2001"],
    [format_date Uk 31 12 5 2000] is ["Friday, December 31, 2000"]. *)
val string_of_Uk_date : int -> int -> int -> int -> string;;
val string_of_Fr_date : int -> int -> int -> int -> string;;
 (* Same as above for french or english translations. *)

val parse_date : Lang.t -> string -> int * int * int * int;;
 (* [parse_date lang s] parse the string [s] according to the language
 [lang], and return a date, the validity of which is not verified.
 Separators between words in [s] can be any of [' '], ['\t'], ['/'], [','],
 ['-'], or ['.'] and can be repeated.
 - If only one word is found in [s], this word is supposed to be made of
 digits that encode the date. Eight digits means [ddmmyyyy] (as
 [01032000] to mean first of March 2000), six digits means [ddmmyy]
 (as [010300] to mean first of March 1900), less than six digits means
 [yy] or [yyyy] (only the year number is provided, day and month
 default to first of January).
 - If two words are found, they are supposed to be the month and the year
 in that order, and the resulting date defaults to the first day of the
 given month and year.
 - If three words are found, they are supposed to be the month day, the
 month and the year. Order is language dependant, and follows the
 conventions of [format_date].
 - If four words are found, they are supposed to be the week day, the
 month day, the month and the year. Order is language dependant, and
 follows the conventions of [format_date].

 Note: if necessary the week day of the date may be found using the
 function [week_day_of_date]. *)

val parse : string -> int * int * int * int;;
 (* [parse s] is equivalent to [parse_date Uk s]. *)
val format : int -> int -> int -> int -> string;;
 (* [format month_day month week_day year] is equivalent to
    [format_date Uk month_day month week_day year]. *)

val valid_date : Lang.t -> string -> int * int * int * int;;
 (* [valid_date lang s] parse the string [s] according to the
 language [lang] and return a valid date or raises [invalid_arg]. *)

val normalize_date : Lang.t -> string -> string * string * string * string;;
----------------------------------------------------------------------------

Hope this helps,

Pierre Weis

INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://pauillac.inria.fr/~weis/

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


  parent reply	other threads:[~2003-09-17  7:57 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-09-15 14:37 Alan Schmitt
2003-09-15 14:48 ` Antoine Schweitzer-Chaput
2003-09-15 15:21 ` Xavier Leroy
2003-09-15 15:40   ` Alan Schmitt
2003-09-15 16:38   ` David Brown
2003-09-15 15:22 ` Julien Signoles
2003-09-15 18:34   ` Stefano Zacchiroli
2003-09-15 18:45     ` Maxence Guesdon
2003-09-15 23:27     ` Julien Signoles
2003-09-16  7:20       ` Stefano Zacchiroli
2003-09-16  7:32         ` Mattias Waldau
2003-09-16  8:29           ` Benjamin Geer
2003-09-16 18:21             ` [Caml-list] Will Emacs camldebug-mode need an update for 3.07? Mattias Waldau
2003-09-15 15:25 ` [Caml-list] date manipulation library Matthieu Sozeau
2003-09-17  7:57 ` Pierre Weis [this message]
2003-09-17  8:24   ` Mattias Waldau
2003-09-17 15:17     ` Pierre Weis
2003-09-19 14:48       ` [Caml-list] A plea for clear licenses (Was: date manipulation library) Florian Hars
2003-09-20 14:22         ` [Caml-list] " Pierre Weis
2003-09-20 18:42         ` [Caml-list] " skaller
2003-09-21 16:33           ` Richard Jones
2003-09-23  6:28           ` [Caml-list] A plea for clear licenses Florian Hars
2003-09-23 23:17             ` Rafael 'Dido' Sevilla
2003-09-23 23:29               ` Michael Beach
2003-09-17  9:19   ` [Caml-list] date manipulation library Stefano Zacchiroli
2003-09-17 15:28     ` Pierre Weis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200309170757.JAA18757@pauillac.inria.fr \
    --to=pierre.weis@inria.fr \
    --cc=alan.schmitt@polytechnique.org \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).