(* COCANWIKI - a wiki written in Objective CAML.
* Written by Richard W.M. Jones <rich@merjis.com>.
* Copyright (C) 2004 Merjis Ltd.
- * $Id: cocanwiki_date.ml,v 1.3 2005/11/23 11:32:38 rich Exp $
+ * $Id: cocanwiki_date.ml,v 1.4 2006/03/27 16:43:44 rich Exp $
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
open Cgi
open Printf
-let short_weekday = function
- | Date.Sun -> "Sun" | Date.Mon -> "Mon" | Date.Tue -> "Tue"
- | Date.Wed -> "Wed" | Date.Thu -> "Thu" | Date.Fri -> "Fri"
- | Date.Sat -> "Sat"
-
-let short_month = function
- | 1 -> "Jan" | 2 -> "Feb" | 3 -> "Mar" | 4 -> "Apr"
- | 5 -> "May" | 6 -> "Jun" | 7 -> "Jul" | 8 -> "Aug"
- | 9 -> "Sep" | 10 -> "Oct" | 11 -> "Nov" | 12 -> "Dec"
- | _ -> invalid_arg "short_month"
-
-let long_month = function
- | 1 -> "January" | 2 -> "February" | 3 -> "March" | 4 -> "April"
- | 5 -> "May" | 6 -> "June" | 7 -> "July" | 8 -> "August"
- | 9 -> "September" | 10 -> "October" | 11 -> "November" | 12 -> "December"
- | _ -> invalid_arg "short_month"
-
(* Generate a printable datestamp for pages. *)
-let printable_date' date =
- sprintf "%d %s %04d" date.Dbi.day (short_month date.Dbi.month) date.Dbi.year
+let printable_date' = Printer.DatePrinter.sprint "%d %b %Y"
-let printable_date (date, _) = printable_date' date
+let printable_date = Printer.CalendarPrinter.sprint "%d %b %Y"
-let printable_date_time (date, time) =
- sprintf "%d %s %04d %02d:%02d" date.Dbi.day (short_month date.Dbi.month)
- date.Dbi.year time.Dbi.hour time.Dbi.min
+let printable_date_time = Printer.CalendarPrinter.sprint "%d %b %Y %H:%M"
(* ISO 8601 timestamp. *)
-let iso_8601_date_time (date, time) =
- sprintf "%04d-%02d-%02dT%02d:%02d:%02d"
- date.Dbi.year date.Dbi.month date.Dbi.day
- time.Dbi.hour time.Dbi.min time.Dbi.sec ^
- match time.Dbi.timezone with
- | None -> "Z"
- | Some t -> sprintf "+%02d:00" t
+let iso_8601_date_time = Printer.CalendarPrinter.sprint "%iT%TZ"