Calendar-Simple-1.23000755001751001751 013243576671 15564 5ustar00davecrossdavecross000000000000Calendar-Simple-1.23/Build.PL000444001751001751 155313243576671 17221 0ustar00davecrossdavecross000000000000use Module::Build; my $build = Module::Build->new( license => 'perl', dist_author => 'Dave Cross ', module_name => 'Calendar::Simple', requires => { perl => '5.6.0', Carp => 0, 'Time::Local' => 0, Config => 0, }, recommends => { DateTime => 0, }, build_requires => { 'Test::More' => 0, }, build_recommends => { 'Test::Pod' => 0, 'Test::Pod::Coverage' => 0, }, create_makefile_pl => 'traditional', script_files => [ 'bin/pcal' ], meta_merge => { resources => { repository => 'https://github.com/davorg/calendar-simple', } }, ); $build->create_build_script; Calendar-Simple-1.23/Changes000444001751001751 1275013243576671 17241 0ustar00davecrossdavecross0000000000002018-02-22 Dave Cross * lib/Calendar/Simple.pm: Bump version for another release. Thanks Mohammed Anwar 2018-02-22 Mohammad S Anwar * Build.PL, MANIFEST, README.xml: - Removed +x bit from Build.PL as reported by CPANTS. 2018-02-22 Dave Cross * lib/Calendar/Simple.pm: Bump version to a number that that's not already on CPAN :-/ * Build.PL: Remove signing. * lib/Calendar/Simple.pm: Bump version for release. * lib/Calendar/Simple.pm: Change the arguments passed to timelocal() Following advice in the documentation: "Whenever possible, use an absolute four digit year instead." 2016-01-04 Dave Cross * Build.PL: Added repo details to Build.PL 2015-07-18 Dave Cross * .travis.yml: Removed 5.22 from .travis.yml 2015-07-17 Dave Cross * .travis.yml: .travis.yml 2015-04-11 Dave Cross * .gitignore: Added .gitignore 2014-01-10 Dave Cross * .travis.yml: Added .travis.yml 2011-07-23 Dave Cross * Build.PL, MANIFEST, README.xml, t/date_span.t, t/pod_coverage.t: Various changes (mainly permissions) 2010-04-02 Dave Cross * t/no_dt.t: Patch to fix tests under 5.11.0+. Thanks to Ruslan Zakirov. 2009-12-02 Dave Cross * lib/Calendar/Simple.pm: Small amount of perlcritic work 2009-03-19 Dave Cross * Build.PL, lib/Calendar/Simple.pm: Switch to hard-coded version number in Calendar/Simple.pm. 2008-04-19 Dave Cross * Build.PL: Increment version * Build.PL: Add Perl version. Add Config to prereqs. 2008-03-09 Dave Cross * Build.PL: Incremented release number. * Build.PL: Added Licence. Slightly rejigged dependencies. 2008-03-08 Dave Cross * MANIFEST: Removed COPYING for MANIFEST. * COPYING: Remove COPYING. * t/no_dt.t: Skip 2100 test on 64-bit systems. * lib/Calendar/Simple.pm: Turn "licence" into a verb so CPANTS will recognise it. * lib/Calendar/Simple.pm: Require Perl 5.6 (and, hence, use "our" and "warnings"). Use svn revision number. Create licence section. * Build.PL, COPYING, MANIFEST: Make files non-executable. * Build.PL: Correct dependencies. Change email address to mag- sol.com. Increment version number. 2006-10-18 Dave Cross * lib/Calendar/Simple.pm: Fixed undef values in comparisons 2006-10-16 Dave Cross * lib/Calendar/Simple.pm: Bump version for release. * Build.PL: Added pcal to Build.PL. 2006-10-15 Dave Cross * MANIFEST, lib/Calendar/Simple.pm: Fixed MANIFEST, bumped version number. * bin/pcal, lib/Calendar/Simple.pm: Added pcal to the distribution * lib/Calendar/Simple.pm, t/date_span.t: Added date_span function (and tests) 2006-10-11 Dave Cross * lib/Calendar/Simple.pm: Removed excess parentheses * t/no_dt.t, t/test.t: Slightly improved some tests 2006-09-10 (no author) <(no author)> * README.xml, lib/Calendar/Simple.pm: Changed copywrite to Magnum Solutions. Updated README to use Build.PL. 2006-09-04 (no author) <(no author)> * lib/Calendar/Simple.pm: Changed to manual version number 2005-05-31 Dave Cross * Build.PL, lib/Calendar/Simple.pm: Fixes to Build.PL. Small changes to Pod. 2005-03-01 Dave Cross * lib/Calendar/Simple.pm: Adding pod coverage tests * MANIFEST, t/no_dt.t, t/pod_coverage.t, t/test.t: Added pod coverage tests 2004-12-04 Dave Cross * lib/Calendar/Simple.pm: Added 'see also' reference to DateTime * t/test.t: Don't run 2100 test if DateTime isn't installed 2004-10-30 Dave Cross * lib/Calendar/Simple.pm: Moved Simple.pm * Build.PL, MANIFEST, Makefile.PL: Removed Makefile.PL (now generated by Build.PL) Added Build.PL Updated MANIFEST 2004-10-23 Dave Cross * lib/Calendar/Simple.pm, t/no_dt.t, t/pod.t, t/test.t: Improved test coverage 2004-05-23 Dave Cross * README, README.xml: Replace README with README.xml 2004-05-22 Dave Cross * t/test.t: Added more tests to increase coverage 2003-05-14 Dave Cross * t/pod.t, t/test.t: Added support for DateTime.pm (but only is it's installed). Updated POD tests. * lib/Calendar/Simple.pm: Added support for DateTime.pm (but only is it's installed). 2003-02-19 Dave Cross * Changes: Removed from CVS * t/pod.t, t/test.t: New test files * Makefile.PL: Added Test::More and Test::Pod as prereqs. * MANIFEST: Removed test.pl Added t/* * test.pl: Moved tests to t/* * lib/Calendar/Simple.pm: Ensure that all week arrays contain seven elements - previously the last one ended on the last day of the month. 2002-07-30 Dave Cross * Changes, lib/Calendar/Simple.pm: Fixed the stupid error from the last fix. * lib/Calendar/Simple.pm: Fixed undefined value errors 2002-07-13 Dave Cross * lib/Calendar/Simple.pm: Doc patches 2002-07-12 Dave Cross * COPYING, MANIFEST: Added COPYING * lib/Calendar/Simple.pm: Added CVS tags * lib/Calendar/Simple.pm, test.pl: Added start day option * Calendar-Simple-0.01.tar, Makefile: Unnecessary Checkin * Calendar-Simple-0.01.tar, Changes, MANIFEST, Makefile, Makefile.PL, README, lib/Calendar/Simple.pm, test.pl: Initial revision Calendar-Simple-1.23/MANIFEST000444001751001751 34013243576671 17027 0ustar00davecrossdavecross000000000000Changes Makefile.PL Build.PL MANIFEST README lib/Calendar/Simple.pm t/test.t t/pod.t t/no_dt.t t/pod_coverage.t t/date_span.t bin/pcal META.yml Module meta-data (added by MakeMaker) META.json Calendar-Simple-1.23/META.json000444001751001751 240413243576671 17342 0ustar00davecrossdavecross000000000000{ "abstract" : "Perl extension to create simple calendars", "author" : [ "Dave Cross " ], "dynamic_config" : 1, "generated_by" : "Module::Build version 0.422", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Calendar-Simple", "prereqs" : { "build" : { "requires" : { "Test::More" : "0" } }, "configure" : { "requires" : { "Module::Build" : "0.42" } }, "runtime" : { "recommends" : { "DateTime" : "0" }, "requires" : { "Carp" : "0", "Config" : "0", "Time::Local" : "0", "perl" : "v5.6.0" } } }, "provides" : { "Calendar::Simple" : { "file" : "lib/Calendar/Simple.pm", "version" : "1.23" } }, "release_status" : "stable", "resources" : { "license" : [ "http://dev.perl.org/licenses/" ], "repository" : { "url" : "https://github.com/davorg/calendar-simple" } }, "version" : "1.23", "x_serialization_backend" : "JSON::PP version 2.27300_01" } Calendar-Simple-1.23/META.yml000444001751001751 140413243576671 17171 0ustar00davecrossdavecross000000000000--- abstract: 'Perl extension to create simple calendars' author: - 'Dave Cross ' build_requires: Test::More: '0' configure_requires: Module::Build: '0.42' dynamic_config: 1 generated_by: 'Module::Build version 0.422, CPAN::Meta::Converter version 2.150005' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Calendar-Simple provides: Calendar::Simple: file: lib/Calendar/Simple.pm version: '1.23' recommends: DateTime: '0' requires: Carp: '0' Config: '0' Time::Local: '0' perl: v5.6.0 resources: license: http://dev.perl.org/licenses/ repository: https://github.com/davorg/calendar-simple version: '1.23' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' Calendar-Simple-1.23/Makefile.PL000444001751001751 100213243576671 17664 0ustar00davecrossdavecross000000000000# Note: this file was auto-generated by Module::Build::Compat version 0.4220 require 5.006000; use ExtUtils::MakeMaker; WriteMakefile ( 'NAME' => 'Calendar::Simple', 'VERSION_FROM' => 'lib/Calendar/Simple.pm', 'PREREQ_PM' => { 'Carp' => 0, 'Config' => 0, 'Test::More' => 0, 'Time::Local' => 0 }, 'INSTALLDIRS' => 'site', 'EXE_FILES' => [ 'bin/pcal' ], 'PL_FILES' => {} ) ; Calendar-Simple-1.23/README000444001751001751 106513243576671 16603 0ustar00davecrossdavecross000000000000Calendar::Simple ---------------- This is a very simple module that models a calendar month. INSTALLATION To install this module type the following: perl Build.P ./Build ./Build test ./Build install Note: The older "perl Makefile.PL; make; make test; make install" sequence will also work. DEPENDENCIES This module has no external dependencies. COPYRIGHT AND LICENCE This script is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Copyright (C) 2002-2010 Magnum Solutions Ltd., All rights reserved. Calendar-Simple-1.23/bin000755001751001751 013243576671 16334 5ustar00davecrossdavecross000000000000Calendar-Simple-1.23/bin/pcal000555001751001751 105213243576671 17334 0ustar00davecrossdavecross000000000000#!/usr/bin/perl -w use strict; use Calendar::Simple; my @months = qw(January February March April May June July August September October November December); my $mon = shift || (localtime)[4] + 1; my $yr = shift || (localtime)[5] + 1900; my @month = calendar($mon, $yr); my $mon_name = $months[$mon - 1]; my $pad = int((20 - length("$mon_name $yr")) / 2); print "\n", ' ' x $pad, "$months[$mon - 1] $yr\n"; print "Su Mo Tu We Th Fr Sa\n"; foreach (@month) { print map { $_ ? sprintf "%2d ", $_ : ' ' } @$_; print "\n"; } Calendar-Simple-1.23/lib000755001751001751 013243576671 16332 5ustar00davecrossdavecross000000000000Calendar-Simple-1.23/lib/Calendar000755001751001751 013243576671 20043 5ustar00davecrossdavecross000000000000Calendar-Simple-1.23/lib/Calendar/Simple.pm000555001751001751 1430413243576671 22014 0ustar00davecrossdavecross000000000000# $Id$ =head1 NAME Calendar::Simple - Perl extension to create simple calendars =head1 SYNOPSIS use Calendar::Simple; my @curr = calendar; # get current month my @this_sept = calendar(9); # get 9th month of current year my @sept_2002 = calendar(9, 2002); # get 9th month of 2002 my @monday = calendar(9, 2002, 1); # get 9th month of 2002, # weeks start on Monday my @span = date_span(mon => 10, # returns span of dates year => 2006, begin => 15, end => 28); =cut package Calendar::Simple; use 5.006; use strict; use warnings; use base 'Exporter'; our @EXPORT = qw(calendar); our @EXPORT_OK = qw(date_span); our $VERSION = '1.23'; use Time::Local; use Carp; eval 'use DateTime'; my $dt = ! $@; $dt = 0 if $ENV{CAL_SIMPLE_NO_DT}; my @days = qw(31 xx 31 30 31 30 31 31 30 31 30 31); =head1 DESCRIPTION A very simple module that exports one function called C. =head2 calendar This function returns a data structure representing the dates in a month. The data structure returned is an array of array references. The first level array represents the weeks in the month. The second level array contains the actual days. By default, each week starts on a Sunday and the value in the array is the date of that day. Any days at the beginning of the first week or the end of the last week that are from the previous or next month have the value C. If the month or year parameters are omitted then the current month or year are assumed. A third, optional parameter, start_day, allows you to set the day each week starts with, with the same values as localtime sets for wday (namely, 0 for Sunday, 1 for Monday and so on). =cut sub calendar { my ($mon, $year, $start_day) = @_; my @now = (localtime)[4, 5]; $mon = ($now[0] + 1) unless $mon; $year = ($now[1] + 1900) unless $year; $start_day = 0 unless defined $start_day; croak "Year $year out of range" if $year < 1970 && !$dt; croak "Month $mon out of range" if ($mon < 1 || $mon > 12); croak "Start day $start_day out of range" if ($start_day < 0 || $start_day > 6); my $first; if ($dt) { $first = DateTime->new(year => $year, month => $mon, day => 1)->day_of_week % 7; } else { $first = (localtime timelocal 0, 0, 0, 1, $mon -1, $year)[6]; } $first -= $start_day; $first += 7 if ($first < 0); my @mon = (1 .. _days($mon, $year)); my @first_wk = (undef) x 7; @first_wk[$first .. 6] = splice @mon, 0, 6 - $first + 1; my @month = (\@first_wk); while (my @wk = splice @mon, 0, 7) { push @month, \@wk; } $#{$month[-1]} = 6; return wantarray ? @month : \@month; } =head2 date_span This function returns a cur-down version of a month data structure which begins and ends on dates other than the first and last dates of the month. Any weeks that fall completely outside of the date range are removed from the structure and any days within the remaining weeks that fall outside of the date range are set to C. As there are a number of parameters to this function, they are passed using a named parameter interface. The parameters are as follows: =over 4 =item year The required year. Defaults to the current year if omitted. =item mon The required month. Defaults to the current month if omitted. =item begin The first day of the required span. Defaults to the first if omitted. =item end The last day of the required span. Defaults to the last day of the month if omitted. =item start_day Indicates the day of the week that each week starts with. This takes the same values as the optional third parameter to C. The default is 0 (for Sunday). =back This function isn't exported by default, so in order to use it in your program you need to use the module like this: use Calendar::Simple 'date_span'; =cut sub date_span { my %params = @_; my @now = (localtime)[4, 5]; my $mon = $params{mon} || ($now[0] + 1); my $year = $params{year} || ($now[1] + 1900); my $begin = $params{begin} || 1; my $end = $params{end} || _days($mon, $year); my $start_day = defined $params{start_day} ? $params{start_day} : 0; my @cal = calendar($mon, $year, $start_day); while ($cal[0][6] < $begin) { shift @cal; } my $i = 0; while (defined $cal[0][$i] and $cal[0][$i] < $begin) { $cal[0][$i++] = undef; } while ($cal[-1][0] > $end) { pop @cal; } $i = -1; while (defined $cal[-1][$i] and $cal[-1][$i] > $end) { $cal[-1][$i--] = undef; } return @cal; } sub _days { my ($mon, $yr) = @_; return $days[$mon - 1] unless $mon == 2; return _isleap($yr) ? 29 : 28; } sub _isleap { return 1 unless $_[0] % 400; return unless $_[0] % 100; return 1 unless $_[0] % 4; return; } 1; __END__ =head2 EXAMPLE A simple C replacement would therefore look like this: #!/usr/bin/perl -w use strict; use Calendar::Simple; my @months = qw(January February March April May June July August September October November December); my $mon = shift || (localtime)[4] + 1; my $yr = shift || (localtime)[5] + 1900; my @month = calendar($mon, $yr); print "\n$months[$mon -1] $yr\n\n"; print "Su Mo Tu We Th Fr Sa\n"; foreach (@month) { print map { $_ ? sprintf "%2d ", $_ : ' ' } @$_; print "\n"; } A version of this example, called C, is installed when you install this module. =head2 Date Range This module will make use of DateTime.pm if it is installed. By using DateTime.pm it can use any date that DateTime can represent. If DateTime is not installed it uses Perl's built-in date handling and therefore can't deal with dates before 1970 and it will also have problems with dates after 2038 on a 32-bit machine. =head2 EXPORT C =head1 AUTHOR Dave Cross =head1 ACKNOWLEDGEMENTS With thanks to Paul Mison for the start day patch. =head1 COPYRIGHT Copyright (C) 2002-2008, Magnum Solutions Ltd. All Rights Reserved. =head1 LICENSE This script is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 SEE ALSO L, L, L =cut Calendar-Simple-1.23/t000755001751001751 013243576671 16027 5ustar00davecrossdavecross000000000000Calendar-Simple-1.23/t/date_span.t000555001751001751 117313243576671 20314 0ustar00davecrossdavecross000000000000use Test::More tests => 14; use_ok('Calendar::Simple', 'date_span'); my @span = date_span(year => 2006, mon => 10, begin => 15, end => 28); is(@span, 2); is($span[0][0], 15); is($span[1][6], 28); @span = date_span(year => 2006, mon => 10, begin => 17, end => 24); is(@span, 2); ok(!defined $span[0][0]); is($span[0][2], 17); ok(!defined $span[1][6]); is($span[1][2], 24); @span = date_span(year => 2006, mon => 10); is(@span, 5); is(defined $span[0][0], 1); is($span[2][2], 17); ok(!defined $span[-1][6]); is($span[-1][2], 31); Calendar-Simple-1.23/t/no_dt.t000555001751001751 251413243576671 17461 0ustar00davecrossdavecross000000000000use Test::More tests => 33; $ENV{CAL_SIMPLE_NO_DT} = 1; use_ok('Calendar::Simple'); use Config; my @month = calendar(9, 2002); is(@month, 5); is(@{$month[0]}, 7); is($month[0][0], 1); ok(not defined $month[-1][-1]); is($#{$month[-1]}, 6); @month = calendar(2, 2009); is(@month, 4); is($month[0][0], 1); is($month[3][6], 28); ok(defined $month[-1][-1]); is($#{$month[-1]}, 6); @month = calendar(1, 2002); ok(not defined $month[0][0]); is($month[0][2], 1); is($month[4][4], 31); ok(not defined $month[4][6]); ok(not defined $month[-1][-1]); is($#{$month[-1]}, 6); @month = calendar(1, 2002, 1); ok(not defined $month[0][0]); is($month[0][1], 1); is($month[4][3], 31); ok(not defined $month[4][4]); ok(not defined $month[-1][-1]); is($#{$month[-1]}, 6); @month = calendar(); ok(@month); eval { @month = calendar(-1) }; ok($@); eval { @month = calendar(13) }; ok($@); eval { @month = calendar(1, 2000, -1) }; ok($@); eval { @month = calendar(1, 2000, 7) }; ok($@); @month = calendar(2, 2000); ok(@month); SKIP: { skip 'Not a problem since perl 5.11.0', 1 if $] >= 5.011; skip 'Not a problem on 64-bit systems', 1 if defined $Config{use64bitint}; eval { @month = calendar(2, 2100) }; ok($@); } eval { @month = calendar(2, 1500) }; ok($@); @month = calendar(2, 2004); ok(@month); my $month = calendar(); is(ref $month, 'ARRAY'); Calendar-Simple-1.23/t/pod.t000555001751001751 20113243576671 17107 0ustar00davecrossdavecross000000000000use Test::More; eval "use Test::Pod 1.00"; plan skip_all => "Test::Pod 1.00 required for testing POD" if $@; all_pod_files_ok(); Calendar-Simple-1.23/t/pod_coverage.t000555001751001751 24113243576671 20766 0ustar00davecrossdavecross000000000000use Test::More; eval "use Test::Pod::Coverage 1.00"; plan skip_all => "Test::Pod::Coverage 1.00 required for testing POD coverage" if $@; all_pod_coverage_ok(); Calendar-Simple-1.23/t/test.t000555001751001751 243013243576671 17332 0ustar00davecrossdavecross000000000000use Test::More tests => 34; use_ok('Calendar::Simple'); my @month = calendar(9, 2002); is(@month, 5); is(@{$month[0]}, 7); is($month[0][0], 1); ok(not defined $month[-1][-1]); is($#{$month[-1]}, 6); @month = calendar(2, 2009); is(@month, 4); is($month[0][0], 1); is($month[3][6], 28); ok(defined $month[-1][-1]); is($#{$month[-1]}, 6); @month = calendar(1, 2002); ok(not defined $month[0][0]); is($month[0][2], 1); is($month[4][4], 31); ok(not defined $month[4][6]); ok(not defined $month[-1][-1]); is($#{$month[-1]}, 6); @month = calendar(1, 2002, 1); ok(not defined $month[0][0]); is($month[0][1], 1); is($month[4][3], 31); ok(not defined $month[4][4]); ok(not defined $month[-1][-1]); is($#{$month[-1]}, 6); @month = calendar(2, 2004, 3); ok(@month); @month = calendar(); ok(@month); eval { @month = calendar(-1) }; ok($@); eval { @month = calendar(13) }; ok($@); eval { @month = calendar(1, 2000, -1) }; ok($@); eval { @month = calendar(1, 2000, 7) }; ok($@); @month = calendar(2, 2000); ok(@month); @month = calendar(2, 2004); ok(@month); my $month = calendar(); is(ref $month, 'ARRAY'); SKIP: { eval { require DateTime }; skip "DateTime not installed", 2, if $@ || $ENV{CAL_SIMPLE_NO_DT}; @month = calendar(1,1500); ok(@month); @month = calendar(2, 2100); ok(@month); }