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