(* OCaml script generating the current date and time. *)

#use "topfind";;
#require "calendar";;

open CalendarLib;;

type language = Fr | En
let language = ref Fr;;

Time_Zone.change Time_Zone.Local;;

Arg.parse 
    [ "-en", Arg.Unit (fun () -> language := En), "\t\tEnglish language";
      "-fr", Arg.Unit (fun () -> language := Fr), "\t\tFrench language" ]
    (fun _ -> ())
    "";;

if !language = Fr then begin
  (Printer.day_name := function
     | Date.Mon -> "lundi"   
     | Date.Tue -> "mardi"   
     | Date.Wed -> "mercredi"
     | Date.Thu -> "jeudi"   
     | Date.Fri -> "vendredi"
     | Date.Sat -> "samedi"  
     | Date.Sun -> "dimanche");
  Printer.month_name := function
    | Date.Jan -> "janvier"
    | Date.Feb -> "février"
    | Date.Mar -> "mars"   
    | Date.Apr -> "avril"  
    | Date.May -> "mai"    
    | Date.Jun -> "juin"   
    | Date.Jul -> "juillet"
    | Date.Aug -> "août"   
    | Date.Sep -> "septembre"
    | Date.Oct -> "octobre"  
    | Date.Nov -> "novembre" 
    | Date.Dec -> "décembre"
end;;

let en_ext = function
  | 1 -> "st"
  | 2 -> "nd"
  | _ -> "th";;

let fr_ext = function
  | 1 -> "er"
  | _ -> "";;

let header, trailer =
  match !language with
  | Fr -> 
      "<div class=\"trailer\">Dernière modification le ", 
      " (heure de Paris).</div>"
  | En ->
      "<div class=\"trailer\">Last modification the ", 
      " (UTC time).</div>"

let now = Calendar.now ();;

let format =
  let d = Calendar.day_of_month now in
  match !language with
  | Fr -> "%A %-d" ^ fr_ext d ^ " %B %Y à %Hh%Mmin%Ssec" 
  | En -> "%A %B %-d" ^ en_ext d ^ ", %Y at %Hh%Mmin%Ssec"

let () = 
  Printer.CalendarPrinter.print (header ^ format ^ trailer) now;
  print_newline ();;


This document was generated using caml2html