Now we're using the Calendar module instead.
/* Minimal list of CSS required for all COCANWIKIs.
/* Minimal list of CSS required for all COCANWIKIs.
- * $Id: basic.css,v 1.2 2005/03/31 14:04:19 rich Exp $
+ * $Id: basic.css,v 1.3 2005/04/02 17:30:54 rich Exp $
border: solid 2px #f00;
color: #c00;
padding: 4px;
border: solid 2px #f00;
color: #c00;
padding: 4px;
margin-left: 10%;
/* clear: both; */
}
margin-left: 10%;
/* clear: both; */
}
# Makefile for COCANWIKI.
# Makefile for COCANWIKI.
-# $Id: Makefile,v 1.45 2004/10/24 19:25:20 rich Exp $
+# $Id: Makefile,v 1.46 2005/04/02 17:30:54 rich Exp $
include ../Makefile.config
OCAMLC := ocamlc
OCAMLCFLAGS := -w s \
include ../Makefile.config
OCAMLC := ocamlc
OCAMLCFLAGS := -w s \
- -I +apache -I +pcre -I +dbi -I +extlib -I +netstring \
- -I +gregoriandate -I lib
+ -I +apache -I +pcre -I +dbi -I +extlib -I +netstring -I +calendar \
+ -I lib
CPP := cpp
SRCS := $(wildcard *.ml)
CPP := cpp
SRCS := $(wildcard *.ml)
(* COCANWIKI - a wiki written in Objective CAML.
* Written by Richard W.M. Jones <rich@merjis.com>.
* Copyright (C) 2004 Merjis Ltd.
(* 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.1 2004/10/21 11:42:05 rich Exp $
+ * $Id: cocanwiki_date.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
*
* 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 Printf
let short_weekday = function
open Printf
let short_weekday = function
- | 0 -> "Sun" | 1 -> "Mon" | 2 -> "Tue" | 3 -> "Wed"
- | 4 -> "Thu" | 5 -> "Fri" | 6 -> "Sat" | 7 -> "Sun"
- | _ -> invalid_arg "short_weekday"
+ | 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"
let short_month = function
| 1 -> "Jan" | 2 -> "Feb" | 3 -> "Mar" | 4 -> "Apr"
(* COCANWIKI - a wiki written in Objective CAML.
* Written by Richard W.M. Jones <rich@merjis.com>.
* Copyright (C) 2004 Merjis Ltd.
(* 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
*
* 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 Cocanwiki
open Cocanwiki_template
open Cocanwiki_strings
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"
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 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
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
(* Return true if there are any events on a particular day. *)
let has_events date = List.exists (fun (d, _) -> date = d) pages in
(* 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.
*)
(* 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);
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 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_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 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 "")
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? *)
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 =
let days = range 1 max_dd in
let table =
"page", Template.VarString page ])
events in
let is_weekend =
"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 ])
[ "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);
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);
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 =
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 =
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);
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.
(* 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
*
* 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 Cocanwiki
open Cocanwiki_template
open Cocanwiki_server_settings
open Cocanwiki
open Cocanwiki_template
open Cocanwiki_server_settings
let year, week =
let date =
let tm = Unix.gmtime (Unix.time ()) in
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
- 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);
template#set "year" (string_of_int year);
template#set "week" (string_of_int week);