123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144(*********************************************************************************)(* Stog *)(* *)(* Copyright (C) 2012-2015 INRIA All rights reserved. *)(* Author: Maxence Guesdon, INRIA Saclay *)(* *)(* 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 the Free Software Foundation, version 3 of the License. *)(* *)(* This program is distributed in the hope that it will be useful, *)(* but WITHOUT ANY WARRANTY; without even the implied warranty of *)(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *)(* GNU General Public License for more details. *)(* *)(* You should have received a copy of the GNU General Public *)(* License along with this program; if not, write to the Free Software *)(* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA *)(* 02111-1307 USA *)(* *)(* As a special exception, you have permission to link this program *)(* with the OCaml compiler and distribute executables, as long as you *)(* follow the requirements of the GNU GPL in regard to all of the *)(* software in the executable aside from the OCaml compiler. *)(* *)(* Contact: Maxence.Guesdon@inria.fr *)(* *)(*********************************************************************************)openTypestypelang_abbrev=stringtypelang_data={days:stringarray;(* 7 *)months:stringarray;(* 12 *)string_of_date:date->string;string_of_datetime:date->string;}letint_of_weekday=function|`Sun->0|`Mon->1|`Tue->2|`Wed->3|`Thu->4|`Fri->5|`Sat->6letfrench=letdays=[|"dimanche";"lundi";"mardi";"mercredi";"jeudi";"vendredi";"samedi"|]inletmonths=[|"janvier";"février";"mars";"avril";"mai";"juin";"juillet";"août";"septembre";"octobre";"novembre";"décembre"|]inletstring_of_datedate=let((y,m,d),_)=Date.to_date_timedateinPrintf.sprintf"%s %d %s %d"days.(int_of_weekday(Date.weekdaydate))dmonths.(m-1)yinletstring_of_datetimedate=let(_,((h,mi,s),_))=Date.to_date_timedateinPrintf.sprintf"%s à %dh%02d"(string_of_datedate)hmiin{days;months;string_of_date;string_of_datetime}letenglish=letdays=[|"Sunday";"Monday";"Tuesday";"Wednesday";"Thursday";"Friday";"Saturday"|]inletmonths=[|"January";"February";"March";"April";"May";"June";"July";"August";"September";"October";"November";"December"|]inletstring_of_datedate=let((y,m,d),_)=Date.to_date_timedateinPrintf.sprintf"%s %d, %d"months.(m-1)dyinletstring_of_datetimedate=let(_,((h,mi,s),_))=Date.to_date_timedateinPrintf.sprintf"%s at %dh%02d"(string_of_datedate)hmiin{days;months;string_of_date;string_of_datetime}letlanguages=refTypes.Str_map.empty;;letregister_langabbrevdata=languages:=Types.Str_map.addabbrevdata!languages;;let()=register_lang"fr"french;;let()=register_lang"en"english;;letdefault_lang=refenglish;;letset_default_langabbrev=trydefault_lang:=Types.Str_map.findabbrev!languageswithNot_found->failwith(Printf.sprintf"Language %S not registered"abbrev);;letdata_of_lang=letwarned=Hashtbl.create10infunlang->matchlangwith|None->!default_lang|Someabbrev->tryTypes.Str_map.findabbrev!languageswithNot_found->ifnot(Hashtbl.memwarnedlang)thenbeginPrintf.eprintf"date_of_lang: unknown lang %S, using default"abbrev;Hashtbl.addwarnedlang();end;!default_langletget_monthlangm=assert(m>=1&&m<=12);(data_of_langlang).months.(m-1)letstring_of_datelangd=(data_of_langlang).string_of_datedletstring_of_datetimelangd=(data_of_langlang).string_of_datetimedletstring_of_date_optlang=functionNone->""|Somed->(data_of_langlang).string_of_dated;;letstring_of_datetime_optlang=functionNone->""|Somed->(data_of_langlang).string_of_datetimed;;