From 18496046f80f1e2338bbfc5b4343e67db6ed3ef6 Mon Sep 17 00:00:00 2001 From: rich Date: Sat, 2 Apr 2005 17:30:54 +0000 Subject: [PATCH] Deprecated GregorianDate. Now we're using the Calendar module instead. --- html/_css/basic.css | 4 +-- scripts/Makefile | 6 ++--- scripts/lib/cocanwiki_date.ml | 8 +++--- scripts/lib/cocanwiki_ext_calendar.ml | 51 +++++++++++++++++++++++++---------- scripts/stats.ml | 10 +++---- 5 files changed, 50 insertions(+), 29 deletions(-) diff --git a/html/_css/basic.css b/html/_css/basic.css index 3642a4e..8311ef2 100644 --- a/html/_css/basic.css +++ b/html/_css/basic.css @@ -1,5 +1,5 @@ /* 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 $ */ /* Links. */ @@ -36,7 +36,7 @@ div#old_version { border: solid 2px #f00; color: #c00; padding: 4px; - width: 80%; + width: 60%; margin-left: 10%; /* clear: both; */ } diff --git a/scripts/Makefile b/scripts/Makefile index cca402c..d77b120 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -1,12 +1,12 @@ # 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 \ - -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) diff --git a/scripts/lib/cocanwiki_date.ml b/scripts/lib/cocanwiki_date.ml index ac63b2e..8450fd6 100644 --- a/scripts/lib/cocanwiki_date.ml +++ b/scripts/lib/cocanwiki_date.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * 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 @@ -25,9 +25,9 @@ open Cgi 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" diff --git a/scripts/lib/cocanwiki_ext_calendar.ml b/scripts/lib/cocanwiki_ext_calendar.ml index 61fab34..2b3951f 100644 --- a/scripts/lib/cocanwiki_ext_calendar.ml +++ b/scripts/lib/cocanwiki_ext_calendar.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * 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 @@ -26,8 +26,6 @@ open Printf open ExtList -open GregorianDate - open Cocanwiki open Cocanwiki_template open Cocanwiki_strings @@ -38,6 +36,16 @@ let month_template = _get_template "calendar_month.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 @@ -76,7 +84,7 @@ let extension (dbh : Dbi.connection) hostid url = 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 @@ -122,6 +130,12 @@ let extension (dbh : Dbi.connection) hostid url = (* 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. *) @@ -131,10 +145,9 @@ let extension (dbh : Dbi.connection) hostid url = 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 @@ -142,8 +155,10 @@ let extension (dbh : Dbi.connection) hostid url = 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 "") @@ -209,7 +224,7 @@ let extension (dbh : Dbi.connection) hostid url = 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 = @@ -223,7 +238,8 @@ let extension (dbh : Dbi.connection) hostid url = "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 ]) @@ -243,13 +259,20 @@ let extension (dbh : Dbi.connection) hostid url = 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); diff --git a/scripts/stats.ml b/scripts/stats.ml index 1369474..f9b2b2a 100644 --- a/scripts/stats.ml +++ b/scripts/stats.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * 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 @@ -24,8 +24,6 @@ open Registry open Cgi open Printf -open GregorianDate - open Cocanwiki open Cocanwiki_template open Cocanwiki_server_settings @@ -48,10 +46,10 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid 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); -- 1.8.3.1