(* COCANWIKI - a wiki written in Objective CAML.
* Written by Richard W.M. Jones <rich@merjis.com>.
* Copyright (C) 2004 Merjis Ltd.
- * $Id: cocanwiki_ext_calendar.ml,v 1.1 2004/10/21 11:42:05 rich Exp $
+ * $Id: cocanwiki_ext_calendar.ml,v 1.2 2005/04/02 17:30:54 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 ExtList
-open GregorianDate
-
open Cocanwiki
open Cocanwiki_template
open Cocanwiki_strings
let year_template = _get_template "calendar_year.html"
let year_1m_template = _get_template "calendar_year_1m.html"
+(* Check a date is valid. *)
+let check_date (y, m, d) =
+ try
+ let t = Date.make y m d in
+ Date.year t = y
+ && Date.int_of_month (Date.month t) = m
+ && Date.day_of_month t = d
+ with
+ Date.Out_of_bounds | Date.Undefined -> false
+
let rec range a b =
if a <= b then
a :: range (a+1) b
let mm = int_of_string (String.sub str 5 2) in
let dd = int_of_string (String.sub str 8 2) in
let date = (yyyy, mm, dd) in
- if GregorianDate.check_date date then date else raise Not_found
+ if check_date date then date else raise Not_found
)
else
raise Not_found
(* Return true if there are any events on a particular day. *)
let has_events date = List.exists (fun (d, _) -> date = d) pages in
+ let int_of_day_of_week = function
+ | Date.Sun -> 0 | Date.Mon -> 1 | Date.Tue -> 2
+ | Date.Wed -> 3 | Date.Thu -> 4 | Date.Fri -> 5
+ | Date.Sat -> 6
+ in
+
(* Generate each month template separately ...
* Wow, finally found a place I can use a for loop.
*)
template#set "yyyy" (string_of_int yyyy);
template#set "mm" (sprintf "%02d" mm);
template#set "month_name" (long_month mm);
- let dow = GregorianDate.day_of_week (yyyy, mm, 1) in
- let dow = if dow = 7 then 0 else dow in
- let max_dd = GregorianDate.days_in_month yyyy mm in
- let dd = ref (1-dow) in
+ let dow = Date.day_of_week (Date.make yyyy mm 1) in
+ let max_dd = Date.days_in_month (Date.make yyyy mm 1) in
+ let dd = ref (1 - int_of_day_of_week dow) in
let rows = ref [] in
for r = 0 to 5 do (* up to 5 rows ... *)
let cols = ref [] in
let is_day = !dd >= 1 && !dd <= max_dd in
let clasz =
if is_day then (
+ let is_weekend =
+ match Date.day_of_week (Date.make yyyy mm !dd) with
+ Date.Sat | Date.Sun -> true | _ -> false in
let date = yyyy, mm, !dd in
- let is_weekend = GregorianDate.day_of_week date >= 6 in
let events = has_events date in
(if is_weekend then "cal_year_1m_weekend " else "") ^
(if events then "cal_year_1m_events" else "")
template#table "monthly_events" table;
(* How many days in this month? *)
- let max_dd = GregorianDate.days_in_month yyyy mm in
+ let max_dd = Date.days_in_month (Date.make yyyy mm 1) in
let days = range 1 max_dd in
let table =
"page", Template.VarString page ])
events in
let is_weekend =
- GregorianDate.day_of_week (yyyy, mm, dd) >= 6 in
+ match Date.day_of_week (Date.make yyyy mm dd) with
+ Date.Sat | Date.Sun -> true | _ -> false in
[ "dd", Template.VarString (sprintf "%02d" dd);
"is_weekend", Template.VarConditional is_weekend;
"events", Template.VarTable table ])
template#set "dd" (sprintf "%02d" dd);
template#set "month_name" (long_month mm);
- let dow = GregorianDate.day_of_week date in
+
+ let t = Date.make yyyy mm dd in
+ let dow = Date.day_of_week t in
template#set "short_weekday" (short_weekday dow);
+ let oneday = Date.Period.day 1 in
+ let prev_t = Date.rem t oneday in
+ let next_t = Date.add t oneday in
let prev_yyyy, prev_mm, prev_dd =
- GregorianDate.add_delta_days date (-1) in
+ Date.year prev_t, Date.int_of_month (Date.month prev_t),
+ Date.day_of_month prev_t in
let next_yyyy, next_mm, next_dd =
- GregorianDate.add_delta_days date 1 in
+ Date.year next_t, Date.int_of_month (Date.month next_t),
+ Date.day_of_month next_t in
template#set "prev_yyyy" (string_of_int prev_yyyy);
template#set "prev_mm" (sprintf "%02d" prev_mm);
(* COCANWIKI - a wiki written in Objective CAML.
* Written by Richard W.M. Jones <rich@merjis.com>.
* Copyright (C) 2004 Merjis Ltd.
- * $Id: stats.ml,v 1.3 2004/10/23 16:34:58 rich Exp $
+ * $Id: stats.ml,v 1.4 2005/04/02 17:30:54 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
-open GregorianDate
-
open Cocanwiki
open Cocanwiki_template
open Cocanwiki_server_settings
let year, week =
let date =
let tm = Unix.gmtime (Unix.time ()) in
- (tm.Unix.tm_year + 1900, tm.Unix.tm_mon + 1, tm.Unix.tm_mday)
+ Date.make (tm.Unix.tm_year + 1900) (tm.Unix.tm_mon + 1) tm.Unix.tm_mday
in
- fst (GregorianDate.business_of_standard date)
- in
+ let year, week, _ = Date.to_business date in
+ year, week in
template#set "year" (string_of_int year);
template#set "week" (string_of_int week);