Class-Date-1.1.17/0000775000175000017500000000000013304242666013047 5ustar yanickyanickClass-Date-1.1.17/xt/0000775000175000017500000000000013304242666013502 5ustar yanickyanickClass-Date-1.1.17/xt/release/0000775000175000017500000000000013304242666015122 5ustar yanickyanickClass-Date-1.1.17/xt/release/unused-vars.t0000644000175000017500000000036213304242666017562 0ustar yanickyanick#!perl use Test::More 0.96 tests => 1; eval { require Test::Vars }; SKIP: { skip 1 => 'Test::Vars required for testing for unused vars' if $@; Test::Vars->import; subtest 'unused vars' => sub { all_vars_ok(); }; }; Class-Date-1.1.17/inc/0000775000175000017500000000000013304242666013620 5ustar yanickyanickClass-Date-1.1.17/inc/Devel/0000775000175000017500000000000013304242666014657 5ustar yanickyanickClass-Date-1.1.17/inc/Devel/CheckOS.pm0000644000175000017500000002304513304242666016476 0ustar yanickyanickpackage # Devel::CheckOS; use strict; use warnings; use Exporter; use vars qw(@ISA @EXPORT_OK %EXPORT_TAGS); our $VERSION = '1.76'; @ISA = qw(Exporter); @EXPORT_OK = qw(os_is os_isnt die_if_os_is die_if_os_isnt die_unsupported list_platforms list_family_members); %EXPORT_TAGS = ( all => \@EXPORT_OK, booleans => [qw(os_is os_isnt die_unsupported)], fatal => [qw(die_if_os_is die_if_os_isnt)] ); =head1 NAME Devel::CheckOS - check what OS we're running on =head1 DESCRIPTION A learned sage once wrote on IRC: $^O is stupid and ugly, it wears its pants as a hat Devel::CheckOS provides a more friendly interface to $^O, and also lets you check for various OS "families" such as "Unix", which includes things like Linux, Solaris, AIX etc. It spares perl the embarrassment of wearing its pants on its head by covering them with a splendid Fedora. =head1 SYNOPSIS use Devel::CheckOS qw(os_is); print "Hey, I know this, it's a Unix system\n" if(os_is('Unix')); print "You've got Linux 2.6\n" if(os_is('Linux::v2_6')); =head1 USING IT IN Makefile.PL or Build.PL If you want to use this from Makefile.PL or Build.PL, do not simply copy the module into your distribution as this may cause problems when PAUSE and search.cpan.org index the distro. Instead, use the use-devel-assertos script. =head1 FUNCTIONS Devel::CheckOS implements the following functions, which load subsidiary OS-specific modules on demand to do the real work. They can be exported by listing their names after C. You can also export groups of functions thus: use Devel::CheckOS qw(:booleans); # export the boolean functions # and 'die_unsupported' use Devel::CheckOS qw(:fatal); # export those that die on no match use Devel::CheckOS qw(:all); # export everything =head2 Boolean functions =head3 os_is Takes a list of OS names. If the current platform matches any of them, it returns true, otherwise it returns false. The names can be a mixture of OSes and OS families, eg ... os_is(qw(Unix VMS)); # Unix is a family, VMS is an OS =cut sub os_is { my @targets = @_; my $rval = 0; foreach my $target (@targets) { die("Devel::CheckOS: $target isn't a legal OS name\n") unless($target =~ /^\w+(::\w+)*$/); eval "use Devel::AssertOS::$target"; if(!$@) { no strict 'refs'; $rval = 1 if(&{"Devel::AssertOS::${target}::os_is"}()); } } return $rval; } =head3 os_isnt If the current platform matches any of the parameters it returns false, otherwise it returns true. =cut sub os_isnt { my @targets = @_; my $rval = 1; foreach my $target (@targets) { $rval = 0 if(os_is($target)); } return $rval; } =head2 Fatal functions =head3 die_if_os_isnt As C, except that it dies instead of returning false. The die() message matches what the CPAN-testers look for to determine if a module doesn't support a particular platform. =cut sub die_if_os_isnt { os_is(@_) ? 1 : die_unsupported(); } =head3 die_if_os_is As C, except that it dies instead of returning false. =cut sub die_if_os_is { os_isnt(@_) ? 1 : die_unsupported(); } =head2 And some utility functions ... =head3 die_unsupported This function simply dies with the message "OS unsupported", which is what the CPAN testers look for to figure out whether a platform is supported or not. =cut sub die_unsupported { die("OS unsupported\n"); } =head3 list_platforms When called in list context, return a list of all the platforms for which the corresponding Devel::AssertOS::* module is available. This includes both OSes and OS families, and both those bundled with this module and any third-party add-ons you have installed. In scalar context, returns a hashref keyed by platform with the filename of the most recent version of the supporting module that is available to you. This is to make sure that the use-devel-assertos script Does The Right Thing in the case where you have installed the module in one version of perl, then upgraded perl, and installed it again in the new version. Sometimes the old version of perl and all its modules will still be hanging around and perl "helpfully" includes the old perl's search path in its own. Unfortunately, on some platforms this list may have file case broken. eg, some platforms might return 'freebsd' instead of 'FreeBSD'. This is because they have case-insensitive filesystems so things should Just Work anyway. =cut my ($re_Devel, $re_AssertOS); sub list_platforms { eval " # only load these if needed use File::Find::Rule; use File::Spec; "; die($@) if($@); if (!$re_Devel) { my $case_flag = File::Spec->case_tolerant ? '(?i)' : ''; $re_Devel = qr/$case_flag ^Devel$/x; $re_AssertOS = qr/$case_flag ^AssertOS$/x; } # sort by mtime, so oldest last my @modules = sort { (stat($a->{file}))[9] <=> (stat($b->{file}))[9] } map { my (undef, $dir_part, $file_part) = File::Spec->splitpath($_); $file_part =~ s/\.pm$//; my (@dirs) = grep {+length} File::Spec->splitdir($dir_part); foreach my $i (reverse 1..$#dirs) { next unless $dirs[$i] =~ $re_AssertOS && $dirs[$i - 1] =~ $re_Devel; splice @dirs, 0, $i + 1; last; } { module => join('::', @dirs, $file_part), file => File::Spec->canonpath($_) } } File::Find::Rule->file()->name('*.pm')->in( grep { -d } map { File::Spec->catdir($_, qw(Devel AssertOS)) } @INC ); my %modules = map { $_->{module} => $_->{file} } @modules; if(wantarray()) { return sort keys %modules; } else { return \%modules; } } =head3 list_family_members Takes the name of an OS 'family' and returns a list of all its members. In list context, you get a list, in scalar context you get an arrayref. If called on something that isn't a family, you get an empty list (or a ref to an empty array). =cut sub list_family_members { my $family = shift() || die(__PACKAGE__."::list_family_members needs a parameter\n"); # this will die if it's the wrong OS, but the module is loaded ... eval qq{use Devel::AssertOS::$family}; # ... so we can now query it my @members = eval qq{ no strict 'refs'; &{"Devel::AssertOS::${family}::matches"}() }; return wantarray() ? @members : \@members; } =head1 PLATFORMS SUPPORTED To see the list of platforms for which information is available, run this: perl -MDevel::CheckOS -e 'print join(", ", Devel::CheckOS::list_platforms())' Note that capitalisation is important. These are the names of the underlying Devel::AssertOS::* modules which do the actual platform detection, so they have to be 'legal' filenames and module names, which unfortunately precludes funny characters, so platforms like OS/2 are mis-spelt deliberately. Sorry. Also be aware that not all of them have been properly tested. I don't have access to most of them and have had to work from information gleaned from L and a few other places. For a complete list of OS families, see L. If you want to add your own OSes or families, see L and please feel free to upload the results to the CPAN. =head1 BUGS and FEEDBACK I welcome feedback about my code, including constructive criticism. Bug reports should be made using L or by email. You will need to include in your bug report the exact value of $^O, what the OS is called (eg Windows Vista 64 bit Ultimate Home Edition), and, if relevant, what "OS family" it should be in and who wrote it. If you are feeling particularly generous you can encourage me in my open source endeavours by buying me something from my wishlist: L =head1 SEE ALSO $^O in L L L L L The use-devel-assertos script L =head1 AUTHOR David Cantrell EFE Thanks to David Golden for the name and ideas about the interface, and to the cpan-testers-discuss mailing list for prompting me to write it in the first place. Thanks to Ken Williams, from whose L I lifted some of the information about what should be in the Unix family. Thanks to Billy Abbott for finding some bugs for me on VMS. Thanks to Matt Kraai for information about QNX. Thanks to Kenichi Ishigaki and Gabor Szabo for reporting a bug on Windows, and to the former for providing a patch. Thanks to Paul Green for some information about VOS. Thanks to Yanick Champoux for a patch to let Devel::AssertOS support negative assertions. Thanks to Brian Fraser for adding Android support. Thanks to Dale Evans for Debian detection, a bunch of Mac OS X specific version detection modules, and perl 5.6 support. =head1 SOURCE CODE REPOSITORY L =head1 COPYRIGHT and LICENCE Copyright 2007-2012 David Cantrell This software is free-as-in-speech software, and may be used, distributed, and modified under the terms of either the GNU General Public Licence version 2 or the Artistic Licence. It's up to you which one you use. The full text of the licences can be found in the files GPL2.txt and ARTISTIC.txt, respectively. =head1 HATS I recommend buying a Fedora from L. =head1 CONSPIRACY This module is also free-as-in-mason software. =cut 1; Class-Date-1.1.17/inc/Devel/AssertOS.pm0000644000175000017500000000453213304242666016722 0ustar yanickyanickpackage # Devel::AssertOS; use Devel::CheckOS; use strict; use warnings; our $VERSION = '1.21'; =head1 NAME Devel::AssertOS - require that we are running on a particular OS =head1 DESCRIPTION Devel::AssertOS is a utility module for Devel::CheckOS and Devel::AssertOS::*. It is nothing but a magic C that lets you do this: use Devel::AssertOS qw(Linux FreeBSD Cygwin); which will die unless the platform the code is running on is Linux, FreeBSD or Cygwin. To assert that the OS is B a specific platform, prepend the platform name with a minus sign. For example, to run on anything but Amiga, do: use Devel::AssertOS qw(-Amiga); =cut sub import { shift; die("Devel::AssertOS needs at least one parameter\n") unless(@_); my @oses = @_; my ( @must, @must_not ); for my $os ( @oses ) { if ( $os =~ s/^-// ) { push @must_not, $os; } else { push @must, $os; } } Devel::CheckOS::die_if_os_is(@must_not) if @must_not; Devel::CheckOS::die_if_os_isnt(@must) if @must; } =head1 BUGS and FEEDBACK I welcome feedback about my code, including constructive criticism. Bug reports should be made using L or by email. You will need to include in your bug report the exact value of $^O, what the OS is called (eg Windows Vista 64 bit Ultimate Home Edition), and, if relevant, what "OS family" it should be in and who wrote it. If you are feeling particularly generous you can encourage me in my open source endeavours by buying me something from my wishlist: L =head1 SEE ALSO $^O in L L L L The use-devel-assertos script L =head1 AUTHOR David Cantrell EFE Thanks to David Golden for suggesting that I add this utility module. =head1 COPYRIGHT and LICENCE Copyright 2007 David Cantrell This software is free-as-in-speech software, and may be used, distributed, and modified under the terms of either the GNU General Public Licence version 2 or the Artistic Licence. It's up to you which one you use. The full text of the licences can be found in the files GPL2.txt and ARTISTIC.txt, respectively. =head1 CONSPIRACY This module is also free-as-in-mason software. =cut $^O; Class-Date-1.1.17/lib/0000775000175000017500000000000013304242666013615 5ustar yanickyanickClass-Date-1.1.17/lib/Class/0000775000175000017500000000000013304242666014662 5ustar yanickyanickClass-Date-1.1.17/lib/Class/Date.pm0000644000175000017500000013140013304242666016072 0ustar yanickyanickpackage Class::Date; our $AUTHORITY = 'cpan:YANICK'; # ABSTRACT: Class for easy date and time manipulation $Class::Date::VERSION = '1.1.17'; use 5.006; use strict; use vars qw( @EXPORT_OK %EXPORT_TAGS @ISA $DATE_FORMAT $DST_ADJUST $MONTH_BORDER_ADJUST $RANGE_CHECK @NEW_FROM_SCALAR @ERROR_MESSAGES $WARNINGS $DEFAULT_TIMEZONE $LOCAL_TIMEZONE $GMT_TIMEZONE $NOTZ_TIMEZONE $RESTORE_TZ ); use Carp; use Exporter; use Time::Local; use Class::Date::Const; use Scalar::Util qw(blessed); use POSIX; use Class::Date::Rel; use Class::Date::Invalid; BEGIN { $WARNINGS = 1 if !defined $WARNINGS; *timelocal = *Time::Local::timelocal_nocheck; *timegm = *Time::Local::timegm_nocheck; @ISA=qw(Exporter); %EXPORT_TAGS = ( errors => $Class::Date::Const::EXPORT_TAGS{errors}); @EXPORT_OK = (qw( date localdate gmdate now @ERROR_MESSAGES), @{$EXPORT_TAGS{errors}}); *strftime_xs = *POSIX::strftime; *tzset_xs = *POSIX::tzset; *tzname_xs = *POSIX::tzname; } $GMT_TIMEZONE = 'GMT'; $DST_ADJUST = 1; $MONTH_BORDER_ADJUST = 0; $RANGE_CHECK = 0; $RESTORE_TZ = 1; $DATE_FORMAT="%Y-%m-%d %H:%M:%S"; sub _set_tz { my ($tz) = @_; my $lasttz = $ENV{TZ}; if (!defined $tz || $tz eq $NOTZ_TIMEZONE) { # warn "_set_tz: deleting TZ\n"; delete $ENV{TZ}; Env::C::unsetenv('TZ') if exists $INC{"Env/C.pm"}; } else { # warn "_set_tz: setting TZ to $tz\n"; $ENV{TZ} = $tz; Env::C::setenv('TZ', $tz) if exists $INC{"Env/C.pm"}; } tzset_xs(); return $lasttz; } sub _set_temp_tz { my ($tz, $sub) = @_; my $lasttz = _set_tz($tz); my $retval = eval { $sub->(); }; _set_tz($lasttz) if $RESTORE_TZ; die $@ if $@; return $retval; } tzset_xs(); $LOCAL_TIMEZONE = $DEFAULT_TIMEZONE = local_timezone(); { my $last_tz = _set_tz(undef); $NOTZ_TIMEZONE = local_timezone(); _set_tz($last_tz); } # warn "LOCAL: $LOCAL_TIMEZONE, NOTZ: $NOTZ_TIMEZONE\n"; # this method is used to determine what is the package name of the relative # time class. It is used at the operators. You only need to redefine it if # you want to derive both Class::Date and Class::Date::Rel. # Look at the Class::Date::Rel::ClassDate also. use constant ClassDateRel => "Class::Date::Rel"; use constant ClassDateInvalid => "Class::Date::Invalid"; use overload '""' => "string", '-' => "subtract", '+' => "add", '<=>' => "compare", 'cmp' => "compare", fallback => 1; sub date ($;$) { my ($date,$tz)=@_; return __PACKAGE__ -> new($date,$tz); } sub now () { date(time); } sub localdate ($) { date($_[0] || time, $LOCAL_TIMEZONE) } sub gmdate ($) { date($_[0] || time, $GMT_TIMEZONE) } sub import { my $package=shift; my @exported; foreach my $symbol (@_) { if ($symbol eq '-DateParse') { if (!$Class::Date::DateParse++) { if ( eval { require Date::Parse } ) { push @NEW_FROM_SCALAR,\&new_from_scalar_date_parse; } else { warn "Date::Parse is not available, although it is requested by Class::Date\n" if $WARNINGS; } } } elsif ($symbol eq '-EnvC') { if (!$Class::Date::EnvC++) { if ( !eval { require Env::C } ) { warn "Env::C is not available, although it is requested by Class::Date\n" if $WARNINGS; } } } else { push @exported,$symbol; } }; $package->export_to_level(1,$package,@exported); } sub new { my ($proto,$time,$tz)=@_; my $class = ref($proto) || $proto; # if the prototype is an object, not a class, then the timezone will be # the same $tz = $proto->[c_tz] if defined($time) && !defined $tz && blessed($proto) && $proto->isa( __PACKAGE__ ); # Default timezone is used if the timezone cannot be determined otherwise $tz = $DEFAULT_TIMEZONE if !defined $tz; return $proto->new_invalid(E_UNDEFINED,"") if !defined $time; if (blessed($time) && $time->isa( __PACKAGE__ ) ) { return $class->new_copy($time,$tz); } elsif (blessed($time) && $time->isa('Class::Date::Rel')) { return $class->new_from_scalar($time,$tz); } elsif (ref($time) eq 'ARRAY') { return $class->new_from_array($time,$tz); } elsif (ref($time) eq 'SCALAR') { return $class->new_from_scalar($$time,$tz); } elsif (ref($time) eq 'HASH') { return $class->new_from_hash($time,$tz); } else { return $class->new_from_scalar($time,$tz); } } sub new_copy { my ($s,$input)=@_; my $new_object=[ @$input ]; # we don't mind $isgmt! return bless($new_object, ref($s) || $s); } sub new_from_array { my ($s,$time,$tz) = @_; my ($y,$m,$d,$hh,$mm,$ss) = @$time; my $obj= [ ($y||2000)-1900, ($m||1)-1, $d||1, $hh||0 , $mm||0 , $ss||0 ]; $obj->[c_tz]=$tz; bless $obj, ref($s) || $s; $obj->_recalc_from_struct; return $obj; } sub new_from_hash { my ($s,$time,$tz) = @_; $s->new_from_array(_array_from_hash($time),$tz); } sub _array_from_hash { my ($val)=@_; [ $val->{year} || ($val->{_year} ? $val->{_year} + 1900 : 0 ), $val->{mon} || $val->{month} || ( $val->{_mon} ? $val->{_mon} + 1 : 0 ), $val->{day} || $val->{mday} || $val->{day_of_month}, $val->{hour}, exists $val->{min} ? $val->{min} : $val->{minute}, exists $val->{sec} ? $val->{sec} : $val->{second}, ]; } sub new_from_scalar { my ($s,$time,$tz)=@_; for (my $i=0;$i<@NEW_FROM_SCALAR;$i++) { my $ret=$NEW_FROM_SCALAR[$i]->($s,$time,$tz); return $ret if defined $ret; } return $s->new_invalid(E_UNPARSABLE,$time); } sub new_from_scalar_internal { my ($s,$time,$tz) = @_; return undef if !$time; if ($time eq 'now') { # now string my $obj=bless [], ref($s) || $s; $obj->[c_epoch]=time; $obj->[c_tz]=$tz; $obj->_recalc_from_epoch; return $obj; } elsif ($time =~ /^\s*(\d{4})(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)\d*\s*$/) { # mysql timestamp my ($y,$m,$d,$hh,$mm,$ss)=($1,$2,$3,$4,$5,$6); return $s->new_from_array([$y,$m,$d,$hh,$mm,$ss],$tz); } elsif ($time =~ /^\s*( \-? \d+ (\.\d+ )? )\s*$/x) { # epoch secs my $obj=bless [], ref($s) || $s; $obj->[c_epoch]=$1; $obj->[c_tz]=$tz; $obj->_recalc_from_epoch; return $obj; } elsif ($time =~ m{ ^\s* ( \d{0,4} ) - ( \d\d? ) - ( \d\d? ) ( (?: T|\s+ ) ( \d\d? ) : ( \d\d? ) ( : ( \d\d? ) (\.\d+)?)? )? }x) { my ($y,$m,$d,$hh,$mm,$ss)=($1,$2,$3,$5,$6,$8); # ISO(-like) date return $s->new_from_array([$y,$m,$d,$hh,$mm,$ss],$tz); } else { return undef; } } push @NEW_FROM_SCALAR,\&new_from_scalar_internal; sub new_from_scalar_date_parse { my ($s,$date,$tz)=@_; my $lt; my ($ss, $mm, $hh, $day, $month, $year, $zone) = Date::Parse::strptime($date); $zone = $tz if !defined $zone; if ($zone eq $GMT_TIMEZONE) { _set_temp_tz($zone, sub { $ss = ($lt ||= [ gmtime ])->[0] if !defined $ss; $mm = ($lt ||= [ gmtime ])->[1] if !defined $mm; $hh = ($lt ||= [ gmtime ])->[2] if !defined $hh; $day = ($lt ||= [ gmtime ])->[3] if !defined $day; $month = ($lt ||= [ gmtime ])->[4] if !defined $month; $year = ($lt ||= [ gmtime ])->[5] if !defined $year; }); } else { _set_temp_tz($zone, sub { $ss = ($lt ||= [ localtime ])->[0] if !defined $ss; $mm = ($lt ||= [ localtime ])->[1] if !defined $mm; $hh = ($lt ||= [ localtime ])->[2] if !defined $hh; $day = ($lt ||= [ localtime ])->[3] if !defined $day; $month = ($lt ||= [ localtime ])->[4] if !defined $month; $year = ($lt ||= [ localtime ])->[5] if !defined $year; }); } return $s->new_from_array( [$year+1900, $month+1, $day, $hh, $mm, $ss], $zone); } sub _check_sum { my ($s) = @_; my $sum=0; $sum += $_ || 0 foreach @{$s}[c_year .. c_sec]; return $sum; } sub _recalc_from_struct { my $s = shift; $s->[c_isdst] = -1; $s->[c_wday] = 0; $s->[c_yday] = 0; $s->[c_epoch] = 0; # these are required to suppress warinngs; eval { local $SIG{__WARN__} = sub { }; my $timecalc = $s->[c_tz] eq $GMT_TIMEZONE ? \&timegm : \&timelocal; _set_temp_tz($s->[c_tz], sub { $s->[c_epoch] = $timecalc->( @{$s}[c_sec,c_min,c_hour,c_day,c_mon], $s->[c_year] + 1900); } ); }; return $s->_set_invalid(E_INVALID,$@) if $@; my $sum = $s->_check_sum; $s->_recalc_from_epoch; @$s[c_error,c_errmsg] = (($s->_check_sum != $sum ? E_RANGE : 0), ""); return $s->_set_invalid(E_RANGE,"") if $RANGE_CHECK && $s->[c_error]; return 1; } sub _recalc_from_epoch { my ($s) = @_; _set_temp_tz($s->[c_tz], sub { @{$s}[c_year..c_isdst] = ($s->[c_tz] eq $GMT_TIMEZONE ? gmtime($s->[c_epoch]) : localtime($s->[c_epoch])) [5,4,3,2,1,0,6,7,8]; } ) } my $SETHASH = { year => sub { shift->[c_year] = shift() - 1900 }, _year => sub { shift->[c_year] = shift }, month => sub { shift->[c_mon] = shift() - 1 }, _month => sub { shift->[c_mon] = shift }, day => sub { shift->[c_day] = shift }, hour => sub { shift->[c_hour] = shift }, min => sub { shift->[c_min] = shift }, sec => sub { shift->[c_sec] = shift }, tz => sub { shift->[c_tz] = shift }, }; $SETHASH->{mon} = $SETHASH->{month}; $SETHASH->{_mon} = $SETHASH->{_month}; $SETHASH->{mday} = $SETHASH->{day_of_month} = $SETHASH->{day}; $SETHASH->{minute} = $SETHASH->{min}; $SETHASH->{second} = $SETHASH->{sec}; sub clone { my $s = shift; my $new_date = $s->new_copy($s); while (@_) { my $key = shift; my $value = shift; $SETHASH->{$key}->($value,$new_date); }; $new_date->_recalc_from_struct; return $new_date; } *set = *clone; # compatibility sub year { shift->[c_year] +1900 } sub _year { shift->[c_year] } sub yr { shift->[c_year] % 100 } sub mon { shift->[c_mon] +1 } *month = *mon; sub _mon { shift->[c_mon] } *_month = *_mon; sub day { shift->[c_day] } *day_of_month= *mday = *day; sub hour { shift->[c_hour] } sub min { shift->[c_min] } *minute = *min; sub sec { shift->[c_sec] } *second = *sec; sub wday { shift->[c_wday] + 1 } sub _wday { shift->[c_wday] } *day_of_week = *_wday; sub yday { shift->[c_yday] } *day_of_year = *yday; sub isdst { shift->[c_isdst] } *daylight_savings = \&isdst; sub epoch { shift->[c_epoch] } *as_sec = *epoch; # for compatibility sub tz { shift->[c_tz] } sub tzdst { shift->strftime("%Z") } sub monname { shift->strftime('%B') } *monthname = *monname; sub wdayname { shift->strftime('%A') } *day_of_weekname= *wdayname; sub error { shift->[c_error] } sub errmsg { my ($s) = @_; sprintf $ERROR_MESSAGES[ $s->[c_error] ]."\n", $s->[c_errmsg] } *errstr = *errmsg; sub new_invalid { my ($proto,$error,$errmsg) = @_; bless([],ref($proto) || $proto)->_set_invalid($error,$errmsg); } sub _set_invalid { my ($s,$error,$errmsg) = @_; bless($s,$s->ClassDateInvalid); @$s = (); @$s[ci_error, ci_errmsg] = ($error,$errmsg); return $s; } sub ampm { my ($s) = @_; return $s->[c_hour] < 12 ? "AM" : "PM"; } sub meridiam { my ($s) = @_; my $hour = $s->[c_hour] % 12; if( $hour == 0 ) { $hour = 12; } sprintf('%02d:%02d %s', $hour, $s->[c_min], $s->ampm); } sub hms { sprintf('%02d:%02d:%02d', @{ shift() }[c_hour,c_min,c_sec]) } sub ymd { my ($s)=@_; sprintf('%04d/%02d/%02d', $s->year, $s->mon, $s->[c_day]) } sub mdy { my ($s)=@_; sprintf('%02d/%02d/%04d', $s->mon, $s->[c_day], $s->year) } sub dmy { my ($s)=@_; sprintf('%02d/%02d/%04d', $s->[c_day], $s->mon, $s->year) } sub array { my ($s)=@_; my @return=@{$s}[c_year .. c_sec]; $return[c_year]+=1900; $return[c_mon]+=1; @return; } sub aref { return [ shift()->array ] } *as_array = *aref; sub struct { return ( @{ shift() } [c_sec,c_min,c_hour,c_day,c_mon,c_year,c_wday,c_yday,c_isdst] ) } sub sref { return [ shift()->struct ] } sub href { my ($s)=@_; my @struct=$s->struct; my $h={}; foreach my $key (qw(sec min hour day _month _year wday yday isdst)) { $h->{$key}=shift @struct; } $h->{epoch} = $s->[c_epoch]; $h->{year} = 1900 + $h->{_year}; $h->{month} = $h->{_month} + 1; $h->{minute} = $h->{min}; return $h; } *as_hash=*href; sub hash { return %{ shift->href } } # Thanks to Tony Olekshy for this algorithm # ripped from Time::Object by Matt Sergeant sub tzoffset { my ($s)=@_; my $epoch = $s->[c_epoch]; my $j = sub { # Tweaked Julian day number algorithm. my ($s,$n,$h,$d,$m,$y) = @_; $m += 1; $y += 1900; # Standard Julian day number algorithm without constant. my $y1 = $m > 2 ? $y : $y - 1; my $m1 = $m > 2 ? $m + 1 : $m + 13; my $day = int(365.25 * $y1) + int(30.6001 * $m1) + $d; # Modify to include hours/mins/secs in floating portion. return $day + ($h + ($n + $s / 60) / 60) / 24; }; # Compute floating offset in hours. my $delta = _set_temp_tz($s->[c_tz], sub { 24 * (&$j(localtime $epoch) - &$j(gmtime $epoch)); } ); # Return value in seconds rounded to nearest minute. return int($delta * 60 + ($delta >= 0 ? 0.5 : -0.5)) * 60; } sub month_begin { my ($s) = @_; my $aref = $s->aref; $aref->[2] = 1; return $s->new($aref); } sub month_end { my ($s)=@_; return $s->clone(day => 1)+'1M'-'1D'; } sub days_in_month { shift->month_end->mday; } sub is_leap_year { my ($s) = @_; my $new_date; eval { $new_date = $s->new([$s->year, 2, 29],$s->tz); } or return 0; return $new_date->day == 29; } sub strftime { my ($s,$format)=@_; $format ||= "%a, %d %b %Y %H:%M:%S %Z"; my $fmt = _set_temp_tz($s->[c_tz], sub { strftime_xs($format,$s->struct) } ); return $fmt; } sub string { my ($s) = @_; $s->strftime($DATE_FORMAT); } sub subtract { my ($s,$rhs)=@_; if (blessed($rhs) && $rhs->isa( __PACKAGE__ )) { my $dst_adjust = 0; $dst_adjust = 60*60*( $s->[c_isdst]-$rhs->[c_isdst] ) if $DST_ADJUST; return $s->ClassDateRel->new($s->[c_epoch]-$rhs->[c_epoch]+$dst_adjust); } elsif (blessed($rhs) && $rhs->isa("Class::Date::Rel")) { return $s->add(-$rhs); } elsif ($rhs) { return $s->add($s->ClassDateRel->new($rhs)->neg); } else { return $s; } } sub add { my ($s,$rhs)=@_; local $RANGE_CHECK; $rhs=$s->ClassDateRel->new($rhs) unless blessed($rhs) && $rhs->isa('Class::Date::Rel'); return $s unless blessed($rhs) && $rhs->isa('Class::Date::Rel'); # adding seconds my $retval= $rhs->[cs_sec] ? $s->new_from_scalar($s->[c_epoch]+$rhs->[cs_sec],$s->[c_tz]) : $s->new_copy($s); # adjust DST if necessary if ( $DST_ADJUST && (my $dstdiff=$retval->[c_isdst]-$s->[c_isdst])) { $retval->[c_epoch] -= $dstdiff*60*60; $retval->_recalc_from_epoch; } # adding months if ($rhs->[cs_mon]) { $retval->[c_mon]+=$rhs->[cs_mon]; my $year_diff= $retval->[c_mon]>0 ? # instead of POSIX::floor int ($retval->[c_mon]/12) : int (($retval->[c_mon]-11)/12); $retval->[c_mon] -= 12*$year_diff; my $expected_month = $retval->[c_mon]; $retval->[c_year] += $year_diff; $retval->_recalc_from_struct; # adjust month border if necessary if ($MONTH_BORDER_ADJUST && $retval && $expected_month != $retval->[c_mon]) { $retval->[c_epoch] -= $retval->[c_day]*60*60*24; $retval->_recalc_from_epoch; } } # sigh! We have finished! return $retval; } sub trunc { my ($s)=@_; return $s->new_from_array([$s->year,$s->month,$s->day,0,0,0],$s->[c_tz]); } *truncate = *trunc; sub get_epochs { my ($lhs,$rhs,$reverse)=@_; unless (blessed($rhs) && $rhs->isa( __PACKAGE__ )) { $rhs = $lhs->new($rhs); } my $repoch= $rhs ? $rhs->epoch : 0; return $repoch, $lhs->epoch if $reverse; return $lhs->epoch, $repoch; } sub compare { my ($lhs, $rhs) = get_epochs(@_); return $lhs <=> $rhs; } sub local_timezone { return (tzname_xs())[0]; } sub to_tz { my ($s, $tz) = @_; return $s->new($s->epoch, $tz); } 1; __END__ =pod =encoding UTF-8 =head1 NAME Class::Date - Class for easy date and time manipulation =head1 VERSION version 1.1.17 =head1 SYNOPSIS use Class::Date qw(:errors date localdate gmdate now -DateParse -EnvC); # creating absolute date object (local time) $date = Class::Date->new( [$year,$month,$day,$hour,$min,$sec]); $date = date [$year,$month,$day,$hour,$min,$sec]; # ^- "date" is an exportable function, the same as Class::Date->new $date = date { year => $year, month => $month, day => $day, hour => $hour, min => $min, sec => $sec }; $date = date "2001-11-12 07:13:12"; $date = localdate "2001-12-11"; $date = now; # the same as date(time) $date = date($other_date_object); # cloning ... # creating absolute date object (GMT) $date = Class::Date->new( [$year,$month,$day,$hour,$min,$sec],'GMT'); $date = gmdate "2001-11-12 17:13"; ... # creating absolute date object in any other timezone $date = Class::Date->new( [$year,$month,$day,$hour,$min,$sec],'Iceland' ); $date = date "2001-11-12 17:13", 'Iceland'; $date2 = $date->new([$y2, $m2, $d2, $h2, $m2, $s2]); # ^- timezone is inherited from the $date object # creating relative date object # (normally you don't need to create this object explicitly) $reldate = Class::Date::Rel->new( "3Y 1M 3D 6h 2m 4s" ); $reldate = Class::Date::Rel->new( "6Y" ); $reldate = Class::Date::Rel->new( $secs ); # secs $reldate = Class::Date::Rel->new( [$year,$month,$day,$hour,$min,$sec] ); $reldate = Class::Date::Rel->new( { year => $year, month => $month, day => $day, hour => $hour, min => $min, sec => $sec } ); $reldate = Class::Date::Rel->new( "2001-11-12 07:13:12" ); $reldate = Class::Date::Rel->new( "2001-12-11" ); # getting values of an absolute date object $date; # prints the date in default output format (see below) $date->year; # year, e.g: 2001 $date->_year; # year - 1900, e.g. 101 $date->yr; # 2-digit year 0-99, e.g 1 $date->mon; # month 1..12 $date->month; # same as prev. $date->_mon; # month 0..11 $date->_month; # same as prev. $date->day; # day of month $date->mday; # day of month $date->day_of_month;# same as prev. $date->hour; $date->min; $date->minute; # same as prev. $date->sec; $date->second; # same as prev. $date->wday; # 1 = Sunday $date->_wday; # 0 = Sunday $date->day_of_week; # same as prev. $date->yday; $date->day_of_year; # same as prev. $date->isdst; # DST? $date->daylight_savings; # same as prev. $date->epoch; # UNIX time_t $date->monname; # name of month, eg: March $date->monthname; # same as prev. $date->wdayname; # Thursday $date->day_of_weekname # same as prev. $date->hms # 01:23:45 $date->ymd # 2000/02/29 $date->mdy # 02/29/2000 $date->dmy # 29/02/2000 $date->meridiam # 01:23 AM $date->ampm # AM/PM $date->string # 2000-02-29 12:21:11 (format can be changed, look below) "$date" # same as prev. $date->tzoffset # timezone-offset $date->strftime($format) # POSIX strftime (without the huge POSIX.pm) $date->tz # returns the base timezone as you specify, eg: CET $date->tzdst # returns the real timezone with dst information, eg: CEST ($year,$month,$day,$hour,$min,$sec)=$date->array; ($year,$month,$day,$hour,$min,$sec)=@{ $date->aref }; # !! $year: 1900-, $month: 1-12 ($sec,$min,$hour,$day,$mon,$year,$wday,$yday,$isdst)=$date->struct; ($sec,$min,$hour,$day,$mon,$year,$wday,$yday,$isdst)=@{ $date->sref }; # !! $year: 0-, $month: 0-11 $hash=$date->href; # $href can be reused as a constructor print $hash->{year}."-".$hash->{month}. ... $hash->{sec} ... ; %hash=$date->hash; # !! $hash{year}: 1900-, $hash{month}: 1-12 $date->month_begin # First day of the month (date object) $date->month_end # Last day of the month $date->days_in_month # 28..31 # constructing new date based on an existing one: $new_date = $date->clone; $new_date = $date->clone( year => 1977, sec => 14 ); # valid keys: year, _year, month, mon, _month, _mon, day, mday, day_of_month, # hour, min, minute, sec, second, tz # constructing a new date, which is the same as the original, but in # another timezone: $new_date = $date->to_tz('Iceland'); # changing date format { local $Class::Date::DATE_FORMAT="%Y%m%d%H%M%S"; print $date # result: 20011222000000 $Class::Date::DATE_FORMAT=undef; print $date # result: Thu Oct 13 04:54:34 1994 $Class::Date::DATE_FORMAT="%Y/%m/%d" print $date # result: 1994/10/13 } # error handling $a = date($date_string); if ($a) { # valid date ... } else { # invalid date if ($a->error == E_INVALID) { ... } print $a->errstr; } # adjusting DST in calculations (see the doc) $Class::Date::DST_ADJUST = 1; # this is the default $Class::Date::DST_ADJUST = 0; # "month-border adjust" flag $Class::Date::MONTH_BORDER_ADJUST = 0; # this is the default print date("2001-01-31")+'1M'; # will print 2001-03-03 $Class::Date::MONTH_BORDER_ADJUST = 1; print date("2001-01-31")+'1M'; # will print 2001-02-28 # date range check $Class::Date::RANGE_CHECK = 0; # this is the default print date("2001-02-31"); # will print 2001-03-03 $Class::Date::RANGE_CHECK = 1; print date("2001-02-31"); # will print nothing # getting values of a relative date object $reldate; # reldate in seconds (assumed 1 month = 2_629_744 secs) $reldate->year; $reldate->mon; $reldate->month; # same as prev. $reldate->day; $reldate->hour; $reldate->min; $reldate->minute; # same as prev. $reldate->sec; # same as $reldate $reldate->second; # same as prev. $reldate->sec_part; # "second" part of the relative date $reldate->mon_part; # "month" part of the relative date # arithmetic with dates: print date([2001,12,11,4,5,6])->truncate; # will print "2001-12-11" $new_date = $date+$reldate; $date2 = $date+'3Y 2D'; # 3 Years and 2 days $date3 = $date+[1,2,3]; # $date plus 1 year, 2 months, 3 days $date4 = $date+'3-1-5' # $date plus 3 years, 1 months, 5 days $new_date = $date-$reldate; $date2 = $date-'3Y'; # 3 Yearss $date3 = $date-[1,2,3]; # $date minus 1 year, 2 months, 3 days $date4 = $date-'3-1-5' # $date minus 3 years, 1 month, 5 days $new_reldate = $date1-$date2; $reldate2 = Class::Date->new('2000-11-12')-'2000-11-10'; $reldate3 = $date3-'1977-11-10'; $days_between = (Class::Date->new('2001-11-12')-'2001-07-04')->day; # comparison between absolute dates print $date1 > $date2 ? "I am older" : "I am younger"; # comparison between relative dates print $reldate1 > $reldate2 ? "I am faster" : "I am slower"; # Adding / Subtracting months and years are sometimes tricky: print date("2001-01-29") + '1M' - '1M'; # gives "2001-02-01" print date("2000-02-29") + '1Y' - '1Y'; # gives "2000-03-01" # Named interface ($date2 does not necessary to be a Class::Date object) $date1->string; # same as $date1 in scalar context $date1->subtract($date2); # same as $date1 - $date2 $date1->add($date2); # same as $date1 + $date2 $date1->compare($date2); # same as $date1 <=> $date2 $reldate1->sec; # same as $reldate1 in numeric or scalar context $reldate1->compare($reldate2);# same as $reldate1 <=> $reldate2 $reldate1->add($reldate2); # same as $reldate1 + $reldate2 $reldate1->neg # used for subtraction # Disabling Class::Date warnings at load time BEGIN { $Class::Date::WARNINGS=0; } use Class::Date; =head1 DESCRIPTION This module is intended to provide a general-purpose date and datetime type for perl. You have a Class::Date class for absolute date and datetime, and have a Class::Date::Rel class for relative dates. You can use "+", "-", "<" and ">" operators as with native perl data types. Note that this module is fairly ancient and dusty. You might want to take a look at L and its related modules for a more standard, and maintained, Perl date manipulation solution. =head1 USAGE If you want to use a date object, you need to do the following: - create a new object - do some operations (+, -, comparison) - get result back =head2 Creating a new date object You can create a date object by the "date", "localdate" or "gmdate" function, or by calling the Class::Date constructor. "date" and "Class::Date->new" are equivalent, both has two arguments: The date and the timezone. $date1= date [2000,11,12]; $date2= Class::Date->new([2000,06,11,13,11,22],'GMT'); $date2= $date1->new([2000,06,11,13,11,22]); If the timezone information is omitted, then it first check if "new" is called as an object method or a class method. If it is an object method, then it inherits the timezone from the base object, otherwise the default timezone is used ($Class::Date::DEFAULT_TIMEZONE), which is usually set to the local timezone (which is stored in $Class::Date::LOCAL_TIMEZONE). These two variables are set only once to the value, which is returned by the Class::Date::local_timezone() function. You can change these values whenever you want. "localdate $x" is equivalent to "date $x, $Class::Date::LOCAL_TIMEZONE", "gmdate $x" is equivalent to "date $x, $Class::Date::GMT_TIMEZONE". $Class::Date::GMT_TIMEZONE is set to 'GMT' by default. $date1= localdate [2000,11,12]; $date2= gmdate [2000,4,2,3,33,33]; $date = localdate(time); The format of the accepted input date can be: =over 4 =item [$year,$month,$day,$hour,$min,$sec] An array reference with 6 elements. The missing elements have default values (year: 2000, month, day: 1, hour, min, sec: 0) =item { year => $year, month => $month, day => $day, hour => $hour, min => $min, sec => $sec } A hash reference with the same 6 elements as above. =item "YYYYMMDDhhmmss" A mysql-style timestamp value, which consist of at least 14 digit. =item "973897262" A valid 32-bit integer: This is parsed as a unix time. =item "YYYY-MM-DD hh:mm:ss" A standard ISO(-like) date format. Additional ".fraction" part is ignored, ":ss" can be omitted. =item additional input formats You can specify "-DateParse" as an import parameter, e.g: use Class::Date qw(date -DateParse); With this, the module will try to load Date::Parse module, and if it find it then all these formats can be used as an input. Please refer to the Date::Parse documentation. =back =head2 Operations =over 4 =item addition You can add the following to a Class::Date object: - a valid Class::Date::Rel object - anything, that can be used for creating a new Class::Date::Rel object It means that you don't need to create a new Class::Date::Rel object every time when you add something to the Class::Date object, it creates them automatically: $date= Class::Date->new('2001-12-11')+Class::Date::Rel->new('3Y'); is the same as: $date= date('2001-12-11')+'3Y'; You can provide a Class::Date::Rel object in the following form: =over 4 =item array ref The same format as seen in Class::Date format, except the default values are different: all zero. =item hash ref The same format as seen in Class::Date format, except the default values are different: all zero. =item "973897262" A valid 32-bit integer is parsed as seconds. =item "YYYY-MM-DD hh:mm:ss" A standard ISO date format, but this is parsed as relative date date and time, so month, day and year can be zero (and defaults to zero). =item "12Y 6M 6D 20h 12m 5s" This special string can be used if you don't want to use the ISO format. This string consists of whitespace separated tags, each tag consists of a number and a unit. The units can be: Y: year M: month D: day h: hour m: min s: sec The number and unit must be written with no space between them. =back =item substraction The same rules are true for substraction, except you can substract two Class::Date object from each other, and you will get a Class::Date::Rel object: $reldate=$date1-$date2; $reldate=date('2001-11-12 12:11:07')-date('2001-10-07 10:3:21'); In this case, the "month" field of the $reldate object will be 0, and the other fields will contain the difference between two dates; =item comparison You can compare two Class::Date objects, or one Class::Date object and another data, which can be used for creating a new Class::Data object. It means that you don't need to bless both objects, one of them can be a simple string, array ref, hash ref, etc (see how to create a date object). if ( date('2001-11-12') > date('2000-11-11') ) { ... } or if ( date('2001-11-12') > '2000-11-11' ) { ... } =item truncate You can chop the time value from this object (set hour, min and sec to 0) with the "truncate" or "trunc" method. It does not modify the specified object, it returns with a new one. =item clone You can create new date object based on an existing one, by using the "clone" method. Note, this DOES NOT modify the base object. $new_date = $date->clone( year => 2001, hour => 14 ); The valid keys are: year, _year, month, mon, _month, _mon, day, mday, day_of_month, hour, min, minute, sec, second, tz. There is a "set" method, which does the same as the "clone", it exists only for compatibility. =item to_tz You can use "to_tz" to create a new object, which means the same time as the base object, but in the different timezone. Note that $date->clone( tz => 'Iceland') and $date->to_tz('Iceland') is not the same! Cloning a new object with setting timezone will preserve the time information (hour, minute, second, etc.), but transfer the time into other timezone, while to_tz usually change these values based on the difference between the source and the destination timezone. =item Operations with Class::Date::Rel The Class::Date::Rel object consists of a month part and a day part. Most people only use the "day" part of it. If you use both part, then you can get these parts with the "sec_part" and "mon_part" method. If you use "sec", "month", etc. methods or if you use this object in a mathematical context, then this object is converted to one number, which is interpreted as second. The conversion is based on a 30.436 days month. Don't use it too often, because it is confusing... If you use Class::Date::Rel in an expression with other Class::Date or Class::Date::Rel objects, then it does what is expected: date('2001-11-12')+'1M' will be '2001-12-12' and date('1996-02-11')+'2M' will be '1996-04-11' =back =head2 Accessing data from a Class::Date and Class::Date::Rel object You can use the methods methods described at the top of the document if you want to access parts of the data which is stored in a Class::Date and Class::Date::Rel object. =head2 Error handling If a date object became invalid, then the object will be reblessed to Class::Date::Invalid. This object is false in boolean environment, so you can test the date validity like this: $a = date($input_date); if ($a) { # valid date ... } else { # invalid date if ($a->error == E_INVALID) { ... } print $a->errstr; } Note even the date is invalid, the expression "defined $a" always returns true, so the following is wrong: $a = date($input_date); if (defined $a) ... # WRONG!!!! You can test the error by getting the $date->error value. You might import the ":errors" tag: use Class::Date qw(:errors); Possible error values are: =over 4 =item E_OK No errors. =item E_INVALID Invalid date. It is set when some of the parts of the date are invalid, and Time::Local functions cannot convert them to a valid date. =item E_RANGE This error is set, when parts of the date are valid, but the whole date is not valid, e.g. 2001-02-31. When the $Class::Date::RANGE_CHECK is not set, then these date values are automatically converted to a valid date: 2001-03-03, but the $date->error value are set to E_RANGE. If $Class::Date::RANGE_CHECK is set, then a date "2001-02-31" became invalid date. =item E_UNPARSABLE This error is set, when the constructor cannot be created from a scalar, e.g: $a = date("4kd sdlsdf lwekrmk"); =item E_UNDEFINED This error is set, when you want to create a date object from an undefined value: $a = Class::Date->new(undef); Note, that localdate(undef) will create a valid object, because it calls $Class::Date(time). =back You can get the error in string form by calling the "errstr" method. =head1 DST_ADJUST $DST_ADJUST is an important configuration option. If it is set to true (default), then the module adjusts the date and time when the operation switches the border of DST. With this setting, you are ignoring the effect of DST. When $DST_ADJUST is set to false, then no adjustment is done, the calculation will be based on the exact time difference. You will see the difference through an example: $Class::Date::DST_ADJUST=1; print date("2000-10-29", "CET") + "1D"; # This will print 2000-10-30 00:00:00 print date("2001-03-24 23:00:00", "CET") + "1D"; # This will be 2001-03-25 23:00:00 print date("2001-03-25", "CET") + "1D"; # This will be 2001-03-26 00:00:00 $Class::Date::DST_ADJUST=0; print date("2000-10-29", "CET") + "1D"; # This will print 2000-10-29 23:00:00 print date("2001-03-24 23:00:00", "CET") + "1D"; # This will be 2001-03-26 00:00:00 =head1 MONTHS AND YEARS If you add or subtract "months" and "years" to a date, you may get wrong dates, e.g when you add one month to 2001-01-31, you expect to get 2001-02-31, but this date is invalid and converted to 2001-03-03. Thats' why date("2001-01-31") + '1M' - '1M' != "2001-01-31" This problem can occur only with months and years, because others can easily be converted to seconds. =head1 MONTH_BORDER_ADJUST $MONTH_BORDER_ADJUST variable is used to switch on or off the month-adjust feature. This is used only when someone adds months or years to a date and then the resulted date became invalid. An example: adding one month to "2001-01-31" will result "2001-02-31", and this is an invalid date. When $MONTH_BORDER_ADJUST is false, this result simply normalized, and becomes "2001-03-03". This is the default behaviour. When $MONTH_BORDER_ADJUST is true, this result becomes "2001-02-28". So when the date overflows, then it returns the last day insted. Both settings keep the time information. =head1 TIMEZONE SUPPORT Since 1.0.11, Class::Date handle timezones natively on most platforms (see the BUGS AND LIMITATIONS section for more info). When the module is loaded, then it determines the local base timezone by calling the Class::Date::local_timezone() function, and stores these values into two variables, these are: $Class::Date::LOCAL_TIMEZONE and $Class::Date::DEFAULT_TIMEZONE. The first value is used, when you call the "localdate" function, the second value is used, when you call the "date" function and you don't specify the timezone. There is a $Class::Date::GMT_TIMEZONE function also, which is used by the "gmdate" function, this is set to 'GMT'. You can query the timezone of a date object by calling the $date->tz method. Note this value returns the timezone as you specify, so if you create the object with an unknown timezone, you will get this back. If you want to query the effective timezone, you can call the $date->tzdst method. This method returns only valid timezones, but it is not necessarily the timezone which can be used to create a new object. For example $date->tzdst can return 'CEST', which is not a valid base timezone, because it contains daylight savings information also. On Linux systems, you can see the possible base timezones in the /usr/share/zoneinfo directory. In Class::Date 1.1.6, a new environment variable is introduced: $Class::Date::NOTZ_TIMEZONE. This variable stores the local timezone, which is used, when the TZ environment variable is not set. It is introduced, because there are some systems, which cannot handle the queried timezone well. For example the local timezone is CST, it is returned by the tzname() perl function, but when I set the TZ environment variable to CST, it works like it would be GMT. The workaround is NOTZ_TIMEZONE: if a date object has a timezone, which is the same as NOTZ_TIMEZONE, then the TZ variable will be removed before each calculation. In normal case, it would be the same as setting TZ to $NOTZ_TIMEZONE, but some systems don't like it, so I decided to introduce this variable. The $Class::Date::NOTZ_TIMEZONE variable is set in the initialization of the module by removing the TZ variable from the environment and querying the tzname variable. =head1 INTERNALS This module uses operator overloading very heavily. I've found it quite stable, but I am afraid of it a bit. A Class::Date object is an array reference. A Class::Date::Rel object is an array reference, which contains month and second information. I need to store it as an array ref, because array and month values cannot be converted into seconds, because of our super calendar. You can add code references to the @Class::Date::NEW_FROM_SCALAR and @Class::Date::Rel::NEW_FROM_SCALAR. These arrays are iterated through when a scalar-format date must be parsed. These arrays only have one or two values at initialization. The parameters which the code references got are the same as the "new" method of each class. In this way, you can personalize the date parses as you want. As of 0.90, the Class::Date has been rewritten. A lot of code and design decision has been borrowed from Matt Sergeant's Time::Object, and there will be some incompatibility with the previous public version (0.5). I tried to keep compatibility methods in Class::Date. If you have problems regarding this, please drop me an email with the description of the problem, and I will set the compatibility back. Invalid dates are Class::Date::Invalid objects. Every method call on this object and every operation with this object returns undef or 0. =head1 DEVELOPMENT FOCUS This module tries to be as full-featured as can be. It currently lacks business-day calculation, which is planned to be implemented in the 1.0.x series. I try to keep this module not to depend on other modules and I want this module usable without a C compiler. Currently the module uses the POSIX localtime function very extensively. This makes the date calculation a bit slow, but provides a rich interface, which is not provided by any other module. When I tried to redesign the internals to not depend on localtime, I failed, because there are no other way to determine the daylight savings information. =head1 SPEED ISSUES There are two kind of adjustment in this module, DST_ADJUST and MONTH_BORDER_ADJUST. Both of them makes the "+" and "-" operations slower. If you don't need them, switch them off to achieve faster calculations. In general, if you really need fast date and datetime calculation, don't use this module. As you see in the previous section, the focus of development is not the speed in 1.0. For fast date and datetime calculations, use Date::Calc module instead. =head1 THREAD SAFETY and MOD_PERL This module is NOT thread-safe, since it uses C library functions, which are not thread-safe. Using this module in a multi-threaded environment can cause timezones to be messed up. I did not put any warning about it, you have to make sure that you understand this! Under some circumstances in a mod_perl environment, you require the Env::C module to set the TZ variable properly before calling the time functions. I added the -EnvC import option to automatically load this module if it is not loaded already. Please read the mod_perl documentation about the environment variables and mod_perl to get the idea why it is required sometimes: http://perl.apache.org/docs/2.0/user/troubleshooting/troubleshooting.html#C_Libraries_Don_t_See_C__ENV__Entries_Set_by_Perl_Code You are sure have this problem if the $Class::Date::NOTZ_TIMEZONE variable is set to 'UTC', althought you are sure that your timezone is not that. Try -EnvC in this case, but make sure that you are not using it in a multi-threaded environment! =head1 OTHER BUGS AND LIMITATIONS =over 4 =item * Not all date/time values can be expressed in all timezones. For example: print date("2010-10-03 02:00:00", "Australia/Sydney") # it will print 2010-10-03 03:00:00 No matter how hard you try you, you are not going to be able to express the time in the example in that timezone. If you don't need the timezone information and you want to make sure that the calculations are always correct, please use GMT as a timezone (the 'gmdate' function can be a shortcut for it). In this case, you might also consider turning off DST_ADJUST to speed up the calculation. =item * I cannot manage to get the timezone code working properly on ActivePerl 5.8.0 on win XP and earlier versions possibly have this problem also. If you have a system like this, then you will have only two timezones, the local and the GMT. Every timezone, which is not equal to $Class::Date::GMT_TIMEZONE is assumed to be local. This seems to be caused by the win32 implementation of timezone routines. I don't really know how to make this thing working, so I gave up this issue. If anyone know a working solution, then I will integrate it into Class::Date, but until then, the timezone support will not be available for these platforms. =item * Perl 5.8.0 and earlier versions has a bug in the strftime code on some operating systems (for example Linux), which is timezone related. I recommend using the strftime, which is provided with Class::Date, so don't try to use the module without the compiled part. The module will not work with a buggy strftime - the test is hardcoded into the beginning of the code. If you anyway want to use the module, remove the hardcoded "die" from the module, but do it for your own risk. =item * This module uses the POSIX functions for date and time calculations, so it is not working for dates beyond 2038 and before 1902. I don't know what systems support dates in 1902-1970 range, it may not work on your system. I know it works on the Linux glibc system with perl 5.6.1 and 5.7.2. I know it does not work with perl 5.005_03 (it may be the bug of the Time::Local module). Please report if you know any system where it does _not_ work with perl 5.6.1 or later. I hope that someone will fix this with new time_t in libc. If you really need dates over 2038 and before 1902, you need to completely rewrite this module or use Date::Calc or other date modules. =item * This module uses Time::Local, and when it croaks, Class::Date returns "Invalid date or time" error message. Time::Local is different in the 5.005 and 5.6.x (and even 5.7.x) version of perl, so the following code will return different results: $a = date("2006-11-11")->clone(year => -1); In perl 5.6.1, it returns an invalid date with error message "Invali date or time", in perl 5.005 it returns an invalid date with range check error. Both are false if you use them in boolean context though, only the error message is different, but don't rely on the error message in this case. It however works in the same way if you change other fields than "year" to an invalid field. =back =head1 SUPPORT Class::Date is free software. IT COMES WITHOUT WARRANTY OF ANY KIND. If you have questions, you can send questions directly to me: dlux@dlux.hu =head1 WIN32 notes You can get a binary win32 version of Class::Date from Chris Winters' .ppd repository with the following commands: For people using PPM2: c:\> ppm PPM> set repository oi http://openinteract.sourceforge.net/ppmpackages/ PPM> set save PPM> install Class-Date For people using PPM3: c:\> ppm PPM> repository http://openinteract.sourceforge.net/ppmpackages/ PPM> install Class-Date The first steps in PPM only needs to be done at the first time. Next time you just run the 'install'. =head1 COPYRIGHT Copyright (c) 2001 Szabó, Balázs (dLux) All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Portions Copyright (c) Matt Sergeant =head1 CREDITS - Matt Sergeant (Lots of code are borrowed from the Time::Object module) - Tatsuhiko Miyagawa (bugfixes) - Stas Bekman (suggestions, bugfix) - Chris Winters (win32 .ppd version) - Benoit Beausejour (Parts of the timezone code is borrowed from his Date::Handler module) =head1 SEE ALSO perl(1). Date::Calc(3pm). Time::Object(3pm). Date::Handler(3pm). =head1 AUTHORS =over 4 =item * dLux (Szabó, Balázs) =item * Gabor Szabo =item * Yanick Champoux =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2018, 2014, 2010, 2003 by Balázs Szabó. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut Class-Date-1.1.17/lib/Class/Date/0000775000175000017500000000000013304242666015537 5ustar yanickyanickClass-Date-1.1.17/lib/Class/Date/Const.pm0000644000175000017500000000350513304242666017164 0ustar yanickyanickpackage Class::Date::Const; our $AUTHORITY = 'cpan:YANICK'; $Class::Date::Const::VERSION = '1.1.17'; use strict; use vars qw(@EXPORT @ISA @ERROR_MESSAGES %EXPORT_TAGS); use Exporter; my %FIELDS = ( # Class::Date fields c_year => 0, c_mon => 1, c_day => 2, c_hour => 3, c_min => 4, c_sec => 5, c_wday => 6, c_yday => 7, c_isdst => 8, c_epoch => 9, c_tz => 10, c_error => 11, c_errmsg => 12, # Class::Date::Rel fields cs_mon => 0, cs_sec => 1, # Class::Date::Invalid fields ci_error => 0, ci_errmsg => 1, ); eval " sub $_ () { ".$FIELDS{$_}."}" foreach keys %FIELDS; @ISA = qw(Exporter); my @ERRORS = ( E_OK => '', E_INVALID => 'Invalid date or time', E_RANGE => 'Range check on date or time failed', E_UNPARSABLE => 'Unparsable date or time: %s', E_UNDEFINED => 'Undefined date object', ); my @ERR; # predeclaring error constants my $c = 0; while (@ERRORS) { my $errorcode = shift @ERRORS; my $errorname = shift @ERRORS; eval "sub $errorcode () { $c }"; $ERROR_MESSAGES[$c] = $errorname; push @{$EXPORT_TAGS{errors}}, $errorcode; $c++; } @EXPORT = (keys %FIELDS, qw(@ERROR_MESSAGES), @{$EXPORT_TAGS{errors}}); 1; __END__ =pod =encoding UTF-8 =head1 NAME Class::Date::Const =head1 VERSION version 1.1.17 =head1 AUTHORS =over 4 =item * dLux (Szabó, Balázs) =item * Gabor Szabo =item * Yanick Champoux =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2018, 2014, 2010, 2003 by Balázs Szabó. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut Class-Date-1.1.17/lib/Class/Date/Invalid.pm0000644000175000017500000000243013304242666017460 0ustar yanickyanickpackage Class::Date::Invalid; our $AUTHORITY = 'cpan:YANICK'; $Class::Date::Invalid::VERSION = '1.1.17'; use strict; use warnings; use Class::Date::Const; use overload '0+' => "zero", '""' => "empty", '<=>' => "compare", 'cmp' => "compare", '+' => "zero", '!' => "true", fallback => 1; sub empty { "" } sub zero { 0 } sub true { 1 } sub compare { return ($_[1] ? 1 : 0) * ($_[2] ? -1 : 1) } sub error { shift->[ci_error]; } sub errmsg { my ($s) = @_; no warnings; # sometimes we need the errmsg, sometimes we don't # should be 'no warnings 'redundant'', but older perls don't # understand that warning sprintf $ERROR_MESSAGES[ $s->[ci_error] ]."\n", $s->[ci_errmsg] } *errstr = *errmsg; sub AUTOLOAD { undef } 1; __END__ =pod =encoding UTF-8 =head1 NAME Class::Date::Invalid =head1 VERSION version 1.1.17 =head1 AUTHORS =over 4 =item * dLux (Szabó, Balázs) =item * Gabor Szabo =item * Yanick Champoux =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2018, 2014, 2010, 2003 by Balázs Szabó. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut Class-Date-1.1.17/lib/Class/Date/Rel.pm0000644000175000017500000001017713304242666016623 0ustar yanickyanickpackage Class::Date::Rel; our $AUTHORITY = 'cpan:YANICK'; $Class::Date::Rel::VERSION = '1.1.17'; use strict; use warnings; use vars qw(@NEW_FROM_SCALAR); use Class::Date::Const; use Scalar::Util qw(blessed); use constant SEC_PER_MONTH => 2_629_744; # see the ClassDateRel const in package Class::Date use constant ClassDate => "Class::Date"; use overload '0+' => "sec", '""' => "sec", '<=>' => "compare", 'cmp' => "compare", '+' => "add", 'neg' => "neg", fallback => 1; sub new { my ($proto,$val)=@_; my $class = ref($proto) || $proto; return undef if !defined $val; my $ref = ref $val or return $class->new_from_scalar($val); return $class->new_copy($val) if (blessed($val) && $val->isa( __PACKAGE__ )); return $class->new_from_array($val) if $ref eq 'ARRAY'; return $class->new_from_hash($val) if $ref eq 'HASH'; # can only be a scalar ref by now return $class->new_from_scalar($$val); } sub new_copy { my ($s,$val)=@_; return bless([@$val], ref($s)||$s); } sub new_from_array { my ($s,$val) = @_; my ($y,$m,$d,$hh,$mm,$ss) = @$val; return bless([ ($y || 0) * 12 + $m , ($ss || 0) + 60*(($mm || 0) + 60*(($hh || 0) + 24* ($d || 0))) ], ref($s)||$s); } sub new_from_hash { my ($s,$val) = @_; $s->new_from_array(Class::Date::_array_from_hash($val)); } sub new_from_scalar { my ($s,$val)=@_; for (my $i=0;$i<@NEW_FROM_SCALAR;$i++) { my $ret=$NEW_FROM_SCALAR[$i]->($s,$val); return $ret if defined $ret; } return undef; } sub new_from_scalar_internal { my ($s,$val)=@_; return undef if !defined $val; return bless([0,$1],ref($s) || $s) if $val =~ / ^ \s* ( \-? \d+ ( \. \d* )? ) \s* $/x; if ($val =~ m{ ^\s* ( \d{1,4} ) - ( \d\d? ) - ( \d\d? ) ( \s+ ( \d\d? ) : ( \d\d? ) ( : ( \d\d? )? (\.\d+)? )? )? }x ) { # ISO date my ($y,$m,$d,$hh,$mm,$ss)=($1,$2,$3,$5,$6,$8); return $s->new_from_array([$y,$m,$d,$hh,$mm,$ss]); } my ($y,$m,$d,$hh,$mm,$ss)=(0,0,0,0,0,0); $val =~ s{ \G \s* ( \-? \d+) \s* (Y|M|D|h|m|s) }{ my ($num,$cmd)=($1,$2); if ($cmd eq 'Y') { $y=$num; } elsif ($cmd eq 'M') { $m=$num; } elsif ($cmd eq 'D') { $d=$num; } elsif ($cmd eq 'h') { $hh=$num; } elsif ($cmd eq 'm') { $mm=$num; } elsif ($cmd eq 's') { $ss=$num; } ""; }gexi; return $s->new_from_array([$y,$m,$d,$hh,$mm,$ss]); } push @NEW_FROM_SCALAR,\&new_from_scalar_internal; sub compare { my ($s,$val2,$reverse) = @_; my $rev_multiply=$reverse ? -1 : 1; if (blessed($val2) && $val2->isa( __PACKAGE__ )) { return ($s->sec <=> $val2->sec) * $rev_multiply; } else { my $date_obj=$s->new($val2); return ($s->sec <=> 0) * $rev_multiply if !defined $date_obj; return ($s->sec <=> $date_obj->sec) * $rev_multiply; } } sub add { my ($s,$val2)=@_; if (my $reldate=$s->new($val2)) { my $months=$s->[cs_mon] + $reldate->[cs_mon]; my $secs =$s->[cs_sec] + $reldate->[cs_sec]; return $s->new_from_hash({ month => $months, sec => $secs }) if $months; return $secs; } else { return $s; } } sub neg { my ($s)=@_; return $s->new_from_hash({ month => -$s->[cs_mon], sec => -$s->[cs_sec] }); } sub year { shift->sec / (SEC_PER_MONTH*12) } sub mon { shift->sec / SEC_PER_MONTH } *month = *mon; sub day { shift->sec / (60*60*24) } sub hour { shift->sec / (60*60) } sub min { shift->sec / 60 } *minute = *min; sub sec { my ($s)=@_; $s->[cs_sec] + SEC_PER_MONTH * $s->[cs_mon]; } *second = *sec; sub sec_part { shift->[cs_sec] } *second_part = *sec_part; sub mon_part { shift->[cs_mon] } *month_part = *mon_part; 1; __END__ =pod =encoding UTF-8 =head1 NAME Class::Date::Rel =head1 VERSION version 1.1.17 =head1 AUTHORS =over 4 =item * dLux (Szabó, Balázs) =item * Gabor Szabo =item * Yanick Champoux =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2018, 2014, 2010, 2003 by Balázs Szabó. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut Class-Date-1.1.17/Makefile.PL0000644000175000017500000000341613304242666015023 0ustar yanickyanickuse lib 'inc'; use Devel::AssertOS qw[-Win32]; # This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v6.011. use strict; use warnings; use 5.006; use ExtUtils::MakeMaker; my %WriteMakefileArgs = ( "ABSTRACT" => "Class for easy date and time manipulation", "AUTHOR" => "dLux (Szab\x{f3}, Bal\x{e1}zs) , Gabor Szabo , Yanick Champoux ", "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => 0 }, "DISTNAME" => "Class-Date", "LICENSE" => "perl", "MIN_PERL_VERSION" => "5.006", "NAME" => "Class::Date", "PREREQ_PM" => { "Carp" => 0, "Date::Parse" => 0, "Exporter" => 0, "POSIX" => 0, "Scalar::Util" => 0, "Time::Local" => 0, "constant" => 0, "overload" => 0, "strict" => 0, "vars" => 0, "warnings" => 0 }, "TEST_REQUIRES" => { "ExtUtils::MakeMaker" => 0, "File::Spec" => 0, "IO::Handle" => 0, "IPC::Open3" => 0, "Test::More" => 0, "Test::Warnings" => 0 }, "VERSION" => "1.1.17", "test" => { "TESTS" => "t/*.t" } ); my %FallbackPrereqs = ( "Carp" => 0, "Date::Parse" => 0, "Exporter" => 0, "ExtUtils::MakeMaker" => 0, "File::Spec" => 0, "IO::Handle" => 0, "IPC::Open3" => 0, "POSIX" => 0, "Scalar::Util" => 0, "Test::More" => 0, "Test::Warnings" => 0, "Time::Local" => 0, "constant" => 0, "overload" => 0, "strict" => 0, "vars" => 0, "warnings" => 0 ); unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) { delete $WriteMakefileArgs{TEST_REQUIRES}; delete $WriteMakefileArgs{BUILD_REQUIRES}; $WriteMakefileArgs{PREREQ_PM} = \%FallbackPrereqs; } delete $WriteMakefileArgs{CONFIGURE_REQUIRES} unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; WriteMakefile(%WriteMakefileArgs); Class-Date-1.1.17/MANIFEST0000644000175000017500000000073413304242666014202 0ustar yanickyanickCONTRIBUTORS Changes INSTALL LICENSE MANIFEST META.json META.yml Makefile.PL README.mkdn SIGNATURE cpanfile doap.xml inc/Devel/AssertOS.pm inc/Devel/CheckOS.pm lib/Class/Date.pm lib/Class/Date/Const.pm lib/Class/Date/Invalid.pm lib/Class/Date/Rel.pm t/00-compile.t t/00-report-prereqs.dd t/00-report-prereqs.t t/00_base.t t/05_parsing.t t/10_fields.t t/20_gmdate.t t/30_localdate.t t/40_errors.t t/50_timezone.t t/bug-reports.t t/class-date-invalid.t xt/release/unused-vars.t Class-Date-1.1.17/Changes0000644000175000017500000001257513304242666014352 0ustar yanickyanickRevision history for Class::Date 1.1.17 2018-06-01 [ BUG FIXES ] - Modules still had the hard-coded $VERSIONs in them. (GH#11) [ STATISTICS ] - code churn: 4 files changed, 191 insertions(+), 180 deletions(-) 1.1.16 2018-05-26 - Remove the xs part of the distribution, which was not adding much for the extra pain. - Quiet spurious warning. (GH#9) - Fix typos in documentation. (GH#5) [ STATISTICS ] - code churn: 22 files changed, 181 insertions(+), 510 deletions(-) 1.1.15 2014-05-05T06:18:37Z - Don't require Env::C due to RT #95332 1.1.14 2014-05-03T11:02:33Z - Move Date/Const.pm to lib/Calss/Date/ - Move Class::Date::Invalid and Class::Date::Rel to their own files in lib/Class/Date/ - Require Scalar::Util and remove work-around lack of Scalar::Util - Require Env::C 1.1.13 2014-05-02T08:32:15Z - Use Test::More for testing 1.1.12 2014-04-30T08:44:29Z - Fixing MANIFEST.SKIP to include Makefile.PL and exclue MYMETA files. 1.1.11 2014-04-30T06:56:24Z - Convert the pod to UTF8 and add =encoding RT #94657 - Minumum version of perl is not 5.006 - Makefile updated - New maintainer: Gabor Szabo 1.1.10 2010-07-18T13:27:39Z - Remove the deprecated UNIVERSAL::import (Vladimir Timofeev) 1.1.9 2006-05-14T22:52:50Z - Added "meridiam" and "ampm" methods by llarian 1.1.8 2005-11-06T16:36:54Z - Added Env::C support for mod_perl environments - Added documentation about thread-safety and mod_perl issues 1.1.7 2003-08-20T23:16:29Z - Bugfix in Date::Parse support 1.1.6 2003-03-16T18:05:23Z - Introducing the NOTZ_TIMEZONE variable to support local time calculations, where TZ variables are not set. 1.1.5 2003-02-05T23:17:50Z - Small documentation fix 1.1.4 2003-02-05T11:15:20Z (test release) - Restored the usage of gmtime and timegm methods, because I cannot solve the timezone issues on win32 platform. 1.1.3 2003-01-03T09:07:01Z - Fixed a warning in the strftime method 1.1.2 2002-12-14T14:46:41Z - Test and report buggy strftime implementation - Fix for strftime - Hardcoded "Class::Date" class names are removed, to enhance inheritance 1.1.1 2002-08-28T23:30:43Z - errstr method of Class::Date::Invalid is documented - Timezone set fix for perl 5.8.0 - Fix for the missing "tzname" declaration on OSX. - NOTE: gmdate and timezone support still does not work on win32! 1.1.0 2002-07-15T20:24:04Z - Date::Parse support now works well with partly defined dates. - Full timezone support (except on the win32 platform) 1.0.10 2002-03-10T21:45:58Z - Extend the range of operation to 1902-2038 where the underlying system (perl, POSIX functions) support 1.0.9 2002-02-25T23:19:49Z - is_leap_year function added 1.0.8 2001-11-07T12:15:28Z - fix Time::Local detection in perl 5.005_03 - The module is now working without a C compiler - You will get warnings if you request for Date::Parse, but it cannot be found 1.0.7 2001-10-15T00:22:47Z - fix for function name clash in bleadperl - Documentation update: Win32 and support chapters added, Development focus rewritten 1.0.6 2001-10-11T14:26:27Z - Fixed a bug with month_end and newer stable perls (5.6.1) - Fixed a bug with Time::Local in perl 5.7.2 1.0.5 2001-07-17T14:31:00Z - Restored and documented the compatibility issues with perl 5.005 1.0.4 2001-07-12T11:00:46Z - Fix a bug with RANGE_CHECK in addition 1.0.3 2001-07-03T13:09:04Z - "errmsg" method is not works as expected - "errstr" is now an alias to "errmsg" 1.0.2 2001-06-27T00:08:05Z - "set" method is renamed to "clone" - named interface is documented - minor documentation fixes 1.0.1 2001-06-16T16:14:02Z - added a "set" method to change parts of the date - fix the "href" method - Added a $RANGE_CHECK variable, to possiby disable dates like "2001-02-31" - Added error handling - Restored compatibility with perl 5.005 1.0.0 2001-06-11T14:58:29Z - it is now requires perl 5.6 because of using Time::Local - stable release, basically the same as 0.98 0.98 2001-05-22T16:46:03Z - bug in "truncate" method fixed - documentation changes 0.97 2001-05-16T23:10:17Z - Accepts the date in "YYYY-MM-DD HH:MM" format - uses Time::Local instead of strftime("%s"), because the latter is not available in not GNU environment 0.96 2001-05-11T01:42:36Z - Fixed $DST_ADJUST bug when adding months - Added $MONTH_BORDER_ADJUST variable and documentation for it - Added "month_begin", "month_end" and "days_in_month" method - Fixed the "aref" method - Doc. grammar fixes 0.95 2001-05-10T00:11:43Z - Fixed comparison problem with undef - date("2001-01-31")+'1M'-'1M' != "2001-01-31" "bug" documented - Fixed the module name in two places (it was Date::Class) 0.94 2001-04-26T16:30:39Z - $date-'1D' bug fixed - added "now" function 0.93 2001-04-18T12:55:15Z - the return value from Date::Parse is fixed 0.92 2001-04-17T17:23:10Z - made 'Date::Parse' usage optional 0.91 2001-04-09T13:42:49Z - small bugfixes for perl 5.005 - date(undef) and Class::Date::Rel(undef) returns undef - array method fix (year + 1900, month + 1) - $DATE_FORMAT is not exportable any more (confusing) - test fixes 0.90 2001-04-05T13:18:18Z - Complete rewrite based on Matt Sergeant's Time::Object - Can handle GMT and local time also - A severe bug fixed concerning the Daylight Saving Time - Dependency to POSIX.pm has been removed 0.5 2001-03-12 - Initial release Class-Date-1.1.17/LICENSE0000644000175000017500000004375113304242666014064 0ustar yanickyanickThis software is copyright (c) 2018, 2014, 2010, 2003 by Balázs Szabó. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This software is Copyright (c) 2018, 2014, 2010, 2003 by Balázs Szabó. This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 2018, 2014, 2010, 2003 by Balázs Szabó. This is free software, licensed under: The Artistic License 1.0 The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End Class-Date-1.1.17/README.mkdn0000644000175000017500000007216413304242666014667 0ustar yanickyanick[![Build Status](https://travis-ci.org/yanick/perl-class-date.svg?branch=master)](https://travis-ci.org/yanick/perl-class-date) # NAME Class::Date - Class for easy date and time manipulation # VERSION version 1.1.17 # SYNOPSIS ```perl use Class::Date qw(:errors date localdate gmdate now -DateParse -EnvC); # creating absolute date object (local time) $date = Class::Date->new( [$year,$month,$day,$hour,$min,$sec]); $date = date [$year,$month,$day,$hour,$min,$sec]; # ^- "date" is an exportable function, the same as Class::Date->new $date = date { year => $year, month => $month, day => $day, hour => $hour, min => $min, sec => $sec }; $date = date "2001-11-12 07:13:12"; $date = localdate "2001-12-11"; $date = now; # the same as date(time) $date = date($other_date_object); # cloning ... # creating absolute date object (GMT) $date = Class::Date->new( [$year,$month,$day,$hour,$min,$sec],'GMT'); $date = gmdate "2001-11-12 17:13"; ... # creating absolute date object in any other timezone $date = Class::Date->new( [$year,$month,$day,$hour,$min,$sec],'Iceland' ); $date = date "2001-11-12 17:13", 'Iceland'; $date2 = $date->new([$y2, $m2, $d2, $h2, $m2, $s2]); # ^- timezone is inherited from the $date object # creating relative date object # (normally you don't need to create this object explicitly) $reldate = Class::Date::Rel->new( "3Y 1M 3D 6h 2m 4s" ); $reldate = Class::Date::Rel->new( "6Y" ); $reldate = Class::Date::Rel->new( $secs ); # secs $reldate = Class::Date::Rel->new( [$year,$month,$day,$hour,$min,$sec] ); $reldate = Class::Date::Rel->new( { year => $year, month => $month, day => $day, hour => $hour, min => $min, sec => $sec } ); $reldate = Class::Date::Rel->new( "2001-11-12 07:13:12" ); $reldate = Class::Date::Rel->new( "2001-12-11" ); # getting values of an absolute date object $date; # prints the date in default output format (see below) $date->year; # year, e.g: 2001 $date->_year; # year - 1900, e.g. 101 $date->yr; # 2-digit year 0-99, e.g 1 $date->mon; # month 1..12 $date->month; # same as prev. $date->_mon; # month 0..11 $date->_month; # same as prev. $date->day; # day of month $date->mday; # day of month $date->day_of_month;# same as prev. $date->hour; $date->min; $date->minute; # same as prev. $date->sec; $date->second; # same as prev. $date->wday; # 1 = Sunday $date->_wday; # 0 = Sunday $date->day_of_week; # same as prev. $date->yday; $date->day_of_year; # same as prev. $date->isdst; # DST? $date->daylight_savings; # same as prev. $date->epoch; # UNIX time_t $date->monname; # name of month, eg: March $date->monthname; # same as prev. $date->wdayname; # Thursday $date->day_of_weekname # same as prev. $date->hms # 01:23:45 $date->ymd # 2000/02/29 $date->mdy # 02/29/2000 $date->dmy # 29/02/2000 $date->meridiam # 01:23 AM $date->ampm # AM/PM $date->string # 2000-02-29 12:21:11 (format can be changed, look below) "$date" # same as prev. $date->tzoffset # timezone-offset $date->strftime($format) # POSIX strftime (without the huge POSIX.pm) $date->tz # returns the base timezone as you specify, eg: CET $date->tzdst # returns the real timezone with dst information, eg: CEST ($year,$month,$day,$hour,$min,$sec)=$date->array; ($year,$month,$day,$hour,$min,$sec)=@{ $date->aref }; # !! $year: 1900-, $month: 1-12 ($sec,$min,$hour,$day,$mon,$year,$wday,$yday,$isdst)=$date->struct; ($sec,$min,$hour,$day,$mon,$year,$wday,$yday,$isdst)=@{ $date->sref }; # !! $year: 0-, $month: 0-11 $hash=$date->href; # $href can be reused as a constructor print $hash->{year}."-".$hash->{month}. ... $hash->{sec} ... ; %hash=$date->hash; # !! $hash{year}: 1900-, $hash{month}: 1-12 $date->month_begin # First day of the month (date object) $date->month_end # Last day of the month $date->days_in_month # 28..31 # constructing new date based on an existing one: $new_date = $date->clone; $new_date = $date->clone( year => 1977, sec => 14 ); # valid keys: year, _year, month, mon, _month, _mon, day, mday, day_of_month, # hour, min, minute, sec, second, tz # constructing a new date, which is the same as the original, but in # another timezone: $new_date = $date->to_tz('Iceland'); # changing date format { local $Class::Date::DATE_FORMAT="%Y%m%d%H%M%S"; print $date # result: 20011222000000 $Class::Date::DATE_FORMAT=undef; print $date # result: Thu Oct 13 04:54:34 1994 $Class::Date::DATE_FORMAT="%Y/%m/%d" print $date # result: 1994/10/13 } # error handling $a = date($date_string); if ($a) { # valid date ... } else { # invalid date if ($a->error == E_INVALID) { ... } print $a->errstr; } # adjusting DST in calculations (see the doc) $Class::Date::DST_ADJUST = 1; # this is the default $Class::Date::DST_ADJUST = 0; # "month-border adjust" flag $Class::Date::MONTH_BORDER_ADJUST = 0; # this is the default print date("2001-01-31")+'1M'; # will print 2001-03-03 $Class::Date::MONTH_BORDER_ADJUST = 1; print date("2001-01-31")+'1M'; # will print 2001-02-28 # date range check $Class::Date::RANGE_CHECK = 0; # this is the default print date("2001-02-31"); # will print 2001-03-03 $Class::Date::RANGE_CHECK = 1; print date("2001-02-31"); # will print nothing # getting values of a relative date object $reldate; # reldate in seconds (assumed 1 month = 2_629_744 secs) $reldate->year; $reldate->mon; $reldate->month; # same as prev. $reldate->day; $reldate->hour; $reldate->min; $reldate->minute; # same as prev. $reldate->sec; # same as $reldate $reldate->second; # same as prev. $reldate->sec_part; # "second" part of the relative date $reldate->mon_part; # "month" part of the relative date # arithmetic with dates: print date([2001,12,11,4,5,6])->truncate; # will print "2001-12-11" $new_date = $date+$reldate; $date2 = $date+'3Y 2D'; # 3 Years and 2 days $date3 = $date+[1,2,3]; # $date plus 1 year, 2 months, 3 days $date4 = $date+'3-1-5' # $date plus 3 years, 1 months, 5 days $new_date = $date-$reldate; $date2 = $date-'3Y'; # 3 Yearss $date3 = $date-[1,2,3]; # $date minus 1 year, 2 months, 3 days $date4 = $date-'3-1-5' # $date minus 3 years, 1 month, 5 days $new_reldate = $date1-$date2; $reldate2 = Class::Date->new('2000-11-12')-'2000-11-10'; $reldate3 = $date3-'1977-11-10'; $days_between = (Class::Date->new('2001-11-12')-'2001-07-04')->day; # comparison between absolute dates print $date1 > $date2 ? "I am older" : "I am younger"; # comparison between relative dates print $reldate1 > $reldate2 ? "I am faster" : "I am slower"; # Adding / Subtracting months and years are sometimes tricky: print date("2001-01-29") + '1M' - '1M'; # gives "2001-02-01" print date("2000-02-29") + '1Y' - '1Y'; # gives "2000-03-01" # Named interface ($date2 does not necessary to be a Class::Date object) $date1->string; # same as $date1 in scalar context $date1->subtract($date2); # same as $date1 - $date2 $date1->add($date2); # same as $date1 + $date2 $date1->compare($date2); # same as $date1 <=> $date2 $reldate1->sec; # same as $reldate1 in numeric or scalar context $reldate1->compare($reldate2);# same as $reldate1 <=> $reldate2 $reldate1->add($reldate2); # same as $reldate1 + $reldate2 $reldate1->neg # used for subtraction # Disabling Class::Date warnings at load time BEGIN { $Class::Date::WARNINGS=0; } use Class::Date; ``` # DESCRIPTION This module is intended to provide a general-purpose date and datetime type for perl. You have a Class::Date class for absolute date and datetime, and have a Class::Date::Rel class for relative dates. You can use "+", "-", "<" and ">" operators as with native perl data types. Note that this module is fairly ancient and dusty. You might want to take a look at [DateTime](https://metacpan.org/pod/DateTime) and its related modules for a more standard, and maintained, Perl date manipulation solution. # USAGE If you want to use a date object, you need to do the following: ``` - create a new object - do some operations (+, -, comparison) - get result back ``` ## Creating a new date object You can create a date object by the "date", "localdate" or "gmdate" function, or by calling the Class::Date constructor. "date" and "Class::Date->new" are equivalent, both has two arguments: The date and the timezone. ``` $date1= date [2000,11,12]; $date2= Class::Date->new([2000,06,11,13,11,22],'GMT'); $date2= $date1->new([2000,06,11,13,11,22]); ``` If the timezone information is omitted, then it first check if "new" is called as an object method or a class method. If it is an object method, then it inherits the timezone from the base object, otherwise the default timezone is used ($Class::Date::DEFAULT\_TIMEZONE), which is usually set to the local timezone (which is stored in $Class::Date::LOCAL\_TIMEZONE). These two variables are set only once to the value, which is returned by the Class::Date::local\_timezone() function. You can change these values whenever you want. "localdate $x" is equivalent to "date $x, $Class::Date::LOCAL\_TIMEZONE", "gmdate $x" is equivalent to "date $x, $Class::Date::GMT\_TIMEZONE". $Class::Date::GMT\_TIMEZONE is set to 'GMT' by default. ``` $date1= localdate [2000,11,12]; $date2= gmdate [2000,4,2,3,33,33]; $date = localdate(time); ``` The format of the accepted input date can be: - \[$year,$month,$day,$hour,$min,$sec\] An array reference with 6 elements. The missing elements have default values (year: 2000, month, day: 1, hour, min, sec: 0) - { year => $year, month => $month, day => $day, hour => $hour, min => $min, sec => $sec } A hash reference with the same 6 elements as above. - "YYYYMMDDhhmmss" A mysql-style timestamp value, which consist of at least 14 digit. - "973897262" A valid 32-bit integer: This is parsed as a unix time. - "YYYY-MM-DD hh:mm:ss" A standard ISO(-like) date format. Additional ".fraction" part is ignored, ":ss" can be omitted. - additional input formats You can specify "-DateParse" as an import parameter, e.g: ```perl use Class::Date qw(date -DateParse); ``` With this, the module will try to load Date::Parse module, and if it find it then all these formats can be used as an input. Please refer to the Date::Parse documentation. ## Operations - addition You can add the following to a Class::Date object: ```perl - a valid Class::Date::Rel object - anything, that can be used for creating a new Class::Date::Rel object ``` It means that you don't need to create a new Class::Date::Rel object every time when you add something to the Class::Date object, it creates them automatically: ``` $date= Class::Date->new('2001-12-11')+Class::Date::Rel->new('3Y'); ``` is the same as: ``` $date= date('2001-12-11')+'3Y'; ``` You can provide a Class::Date::Rel object in the following form: - array ref The same format as seen in Class::Date format, except the default values are different: all zero. - hash ref The same format as seen in Class::Date format, except the default values are different: all zero. - "973897262" A valid 32-bit integer is parsed as seconds. - "YYYY-MM-DD hh:mm:ss" A standard ISO date format, but this is parsed as relative date date and time, so month, day and year can be zero (and defaults to zero). - "12Y 6M 6D 20h 12m 5s" This special string can be used if you don't want to use the ISO format. This string consists of whitespace separated tags, each tag consists of a number and a unit. The units can be: ``` Y: year M: month D: day h: hour m: min s: sec ``` The number and unit must be written with no space between them. - substraction The same rules are true for substraction, except you can substract two Class::Date object from each other, and you will get a Class::Date::Rel object: ``` $reldate=$date1-$date2; $reldate=date('2001-11-12 12:11:07')-date('2001-10-07 10:3:21'); ``` In this case, the "month" field of the $reldate object will be 0, and the other fields will contain the difference between two dates; - comparison You can compare two Class::Date objects, or one Class::Date object and another data, which can be used for creating a new Class::Data object. It means that you don't need to bless both objects, one of them can be a simple string, array ref, hash ref, etc (see how to create a date object). ``` if ( date('2001-11-12') > date('2000-11-11') ) { ... } ``` or ``` if ( date('2001-11-12') > '2000-11-11' ) { ... } ``` - truncate You can chop the time value from this object (set hour, min and sec to 0) with the "truncate" or "trunc" method. It does not modify the specified object, it returns with a new one. - clone You can create new date object based on an existing one, by using the "clone" method. Note, this DOES NOT modify the base object. ```perl $new_date = $date->clone( year => 2001, hour => 14 ); ``` The valid keys are: year, \_year, month, mon, \_month, \_mon, day, mday, day\_of\_month, hour, min, minute, sec, second, tz. There is a "set" method, which does the same as the "clone", it exists only for compatibility. - to\_tz You can use "to\_tz" to create a new object, which means the same time as the base object, but in the different timezone. Note that $date->clone( tz => 'Iceland') and $date->to\_tz('Iceland') is not the same! Cloning a new object with setting timezone will preserve the time information (hour, minute, second, etc.), but transfer the time into other timezone, while to\_tz usually change these values based on the difference between the source and the destination timezone. - Operations with Class::Date::Rel The Class::Date::Rel object consists of a month part and a day part. Most people only use the "day" part of it. If you use both part, then you can get these parts with the "sec\_part" and "mon\_part" method. If you use "sec", "month", etc. methods or if you use this object in a mathematical context, then this object is converted to one number, which is interpreted as second. The conversion is based on a 30.436 days month. Don't use it too often, because it is confusing... If you use Class::Date::Rel in an expression with other Class::Date or Class::Date::Rel objects, then it does what is expected: ``` date('2001-11-12')+'1M' will be '2001-12-12' ``` and ``` date('1996-02-11')+'2M' will be '1996-04-11' ``` ## Accessing data from a Class::Date and Class::Date::Rel object You can use the methods methods described at the top of the document if you want to access parts of the data which is stored in a Class::Date and Class::Date::Rel object. ## Error handling If a date object became invalid, then the object will be reblessed to Class::Date::Invalid. This object is false in boolean environment, so you can test the date validity like this: ``` $a = date($input_date); if ($a) { # valid date ... } else { # invalid date if ($a->error == E_INVALID) { ... } print $a->errstr; } ``` Note even the date is invalid, the expression "defined $a" always returns true, so the following is wrong: ``` $a = date($input_date); if (defined $a) ... # WRONG!!!! ``` You can test the error by getting the $date->error value. You might import the ":errors" tag: ```perl use Class::Date qw(:errors); ``` Possible error values are: - E\_OK No errors. - E\_INVALID Invalid date. It is set when some of the parts of the date are invalid, and Time::Local functions cannot convert them to a valid date. - E\_RANGE This error is set, when parts of the date are valid, but the whole date is not valid, e.g. 2001-02-31. When the $Class::Date::RANGE\_CHECK is not set, then these date values are automatically converted to a valid date: 2001-03-03, but the $date->error value are set to E\_RANGE. If $Class::Date::RANGE\_CHECK is set, then a date "2001-02-31" became invalid date. - E\_UNPARSABLE This error is set, when the constructor cannot be created from a scalar, e.g: ``` $a = date("4kd sdlsdf lwekrmk"); ``` - E\_UNDEFINED This error is set, when you want to create a date object from an undefined value: ``` $a = Class::Date->new(undef); ``` Note, that localdate(undef) will create a valid object, because it calls $Class::Date(time). You can get the error in string form by calling the "errstr" method. # DST\_ADJUST $DST\_ADJUST is an important configuration option. If it is set to true (default), then the module adjusts the date and time when the operation switches the border of DST. With this setting, you are ignoring the effect of DST. When $DST\_ADJUST is set to false, then no adjustment is done, the calculation will be based on the exact time difference. You will see the difference through an example: ``` $Class::Date::DST_ADJUST=1; print date("2000-10-29", "CET") + "1D"; # This will print 2000-10-30 00:00:00 print date("2001-03-24 23:00:00", "CET") + "1D"; # This will be 2001-03-25 23:00:00 print date("2001-03-25", "CET") + "1D"; # This will be 2001-03-26 00:00:00 $Class::Date::DST_ADJUST=0; print date("2000-10-29", "CET") + "1D"; # This will print 2000-10-29 23:00:00 print date("2001-03-24 23:00:00", "CET") + "1D"; # This will be 2001-03-26 00:00:00 ``` # MONTHS AND YEARS If you add or subtract "months" and "years" to a date, you may get wrong dates, e.g when you add one month to 2001-01-31, you expect to get 2001-02-31, but this date is invalid and converted to 2001-03-03. Thats' why ``` date("2001-01-31") + '1M' - '1M' != "2001-01-31" ``` This problem can occur only with months and years, because others can easily be converted to seconds. # MONTH\_BORDER\_ADJUST $MONTH\_BORDER\_ADJUST variable is used to switch on or off the month-adjust feature. This is used only when someone adds months or years to a date and then the resulted date became invalid. An example: adding one month to "2001-01-31" will result "2001-02-31", and this is an invalid date. When $MONTH\_BORDER\_ADJUST is false, this result simply normalized, and becomes "2001-03-03". This is the default behaviour. When $MONTH\_BORDER\_ADJUST is true, this result becomes "2001-02-28". So when the date overflows, then it returns the last day insted. Both settings keep the time information. # TIMEZONE SUPPORT Since 1.0.11, Class::Date handle timezones natively on most platforms (see the BUGS AND LIMITATIONS section for more info). When the module is loaded, then it determines the local base timezone by calling the Class::Date::local\_timezone() function, and stores these values into two variables, these are: $Class::Date::LOCAL\_TIMEZONE and $Class::Date::DEFAULT\_TIMEZONE. The first value is used, when you call the "localdate" function, the second value is used, when you call the "date" function and you don't specify the timezone. There is a $Class::Date::GMT\_TIMEZONE function also, which is used by the "gmdate" function, this is set to 'GMT'. You can query the timezone of a date object by calling the $date->tz method. Note this value returns the timezone as you specify, so if you create the object with an unknown timezone, you will get this back. If you want to query the effective timezone, you can call the $date->tzdst method. This method returns only valid timezones, but it is not necessarily the timezone which can be used to create a new object. For example $date->tzdst can return 'CEST', which is not a valid base timezone, because it contains daylight savings information also. On Linux systems, you can see the possible base timezones in the /usr/share/zoneinfo directory. In Class::Date 1.1.6, a new environment variable is introduced: $Class::Date::NOTZ\_TIMEZONE. This variable stores the local timezone, which is used, when the TZ environment variable is not set. It is introduced, because there are some systems, which cannot handle the queried timezone well. For example the local timezone is CST, it is returned by the tzname() perl function, but when I set the TZ environment variable to CST, it works like it would be GMT. The workaround is NOTZ\_TIMEZONE: if a date object has a timezone, which is the same as NOTZ\_TIMEZONE, then the TZ variable will be removed before each calculation. In normal case, it would be the same as setting TZ to $NOTZ\_TIMEZONE, but some systems don't like it, so I decided to introduce this variable. The $Class::Date::NOTZ\_TIMEZONE variable is set in the initialization of the module by removing the TZ variable from the environment and querying the tzname variable. # INTERNALS This module uses operator overloading very heavily. I've found it quite stable, but I am afraid of it a bit. A Class::Date object is an array reference. A Class::Date::Rel object is an array reference, which contains month and second information. I need to store it as an array ref, because array and month values cannot be converted into seconds, because of our super calendar. You can add code references to the @Class::Date::NEW\_FROM\_SCALAR and @Class::Date::Rel::NEW\_FROM\_SCALAR. These arrays are iterated through when a scalar-format date must be parsed. These arrays only have one or two values at initialization. The parameters which the code references got are the same as the "new" method of each class. In this way, you can personalize the date parses as you want. As of 0.90, the Class::Date has been rewritten. A lot of code and design decision has been borrowed from Matt Sergeant's Time::Object, and there will be some incompatibility with the previous public version (0.5). I tried to keep compatibility methods in Class::Date. If you have problems regarding this, please drop me an email with the description of the problem, and I will set the compatibility back. Invalid dates are Class::Date::Invalid objects. Every method call on this object and every operation with this object returns undef or 0. # DEVELOPMENT FOCUS This module tries to be as full-featured as can be. It currently lacks business-day calculation, which is planned to be implemented in the 1.0.x series. I try to keep this module not to depend on other modules and I want this module usable without a C compiler. Currently the module uses the POSIX localtime function very extensively. This makes the date calculation a bit slow, but provides a rich interface, which is not provided by any other module. When I tried to redesign the internals to not depend on localtime, I failed, because there are no other way to determine the daylight savings information. # SPEED ISSUES There are two kind of adjustment in this module, DST\_ADJUST and MONTH\_BORDER\_ADJUST. Both of them makes the "+" and "-" operations slower. If you don't need them, switch them off to achieve faster calculations. In general, if you really need fast date and datetime calculation, don't use this module. As you see in the previous section, the focus of development is not the speed in 1.0. For fast date and datetime calculations, use Date::Calc module instead. # THREAD SAFETY and MOD\_PERL This module is NOT thread-safe, since it uses C library functions, which are not thread-safe. Using this module in a multi-threaded environment can cause timezones to be messed up. I did not put any warning about it, you have to make sure that you understand this! Under some circumstances in a mod\_perl environment, you require the Env::C module to set the TZ variable properly before calling the time functions. I added the -EnvC import option to automatically load this module if it is not loaded already. Please read the mod\_perl documentation about the environment variables and mod\_perl to get the idea why it is required sometimes: ```perl http://perl.apache.org/docs/2.0/user/troubleshooting/troubleshooting.html#C_Libraries_Don_t_See_C__ENV__Entries_Set_by_Perl_Code ``` You are sure have this problem if the $Class::Date::NOTZ\_TIMEZONE variable is set to 'UTC', althought you are sure that your timezone is not that. Try \-EnvC in this case, but make sure that you are not using it in a multi-threaded environment! # OTHER BUGS AND LIMITATIONS - Not all date/time values can be expressed in all timezones. For example: ``` print date("2010-10-03 02:00:00", "Australia/Sydney") # it will print 2010-10-03 03:00:00 ``` No matter how hard you try you, you are not going to be able to express the time in the example in that timezone. If you don't need the timezone information and you want to make sure that the calculations are always correct, please use GMT as a timezone (the 'gmdate' function can be a shortcut for it). In this case, you might also consider turning off DST\_ADJUST to speed up the calculation. - I cannot manage to get the timezone code working properly on ActivePerl 5.8.0 on win XP and earlier versions possibly have this problem also. If you have a system like this, then you will have only two timezones, the local and the GMT. Every timezone, which is not equal to $Class::Date::GMT\_TIMEZONE is assumed to be local. This seems to be caused by the win32 implementation of timezone routines. I don't really know how to make this thing working, so I gave up this issue. If anyone know a working solution, then I will integrate it into Class::Date, but until then, the timezone support will not be available for these platforms. - Perl 5.8.0 and earlier versions has a bug in the strftime code on some operating systems (for example Linux), which is timezone related. I recommend using the strftime, which is provided with Class::Date, so don't try to use the module without the compiled part. The module will not work with a buggy strftime - the test is hardcoded into the beginning of the code. If you anyway want to use the module, remove the hardcoded "die" from the module, but do it for your own risk. - This module uses the POSIX functions for date and time calculations, so it is not working for dates beyond 2038 and before 1902. I don't know what systems support dates in 1902-1970 range, it may not work on your system. I know it works on the Linux glibc system with perl 5.6.1 and 5.7.2. I know it does not work with perl 5.005\_03 (it may be the bug of the Time::Local module). Please report if you know any system where it does \_not\_ work with perl 5.6.1 or later. I hope that someone will fix this with new time\_t in libc. If you really need dates over 2038 and before 1902, you need to completely rewrite this module or use Date::Calc or other date modules. - This module uses Time::Local, and when it croaks, Class::Date returns "Invalid date or time" error message. Time::Local is different in the 5.005 and 5.6.x (and even 5.7.x) version of perl, so the following code will return different results: ```perl $a = date("2006-11-11")->clone(year => -1); ``` In perl 5.6.1, it returns an invalid date with error message "Invali date or time", in perl 5.005 it returns an invalid date with range check error. Both are false if you use them in boolean context though, only the error message is different, but don't rely on the error message in this case. It however works in the same way if you change other fields than "year" to an invalid field. # SUPPORT Class::Date is free software. IT COMES WITHOUT WARRANTY OF ANY KIND. If you have questions, you can send questions directly to me: ``` dlux@dlux.hu ``` # WIN32 notes You can get a binary win32 version of Class::Date from Chris Winters' .ppd repository with the following commands: For people using PPM2: ``` c:\> ppm PPM> set repository oi http://openinteract.sourceforge.net/ppmpackages/ PPM> set save PPM> install Class-Date ``` For people using PPM3: ``` c:\> ppm PPM> repository http://openinteract.sourceforge.net/ppmpackages/ PPM> install Class-Date ``` The first steps in PPM only needs to be done at the first time. Next time you just run the 'install'. # COPYRIGHT Copyright (c) 2001 Szabó, Balázs (dLux) All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Portions Copyright (c) Matt Sergeant # CREDITS ```perl - Matt Sergeant (Lots of code are borrowed from the Time::Object module) - Tatsuhiko Miyagawa (bugfixes) - Stas Bekman (suggestions, bugfix) - Chris Winters (win32 .ppd version) - Benoit Beausejour (Parts of the timezone code is borrowed from his Date::Handler module) ``` # SEE ALSO perl(1). Date::Calc(3pm). Time::Object(3pm). Date::Handler(3pm). # AUTHORS - dLux (Szabó, Balázs) - Gabor Szabo - Yanick Champoux [![endorse](http://api.coderwall.com/yanick/endorsecount.png)](http://coderwall.com/yanick) # COPYRIGHT AND LICENSE This software is copyright (c) 2018, 2014, 2010, 2003 by Balázs Szabó. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Class-Date-1.1.17/SIGNATURE0000644000175000017500000000475713304242666014346 0ustar yanickyanickThis file contains message digests of all files listed in MANIFEST, signed via the Module::Signature module, version 0.79. To verify the content in this distribution, first make sure you have Module::Signature installed, then type: % cpansign -v It will check each file's integrity, as well as the signature's validity. If "==> Signature verified OK! <==" is not displayed, the distribution may already have been compromised, and you should not run its Makefile.PL or Build.PL. -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 SHA1 baa78bd5dc14c91ab53bb8507d3e42fe0767009b CONTRIBUTORS SHA1 278a0c79c4a970532f7586d6f17ca3536dc9b241 Changes SHA1 7fb470d2eb1d9873620ffc19b853c7eda6f49e00 INSTALL SHA1 3cea48a9445c7071ed158759f9f8ad8a953666f5 LICENSE SHA1 b16e8c742a737afa5d670b63e53b8fbe6c68743f MANIFEST SHA1 b15254e9ed935f385f1c458930f747cdb627994b META.json SHA1 2ddd3b7ffcf80bbeb301fbd0e81be1813f81b35b META.yml SHA1 192585535b73f622daf75c9b7cb93888955e62b2 Makefile.PL SHA1 348b3493f80e318a9233b131b2b4b9dcd5e49842 README.mkdn SHA1 75797ea64f4b5cea320cc7d3b93cb54a8ecd34ec cpanfile SHA1 c39c730be86983be1c185ef71e77942070fe25d4 doap.xml SHA1 1b7d4632976d250956d49d509b30bdd2ac5f48e5 inc/Devel/AssertOS.pm SHA1 52dcb8b2b98363d1e1fdebd5e193bc12c57c220a inc/Devel/CheckOS.pm SHA1 66952d97abfae9fffb8a2aa9de4ec8ee576e8170 lib/Class/Date.pm SHA1 44e2bd2d46203364f6385cb604d1ca79905a59ea lib/Class/Date/Const.pm SHA1 4c41f99ea6c4d3ce603b3813a6b659250e4e6ec4 lib/Class/Date/Invalid.pm SHA1 94400b18a356e1703ad6ced1a69ee3a4acd34b71 lib/Class/Date/Rel.pm SHA1 a956a1d1b8fd1a34b8b91e05eed9e5038a9f8612 t/00-compile.t SHA1 d360e9d6be28c72654897045866911191dbdeb17 t/00-report-prereqs.dd SHA1 504a672015f8761f5bad3863d844954c9e803c3f t/00-report-prereqs.t SHA1 eb05e1a1186d22885ad0d1a1c4ca087b5bb85847 t/00_base.t SHA1 71d4a0eb06041ba3ea10101de89c1c74b5b25678 t/05_parsing.t SHA1 2d5c3b6c67646439a3d00be2453317f2bd281b28 t/10_fields.t SHA1 c8500928554ee619cab4ab8e8128a87e31e46d0f t/20_gmdate.t SHA1 9aff6e4ef83fba958c78a3d17d0997d7aa3563a0 t/30_localdate.t SHA1 f04bce03139454007e5d74a3a21036156e8626ad t/40_errors.t SHA1 101b5b78047b061815643d136bb15fdb3af48aa0 t/50_timezone.t SHA1 c3d46608c3a977c64ff2893e9d507601301173d6 t/bug-reports.t SHA1 35d858c137ad0997e7d91ab99f757d4da075aa69 t/class-date-invalid.t SHA1 d1fe7d94b3edc7847eb187d4ee41f66e19cf8907 xt/release/unused-vars.t -----BEGIN PGP SIGNATURE----- iEUEARECAAYFAlsRRbYACgkQ34Hwf+GwC4wXxwCY1074wywahAYZr1xrs3VID5Z4 5gCg8nCPtOmYvXNCFHdOsgHxgG3e6oM= =cBNB -----END PGP SIGNATURE----- Class-Date-1.1.17/INSTALL0000644000175000017500000000165313304242666014103 0ustar yanickyanickThis is the Perl distribution Class-Date. Installing Class-Date is straightforward. ## Installation with cpanm If you have cpanm, you only need one line: % cpanm Class::Date If you are installing into a system-wide directory, you may need to pass the "-S" flag to cpanm, which uses sudo to install the module: % cpanm -S Class::Date ## Installing with the CPAN shell Alternatively, if your CPAN shell is set up, you should just be able to do: % cpan Class::Date ## Manual installation As a last resort, you can manually install it. Download the tarball, untar it, then build it: % perl Makefile.PL % make && make test Then install it: % make install If you are installing into a system-wide directory, you may need to run: % sudo make install ## Documentation Class-Date documentation is available as POD. You can run perldoc from a shell to read the documentation: % perldoc Class::Date Class-Date-1.1.17/CONTRIBUTORS0000644000175000017500000000042413304242666014725 0ustar yanickyanick # CLASS-DATE CONTRIBUTORS # This is the (likely incomplete) list of people who have helped make this distribution what it is, either via code contributions, patches, bug reports, help with troubleshooting, etc. A huge 'thank you' to all of them. * Vladimir Timofeev Class-Date-1.1.17/META.json0000644000175000017500000000516013304242666014470 0ustar yanickyanick{ "abstract" : "Class for easy date and time manipulation", "author" : [ "dLux (Szab\u00f3, Bal\u00e1zs) ", "Gabor Szabo ", "Yanick Champoux " ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 6.011, CPAN::Meta::Converter version 2.150010", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Class-Date", "no_index" : { "directory" : [ "inc" ] }, "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "develop" : { "requires" : { "Test::More" : "0.96", "Test::Vars" : "0" } }, "runtime" : { "requires" : { "Carp" : "0", "Date::Parse" : "0", "Exporter" : "0", "POSIX" : "0", "Scalar::Util" : "0", "Time::Local" : "0", "constant" : "0", "overload" : "0", "perl" : "5.006", "strict" : "0", "vars" : "0", "warnings" : "0" } }, "test" : { "recommends" : { "CPAN::Meta" : "2.120900" }, "requires" : { "ExtUtils::MakeMaker" : "0", "File::Spec" : "0", "IO::Handle" : "0", "IPC::Open3" : "0", "Test::More" : "0", "Test::Warnings" : "0" } } }, "provides" : { "Class::Date" : { "file" : "lib/Class/Date.pm", "version" : "v1.1.17" }, "Class::Date::Const" : { "file" : "lib/Class/Date/Const.pm", "version" : "v1.1.17" }, "Class::Date::Invalid" : { "file" : "lib/Class/Date/Invalid.pm", "version" : "v1.1.17" }, "Class::Date::Rel" : { "file" : "lib/Class/Date/Rel.pm", "version" : "v1.1.17" } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/yanick/perl-class-date/issues" }, "homepage" : "https://github.com/yanick/perl-class-date", "repository" : { "type" : "git", "url" : "https://github.com/yanick/perl-class-date.git", "web" : "https://github.com/yanick/perl-class-date" } }, "version" : "1.1.17", "x_authority" : "cpan:YANICK", "x_contributors" : [ "Vladimir Timofeev " ], "x_serialization_backend" : "JSON::XS version 3.01" } Class-Date-1.1.17/META.yml0000644000175000017500000000267713304242666014332 0ustar yanickyanick--- abstract: 'Class for easy date and time manipulation' author: - 'dLux (Szabó, Balázs) ' - 'Gabor Szabo ' - 'Yanick Champoux ' build_requires: ExtUtils::MakeMaker: '0' File::Spec: '0' IO::Handle: '0' IPC::Open3: '0' Test::More: '0' Test::Warnings: '0' configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 0 generated_by: 'Dist::Zilla version 6.011, CPAN::Meta::Converter version 2.150010' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Class-Date no_index: directory: - inc provides: Class::Date: file: lib/Class/Date.pm version: v1.1.17 Class::Date::Const: file: lib/Class/Date/Const.pm version: v1.1.17 Class::Date::Invalid: file: lib/Class/Date/Invalid.pm version: v1.1.17 Class::Date::Rel: file: lib/Class/Date/Rel.pm version: v1.1.17 requires: Carp: '0' Date::Parse: '0' Exporter: '0' POSIX: '0' Scalar::Util: '0' Time::Local: '0' constant: '0' overload: '0' perl: '5.006' strict: '0' vars: '0' warnings: '0' resources: bugtracker: https://github.com/yanick/perl-class-date/issues homepage: https://github.com/yanick/perl-class-date repository: https://github.com/yanick/perl-class-date.git version: 1.1.17 x_authority: cpan:YANICK x_contributors: - 'Vladimir Timofeev ' x_serialization_backend: 'YAML::Tiny version 1.67' Class-Date-1.1.17/cpanfile0000644000175000017500000000142313304242666014551 0ustar yanickyanickrequires "Carp" => "0"; requires "Date::Parse" => "0"; requires "Exporter" => "0"; requires "POSIX" => "0"; requires "Scalar::Util" => "0"; requires "Time::Local" => "0"; requires "constant" => "0"; requires "overload" => "0"; requires "perl" => "5.006"; requires "strict" => "0"; requires "vars" => "0"; requires "warnings" => "0"; on 'test' => sub { requires "ExtUtils::MakeMaker" => "0"; requires "File::Spec" => "0"; requires "IO::Handle" => "0"; requires "IPC::Open3" => "0"; requires "Test::More" => "0"; requires "Test::Warnings" => "0"; }; on 'test' => sub { recommends "CPAN::Meta" => "2.120900"; }; on 'configure' => sub { requires "ExtUtils::MakeMaker" => "0"; }; on 'develop' => sub { requires "Test::More" => "0.96"; requires "Test::Vars" => "0"; }; Class-Date-1.1.17/t/0000775000175000017500000000000013304242666013312 5ustar yanickyanickClass-Date-1.1.17/t/10_fields.t0000755000175000017500000000167713304242666015261 0ustar yanickyanickuse strict; use warnings; use Test::More; plan tests => 18; use Class::Date qw(gmdate); ok(1); my $t = gmdate("2001-07-26 16:15:23"); is $t->set(year => 2002), "2002-07-26 16:15:23"; is $t,"2001-07-26 16:15:23"; is $t->set(_year => 105), "2005-07-26 16:15:23"; is $t,"2001-07-26 16:15:23"; is $t->set(month => 4), "2001-04-26 16:15:23"; is $t->set(mon => 9), "2001-09-26 16:15:23"; is $t->set(_month=> 7), "2001-08-26 16:15:23"; is $t->set(_mon => 2), "2001-03-26 16:15:23"; is $t->set(day => 12), "2001-07-12 16:15:23"; is $t->set(mday => 21), "2001-07-21 16:15:23"; is $t->set(day_of_month=>5), "2001-07-05 16:15:23"; is $t->set(hour => 14), "2001-07-26 14:15:23"; is $t->set(min => 34), "2001-07-26 16:34:23"; is $t->set(minute=> 19), "2001-07-26 16:19:23"; is $t->set(sec => 49), "2001-07-26 16:15:49"; is $t->set(second=> 44), "2001-07-26 16:15:44"; is $t->set(year => 1985, day => 16), "1985-07-16 16:15:23"; Class-Date-1.1.17/t/05_parsing.t0000644000175000017500000000045213304242666015445 0ustar yanickyanickuse strict; use warnings; use Test::More; plan tests => 7; use Class::Date qw(gmdate); ok(1); my $t = gmdate("2008-8-3T11:7:10"); is $t->year, 2008, 'year'; is $t->month, 8, 'month'; is $t->day, 3, 'day'; is $t->hour, 11, 'hour'; is $t->min, 7, 'min'; is $t->second, 10, 'second'; Class-Date-1.1.17/t/00-report-prereqs.t0000644000175000017500000001273113304242666016710 0ustar yanickyanick#!perl use strict; use warnings; # This test was generated by Dist::Zilla::Plugin::Test::ReportPrereqs 0.021 use Test::More tests => 1; use ExtUtils::MakeMaker; use File::Spec; # from $version::LAX my $lax_version_re = qr/(?: undef | (?: (?:[0-9]+) (?: \. | (?:\.[0-9]+) (?:_[0-9]+)? )? | (?:\.[0-9]+) (?:_[0-9]+)? ) | (?: v (?:[0-9]+) (?: (?:\.[0-9]+)+ (?:_[0-9]+)? )? | (?:[0-9]+)? (?:\.[0-9]+){2,} (?:_[0-9]+)? ) )/x; # hide optional CPAN::Meta modules from prereq scanner # and check if they are available my $cpan_meta = "CPAN::Meta"; my $cpan_meta_pre = "CPAN::Meta::Prereqs"; my $HAS_CPAN_META = eval "require $cpan_meta; $cpan_meta->VERSION('2.120900')" && eval "require $cpan_meta_pre"; ## no critic # Verify requirements? my $DO_VERIFY_PREREQS = 1; sub _max { my $max = shift; $max = ( $_ > $max ) ? $_ : $max for @_; return $max; } sub _merge_prereqs { my ($collector, $prereqs) = @_; # CPAN::Meta::Prereqs object if (ref $collector eq $cpan_meta_pre) { return $collector->with_merged_prereqs( CPAN::Meta::Prereqs->new( $prereqs ) ); } # Raw hashrefs for my $phase ( keys %$prereqs ) { for my $type ( keys %{ $prereqs->{$phase} } ) { for my $module ( keys %{ $prereqs->{$phase}{$type} } ) { $collector->{$phase}{$type}{$module} = $prereqs->{$phase}{$type}{$module}; } } } return $collector; } my @include = qw( ); my @exclude = qw( ); # Add static prereqs to the included modules list my $static_prereqs = do 't/00-report-prereqs.dd'; # Merge all prereqs (either with ::Prereqs or a hashref) my $full_prereqs = _merge_prereqs( ( $HAS_CPAN_META ? $cpan_meta_pre->new : {} ), $static_prereqs ); # Add dynamic prereqs to the included modules list (if we can) my ($source) = grep { -f } 'MYMETA.json', 'MYMETA.yml'; if ( $source && $HAS_CPAN_META ) { if ( my $meta = eval { CPAN::Meta->load_file($source) } ) { $full_prereqs = _merge_prereqs($full_prereqs, $meta->prereqs); } } else { $source = 'static metadata'; } my @full_reports; my @dep_errors; my $req_hash = $HAS_CPAN_META ? $full_prereqs->as_string_hash : $full_prereqs; # Add static includes into a fake section for my $mod (@include) { $req_hash->{other}{modules}{$mod} = 0; } for my $phase ( qw(configure build test runtime develop other) ) { next unless $req_hash->{$phase}; next if ($phase eq 'develop' and not $ENV{AUTHOR_TESTING}); for my $type ( qw(requires recommends suggests conflicts modules) ) { next unless $req_hash->{$phase}{$type}; my $title = ucfirst($phase).' '.ucfirst($type); my @reports = [qw/Module Want Have/]; for my $mod ( sort keys %{ $req_hash->{$phase}{$type} } ) { next if $mod eq 'perl'; next if grep { $_ eq $mod } @exclude; my $file = $mod; $file =~ s{::}{/}g; $file .= ".pm"; my ($prefix) = grep { -e File::Spec->catfile($_, $file) } @INC; my $want = $req_hash->{$phase}{$type}{$mod}; $want = "undef" unless defined $want; $want = "any" if !$want && $want == 0; my $req_string = $want eq 'any' ? 'any version required' : "version '$want' required"; if ($prefix) { my $have = MM->parse_version( File::Spec->catfile($prefix, $file) ); $have = "undef" unless defined $have; push @reports, [$mod, $want, $have]; if ( $DO_VERIFY_PREREQS && $HAS_CPAN_META && $type eq 'requires' ) { if ( $have !~ /\A$lax_version_re\z/ ) { push @dep_errors, "$mod version '$have' cannot be parsed ($req_string)"; } elsif ( ! $full_prereqs->requirements_for( $phase, $type )->accepts_module( $mod => $have ) ) { push @dep_errors, "$mod version '$have' is not in required range '$want'"; } } } else { push @reports, [$mod, $want, "missing"]; if ( $DO_VERIFY_PREREQS && $type eq 'requires' ) { push @dep_errors, "$mod is not installed ($req_string)"; } } } if ( @reports ) { push @full_reports, "=== $title ===\n\n"; my $ml = _max( map { length $_->[0] } @reports ); my $wl = _max( map { length $_->[1] } @reports ); my $hl = _max( map { length $_->[2] } @reports ); if ($type eq 'modules') { splice @reports, 1, 0, ["-" x $ml, "", "-" x $hl]; push @full_reports, map { sprintf(" %*s %*s\n", -$ml, $_->[0], $hl, $_->[2]) } @reports; } else { splice @reports, 1, 0, ["-" x $ml, "-" x $wl, "-" x $hl]; push @full_reports, map { sprintf(" %*s %*s %*s\n", -$ml, $_->[0], $wl, $_->[1], $hl, $_->[2]) } @reports; } push @full_reports, "\n"; } } } if ( @full_reports ) { diag "\nVersions for all modules listed in $source (including optional ones):\n\n", @full_reports; } if ( @dep_errors ) { diag join("\n", "\n*** WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING ***\n", "The following REQUIRED prerequisites were not satisfied:\n", @dep_errors, "\n" ); } pass; # vim: ts=4 sts=4 sw=4 et: Class-Date-1.1.17/t/00-report-prereqs.dd0000644000175000017500000000351213304242666017031 0ustar yanickyanickdo { my $x = { 'configure' => { 'requires' => { 'ExtUtils::MakeMaker' => '0' } }, 'develop' => { 'requires' => { 'Test::More' => '0.96', 'Test::Vars' => '0' } }, 'runtime' => { 'requires' => { 'Carp' => '0', 'Date::Parse' => '0', 'Exporter' => '0', 'POSIX' => '0', 'Scalar::Util' => '0', 'Time::Local' => '0', 'constant' => '0', 'overload' => '0', 'perl' => '5.006', 'strict' => '0', 'vars' => '0', 'warnings' => '0' } }, 'test' => { 'recommends' => { 'CPAN::Meta' => '2.120900' }, 'requires' => { 'ExtUtils::MakeMaker' => '0', 'File::Spec' => '0', 'IO::Handle' => '0', 'IPC::Open3' => '0', 'Test::More' => '0', 'Test::Warnings' => '0' } } }; $x; }Class-Date-1.1.17/t/30_localdate.t0000755000175000017500000001022313304242666015730 0ustar yanickyanickuse strict; use warnings; use Test::More; plan tests => 77; use Class::Date qw(localdate date); $Class::Date::DST_ADJUST=1; ok(1); # Class::Date::new my $date1 = Class::Date->new([2000,11,11,0,1,2]); is $date1, "2000-11-11 00:01:02"; my $date2 = localdate [2000,10,5]; is $date2, "2000-10-05 00:00:00"; my $date3 = date({ year => 2001, month => 03, day => 11, hour => 12, min => 13, sec => 55 }); is $date3, "2001-03-11 12:13:55"; my $date4 = localdate({ year => 2001, month => 03, day => 11 }); is $date4, "2001-03-11 00:00:00"; my $date5 = localdate("2001-2-21 13:11:10.123456"); is $date5, "2001-02-21 13:11:10"; my $date6 = localdate("2001-2-21 13:11"); is $date6, "2001-02-21 13:11"; my $date7 = localdate("2000-11-11 0:0:0"); is $date7, "2000-11-11"; my $date8 = localdate("2001011312220112"); is $date8, "2001-01-13 12:22:01"; my $date9 = localdate("2001-5-11"); is $date9, "2001-05-11 00:00:00"; my $date10 = $date9->new($date9); is $date10, "2001-05-11"; # Class::Date::Rel::new my $reldate1 = Class::Date::Rel->new('1D'); is $reldate1, "0000-00-01 00:00:00"; my $reldate2 = Class::Date::Rel->new('1Y 1M 15h 20m'); is $reldate2, "0001-01-00 15:20"; my $reldate3 = Class::Date::Rel->new('3Y 3M 5D 13h 20m 15s'); is $reldate3, "0003-03-05 13:20:15"; my $reldate4 = Class::Date::Rel->new({ year => 5, day => 7}); is $reldate4, "0005-00-07 00:00:00"; my $reldate5 = Class::Date::Rel->new({ year => 9, month => 8, day => 7, hour => 6, min => 65, sec => 55, }); is $reldate5, "0009-08-07 07:05:55"; my $reldate6 = Class::Date::Rel->new([9,8,7,6,65,55]); is $reldate6, "0009-08-07 07:05:55"; my $reldate7 = Class::Date::Rel->new("7-8-6 07:11:10"); is $reldate7, "0007-08-06 07:11:10"; my $reldate8 = $reldate5->new($reldate7); is $reldate8, "7Y 8M 6D 7h 11m 10s"; # Class::Date::add is $date1+$reldate1, "2000-11-12 00:01:02"; is $date7+$reldate3, "2004-02-16 13:20:15"; is $date1+"2Y", "2002-11-11 00:01:02"; is $date1+"2-0-0", "2002-11-11 00:01:02"; # Class::Date::subs is $date1-$reldate1, "2000-11-10 00:01:02"; is $date7-$reldate3+$reldate3, $date7; is $date3-$date1, '120D 12h 12m 53s'; is $date1-'1D', "2000-11-10 0:1:2"; is $date1-[0,0,1], "2000-11-10 0:1:2"; # Class::Date Comparison ok $date1 > $date2; ok $date1 >= $date1; ok ! ($date1<"2000-01-01"); ok ! ("2000-01-01">$date1); is "2000-01-02" <=> $date1, -1; is "2001-01-02" cmp $date1, 1 ; is $date1 <=> "2000-01-02", 1; is $date1 cmp "2001-01-02", -1; # Class::Date::Rel Comparison ok $reldate1 < $reldate2; ok $reldate2 < '2Y'; ok '2Y' < $reldate3; is '2Y' <=> $reldate3, -1; is $reldate3 <=> '2Y', 1; # Class::Date field methods; is $date1->year, 2000; is $date1->mon, 11; is $date1->day, 11; is $date1->hour, 0; is $date1->min, 1; is $date1->sec, 2; # Default values for hash initialization my $date11 = Class::Date->new({ year => 2001 }); is $date11, "2001-01-01 00:00:00"; my $date12 = new Class::Date { month => 2 }; is $date12, "2000-02-01 00:00:00"; my $date13 = localdate [1998]; is $date13, "1998-01-01"; my $reldate9 = Class::Date::Rel->new( { year => 4 }); is $reldate9, "4-0-0 0:0:0"; my $reldate10 = Class::Date::Rel->new( { month => 5 }); is $reldate10, "0-5-0 0:0:0"; my ($y,$m,$d,$hh,$mm,$ss) = $date1->array; is $y, 2000; is $m, 11; is $d, 11; is $hh, 0; is $mm, 1; is $ss, 2; # undef comparison ok $date11 > undef() ? 1 : 0; ok undef() > $date11 ? 0 : 1; ok $date13 < undef() ? 0 : 1; ok undef() < $date13 ? 1 : 0; is $date1->month_begin, "2000-11-01 00:01:02"; is $date1->month_end , "2000-11-30 00:01:02"; is $date1->days_in_month, 30; is $date2->days_in_month,31; is $date5->days_in_month,28; is $date1->truncate, "2000-11-11 00:00:00"; is $date1->trunc, "2000-11-11 00:00:00"; is $date1, "2000-11-11 00:01:02"; { local $Class::Date::MONTH_BORDER_ADJUST = 0; my $date11 = date("2001-05-31"); is $date11+'4M', "2001-10-01"; is $date11-'3M', "2001-03-03"; $Class::Date::MONTH_BORDER_ADJUST = 1; is $date11+'4M', "2001-09-30"; is $date11-'3M', "2001-02-28"; } my $date14 = date("2001-12-18"); is $date14->days_in_month, 31; is date([2001,11,17])->is_leap_year ? 1 : 0, 0; is date([2004,03,05])->is_leap_year ? 1 : 0, 1; Class-Date-1.1.17/t/class-date-invalid.t0000644000175000017500000000034413304242666017142 0ustar yanickyanickuse strict; use warnings; use Test::More tests => 2; use Test::Warnings; use Class::Date::Invalid; my $self = [ 1, 123 ]; bless $self, 'Class::Date::Invalid'; # that used to warn - GH#9 like $self->errmsg, qr'Invalid'; Class-Date-1.1.17/t/50_timezone.t0000755000175000017500000000163713304242666015645 0ustar yanickyanickuse strict; use warnings; use Test::More tests => 8; use Class::Date qw(date gmdate); eval { require Env::C }; diag "Env::C version $Env::C::VERSION loaded" if not $@; $Class::Date::DST_ADJUST=1; ok(1); # Class::Date::new my $date1 = Class::Date->new([2002,05,04,0,1,2],'CET'); is $date1, "2002-05-04 00:01:02", 'date1'; is $date1->tz, 'CET', 'tz'; is $date1->tzdst, 'CEST', 'tzdst'; is $date1->epoch, 1020463262, 'epoch'; subtest 'to GMT' => sub { my $date2 = $date1->to_tz('GMT'); is $date2, "2002-05-03 22:01:02", 'date2'; is $date2->tz, 'GMT', 'tz'; { local $TODO = 'known to fail on non-linux machines - GH#8'; is $date2->tzdst, 'GMT', 'tzdst'; } is $date1->epoch, 1020463262, 'epoch'; }; my $date3 = $date1->clone(tz => 'GMT'); is $date3->epoch, 1020470462, 'epoch'; is $date3, gmdate([2002,05,04,0,1,2]), 'gmdate'; Class-Date-1.1.17/t/00-compile.t0000644000175000017500000000223713304242666015346 0ustar yanickyanickuse 5.006; use strict; use warnings; # this test was generated with Dist::Zilla::Plugin::Test::Compile 2.052 use Test::More; plan tests => 4 + ($ENV{AUTHOR_TESTING} ? 1 : 0); my @module_files = ( 'Class/Date.pm', 'Class/Date/Const.pm', 'Class/Date/Invalid.pm', 'Class/Date/Rel.pm' ); # no fake home requested my $inc_switch = -d 'blib' ? '-Mblib' : '-Ilib'; use File::Spec; use IPC::Open3; use IO::Handle; open my $stdin, '<', File::Spec->devnull or die "can't open devnull: $!"; my @warnings; for my $lib (@module_files) { # see L my $stderr = IO::Handle->new; my $pid = open3($stdin, '>&STDERR', $stderr, $^X, $inc_switch, '-e', "require q[$lib]"); binmode $stderr, ':crlf' if $^O eq 'MSWin32'; my @_warnings = <$stderr>; waitpid($pid, 0); is($?, 0, "$lib loaded ok"); if (@_warnings) { warn @_warnings; push @warnings, @_warnings; } } is(scalar(@warnings), 0, 'no warnings found') or diag 'got warnings: ', ( Test::More->can('explain') ? Test::More::explain(\@warnings) : join("\n", '', @warnings) ) if $ENV{AUTHOR_TESTING}; Class-Date-1.1.17/t/00_base.t0000644000175000017500000000044613304242666014712 0ustar yanickyanickuse strict; use warnings; use Test::More; plan tests => 6; use Class::Date qw(now gmdate); ok(1); my $t = gmdate(315532800); # 00:00:00 1/1/1980 is $t->year, 1980, 'year'; is $t->hour, 0, 'hour'; is $t->mon, 1, 'mon'; cmp_ok now, '>', "1970-1-1"; cmp_ok gmdate("now"), '>', "1970-1-1"; Class-Date-1.1.17/t/bug-reports.t0000644000175000017500000000031213304242666015742 0ustar yanickyanickuse Test::More tests => 1; use Class::Date; my $d2 = Class::Date->new('1935-12-23'); my $d1 = Class::Date->new('2008-12-17'); my $k = int( (Class::Date->new($d1)-$d2)->year ); is $k => 72, 'gh#3'; Class-Date-1.1.17/t/40_errors.t0000755000175000017500000000145413304242666015323 0ustar yanickyanickuse strict; use warnings; use Test::More; plan tests => 18; use Class::Date qw(:errors gmdate); $Class::Date::DST_ADJUST=1; ok(1); my $t = gmdate("195xwerf9"); ok !$t; is $t->error, E_UNPARSABLE; is $t->errstr, "Unparsable date or time: 195xwerf9\n"; $Class::Date::RANGE_CHECK=0; $t = gmdate("2001-02-31"); is $t, "2001-03-03"; $Class::Date::RANGE_CHECK=1; $t = gmdate("2001-02-31"); ok !$t; ok $t ? 0 : 1; is $t->error, E_RANGE; is $t->errstr, "Range check on date or time failed\n"; $t = gmdate("2006-2-6")->clone( month => -1); ok !$t; ok $t ? 0 : 1; $t = new Class::Date(undef); ok ! $t; ok $t ? 0 : 1; is $t->error, E_UNDEFINED; is $t->errstr, "Undefined date object\n"; $t = gmdate("2006-2-6")->clone(month => 16); ok !$t; ok $t ? 0 : 1; $t = gmdate("2001-05-04 07:09:09") + [1,-2,-4]; ok $t; Class-Date-1.1.17/t/20_gmdate.t0000755000175000017500000000622613304242666015250 0ustar yanickyanickuse strict; use warnings; use Test::More; plan tests => 56; use Class::Date qw(gmdate date); $Class::Date::DST_ADJUST=1; ok(1); # Class::Date::new my $date1=gmdate([2000,11,11,0,1,2]); is$date1,"2000-11-11 00:01:02"; my $date2=date [2000,10,5],1; is $date2,"2000-10-05 00:00:00"; my $date3=gmdate({ year => 2001, month => 03, day => 11, hour => 12, min => 13, sec => 55 }); is $date3,"2001-03-11 12:13:55"; my $date4=gmdate({ year => 2001, month => 03, day => 11 }); is $date4,"2001-03-11 00:00:00"; my $date5=gmdate("2001-2-21 13:11:10.123456"); is $date5,"2001-02-21 13:11:10"; my $date6=gmdate("2001-2-21 13:11:06"); is $date6,"2001-02-21 13:11:06"; my $date7=gmdate("973897200"); is $date7,"2000-11-10 23:00:00"; my $date8=gmdate("2001011312220112"); is $date8,"2001-01-13 12:22:01"; my $date9=gmdate("2001-5-11"); is $date9,"2001-05-11 00:00:00"; my $date10=$date9->new($date9); is $date10,"2001-05-11"; # Class::Date::Rel::new my $reldate1=Class::Date::Rel->new('1D'); is $reldate1,"0000-00-01 00:00:00"; my $reldate2=Class::Date::Rel->new('1Y 1M 15h 20m'); is $reldate2,"0001-01-00 15:20:00"; my $reldate3=Class::Date::Rel->new('3Y 3M 5D 13h 20m 15s'); is $reldate3,"0003-03-05 13:20:15"; my $reldate4=Class::Date::Rel->new({ year => 5, day => 7}); is $reldate4,"0005-00-07 00:00:00"; my $reldate5=Class::Date::Rel->new({ year => 9, month => 8, day => 7, hour => 6, min => 65, sec => 55, }); is $reldate5,"0009-08-07 07:05:55"; my $reldate6=Class::Date::Rel->new([9,8,7,6,65,55]); is $reldate6,"0009-08-07 07:05:55"; my $reldate7=Class::Date::Rel->new("7-8-6 07:11:10"); is $reldate7,"0007-08-06 07:11:10"; my $reldate8=$reldate5->new($reldate7); is $reldate8,"7Y 8M 6D 7h 11m 10s"; # Class::Date::add is $date1+$reldate1,"2000-11-12 00:01:02"; is $date7+$reldate3,"2004-02-16 12:20:15"; is $date1+"2Y","2002-11-11 00:01:02"; is $date1+"2-0-0","2002-11-11 00:01:02"; # Class::Date::subs is $date1-$reldate1,"2000-11-10 00:01:02"; is $date7-$reldate3+$reldate3,$date7; is $date3-$date1,'120D 12h 12m 53s'; # Class::Date Comparison cmp_ok $date1, '>', $date2; cmp_ok $date1, '>=', $date1; ok ! ($date1<"2000-01-01"); ok ! ("2000-01-01">$date1); is "2000-01-02" <=> $date1, -1; is "2001-01-02" cmp $date1, 1 ; is $date1 <=> "2000-01-02", 1; is $date1 cmp "2001-01-02", -1; # Class::Date::Rel Comparison cmp_ok $reldate1, '<', $reldate2; cmp_ok $reldate2, '<', '2Y'; cmp_ok '2Y', '<', $reldate3; is '2Y' <=> $reldate3, -1; is $reldate3 <=> '2Y', 1; # Class::Date field methods; is $date1->year, 2000; is $date1->mon, 11; is $date1->mday, 11; is $date1->hour, 0; is $date1->min, 1; is $date1->sec, 2; # Default values for hash initialization my $date11 = Class::Date->new( { year => 2001 } ); is $date11,"2001-01-01 00:00:00"; my $date12 = Class::Date->new( { month => 2 } ); is $date12,"2000-02-01 00:00:00"; my $date13 = gmdate [1998]; is $date13,"1998-01-01"; my $reldate9 = Class::Date::Rel->new( { year => 4 }); is $reldate9, "4-0-0 0:0:0"; my $reldate10 = Class::Date::Rel->new( { month => 5 }); is $reldate10, "0-5-0 0:0:0"; my ($y,$m,$d,$hh,$mm,$ss)=$date1->array; is $y, 2000; is $m, 11; is $d, 11; is $hh, 0; is $mm, 1; is $ss, 2; Class-Date-1.1.17/doap.xml0000644000175000017500000002535413304242666014523 0ustar yanickyanick Class-Date Class for easy date and time manipulation dLux (Szabó, Balázs) Gabor Szabo Yanick Champoux Vladimir Timofeev 0.5 2001-03-12 0.90 2001-04-05T13:18:18Z 0.91 2001-04-09T13:42:49Z 0.92 2001-04-17T17:23:10Z 0.93 2001-04-18T12:55:15Z 0.94 2001-04-26T16:30:39Z 0.95 2001-05-10T00:11:43Z 0.96 2001-05-11T01:42:36Z 0.97 2001-05-16T23:10:17Z 0.98 2001-05-22T16:46:03Z 1.0.0 2001-06-11T14:58:29Z 1.0.1 2001-06-16T16:14:02Z 1.0.2 2001-06-27T00:08:05Z 1.0.3 2001-07-03T13:09:04Z 1.0.4 2001-07-12T11:00:46Z 1.0.5 2001-07-17T14:31:00Z 1.0.6 2001-10-11T14:26:27Z 1.0.7 2001-10-15T00:22:47Z 1.0.8 2001-11-07T12:15:28Z 1.0.9 2002-02-25T23:19:49Z 1.0.10 2002-03-10T21:45:58Z 1.1.0 2002-07-15T20:24:04Z 1.1.1 2002-08-28T23:30:43Z 1.1.2 2002-12-14T14:46:41Z 1.1.3 2003-01-03T09:07:01Z 1.1.4 2003-02-05T11:15:20Z 1.1.5 2003-02-05T23:17:50Z 1.1.6 2003-03-16T18:05:23Z 1.1.7 2003-08-20T23:16:29Z 1.1.8 2005-11-06T16:36:54Z 1.1.9 2006-05-14T22:52:50Z 1.1.10 2010-07-18T13:27:39Z 1.1.11 2014-04-30T06:56:24Z 1.1.12 2014-04-30T08:44:29Z 1.1.13 2014-05-02T08:32:15Z 1.1.14 2014-05-03T11:02:33Z 1.1.15 2014-05-05T06:18:37Z 1.1.16 2018-05-26 Perl