Fixed for Perl 5.8.2.
[perl4caml.git] / wrappers / pl_Date_Calc.ml
1 (** Wrapper around Perl [Date::Calc] class.
2   *
3   * Copyright (C) 2003 Merjis Ltd.
4   *
5   * $Id: pl_Date_Calc.ml,v 1.1 2003-11-19 16:28:23 rich Exp $
6   *)
7
8 open Perl
9
10 let _ = eval "use Date::Calc qw()"
11
12 let days_in_year year month =
13   int_of_sv (call ~fn:"Date::Calc::Days_in_Year"
14                [sv_of_int year; sv_of_int month])
15
16 let days_in_month year month =
17   int_of_sv (call ~fn:"Date::Calc::Days_in_Month"
18                [sv_of_int year; sv_of_int month])
19
20 let weeks_in_year year =
21   int_of_sv (call ~fn:"Date::Calc::Weeks_in_Year" [sv_of_int year])
22
23 let leap_year year =
24   bool_of_sv (call ~fn:"Date::Calc::leap_year" [sv_of_int year])
25
26 let check_date year month day =
27   bool_of_sv (call ~fn:"Date::Calc::check_date"
28                 [sv_of_int year; sv_of_int month; sv_of_int day])
29
30 let check_time hour min sec =
31   bool_of_sv (call ~fn:"Date::Calc::check_time"
32                 [sv_of_int hour; sv_of_int min; sv_of_int sec])
33
34 let check_business_date year week dow =
35   bool_of_sv (call ~fn:"Date::Calc::check_business_date"
36                 [sv_of_int year; sv_of_int week; sv_of_int dow])
37
38 let day_of_year year month day =
39   int_of_sv (call ~fn:"Date::Calc::Day_of_Year"
40                [sv_of_int year; sv_of_int month; sv_of_int day])
41
42 let date_to_days year month day =
43   int_of_sv (call ~fn:"Date::Calc::Date_to_Days"
44                [sv_of_int year; sv_of_int month; sv_of_int day])
45
46 let day_of_week year month day =
47   int_of_sv (call ~fn:"Date::Calc::Day_of_Week"
48                [sv_of_int year; sv_of_int month; sv_of_int day])
49
50 let week_number year month day =
51   int_of_sv (call ~fn:"Date::Calc::Week_Number"
52                [sv_of_int year; sv_of_int month; sv_of_int day])
53
54 let week_of_year year month day =
55   let r = call_array ~fn:"Date::Calc::Week_of_Year"
56             [sv_of_int year; sv_of_int month; sv_of_int day] in
57   match r with
58       [week; year] -> int_of_sv week, int_of_sv year
59     | _ -> failwith "Pl_Date_Calc: week_of_year: unexpected return value"
60
61 let monday_of_week week year =
62   let r = call_array ~fn:"Date::Calc::Monday_of_Week"
63             [sv_of_int week; sv_of_int year] in
64   match r with
65       [year; month; day] -> int_of_sv year, int_of_sv month, int_of_sv day
66     | _ -> failwith "Pl_Date_Calc: monday_of_week: unexpected return value"
67
68 (* at this point I got bored ... - RWMJ *)