Added proper LGPL statements to all files.
[perl4caml.git] / wrappers / pl_Date_Calc.ml
1 (** Wrapper around Perl [Date::Calc] class. *)
2 (*  Copyright (C) 2003 Merjis Ltd.
3
4     This library is free software; you can redistribute it and/or
5     modify it under the terms of the GNU Library General Public
6     License as published by the Free Software Foundation; either
7     version 2 of the License, or (at your option) any later version.
8
9     This library is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12     Library General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this library; see the file COPYING.  If not, write to
16     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17     Boston, MA 02111-1307, USA.
18
19     $Id: pl_Date_Calc.ml,v 1.2 2008-03-01 13:02:21 rich Exp $
20   *)
21
22 open Perl
23
24 let _ = eval "use Date::Calc qw()"
25
26 let days_in_year year month =
27   int_of_sv (call ~fn:"Date::Calc::Days_in_Year"
28                [sv_of_int year; sv_of_int month])
29
30 let days_in_month year month =
31   int_of_sv (call ~fn:"Date::Calc::Days_in_Month"
32                [sv_of_int year; sv_of_int month])
33
34 let weeks_in_year year =
35   int_of_sv (call ~fn:"Date::Calc::Weeks_in_Year" [sv_of_int year])
36
37 let leap_year year =
38   bool_of_sv (call ~fn:"Date::Calc::leap_year" [sv_of_int year])
39
40 let check_date year month day =
41   bool_of_sv (call ~fn:"Date::Calc::check_date"
42                 [sv_of_int year; sv_of_int month; sv_of_int day])
43
44 let check_time hour min sec =
45   bool_of_sv (call ~fn:"Date::Calc::check_time"
46                 [sv_of_int hour; sv_of_int min; sv_of_int sec])
47
48 let check_business_date year week dow =
49   bool_of_sv (call ~fn:"Date::Calc::check_business_date"
50                 [sv_of_int year; sv_of_int week; sv_of_int dow])
51
52 let day_of_year year month day =
53   int_of_sv (call ~fn:"Date::Calc::Day_of_Year"
54                [sv_of_int year; sv_of_int month; sv_of_int day])
55
56 let date_to_days year month day =
57   int_of_sv (call ~fn:"Date::Calc::Date_to_Days"
58                [sv_of_int year; sv_of_int month; sv_of_int day])
59
60 let day_of_week year month day =
61   int_of_sv (call ~fn:"Date::Calc::Day_of_Week"
62                [sv_of_int year; sv_of_int month; sv_of_int day])
63
64 let week_number year month day =
65   int_of_sv (call ~fn:"Date::Calc::Week_Number"
66                [sv_of_int year; sv_of_int month; sv_of_int day])
67
68 let week_of_year year month day =
69   let r = call_array ~fn:"Date::Calc::Week_of_Year"
70             [sv_of_int year; sv_of_int month; sv_of_int day] in
71   match r with
72       [week; year] -> int_of_sv week, int_of_sv year
73     | _ -> failwith "Pl_Date_Calc: week_of_year: unexpected return value"
74
75 let monday_of_week week year =
76   let r = call_array ~fn:"Date::Calc::Monday_of_Week"
77             [sv_of_int week; sv_of_int year] in
78   match r with
79       [year; month; day] -> int_of_sv year, int_of_sv month, int_of_sv day
80     | _ -> failwith "Pl_Date_Calc: monday_of_week: unexpected return value"
81
82 (* at this point I got bored ... - RWMJ *)