1Calendar::Simple(3)   User Contributed Perl Documentation  Calendar::Simple(3)
2
3
4

NAME

6       Calendar::Simple - Perl extension to create simple calendars
7

SYNOPSIS

9         use Calendar::Simple;
10
11         my @curr      = calendar;             # get current month
12         my @this_sept = calendar(9);          # get 9th month of current year
13         my @sept_2002 = calendar(9, 2002);    # get 9th month of 2002
14         my @monday    = calendar(9, 2002, 1); # get 9th month of 2002,
15                                               # weeks start on Monday
16
17         my @span      = date_span(mon   => 10,  # returns span of dates
18                                   year  => 2006,
19                                   begin => 15,
20                                   end   => 28);
21

DESCRIPTION

23       A very simple module that exports one function called "calendar".
24
25       calendar
26
27       This function returns a data structure representing the dates in a
28       month.  The data structure returned is an array of array references.
29       The first level array represents the weeks in the month. The second
30       level array contains the actual days. By default, each week starts on a
31       Sunday and the value in the array is the date of that day. Any days at
32       the beginning of the first week or the end of the last week that are
33       from the previous or next month have the value "undef".
34
35       If the month or year parameters are omitted then the current month or
36       year are assumed.
37
38       A third, optional parameter, start_day, allows you to set the day each
39       week starts with, with the same values as localtime sets for wday
40       (namely, 0 for Sunday, 1 for Monday and so on).
41
42       date_span
43
44       This function returns a cur-down version of a month data structure
45       which begins and ends on dates other than the first and last dates of
46       the month.  Any weeks that fall completely outside of the date range
47       are removed from the structure and any days within the remaining weeks
48       that fall outside of the date range are set to "undef".
49
50       As there are a number of parameters to this function, they are passed
51       using a named parameter interface. The parameters are as follows:
52
53       year
54           The required year. Defaults to the current year if omitted.
55
56       mon The required month. Defaults to the current month if omitted.
57
58       begin
59           The first day of the required span. Defaults to the first if omit‐
60           ted.
61
62       end The last day of the required span. Defaults to the last day of the
63           month if omitted.
64
65       start_day
66           Indicates the day of the week that each week starts with. This
67           takes the same values as the optional third parameter to "calen‐
68           dar". The default is 0 (for Sunday).
69
70       This function isn't exported by default, so in order to use it in your
71       program you need to use the module like this:
72
73         use Calendar::Simple 'date_span';
74
75       EXAMPLE
76
77       A simple "cal" replacement would therefore look like this:
78
79         #!/usr/bin/perl -w
80
81         use strict;
82         use Calendar::Simple;
83
84         my @months = qw(January February March April May June July August
85                         September October November December);
86
87         my $mon = shift ⎪⎪ (localtime)[4] + 1;
88         my $yr  = shift ⎪⎪ (localtime)[5] + 1900;
89
90         my @month = calendar($mon, $yr);
91
92         print "\n$months[$mon -1] $yr\n\n";
93         print "Su Mo Tu We Th Fr Sa\n";
94         foreach (@month) {
95           print map { $_ ? sprintf "%2d ", $_ : '   ' } @$_;
96           print "\n";
97         }
98
99       A version of this example, called "pcal", is installed when you install
100       this module.
101
102       Date Range
103
104       This module will make use of DateTime.pm if it is installed. By using
105       DateTime.pm it can use any date that DateTime can represent. If Date‐
106       Time is not installed it uses Perl's built-in date handling and there‐
107       fore can't deal with dates before 1970 and it will also have problems
108       with dates after 2038 on a 32-bit machine.
109
110       EXPORT
111
112       "calendar"
113

AUTHOR

115       Dave Cross <dave@mag-sol.com>
116

ACKNOWLEDGEMENTS

118       With thanks to Paul Mison <cpan@husk.org> for the start day patch.
119
121       Copyright (C) 2002-2008, Magnum Solutions Ltd.  All Rights Reserved.
122

LICENSE

124       This script is free software; you can redistribute it and/or modify it
125       under the same terms as Perl itself.
126

SEE ALSO

128       perl, localtime, DateTime
129
130
131
132perl v5.8.8                       2008-03-09               Calendar::Simple(3)
Impressum