Date-Simple-3.03_03/0000755000076500007650000000000010741774043014010 5ustar igorigor00000000000000Date-Simple-3.03_03/ChangeLog0000755000076500007650000000536410741773657015607 0ustar igorigor000000000000002008-01-12 Igor Sutton * Subclassing should now work with today, ymd and d8 constructors (bug #32250). 2008-01-10 Igor Sutton * Copy default_format from old Date::Simple object when adding or subtracting (bug #31037). 2008-01-09 Igor Sutton * Applied patch proposed for 64bit support (bug #28549). 2004-12-18 Yves Orton * YO -- Version number kick to 3.02, doc fix. Patch merge. 2004-11-27 John Tobey * Simple.xs (is_leap_year): Fixed math for dates before 1900-03-01. Thanks to Anil Natha for finding the bug. * t/date.t: Added day_of_week tests. 2004-04-02 Yves Orton * lib/Date/Simple.pm ($VERSION): Version 3. Added formatting support and as_iso() XS method. Switched to using Test::More instead of Test. Prereqs expanded to include Test::More and Scalar::Util Both are standard distro in later perls. * Makefile.pl: Dont mess with filenames xs is true. 2002-12-06 John Tobey * lib/Date/Simple.pm ($VERSION): Version 2.04. * lib/Date/Simple.pm (use overload): Overload more operators: == != eq ne (_inval): Stylistic changes. (_new): New sub, built from the old 'new'. Accept YYYYMMDD strings without hyphens. Return undef rather than dying on unrecognized format. ('new' still dies for compatibility.) (date): Use '_new'. Avoid use of 'eval' and $@. (new): Use '_new'. (pod): Update docs. * lib/Date/Simple/NoXS.pm (_eq): New sub. (_ne): New sub. * Simple.xs (is_object): New function. (new_for_cmp): New function. (_add): Use is_object(). (_subtract): Use is_object(). (_compare): Use is_object() and new_for_cmp(). (_eq): New sub. (_ne): New sub. * t/date.t: Test new equality operators. * README: Regenerated from lib/Date/Simple.pm. 2002-03-11 John Tobey * lib/Date/Simple.pm ($VERSION): Version 2.03. * t/date.t: Remove a locale dependency. Thanks to ASSAD Arnaud for the fix. 2001-10-02 John Tobey * lib/Date/Simple.pm ($VERSION): Version 2.02. * Simple.xs (days_in_month): avoid crash due to reversed args. 2001-08-27 John Tobey * lib/Date/Simple.pm: Version 2.01. * t/date.t: Test today() fix. * lib/Date/Simple.pm (today): Replace use of deleted function. * Version 2.00. * Added functional interface (date, d8, ymd). * Load POSIX module only when needed. * Crunch numbers in C if compiler found. (Install with 'perl Makefile.PL noxs' to select the pure Perl implementation.) * Can calculate the day of the week. * Reduced dependence on time_t, most functions work for dates up to 9999. Date-Simple-3.03_03/COPYING0000755000076500007650000004312707340121626015047 0ustar igorigor00000000000000 GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU 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. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), 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 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 show them these terms so they know 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. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. 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 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 derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 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 License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. 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. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary 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 License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 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 Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing 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 for copying, distributing or modifying the Program or works based on it. 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. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. 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 this 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 this License, you may choose any version ever published by the Free Software Foundation. 10. 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 11. 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. 12. 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 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 the public, 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 2 of the License, 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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) 19yy 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 is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. Date-Simple-3.03_03/lib/0000755000076500007650000000000010741774042014555 5ustar igorigor00000000000000Date-Simple-3.03_03/lib/Date/0000755000076500007650000000000010741774042015432 5ustar igorigor00000000000000Date-Simple-3.03_03/lib/Date/Simple/0000755000076500007650000000000010741774042016663 5ustar igorigor00000000000000Date-Simple-3.03_03/lib/Date/Simple/D8.pm0000755000076500007650000000163310741767032017503 0ustar igorigor00000000000000package Date::Simple::D8; use Date::Simple 3; use base qw/Date::Simple/; use overload '""' => 'as_d8'; *EXPORT = *Date::Simple::EXPORT; *EXPORT_OK = *Date::Simple::EXPORT_OK; *EXPORT_TAGS = *Date::Simple::EXPORT_TAGS; sub d8 { shift->_d8(@_) } sub today { shift->_today(@_) } sub ymd { shift->_ymd(@_) } 1; =head1 NAME Date::Simple::D8 - Sub class of Date::Simple with eight digit date style formatting as default. =head1 SYNOPSIS use Date::Simple::D8; =head1 DESCRIPTION This module changes the default stringification behaviour of Date::Simple objects to use the as_d8() method instead. =item Date::Simple::D8->new ([ARG, ...]) =item date_d8 ([ARG, ...]) Identical to Date::Simple except that uses the D8 style formatting ('%Y%m%d') for overloaded stringification or when not providing a format argument to the format() method. =head1 SEE ALSO L for full documentation. =cut Date-Simple-3.03_03/lib/Date/Simple/Fmt.pm0000755000076500007650000000246510741767065017770 0ustar igorigor00000000000000package Date::Simple::Fmt; use Date::Simple 3; use base qw/Date::Simple/; use overload '""' => '_format'; *EXPORT = *Date::Simple::EXPORT; *EXPORT_OK = *Date::Simple::EXPORT_OK; *EXPORT_TAGS = *Date::Simple::EXPORT_TAGS; sub d8 { shift->_d8(@_) } sub today { shift->_today(@_) } sub ymd { shift->_ymd(@_) } sub new { my ( $class, $fmt, @args ) = @_; my $self = $class->SUPER::new(@args); $self->default_format($fmt); $self; } sub _format { shift->format() } 1; =head1 NAME Date::Simple::Fmt - Sub class of Date::Simple with per object level formatting for overloaded stringification. =head1 SYNOPSIS use Date::Simple::Fmt; =head1 DESCRIPTION This module changes the default stringification behaviour of Date::Simple objects to use the format() method instead. It also changes the behaviour of the constructor. =item Date::Simple::Fmt->new (FMT, [ARG, ...]) =item date_fmt (FMT, [ARG, ...]) Follows the same rules as for the equivelent method (new) and subroutine (date) in Date::Simple except that the first argument is expected to be the default format for the newly created object. It is this format that will be used when using overloaded stringification or when not providing a format argument to the format() method. =head1 SEE ALSO L for full documentation. =cut Date-Simple-3.03_03/lib/Date/Simple/ISO.pm0000755000076500007650000000141710741766750017670 0ustar igorigor00000000000000package Date::Simple::ISO; use Date::Simple 3; use base qw/Date::Simple/; use overload '""' => 'as_iso'; # sub { $_[0]->as_iso }; *EXPORT = *Date::Simple::EXPORT; *EXPORT_OK = *Date::Simple::EXPORT_OK; *EXPORT_TAGS = *Date::Simple::EXPORT_TAGS; sub d8 { shift->_d8(@_); } sub today { shift->_today(@_); } sub ymd { shift->_ymd(@_); } 1; =head1 NAME Date::Simple::ISO - Sub class of Date::Simple =head1 SYNOPSIS use Date::Simple::ISO; =head1 DESCRIPTION This module is entirely identical to Date::Simple. It is included for completness and self documenting sake. IMO it is preferable to say my $obj=Date::Simple::ISO->new(...); As this makes the implicit formatting of the object clear. =head1 SEE ALSO L for full documentation. =cut Date-Simple-3.03_03/lib/Date/Simple/NoXS.pm0000755000076500007650000001205610741766250020061 0ustar igorigor00000000000000# Date::Simple::NoXS - used internally by Date::Simple. use strict; package Date::Simple; sub _ymd { my ( $class, @args ) = @_; my $days = ymd_to_days(@args); return unless defined($days); return ( bless \$days, $class ); } sub _d8 { my ( $o, $d8 ) = @_; my @ymd = $d8 =~ m/^(\d{4})(\d\d)(\d\d)$/ or return undef; return $o->_ymd(@ymd); } # Precise integer arithmetic functions unfortunately missing from # Perl's core: sub _divmod { my ( $quot, $int ); $quot = $_[0] / $_[1]; $int = int($quot); $int -= 1 if $int > $quot; $_[0] %= $_[1]; return $int; } sub _div { my ( $quot, $int ); $quot = $_[0] / $_[1]; $int = int($quot); return $int - 1 if $int > $quot; return $int; } sub leap_year { my $y = shift; return ( ( $y % 4 == 0 ) and ( $y % 400 == 0 or $y % 100 != 0 ) ) || 0; } my @days_in_month = ( [ 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ], [ 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ], ); sub days_in_month ($$) { my ( $y, $m ) = @_; return $days_in_month[ leap_year($y) ][$m]; } sub validate ($$$) { my ( $y, $m, $d ) = @_; # any +ve integral year is valid return 0 if $y != abs int $y; return 0 unless 1 <= $m and $m <= 12; return 0 unless 1 <= $d and $d <= $days_in_month[ leap_year($y) ][$m]; return 1; } # Given a year, month, and day, return the canonical day number. # That is the number of days since 1 January 1970, negative if earlier. sub ymd_to_days { my ( $Y, $M, $D ) = @_; my ( $days, $x ); if ( $M < 1 || $M > 12 || $D < 1 || ( $D > 28 && $D > days_in_month( $Y, $M ) ) ) { return undef; } $days = $D + ( undef, -1, 30, 58, 89, 119, 150, 180, 211, 242, 272, 303, 333 )[$M]; $days += 365 * ( $Y - 1970 ); $x = ( $M <= 2 ? $Y - 1 : $Y ); $days += _div( ( $x - 1968 ), 4 ); $days -= _div( ( $x - 1900 ), 100 ); $days += _div( ( $x - 1600 ), 400 ); return $days; } sub days_since_1970 { ${ $_[0] } } # Given a canonical day number (days since 1 Jan 1970), return the # year, month, and day. sub days_to_ymd { my ($days) = @_; my ( $year, $mnum, $mday, $tmp ); # Shift frame of reference from 1 Jan 1970 to (the imaginary) 1 Mar 0AD. $tmp = $days + 719468; # Do the math. $year = 400 * _divmod( $tmp, 146097 ); if ( $tmp == 146096 ) { # Handle 29 Feb 2000, 2400, ... $year += 400; $mnum = 2; $mday = 29; } else { $year += 100 * _divmod( $tmp, 36524 ); $year += 4 * _divmod( $tmp, 1461 ); if ( $tmp == 1460 ) { $year += 4; $mnum = 2; $mday = 29; } else { $year += _divmod( $tmp, 365 ); $mnum = _divmod( $tmp, 31 ); $mday = $tmp + ( 1, 1, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5 )[$mnum]; $tmp = ( 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28 )[$mnum]; if ( $mday > $tmp ) { $mday -= $tmp; $mnum += 1; } if ( $mnum > 9 ) { $mnum -= 9; $year += 1; } else { $mnum += 3; } } } return ( $year, $mnum, $mday ); } sub as_ymd { return days_to_ymd( ${ $_[0] } ); } sub as_d8 { return sprintf( "%04d%02d%02d", &as_ymd ); } sub as_iso { return sprintf( "%04d-%02d-%02d", &as_ymd ); } sub year { return (&as_ymd)[0]; } sub month { return (&as_ymd)[1]; } sub day { return (&as_ymd)[2]; } sub day_of_week { return ( ( ${ $_[0] } + 4 ) % 7 ); } #------------------------------------------------------------------------------ # the following methods are called by the overloaded operators, so they should # not normally be called directly. #------------------------------------------------------------------------------ sub _add { my ( $date, $diff ) = @_; if ( $diff !~ /^-?\d+$/ ) { Carp::croak("Date interval must be an integer"); } my $new_date = bless( \( $$date + $diff ), ref($date) ); $new_date->default_format( $date->default_format ); return $new_date; } sub _subtract { my ( $left, $right, $reverse ) = @_; my $new_date; if ($reverse) { Carp::croak("Can't subtract a date from a non-date"); } if ( ref($right) eq '' && $right =~ /^-?\d+$/ ) { $new_date = bless( \( $$left - $right ), ref($left) ); $new_date->default_format( $left->default_format ); return $new_date; } return ( $$left - $$right ); } sub _compare { my ( $left, $right, $reverse ) = @_; $right = $left->new($right) || _inval( $left, $right ); return ( $reverse ? $$right <=> $$left : $$left <=> $$right ); } sub _eq { my ( $left, $right ) = @_; return ( ( $right = $left->_new($right) ) && $$right == $$left ); } sub _ne { return ( !&_eq ); } 1; =head1 NAME Date::Simple::NoXS - Pure Perl support for Date::Simple. =head1 SYNOPSIS use Date::Simple; =head1 DESCRIPTION Used internally by Date::Simple. =head1 SEE ALSO L. =cut Date-Simple-3.03_03/lib/Date/Simple.pm0000755000076500007650000004211610741772727017240 0ustar igorigor00000000000000# Date::Simple - a simple date object package Date::Simple; BEGIN { $VERSION = '3.03_03'; } use Exporter (); @ISA = ('Exporter'); @EXPORT_OK = qw( today ymd d8 leap_year days_in_month date date_fmt date_d8 date_iso ); %EXPORT_TAGS = ( 'all' => \@EXPORT_OK ); # Try to load the C code. If that fails, fall back to Date::Simple::NoXS. if ( !defined(&_add) ) { my $err = $Date::Simple::NoXS; unless ($err) { # Use DynaLoader instead of XSLoader for pre-5.005. local ($@); local @ISA = ('DynaLoader'); require DynaLoader; eval { __PACKAGE__->bootstrap($VERSION); }; $err = $@; } if ($err) { $Date::Simple::NoXs = 1; require Date::Simple::NoXS; } } use strict; use Carp (); use overload '+' => '_add', '-' => '_subtract', '==' => '_eq', '!=' => '_ne', '<=>' => '_compare', 'eq' => '_eq', 'ne' => '_ne', 'cmp' => '_compare', 'bool' => sub { 1 }, '""' => 'as_iso'; use Scalar::Util qw(refaddr reftype); use warnings::register; require Date::Simple::Fmt; require Date::Simple::ISO; require Date::Simple::D8; sub d8 { # called as function if ( $#_ == 0 ) { return __PACKAGE__->_d8(@_); } # called as method else { if ( ref $_[0] eq 'SCALAR' ) { return $_[0]->SUPER::_d8(@_); } else { return $_[0]->_d8(@_); } } } sub today { if ( $#_ == -1 ) { return __PACKAGE__->_today(@_); } else { return shift->_today(@_); } } sub ymd { # called as function if ( $#_ == 2 ) { return __PACKAGE__->_ymd(@_); } # called as method else { if ( ref $_[0] eq 'SCALAR' ) { return $_[0]->SUPER::_ymd(@_); } else { return $_[0]->_ymd(@_); } } } sub _today { my ( $y, $m, $d ) = (localtime)[ 5, 4, 3 ]; $y += 1900; $m += 1; return $_[0]->_ymd( $y, $m, $d ); } sub _inval { my ($first); $first = shift; Carp::croak( "Invalid " . ( ref($first) || $first ) . " constructor args: ('" . join( "', '", @_ ) . "')" ); } sub _new { my ( $that, @ymd ) = @_; my $class = ref($that) || $that; if ( @ymd == 1 ) { my $x = $ymd[0]; if ( ref $x and reftype($x) eq 'ARRAY' ) { @ymd = @$x; } elsif ( UNIVERSAL::isa( $x, __PACKAGE__ ) ) { return ($x); } elsif ($x =~ /^(\d\d\d\d)-(\d\d)-(\d\d)$/ || $x =~ /^(\d\d\d\d)(\d\d)(\d\d)$/ ) { @ymd = ( $1, $2, $3 ); } else { return (undef); } } # we fall through here... # note we can end up here is they pass in [] as the date return $class->_today() unless @ymd; # to get here, we had one arg which was split, # or 3 in the first place if ( @ymd == 3 ) { my $days = ymd_to_days(@ymd); return undef if !defined($days); return ( bless( \$days, $class ) ); } $class->_inval(@ymd); } sub date { scalar __PACKAGE__->_new(@_) } sub date_fmt { my $format = shift; my $obj = Date::Simple::Fmt->_new(@_); $obj->default_format($format) if $obj; $obj; } sub date_d8 { scalar Date::Simple::D8->_new(@_) } sub date_iso { scalar Date::Simple::ISO->_new(@_) } # Same as date() but it's a method and croaks on error if called with # one arg. sub new { my ( $class, $date ); $date = &_new; if ( !$date && scalar(@_) == 1 ) { Carp::croak( "'" . shift() . "' is not a valid ISO formated date" ); } return ($date); } sub next { return ( $_[0] + 1 ); } sub prev { return ( $_[0] - 1 ); } sub _gmtime { my ( $y, $m, $d ) = days_to_ymd( ${ $_[0] } ); $y -= 1900; $m -= 1; return ( 0, 0, 0, $d, $m, $y ); } BEGIN { our $Standard_Format = "%Y-%m-%d"; my %fmts = ( # Inside out parameter 'Date::Simple' => $Standard_Format, 'Date::Simple::ISO' => $Standard_Format, 'Date::Simple::D8' => "%Y%m%d", 'Date::Simple::Fmt' => $Standard_Format, ); sub format { my ( $self, $format ) = @_; $format = $fmts{ refaddr($self) || '' } || $fmts{ ref($self) } || $Standard_Format if @_ == 1; return "$self" unless defined($format); require POSIX; local $ENV{TZ} = 'UTC+0'; return POSIX::strftime( $format, _gmtime($self) ); } sub strftime { &format } sub as_str { &format } sub default_format { my ( $self, $val ) = @_; my $o = refaddr($self) || $self; if ( @_ > 1 ) { $fmts{$o} = $val; warnings::warnif "Setting class specific date format '$o' to" . "'" . ( defined $val ? $val : 'undef' ) . "'" unless ref $self; } return $fmts{$o} || $Standard_Format; } sub DESTROY { delete $fmts{ refaddr $_[0] }; } } 1; =head1 NAME Date::Simple - a simple date object =head1 SYNOPSIS use Date::Simple ('date', 'today'); # Difference in days between two dates: $diff = date('2001-08-27') - date('1977-10-05'); # Offset $n days from now: $date = today() + $n; print "$date\n"; # uses ISO 8601 format (YYYY-MM-DD) use Date::Simple (); my $date = Date::Simple->new('1972-01-17'); my $year = $date->year; my $month = $date->month; my $day = $date->day; use Date::Simple (':all'); my $date2 = ymd($year, $month, $day); my $date3 = d8('19871218'); my $today = today(); my $tomorrow = $today + 1; if ($tomorrow->year != $today->year) { print "Today is New Year's Eve!\n"; } if ($today > $tomorrow) { die "warp in space-time continuum"; } print "Today is "; print(('Sun','Mon','Tues','Wednes','Thurs','Fri','Satur') [$today->day_of_week]); print "day.\n"; # you can also do this: ($date cmp "2001-07-01") # and this ($date <=> [2001, 7, 1]) =begin text INSTALLATION If your system has the "make" program or a clone: perl Makefile.PL make make test make install If you lack "make", copy the "lib/Date" directory to your module directory (run "perl -V:sitelib" to find it). If "make test" fails, perhaps it means your system can't compile C code. Try: make distclean perl Makefile.PL noxs make make test make install This will use the pure-Perl implementation. =end text =head1 DESCRIPTION Dates are complex enough without times and timezones. This module may be used to create simple date objects. It handles: =over 4 =item Validation. Reject 1999-02-29 but accept 2000-02-29. =item Interval arithmetic. How many days were between two given dates? What date comes N days after today? =item Day-of-week calculation. What day of the week is a given date? =item Transparent date formatting. How should a date object be formatted. =back It does B deal with hours, minutes, seconds, and time zones. A date is uniquely identified by year, month, and day integers within valid ranges. This module will not allow the creation of objects for invalid dates. Attempting to create an invalid date will return undef. Month numbering starts at 1 for January, unlike in C and Java. Years are 4-digit. Gregorian dates up to year 9999 are handled correctly, but we rely on Perl's builtin C function when the current date is requested. On some platforms, C may be vulnerable to rollovers such as the Unix C wraparound of 18 January 2038. Overloading is used so you can compare or subtract two dates using standard numeric operators such as C<==>, and the sum of a date object and an integer is another date object. Date::Simple objects are immutable. After assigning C<$date1> to C<$date2>, no change to C<$date1> can affect C<$date2>. This means, for example, that there is nothing like a C operation, and C<$date++> assigns a new object to C<$date>. This module contains various undocumented functions. They may not be available on all platforms and are likely to change or disappear in future releases. Please let the author know if you think any of them should be public. =head2 Controlling output format. As of version 3.0 new ways of controlling the output formats of Date::Simple objects has been provided. However Date::Simple has traditionally provided few ways of stringification, a primary one via the format() method and another primary one via direct stringification. However the later is currently implemented as an XS routine and the former is implemented through a perl routine. This means that using format() is more expensive than stringification and that the stringification format is class specific. In order to alleviate some of these problems a new mechanism has been introduced to Date::Simple that allows for a per object level format default. In addition a set of utility classes that have different stringification overloads provided. These classes are simple subclasses of Date::Simple and beside the default format() and the overloaded stringification behaviour are identical to Date::Simple. In fact one is totally identical to Date::Simple and is provided mostly for completeness. The classes included are: =over 4 =item Date::Simple::ISO Identical to Date::Simple in every respect but name. =item Date::Simple::D8 Uses the D8 format (%Y%m%d) as the default format for printing. Uses XS for the overloaded stringification. =item Date::Simple::Fmt Uses the perl implemented format() as the default stringification mechanism. The first argument to the constructor is expected to be the format to use for the object. =back B its important to remember that the primary difference between the behaviour of objects of the different classes is how they are stringified when quoted, and what date format is used by default when the format() method is called. Nothing else differs. =head1 CONSTRUCTORS Several functions take a string or numeric representation and generate a corresponding date object. The most general is C, whose argument list may be empty (returning the current date), a string in format YYYY-MM-DD or YYYYMMDD, a list or arrayref of year, month, and day number, or an existing date object. =over 4 =item Date::Simple->new ([ARG, ...]) =item date ([ARG, ...]) my $date = Date::Simple->new('1972-01-17'); The C method will return a date object if the values passed in specify a valid date. (See above.) If an invalid date is passed, the method returns undef. If the argument is invalid in form as opposed to numeric range, C dies. The C function provides the same functionality but must be imported or qualified as C. (To import all public functions, do C.) This function returns undef on all invalid input, rather than dying in some cases like C. =item date_fmt (FMT,[ARG, ...]) Equivelent to C but creates a Date::Simple::Fmt object instead. The format is expected to be a valid POSIX::strftime format string. =item date_iso ([ARG, ...]) Identical to C but creates a Date::Simple::ISO object instead. =item date_d8 ([ARG, ...]) Equivelent to C but creates a Date::Simple::D8 object instead. =item today() Returns the current date according to C. B To get tomorrow's date (or any fixed offset from today), do not use C. Perl parses this as C. You need to put empty parentheses after the function: C. =item ymd (YEAR, MONTH, DAY) Returns a date object with the given year, month, and day numbers. If the arguments do not specify a valid date, undef is returned. Example: use Date::Simple ('ymd'); $pbd = ymd(1987, 12, 18); =item d8 (STRING) Parses STRING as "YYYYMMDD" and returns the corresponding date object, or undef if STRING has the wrong format or specifies an invalid date. Example: use Date::Simple ('d8'); $doi = d8('17760704'); Mnemonic: The string matches C. Also, "d8" spells "date", if 8 is expanded phonetically. =back =head1 INSTANCE METHODS =over 4 =item DATE->next my $tomorrow = $today->next; Returns an object representing tomorrow. =item DATE->prev my $yesterday = $today->prev; Returns an object representing yesterday. =item DATE->year my $year = $date->year; Return the year of DATE as an integer. =item DATE->month my $month = $date->month; Return the month of DATE as an integer from 1 to 12. =item DATE->day my $day = $date->day; Return the DATE's day of the month as an integer from 1 to 31. =item DATE->day_of_week Return a number representing DATE's day of the week from 0 to 6, where 0 means Sunday. =item DATE->as_ymd my ($year, $month, $day) = $date->as_ymd; Returns a list of three numbers: year, month, and day. =item DATE->as_d8 Returns the "d8" representation (see C), like C<$date-Eformat("%Y%m%d")>. =item DATE->as_iso Returns the ISO 8601 representation of the date (eg '2004-01-01'), like C<$date-Eformat("%Y-%m-%d")>. This is in fact the default overloaded stringification mechanism and is provided mostly so other subclasses with different overloading can still do fast ISO style date output. =item DATE->as_str ([STRING]) =item DATE->format ([STRING]) =item DATE->strftime ([STRING]) These functions are equivalent. Return a string representing the date, in the format specified. If you don't pass a parameter, the default date format for the object is used if one has been specified, otherwise uses the default date format for the class the object is a member of, or as a last fallback uses the $Date::Simple::Standard_Format which is changeable, but probably shouldn't be modified. See C for details. my $change_date = $date->format("%d %b %y"); my $iso_date1 = $date->format("%Y-%m-%d"); my $iso_date2 = $date->format; The formatting parameter is similar to one you would pass to strftime(3). This is because we actually do pass it to strftime to format the date. This may result in differing behavior across platforms and locales and may not even work everywhere. =item DATE->default_format ([FORMAT]) This method sets or gets the default_format for the DATE object or class that it is called on. =back =head1 OPERATORS Some operators can be used with Date::Simple instances. If one side of an expression is a date object, and the operator expects two date objects, the other side is interpreted as C, so an array reference or ISO 8601 string will work. =over 4 =item DATE + NUMBER =item DATE - NUMBER You can construct a new date offset by a number of days using the C<+> and C<-> operators. =item DATE1 - DATE2 You can subtract two dates to find the number of days between them. =item DATE1 == DATE2 =item DATE1 < DATE2 =item DATE1 <=> DATE2 =item DATE1 cmp DATE2 =item etc. You can compare two dates using the arithmetic or string comparison operators. Equality tests (C<==> and C) return false when one of the expressions can not be converted to a date. Other comparison tests die in such cases. This is intentional, because in a sense, all non-dates are not "equal" to all dates, but in no sense are they "greater" or "less" than dates. =item DATE += NUMBER =item DATE -= NUMBER You can increment or decrement a date by a number of days using the += and -= operators. This actually generates a new date object and is equivalent to C<$date = $date + $number>. =item "$date" You can interpolate a date instance directly into a string, in the format specified by ISO 8601 (eg: 2000-01-17) for Date::Simple and Date::Simple::ISO, for Date::Simple::D8 this is the same as calling as_d8() on the object, and for Date::Simple::Fmt this is the same as calling format() on the object. =back =head1 UTILITIES =over 4 =item leap_year (YEAR) Returns true if YEAR is a leap year. =item days_in_month (YEAR, MONTH) Returns the number of days in MONTH, YEAR. =back =over 4 =item leap_year (YEAR) Returns true if YEAR is a leap year. =item days_in_month (YEAR, MONTH) Returns the number of days in MONTH, YEAR. =back =head1 AUTHOR Marty Pauley John Tobey Yves Orton =head1 COPYRIGHT Copyright (C) 2001 Kasei. Copyright (C) 2001,2002 John Tobey. Copyright (C) 2004 Yves Orton. This program is free software; you can redistribute it and/or modify it under the terms of either: a) the GNU General Public License; either version 2 of the License, or (at your option) any later version. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA b) the Perl Artistic License. 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. =head1 SEE ALSO L L L and of course L =cut Date-Simple-3.03_03/Makefile.PL0000755000076500007650000000231110033236042015744 0ustar igorigor00000000000000use ExtUtils::MakeMaker; $xs = 1; @noxs = (); if (@ARGV && $ARGV[0] eq 'noxs') { shift (@ARGV); print "Disabling XS code.\n"; # Attempt to disable the C code in three ways, since MakeMaker # documentation is unclear. Set 'XS' to an empty hash. Set 'C' # to an empty array. As a last resort, strip Simple.* from # the constants section. # XXX Maybe it would be more robust to simply delete or disguise # Simple.xs. But normally packages don't modify their own files. $xs = 0; @noxs = ('XS' => {}, 'C' => []); } else { print "Enabling XS code.\n"; print "If you get errors, run `make distclean'\n"; print "and try again using `perl Makefile.PL noxs'.\n"; } WriteMakefile( 'NAME' => 'Date::Simple', 'VERSION_FROM' => 'lib/Date/Simple.pm', 'PREREQ_PM' => { 'Test::More' => undef, 'Scalar::Util' => undef, }, @noxs, ); package MY; sub constants { my ($self) = @_; my $ret = $self->SUPER::constants; unless ($::xs) { $ret =~ s/Simple.(pm|pod)/SimpleFoo.$1/g; $ret =~ s/Simple\.\S+//gs; $ret =~ s/SimpleFoo/Simple/g; } return $ret; } Date-Simple-3.03_03/MANIFEST0000755000076500007650000000045010741773354015147 0ustar igorigor00000000000000MANIFEST MANIFEST.SKIP Makefile.PL t/date.t t/bug31037.t t/bug32315.t lib/Date/Simple.pm lib/Date/Simple/Fmt.pm lib/Date/Simple/ISO.pm lib/Date/Simple/D8.pm lib/Date/Simple/NoXS.pm README COPYING Simple.xs ChangeLog META.yml Module meta-data (added by MakeMaker) Date-Simple-3.03_03/MANIFEST.SKIP0000755000076500007650000000003610741240727015705 0ustar igorigor00000000000000\bCVS\b \b.hg\b \b.hgignore\b Date-Simple-3.03_03/META.yml0000644000076500007650000000063310741774043015263 0ustar igorigor00000000000000--- #YAML:1.0 name: Date-Simple version: 3.03_03 abstract: ~ license: ~ author: ~ generated_by: ExtUtils::MakeMaker version 6.42 distribution_type: module requires: Scalar::Util: Test::More: meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.3.html version: 1.3 Date-Simple-3.03_03/README0000755000076500007650000002255507574270031014702 0ustar igorigor00000000000000NAME Date::Simple - a simple date object SYNOPSIS use Date::Simple ('date', 'today'); # Difference in days between two dates: $diff = date('2001-08-27') - date('1977-10-05'); # Offset $n days from now: $date = today() + $n; print "$date\n"; # uses ISO 8601 format (YYYY-MM-DD) use Date::Simple (); my $date = Date::Simple->new('1972-01-17'); my $year = $date->year; my $month = $date->month; my $day = $date->day; use Date::Simple (':all'); my $date2 = ymd($year, $month, $day); my $date3 = d8('19871218'); my $today = today(); my $tomorrow = $today + 1; if ($tomorrow->year != $today->year) { print "Today is New Year's Eve!\n"; } if ($today > $tomorrow) { die "warp in space-time continuum"; } print "Today is "; print(('Sun','Mon','Tues','Wednes','Thurs','Fri','Satur') [$today->day_of_week]); print "day.\n"; # you can also do this: ($date cmp "2001-07-01") # and this ($date <=> [2001, 7, 1]) INSTALLATION If your system has the "make" program or a clone: perl Makefile.PL make make test make install If you lack "make", copy the "lib/Date" directory to your module directory (run "perl -V:sitelib" to find it). If "make test" fails, perhaps it means your system can't compile C code. Try: make distclean perl Makefile.PL noxs make make test make install This will use the pure-Perl implementation. DESCRIPTION Dates are complex enough without times and timezones. This module may be used to create simple date objects. It handles: Validation. Reject 1999-02-29 but accept 2000-02-29. Interval arithmetic. How many days were between two given dates? What date comes N days after today? Day-of-week calculation. What day of the week is a given date? It does not deal with hours, minutes, seconds, and time zones. A date is uniquely identified by year, month, and day integers within valid ranges. This module will not allow the creation of objects for invalid dates. Attempting to create an invalid date will return undef. Month numbering starts at 1 for January, unlike in C and Java. Years are 4-digit. Gregorian dates up to year 9999 are handled correctly, but we rely on Perl's builtin "localtime" function when the current date is requested. On some platforms, "localtime" may be vulnerable to rollovers such as the Unix "time_t" wraparound of 18 January 2038. Overloading is used so you can compare or subtract two dates using standard numeric operators such as "==", and the sum of a date object and an integer is another date object. Date::Simple objects are immutable. After assigning "$date1" to "$date2", no change to "$date1" can affect "$date2". This means, for example, that there is nothing like a "set_year" operation, and "$date++" assigns a new object to "$date". This module contains various undocumented functions. They may not be available on all platforms and are likely to change or disappear in future releases. Please let the author know if you think any of them should be public. CONSTRUCTORS Several functions take a string or numeric representation and generate a corresponding date object. The most general is "new", whose argument list may be empty (returning the current date), a string in format YYYY-MM-DD or YYYYMMDD, a list or arrayref of year, month, and day number, or an existing date object. Date::Simple->new ([ARG, ...]) date ([ARG, ...]) my $date = Date::Simple->new('1972-01-17'); The "new" method will return a date object if the values passed in specify a valid date. (See above.) If an invalid date is passed, the method returns undef. If the argument is invalid in form as opposed to numeric range, "new" dies. The "date" function provides the same functionality but must be imported or qualified as "Date::Simple::date". (To import all public functions, do "use Date::Simple (':all');".) This function returns undef on all invalid input, rather than dying in some cases like "new". today() Returns the current date according to "localtime". Caution: To get tomorrow's date (or any fixed offset from today), do not use "today + 1". Perl parses this as "today(+1)". You need to put empty parentheses after the function: "today() + 1". ymd (YEAR, MONTH, DAY) Returns a date object with the given year, month, and day numbers. If the arguments do not specify a valid date, undef is returned. Example: use Date::Simple ('ymd'); $pbd = ymd(1987, 12, 18); d8 (STRING) Parses STRING as "YYYYMMDD" and returns the corresponding date object, or undef if STRING has the wrong format or specifies an invalid date. Example: use Date::Simple ('d8'); $doi = d8('17760704'); Mnemonic: The string matches "/\d{8}/". Also, "d8" spells "date", if 8 is expanded phonetically. INSTANCE METHODS DATE->next my $tomorrow = $today->next; Returns an object representing tomorrow. DATE->prev my $yesterday = $today->prev; Returns an object representing yesterday. DATE->year my $year = $date->year; Return the year of DATE as an integer. DATE->month my $month = $date->month; Return the month of DATE as an integer from 1 to 12. DATE->day my $day = $date->day; Return the DATE's day of the month as an integer from 1 to 31. DATE->day_of_week Return a number representing DATE's day of the week from 0 to 6, where 0 means Sunday. DATE->as_ymd my ($year, $month, $day) = $date->as_ymd; Returns a list of three numbers: year, month, and day. DATE->as_d8 Returns the "d8" representation (see "d8"), like "$date->format("%Y%m%d")". DATE->format (STRING) DATE->strftime (STRING) These functions are equivalent. Return a string representing the date, in the format specified. If you don't pass a parameter, an ISO 8601 formatted date is returned. my $change_date = $date->format("%d %b %y"); my $iso_date1 = $date->format("%Y-%m-%d"); my $iso_date2 = $date->format; The formatting parameter is similar to one you would pass to strftime(3). This is because we actually do pass it to strftime to format the date. This may result in differing behavior across platforms and locales and may not even work everywhere. OPERATORS Some operators can be used with Date::Simple instances. If one side of an expression is a date object, and the operator expects two date objects, the other side is interpreted as "date(ARG)", so an array reference or ISO 8601 string will work. DATE + NUMBER DATE - NUMBER You can construct a new date offset by a number of days using the "+" and "-" operators. DATE1 - DATE2 You can subtract two dates to find the number of days between them. DATE1 == DATE2 DATE1 < DATE2 DATE1 <=> DATE2 DATE1 cmp DATE2 etc. You can compare two dates using the arithmetic or string comparison operators. Equality tests ("==" and "eq") return false when one of the expressions can not be converted to a date. Other comparison tests die in such cases. This is intentional, because in a sense, all non-dates are not "equal" to all dates, but in no sense are they "greater" or "less" than dates. DATE += NUMBER DATE -= NUMBER You can increment or decrement a date by a number of days using the += and -= operators. This actually generates a new date object and is equivalent to "$date = $date + $number". "$date" You can interpolate a date instance directly into a string, in the format specified by ISO 8601 (eg: 2000-01-17). UTILITIES leap_year (YEAR) Returns true if YEAR is a leap year. days_in_month (YEAR, MONTH) Returns the number of days in MONTH, YEAR. AUTHOR Marty Pauley John Tobey COPYRIGHT Copyright (C) 2001 Kasei Copyright (C) 2001,2002 John Tobey. This program is free software; you can redistribute it and/or modify it under the terms of either: a) the GNU General Public License; either version 2 of the License, or (at your option) any later version. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA b) the Perl Artistic License. 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. Date-Simple-3.03_03/Simple.xs0000755000076500007650000002163610741374713015630 0ustar igorigor00000000000000#define PERL_POLLUTE #include #include #include static UV dim[14] = { 31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28 }; static IV tweak[12] = { 1, 2, 4, 5, 7, 8, 9, 11, 12, 14, 15, 16 }; static IV cum_days[12] = { -1, 30, 58, 89, 119, 150, 180, 211, 242, 272, 303, 333 }; static bool is_leap_year (IV y) { return (y % 4 == 0) && ((y % 100 != 0) || (y % 400 == 0)); } static IV days_in_month (IV month, IV year) { IV ret = dim [ month - 1 ]; if (ret == 0) ret = is_leap_year (year) ? 29 : 28; return ret; } /* Compute the number of days since 1970. */ static bool ymd_to_days (IV y, IV m, IV d, IV* days) { IV x; IV nonleap_days; IV leap_days_4; IV leap_holes_100; IV leap_days_400; if (m < 1 || m > 12 || d < 1 || (d > 28 && d > days_in_month (m, y))) return FALSE; x = (m <= 2 ? y - 1 : y); nonleap_days = d + cum_days [m - 1] + 365 * (y - 1970); leap_days_4 = (x - 1968) >> 2; if (x >= 1900) leap_holes_100 = (x - 1900) / 100; else leap_holes_100 = - (1999 - x) / 100; if (x >= 1600) leap_days_400 = (x - 1600) / 400; else leap_days_400 = - (1999 - x) / 400; *days = nonleap_days + leap_days_4 - leap_holes_100 + leap_days_400; return TRUE; } /* Compute year, month, and day given days_since_1970. */ static void days_to_ymd (IV days, IV ymd[3]) { IV year; IV month, day, quot; /* Shift frame of reference from 1 Jan 1970 to (the imaginary) 1 Mar 0AD. */ days += 719468; /* Do the math. */ quot = days / 146097; days -= 146097 * quot; year = 400 * quot; if (days == 146096) { /* Handle 29 Feb 2000, 2400, ... */ year += 400; month = 2; day = 29; } else { quot = days / 36524; days -= 36524 * quot; year += 100 * quot; quot = days / 1461; days -= 1461 * quot; year += 4 * quot; if (days == 1460) { year += 4; month = 2; day = 29; } else { quot = days / 365; days -= 365 * quot; year += quot; quot = days / 32; days -= 32 * quot; month = quot; day = days + tweak [month]; days = dim [month + 2]; if (day > days) { day -= days; month += 1; } if (month > 9) { month -= 9; year += 1; } else month += 3; } } ymd[0] = year; ymd[1] = month; ymd[2] = day; } static bool d8_to_days (SV* d8, IV* days) { char buf[5]; STRLEN len; char* p; p = SvPV(d8, len); if (len == 8) { while (len > 0) { if (!isDIGIT(p[len - 1])) break; len--; } if (len != 0) return FALSE; } else return FALSE; return ymd_to_days(10*(10*(10*(p[0]-'0')+p[1]-'0')+p[2]-'0')+p[3]-'0', 10*(p[4]-'0')+p[5]-'0', 10*(p[6]-'0')+p[7]-'0', days); } static SV* days_to_date (IV days, SV* pkg) { char* pack=0; if (SvROK (pkg)) { HV* stash; stash=SvSTASH(SvRV(pkg)); return sv_bless( newRV_noinc (newSViv (days)), stash ); } else if (SvTRUE(pkg)) { pack=SvPV_nolen(pkg); } return sv_bless( newRV_noinc (newSViv (days)), gv_stashpv (pack == 0 ? "Date::Simple" : pack, 1)); } static int is_object (SV* sv) { return (SvROK (sv) && SvTYPE (SvRV (sv)) == SVt_PVMG); } static SV* new_for_cmp (SV* left, SV* right, int croak_on_fail) { dSP; SV* ret; /* Comparing date with non-date. Try to convert the right side to a date. */ EXTEND (sp, 2); PUSHMARK(sp); PUSHs (left); PUSHs (right); PUTBACK; perl_call_method (croak_on_fail ? "new" : "_new", G_SCALAR); SPAGAIN; ret = POPs; if (croak_on_fail && ! is_object (ret)) { PUSHMARK(sp); PUSHs (left); PUSHs (right); PUTBACK; perl_call_pv ("Date::Simple::_inval", G_VOID); SPAGAIN; } return ret; } MODULE = Date::Simple PACKAGE = Date::Simple SV* _ymd(obj_or_class, y, m, d) SV* obj_or_class IV y IV m IV d CODE: { IV days; if (ymd_to_days (y, m, d, &days)) RETVAL = days_to_date (days, obj_or_class); else XSRETURN_UNDEF; } OUTPUT: RETVAL SV* _d8(obj_or_class, d8) SV* obj_or_class SV* d8 CODE: { IV days; if (d8_to_days (d8, &days)) RETVAL = days_to_date (days, obj_or_class); else XSRETURN_UNDEF; } OUTPUT: RETVAL bool leap_year(y) IV y CODE: { RETVAL = is_leap_year (y); } OUTPUT: RETVAL IV days_in_month(y, m) IV y IV m CODE: { if (m < 1 || m > 12) croak ("days_in_month: month out of range (%d)", (int) m); RETVAL = days_in_month (m, y); } OUTPUT: RETVAL IV validate(ysv, m, d) SV* ysv IV m IV d CODE: { IV y; y = SvIV (ysv); if ((IV) SvNV (ysv) != y) RETVAL = 0; else if (m < 1 || m > 12) RETVAL = 0; else if (d < 1 || d > days_in_month (m, y)) RETVAL = 0; else RETVAL = 1; } OUTPUT: RETVAL void ymd_to_days(y, m, d) IV y IV m IV d CODE: { IV days; if (! ymd_to_days (y, m, d, &days)) XSRETURN_UNDEF; else XSRETURN_IV (days); } SV* days_since_1970(date) SV* date CODE: { if (SvROK(date)) RETVAL = SvREFCNT_inc (SvRV(date)); else XSRETURN_UNDEF; } OUTPUT: RETVAL void days_to_ymd(days) IV days PPCODE: { IV ymd[3]; days_to_ymd (days, ymd); EXTEND (sp, 3); PUSHs (sv_2mortal (newSViv (ymd[0]))); PUSHs (sv_2mortal (newSViv (ymd[1]))); PUSHs (sv_2mortal (newSViv (ymd[2]))); } IV year(date) SV* date CODE: { IV ymd[3]; if (! SvROK (date)) XSRETURN_UNDEF; days_to_ymd (SvIV (SvRV (date)), ymd); RETVAL = ymd[0]; } OUTPUT: RETVAL IV month(date) SV* date CODE: { IV ymd[3]; if (! SvROK (date)) XSRETURN_UNDEF; days_to_ymd (SvIV (SvRV (date)), ymd); RETVAL = ymd[1]; } OUTPUT: RETVAL IV day(date) SV* date CODE: { IV ymd[3]; if (! SvROK (date)) XSRETURN_UNDEF; days_to_ymd (SvIV (SvRV (date)), ymd); RETVAL = ymd[2]; } OUTPUT: RETVAL SV* as_iso(date, ...) SV* date CODE: { IV ymd[3]; if (! SvROK (date)) XSRETURN_UNDEF; days_to_ymd (SvIV (SvRV (date)), ymd); RETVAL = newSVpvf ("%04d-%02d-%02d", (int) ymd[0] % 10000, (int) ymd[1], (int) ymd[2]); } OUTPUT: RETVAL SV* as_d8(date, ...) SV* date CODE: { IV ymd[3]; if (! SvROK (date)) XSRETURN_UNDEF; days_to_ymd (SvIV (SvRV (date)), ymd); RETVAL = newSVpvf ("%04d%02d%02d", (int)ymd[0] % 10000, (int) ymd[1], (int) ymd[2]); } OUTPUT: RETVAL void as_ymd(date) SV* date PPCODE: { IV ymd[3]; if (! SvROK (date)) XSRETURN_EMPTY; days_to_ymd (SvIV (SvRV (date)), ymd); EXTEND (sp, 3); PUSHs (sv_2mortal (newSViv (ymd[0]))); PUSHs (sv_2mortal (newSViv (ymd[1]))); PUSHs (sv_2mortal (newSViv (ymd[2]))); } SV* _add(date, diff, ...) SV* date IV diff CODE: { dSP; SV* new_date; SV* format; IV days; if (! is_object (date)) XSRETURN_UNDEF; days = SvIV (SvRV (date)) + diff; new_date = sv_bless(newRV_noinc(newSViv(days)), SvSTASH(SvRV(date))); PUSHMARK(SP); XPUSHs(date); PUTBACK; call_method("default_format", G_SCALAR); SPAGAIN; format = POPs; PUSHMARK(SP); XPUSHs(new_date); XPUSHs(format); PUTBACK; call_method("default_format", G_DISCARD); RETVAL = new_date; } OUTPUT: RETVAL SV* _subtract(left, right, reverse) SV* left SV* right SV* reverse CODE: { if (! is_object (left)) XSRETURN_UNDEF; if (SvTRUE (reverse)) croak ("Can't subtract a date from a non-date"); if (SvROK (right)) { IV diff = SvIV (SvRV (left)) - SvIV (SvRV (right)); RETVAL = newSViv (diff); } else { IV days = SvIV (SvRV (left)) - SvIV (right); SV* new_date = sv_bless (newRV_noinc (newSViv (days)), SvSTASH (SvRV (left))); SV* format; dSP; PUSHMARK(SP); XPUSHs(left); PUTBACK; call_method("default_format", G_SCALAR); SPAGAIN; format = POPs; PUSHMARK(SP); XPUSHs(new_date); XPUSHs(format); PUTBACK; call_method("default_format", G_DISCARD); RETVAL = new_date; } } OUTPUT: RETVAL IV _compare(left, right, reverse) SV* left SV* right bool reverse CODE: { IV diff; if (! is_object (left)) XSRETURN_UNDEF; if (! is_object (right)) right = new_for_cmp (left, right, 1); diff = SvIV (SvRV (left)) - SvIV (SvRV (right)); RETVAL = diff > 0 ? 1 : (diff < 0 ? -1 : 0); if (reverse) RETVAL = -RETVAL; } OUTPUT: RETVAL SV* _eq(left, right, reverse) SV* left SV* right bool reverse CODE: { if (! is_object (left)) XSRETURN_UNDEF; if (! is_object (right)) right = new_for_cmp (left, right, 0); if (! is_object (right)) XSRETURN_NO; if (SvIV (SvRV (left)) == SvIV (SvRV (right))) XSRETURN_YES; else XSRETURN_NO; } OUTPUT: RETVAL SV* _ne(left, right, reverse) SV* left SV* right bool reverse CODE: { if (! is_object (left)) XSRETURN_UNDEF; if (! is_object (right)) right = new_for_cmp (left, right, 0); if (! is_object (right)) XSRETURN_YES; if (SvIV (SvRV (left)) == SvIV (SvRV (right))) XSRETURN_NO; else XSRETURN_YES; } OUTPUT: RETVAL IV day_of_week(date) SV* date CODE: { IV days; if (! SvROK (date)) XSRETURN_UNDEF; RETVAL = (SvIV (SvRV (date)) + 4) % 7; if (RETVAL < 0) RETVAL += 7; } OUTPUT: RETVAL Date-Simple-3.03_03/t/0000755000076500007650000000000010741774042014252 5ustar igorigor00000000000000Date-Simple-3.03_03/t/bug31037.t0000644000076500007650000000043310741355511015606 0ustar igorigor00000000000000use strict; use warnings; use Test::More; plan tests => 3; use Date::Simple; my $date = Date::Simple->new("2007-11-05"); $date->default_format("%m.%d.%Y"); is($date->as_str, "11.05.2007"); $date++; is($date->as_str, "11.06.2007"); $date--; is($date->as_str, "11.05.2007"); Date-Simple-3.03_03/t/bug32315.t0000644000076500007650000000070010741772704015612 0ustar igorigor00000000000000use strict; use warnings; use Test::More tests => 3; package Date::Simple::Subclass; use base qw(Date::Simple::ISO); package main; { my $date = Date::Simple::Subclass->today; is( ref $date, 'Date::Simple::Subclass' ); } { my $date = Date::Simple::Subclass->d8('20000101'); is( ref $date, 'Date::Simple::Subclass' ); } { my $date = Date::Simple::Subclass->ymd(2000, 8, 1); is( ref $date, 'Date::Simple::Subclass' ); } Date-Simple-3.03_03/t/date.t0000755000076500007650000002060410741772125015361 0ustar igorigor00000000000000#!/usr/bin/perl -w use strict; use Test::More tests => 227; use Date::Simple; #------------------------------------------------------------------------------ # Check validate method #------------------------------------------------------------------------------ use strict; use warnings; my $d; #1 ok( $d = Date::Simple->new( 2000, 12, 25 ) ); ok( not Date::Simple->new( 2000, 13, 25 ) ); ok( not Date::Simple->new( 2000, 0, 25 ) ); ok( not Date::Simple->new( 2000, 12, 32 ) ); ok( not Date::Simple->new( 2000, 12, 0 ) ); ok( $d = Date::Simple->new( 1996, 02, 29 ) ); ok( not Date::Simple->new( 1900, 02, 29 ) ); #8 ok( $d = Date::Simple->new('2000-12-25') ); ok( not Date::Simple->new('2000-13-25') ); ok( not Date::Simple->new('2000-00-25') ); ok( not Date::Simple->new('2000-12-32') ); ok( not Date::Simple->new('2000-12-00') ); ok( $d = Date::Simple->new('1996-02-29') ); ok( not Date::Simple->new('1900-02-29') ); #------------------------------------------------------------------------------ # Check new method with parameters #------------------------------------------------------------------------------ #15 ok( not Date::Simple->new( 2000, 2, 30 ) ); ok( $d = Date::Simple->new( 2000, 2, 28 ) ); ok( my $d2 = Date::Simple->new('2000-02-28') ); #18 is( $d, $d2 ); is( 2000, $d->year ); is( 2, $d->month ); is( 28, $d->day ); ok( "$d" eq "2000-02-28" ); #------------------------------------------------------------------------------ # Date arithmetic #------------------------------------------------------------------------------ #23 ok( $d += 7 ); is( "$d", "2000-03-06" ); ok( $d -= 14 ); is( "$d", "2000-02-21" ); is( $d cmp "2001-07-01", -1, 'cmp check' ); is( $d <=> [ 2001, 7, 1 ], -1, '<=> check' ); ok( $d2 = $d + 7 ); is( "$d2", "2000-02-28" ); #31 is( $d2->prev, "2000-02-27" ); is( $d2->next, "2000-02-29" ); is( $d2 - $d, 7 ); is( ( $d + 0 ), $d ); is( ( $d + -3 ), ( $d - 3 ) ); is( ( $d - -3 ), ( $d + 3 ) ); #------------------------------------------------------------------------------ # try again with another date #------------------------------------------------------------------------------ ok( $d = Date::Simple->new('1998-02-28') ); ok( 1998 == $d->year ); ok( 2 == $d->month ); ok( 28 == $d->day ); ok( $d += 7 ); is( "$d", "1998-03-07" ); ok( $d -= 14 ); is( "$d", "1998-02-21" ); ok( $d2 = $d + 7 ); is( "$d2", "1998-02-28" ); is( $d2->prev, "1998-02-27" ); is( $d2->next, "1998-03-01" ); ok( $d = Date::Simple->new('1972-01-17') ); is( $d->year, 1972 ); is( $d->month, 1 ); is( $d->day, 17 ); is( $d->format, '1972-01-17' ); # Don't assume much about how this locale spells 'Jan'. ok( $d->format('%d %b %Y') =~ m/17 \D+ 1972/ ); is( $d->format('Foo'), 'Foo' ); use Date::Simple ( 'date', 'd8' ); $d = Date::Simple->new( 1996, 10, 13 ); ok( $d == Date::Simple->new( [ 1996, 10, 13 ] ) ); ok( $d > date( 1996, 10, 12 ) ); ok( date('1996-10-12') <= $d ); is( Date::Simple->new( 2000, 3, 12 ) - d8(19690219), 11344 ); ok( $d = Date::Simple->new( 2000, 2, 12 ) ); ok( $d = $d + 17 ); is( $d->strftime("%Y %m %d"), "2000 02 29" ); $d += 1; is( $d->as_d8, "20000301", 'as_d8()' ); is( $d - Date::Simple::ymd( 2000, 2, 12 ), 18, 'ymd()' ); is( ( $d - 18 )->format("%Y %m %d"), "2000 02 12" ); is( Date::Simple::ymd( 1966, 10, 15 )->day_of_week, 6 ); is( Date::Simple::ymd( 2401, 3, 1 )->day_of_week, 4 ); is( Date::Simple::ymd( 2401, 2, 28 )->day_of_week, 3 ); is( Date::Simple::ymd( 2400, 3, 1 )->day_of_week, 3 ); is( Date::Simple::ymd( 2400, 2, 29 )->day_of_week, 2 ); is( Date::Simple::ymd( 2400, 2, 28 )->day_of_week, 1 ); is( Date::Simple::ymd( 2101, 3, 1 )->day_of_week, 2 ); is( Date::Simple::ymd( 2101, 2, 28 )->day_of_week, 1 ); is( Date::Simple::ymd( 2100, 3, 1 )->day_of_week, 1 ); is( Date::Simple::ymd( 2100, 2, 28 )->day_of_week, 0 ); is( Date::Simple::ymd( 2001, 3, 1 )->day_of_week, 4 ); is( Date::Simple::ymd( 2001, 2, 28 )->day_of_week, 3 ); is( Date::Simple::ymd( 2000, 3, 1 )->day_of_week, 3 ); is( Date::Simple::ymd( 2000, 2, 29 )->day_of_week, 2 ); is( Date::Simple::ymd( 2000, 2, 28 )->day_of_week, 1 ); is( Date::Simple::ymd( 1901, 3, 1 )->day_of_week, 5 ); is( Date::Simple::ymd( 1901, 2, 28 )->day_of_week, 4 ); is( Date::Simple::ymd( 1900, 3, 1 )->day_of_week, 4 ); is( Date::Simple::ymd( 1900, 2, 28 )->day_of_week, 3 ); is( Date::Simple::ymd( 1801, 3, 1 )->day_of_week, 0 ); is( Date::Simple::ymd( 1801, 2, 28 )->day_of_week, 6 ); is( Date::Simple::ymd( 1800, 3, 1 )->day_of_week, 6 ); is( Date::Simple::ymd( 1800, 2, 28 )->day_of_week, 5 ); is( Date::Simple::ymd( 1701, 3, 1 )->day_of_week, 2 ); is( Date::Simple::ymd( 1701, 2, 28 )->day_of_week, 1 ); is( Date::Simple::ymd( 1700, 3, 1 )->day_of_week, 1 ); is( Date::Simple::ymd( 1700, 2, 28 )->day_of_week, 0 ); is( Date::Simple::ymd( 1601, 3, 1 )->day_of_week, 4 ); is( Date::Simple::ymd( 1601, 2, 28 )->day_of_week, 3 ); is( Date::Simple::ymd( 1600, 3, 1 )->day_of_week, 3 ); is( Date::Simple::ymd( 1600, 2, 29 )->day_of_week, 2 ); is( Date::Simple::ymd( 1600, 2, 28 )->day_of_week, 1, 'lala' ); foreach ( [ 1969, 2, 19, 1 ], [ 1975, 6, 14, 1 ], [ 1999, 0, 1, 0 ], [ 1999, 1, 1, 1 ], [ 1999, 2, 28, 1 ], [ 1999, 2, 29, 0 ], [ 1999, 4, 31, 0 ], [ 1999, 4, 30, 1 ], [ 1999, 8, 1, 1 ], [ 1999, 8, 31, 1 ], # produced '1999 09 00' due to buggy POSIX.xs # in perl 5.005_63 and 5.5.560. [ 1999, 8, 32, 0 ], [ 1999, 12, 31, 1 ], [ 1999, 13, 1, 0 ], [ 2000, 1, 1, 1 ], [ 2000, 2, 12, 1 ], [ 2000, 2, 28, 1 ], [ 2000, 2, 29, 1 ], [ 2000, 3, 1, 1 ], [ 2001, 2, 29, 0 ], [ 2004, 2, 29, 1 ], [ 2100, 2, 29, 0 ], ) { $d = Date::Simple->new( @$_[ 0, 1, 2 ] ); is( ( $d ? 1 : 0 ), $$_[3] ); if ( $$_[3] ) { is( $d->year, $$_[0] ); is( $d->month, $$_[1] ); is( $d->day, $$_[2] ); is( $d->strftime("%Y %m %d"), sprintf( "%04d %02d %02d", @$_[ 0, 1, 2 ] ) ); is( join( ' ', $d->as_ymd ), join( ' ', Date::Simple::days_to_ymd( Date::Simple::ymd_to_days( @$_[ 0, 1, 2 ] ) ) ) ); } } ok( Date::Simple::today() , 'lala'); is( Date::Simple::days_in_month( 2001, 10 ), 31 ); ok( d8('20021206') == 20021206); ok( d8('20021206') eq '20021206' ); ok( d8('20021206') eq '2002-12-06' ); ok( d8('20021206') ne 'bla' ); ok( d8('20021206') != 123 ); $d = Date::Simple->new('1972-04-28'); my $d8 = Date::Simple::D8->new('1972-04-28'); my $iso = Date::Simple::ISO->new('1972-04-28'); my $fmt = Date::Simple::Fmt->new( '%d-%m-%Y', '1972-04-28' ); isa_ok( $d, 'Date::Simple' ); isa_ok( $d8, 'Date::Simple::D8' ); isa_ok( $iso, 'Date::Simple::ISO' ); isa_ok( $fmt, 'Date::Simple::Fmt' ); is( "$d", '1972-04-28', 'Normal overloaded stringify' ); is( "$d8", '19720428', 'D8 overloaded stringify' ); is( "$iso", '1972-04-28', 'ISO overloaded stringify' ); is( "$fmt", '28-04-1972', 'Fmt overloaded stringify' ); is( $d->as_str, '1972-04-28', 'Normal as_str' ); is( $d8->as_str, '19720428', 'D8 as_str' ); is( $iso->as_str, '1972-04-28', 'ISO as_str' ); is( $fmt->as_str, '28-04-1972', 'Fmt as_str' ); is( $d->as_d8, '19720428', 'Normal as_d8' ); is( $d8->as_d8, '19720428', 'D8 as_d8' ); is( $iso->as_d8, '19720428', 'ISO as_d8' ); is( $fmt->as_d8, '19720428', 'Fmt as_d8' ); is( $d->as_iso, '1972-04-28', 'Normal as_iso' ); is( $d8->as_iso, '1972-04-28', 'D8 as_iso' ); is( $iso->as_iso, '1972-04-28', 'ISO as_iso' ); is( $fmt->as_iso, '1972-04-28', 'Fmt as_iso' ); is( $d->as_str('<%Y><%m><%d>'), '<1972><04><28>', 'Normal as_str(FMT)' ); is( $d8->as_str('<%Y><%m><%d>'), '<1972><04><28>', 'D8 as_str(FMT)' ); is( $iso->as_str('<%Y><%m><%d>'), '<1972><04><28>', 'ISO as_str(FMT)' ); is( $fmt->as_str('<%Y><%m><%d>'), '<1972><04><28>', 'Fmt as_str(FMT)' ); $d = Date::Simple->new(); $d8 = Date::Simple::D8->new(); $iso = Date::Simple::ISO->new(); $fmt = Date::Simple::Fmt->new('%d-%m-%Y'); isa_ok( $d, 'Date::Simple' ); isa_ok( $d8, 'Date::Simple::D8' ); isa_ok( $fmt, 'Date::Simple::Fmt' ); isa_ok( $iso, 'Date::Simple::ISO' ); my ( $Y, $M, $D ) = (localtime)[ 5, 4, 3 ]; $Y += 1900; $M += 1; $_ = sprintf "%02d", $_ for $M, $D; is( "$d", "$Y-$M-$D", 'Normal overloaded stringify' ); is( "$d8", "$Y$M$D", 'D8 overloaded stringify' ); is( "$iso", "$Y-$M-$D", 'ISO overloaded stringify' ); is( "$fmt", "$D-$M-$Y", 'Fmt overloaded stringify' );