DateTime-Format-Epoch-0.13000755000000000000 011435047726 15753 5ustar00unknownunknown000000000000DateTime-Format-Epoch-0.13/Build.PL000444000000000000 144411435047674 17411 0ustar00unknownunknown000000000000use strict; use Module::Build; #created by eumm-migrate.pl my $build = Module::Build->new( 'dist_abstract' => 'Convert dates to seconds since epoch, for arbritrary epochs', 'auto_configure_requires' => 0, 'license' => 'perl', 'dist_author' => 'Eugene van der Pijll (pijll@gmx.net)', 'module_name' => 'DateTime::Format::Epoch', 'requires' => { 'DateTime' => '0.31', 'Math::BigInt' => '1.66', 'Params::Validate' => 0, 'perl' => 5.00503, }, 'build_requires' => { 'Test::More' => 0, }, 'meta_merge' => { 'resources' => { 'repository' => 'http://github.com/chorny/DateTime-Format-Epoch' } }, 'dist_version_from' => 'lib/DateTime/Format/Epoch.pm', create_makefile_pl => 'traditional', ); $build->create_build_script(); DateTime-Format-Epoch-0.13/Changes000444000000000000 432611435047616 17406 0ustar00unknownunknown000000000000Revision history for Perl module DateTime::Format::Epoch 0.13 2010-08-25 - GMP is used in two places, so fix second 0.12 2010-08-23 - Move to Module::Build - Do not use GMP on Windows - Report bigint library used in tests 0.11 2007-12-04 - Tried to make code work with Math::BigInt::* packages (tries to solve bug reported by Philip (Flip) Kromer) 0.10 2006-05-23 - Removed midnight bug, reported by Jason Thaxter. 0.09 2004-10-18 - Worked around Math::BigInt bug on Solaris (hopefully) - For the predefined epoch modules, format_datetime() and parse_datetime() can now be called as class methods. 0.0801 2004-08-31 - Documentation change only 0.08 2004-08-27 - Added DateTime::Format::Epoch::ActiveDirectory. Thanks to Andrew Sterling Hanenkamp for the information. - Added modules for day counts: JD, MJD, RJD, TJD, RataDie, Lillian. Thanks again to Andrew Sterling Hanenkamp for the idea. 0.07 2004-07-28 - Changed ::TAI64, test scripts after a DateTime.pm change concerning leap seconds. +++ ATTENTION +++ If you use an epoch before 1972, and you do not ignore leap seconds, you may see a 1 second difference in the results compared to the output of version 0.06 or earlier. If you use ::TAI64, the epoch has been corrected for this, and timestamps after 1972 are unchanged. If you use ::Unix or any of the other predefined epochs, you're safe; these ignore leap seconds 0.06 2003-11-25 - Added support for other time units - Added DateTime::Format::Epoch::DotNet 0.05 2003-07-18 - Changed API of DT::F::E::TAI64 (the format_datetime_as_string() method is replaced by a parameter to the constructor) - Added dhms parameter to new(), to return '2d, 4h, 15m, 45s' values 0.04 2003-06-19 - Added start_at parameter to new() - Added DateTime::Format::Epoch::TAI64 0.03 2003-05-06 - Removed a bug, which appeared after a DateTime change 0.02 2003-05-05 - First CPAN release version, with too many changes to mention 0.01 2003-04-27 - original version, only released to the sourceforge CVS DateTime-Format-Epoch-0.13/LICENSE000444000000000000 5070011434544356 17137 0ustar00unknownunknown000000000000Terms of Perl 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 General Public License (GPL) Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 675 Mass Ave, Cambridge, MA 02139, 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 --------------------------------------------------------------------------- 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. Aggregation of this Package with a commercial distribution is always permitted provided that the use of this Package is embedded; that is, when no overt attempt is made to make this Package's interfaces visible to the end user of the commercial distribution. Such use shall not be construed as a distribution of this Package. 9. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 10. 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 DateTime-Format-Epoch-0.13/Makefile.PL000444000000000000 115211435047725 20060 0ustar00unknownunknown000000000000# Note: this file was auto-generated by Module::Build::Compat version 0.3603 require 5.005030; use ExtUtils::MakeMaker; WriteMakefile ( 'NAME' => 'DateTime::Format::Epoch', 'VERSION_FROM' => 'lib/DateTime/Format/Epoch.pm', 'PREREQ_PM' => { 'DateTime' => '0.31', 'Math::BigInt' => '1.66', 'Params::Validate' => 0, 'Test::More' => 0 }, 'INSTALLDIRS' => 'site', 'EXE_FILES' => [], 'PL_FILES' => {} ) ; DateTime-Format-Epoch-0.13/MANIFEST000444000000000000 154211434571765 17247 0ustar00unknownunknown000000000000MANIFEST LICENSE README TODO Changes lib/DateTime/Format/Epoch.pm lib/DateTime/Format/Epoch/Unix.pm lib/DateTime/Format/Epoch/MacOS.pm lib/DateTime/Format/Epoch/TAI64.pm lib/DateTime/Format/Epoch/DotNet.pm lib/DateTime/Format/Epoch/ActiveDirectory.pm lib/DateTime/Format/Epoch/JD.pm lib/DateTime/Format/Epoch/MJD.pm lib/DateTime/Format/Epoch/TJD.pm lib/DateTime/Format/Epoch/RJD.pm lib/DateTime/Format/Epoch/RataDie.pm lib/DateTime/Format/Epoch/Lilian.pm t/001_load.t t/002_format.t t/003_bigint.t t/004_nano.t t/005_leap.t t/006_local.t t/007_parse.t t/008_dhms.t t/101_load.t t/102_format.t t/201_load.t t/202_format.t t/301_load.t t/302_format.t t/303_parse.t t/401_load.t t/402_format.t t/502_format.t t/601_load.t t/pod.t META.yml Module meta-data (added by MakeMaker) Build.PL Makefile.PL DateTime-Format-Epoch-0.13/META.yml000444000000000000 335711435047725 17370 0ustar00unknownunknown000000000000--- abstract: 'Convert dates to seconds since epoch, for arbritrary epochs' author: - 'Eugene van der Pijll (pijll@gmx.net)' build_requires: Test::More: 0 generated_by: 'Module::Build version 0.3603' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: DateTime-Format-Epoch provides: DateTime::Format::Epoch: file: lib/DateTime/Format/Epoch.pm version: 0.13 DateTime::Format::Epoch::ActiveDirectory: file: lib/DateTime/Format/Epoch/ActiveDirectory.pm version: 0.13 DateTime::Format::Epoch::DotNet: file: lib/DateTime/Format/Epoch/DotNet.pm version: 0.13 DateTime::Format::Epoch::JD: file: lib/DateTime/Format/Epoch/JD.pm version: 0.13 DateTime::Format::Epoch::Lilian: file: lib/DateTime/Format/Epoch/Lilian.pm version: 0.13 DateTime::Format::Epoch::MJD: file: lib/DateTime/Format/Epoch/MJD.pm version: 0.13 DateTime::Format::Epoch::MacOS: file: lib/DateTime/Format/Epoch/MacOS.pm version: 0.13 DateTime::Format::Epoch::RJD: file: lib/DateTime/Format/Epoch/RJD.pm version: 0.13 DateTime::Format::Epoch::RataDie: file: lib/DateTime/Format/Epoch/RataDie.pm version: 0.13 DateTime::Format::Epoch::TAI64: file: lib/DateTime/Format/Epoch/TAI64.pm version: 0.13 DateTime::Format::Epoch::TJD: file: lib/DateTime/Format/Epoch/TJD.pm version: 0.13 DateTime::Format::Epoch::Unix: file: lib/DateTime/Format/Epoch/Unix.pm version: 0.13 requires: DateTime: 0.31 Math::BigInt: 1.66 Params::Validate: 0 perl: 5.00503 resources: license: http://dev.perl.org/licenses/ repository: http://github.com/chorny/DateTime-Format-Epoch version: 0.13 DateTime-Format-Epoch-0.13/README000444000000000000 53411434544356 16752 0ustar00unknownunknown000000000000DateTime-Format-Epoch ======================= This module implements a conversion from DateTime objects to epoch seconds and back. The epoch can be an arbritrary date, or one of the predefined epochs (UNIX, MacOS, TAI64, etc.). INSTALLATION To install this module type the following: perl Makefile.PL make make test make install DateTime-Format-Epoch-0.13/TODO000444000000000000 24411434544356 16560 0ustar00unknownunknown000000000000* Add more specific epochs (Windows? DOS?) * Accessors for formatter/parser attributes * Adding DT::Duration support for units and much more, undoubtedly DateTime-Format-Epoch-0.13/lib000755000000000000 011435047726 16521 5ustar00unknownunknown000000000000DateTime-Format-Epoch-0.13/lib/DateTime000755000000000000 011435047726 20215 5ustar00unknownunknown000000000000DateTime-Format-Epoch-0.13/lib/DateTime/Format000755000000000000 011435047726 21445 5ustar00unknownunknown000000000000DateTime-Format-Epoch-0.13/lib/DateTime/Format/Epoch.pm000444000000000000 2305511435047521 23214 0ustar00unknownunknown000000000000package DateTime::Format::Epoch; use 5.00503; #qr use strict; use vars qw($VERSION); $VERSION = '0.13'; use DateTime 0.22; use DateTime::LeapSecond; use Math::BigInt ('lib' => $^O eq 'MSWin32' ? 'Pari,FastCalc' : 'GMP,Pari,FastCalc'); use Params::Validate qw/validate BOOLEAN OBJECT/; sub _floor { my $x = shift; my $ix = int $x; if ($ix <= $x) { return $ix; } else { return $ix - 1; } } my %units_per_second = ( seconds => 1, milliseconds => 1000, microseconds => 1e6, nanoseconds => 1e9, ); sub new { my $class = shift; my %p = validate( @_, { epoch => {type => OBJECT, can => 'utc_rd_values'}, unit => {callbacks => {'valid unit' => sub { exists $units_per_second{$_[0]} or $_[0] > 0 }}, default => 'seconds'}, type => {regex => qr/^(?:int|float|bigint)$/, default => 0}, local_epoch => {type => BOOLEAN, default => 0}, dhms => {type => BOOLEAN, default => 0}, skip_leap_seconds => {type => BOOLEAN, default => 1}, start_at => {default => 0}, } ); $p{epoch} = $p{epoch}->clone if $p{epoch}->can('clone'); $p{unit} = $units_per_second{$p{unit}} || $p{unit}; $p{unit} = 1 if $p{dhms}; if (!$p{type}) { $p{type} = ($p{unit} > 1e6 ? 'bigint' : 'int'); } ($p{epoch_rd_days}, $p{epoch_rd_secs}) = $p{epoch}->utc_rd_values; $p{epoch_class} = ref $p{epoch}; if (!$p{skip_leap_seconds}) { $p{leap_secs} = DateTime::LeapSecond::leap_seconds( $p{epoch_rd_days} ); } my $self = bless \%p, $class; return $self; } sub format_datetime { my ($self, $dt) = @_; unless (ref $self) { $self = $self->new; } $dt = $dt->clone->set_time_zone('floating') if $self->{local_epoch} && $self->{epoch}->can('time_zone') && $self->{epoch}->time_zone->is_floating && $dt->can('time_zone') && !$dt->time_zone->is_floating; my ($rd_days, $rd_secs) = $dt->utc_rd_values; my $delta_days = $rd_days - $self->{epoch_rd_days}; my $delta_secs = $rd_secs - $self->{epoch_rd_secs}; my $secs = $delta_days * 86_400 + $delta_secs; if (!$self->{skip_leap_seconds}) { $secs += DateTime::LeapSecond::leap_seconds( $rd_days ) - $self->{leap_secs}; } if ($self->{type} eq 'bigint') { $secs = Math::BigInt->new($secs); } $secs *= $self->{unit}; if ($dt->can('nanosecond')) { my $fraction = $dt->nanosecond / 1e9 * $self->{unit}; if ($self->{type} eq 'float') { $secs += $fraction; } else { $secs += int $fraction; } } $secs += $self->{start_at}; if ($self->{dhms}) { my $mins = int($secs / 60); $secs -= $mins * 60; my $hours = int($mins / 60); $mins -= $hours * 60; my $days = int($hours / 24); $hours -= $days * 24; return $days, $hours, $mins, $secs; } return $secs; } sub parse_datetime { my ($self, $str) = @_; unless (ref $self) { $self = $self->new; } if ($self->{dhms}) { my (undef, $d, $h, $m, $s) = @_; $str = (($d * 24 + $h) * 60 + $m) + $s; } $str -= $self->{start_at}; my $delta_days = _floor( $str / (86_400 * $self->{unit}) ); $str -= $delta_days * 86_400 * $self->{unit}; # $str cannot be negative now, so int() instead of _floor() my $delta_secs = int( $str / $self->{unit} ); $str -= $delta_secs * $self->{unit}; my $delta_nano = $str / $self->{unit} * 1e9; my $rd_days = $self->{epoch_rd_days} + $delta_days; my $rd_secs = $self->{epoch_rd_secs} + $delta_secs; if (!$self->{skip_leap_seconds}) { $rd_secs -= DateTime::LeapSecond::leap_seconds( $rd_days ) - $self->{leap_secs}; if ($rd_secs >= DateTime::LeapSecond::day_length( $rd_days )) { $rd_secs -= DateTime::LeapSecond::day_length( $rd_days ); $rd_days++; } elsif ($rd_secs < 0) { $rd_days--; $rd_secs += DateTime::LeapSecond::day_length( $rd_days ); } } else { if ($rd_secs >= 86400) { $rd_secs -= 86400; $rd_days++; } } $rd_days = $rd_days->numify if UNIVERSAL::isa($rd_days, 'Math::BigInt'); $rd_secs = $rd_secs->numify if UNIVERSAL::isa($rd_secs, 'Math::BigInt'); my $temp_dt = bless { rd_days => $rd_days, rd_secs => $rd_secs}, 'DateTime::Format::Epoch::_DateTime'; my $dt = $self->{epoch_class}->from_object( object => $temp_dt ); if (!$self->{local_epoch}) { $dt->set_time_zone( 'UTC' ) if $dt->can('set_time_zone'); } return $dt; } sub DateTime::Format::Epoch::_DateTime::utc_rd_values { my $self = shift; return $self->{rd_days}, $self->{rd_secs}; } 1; __END__ =head1 NAME DateTime::Format::Epoch - Convert DateTimes to/from epoch seconds =head1 SYNOPSIS use DateTime::Format::Epoch; my $dt = DateTime->new( year => 1970, month => 1, day => 1 ); my $formatter = DateTime::Format::Epoch->new( epoch => $dt, unit => 'seconds', type => 'int', # or 'float', 'bigint' skip_leap_secondss => 1, start_at => 0, local_epoch => undef, ); my $dt2 = $formatter->parse_datetime( 1051488000 ); # 2003-04-28T00:00:00 $formatter->format_datetime($dt2); # 1051488000 =head1 DESCRIPTION This module can convert a DateTime object (or any object that can be converted to a DateTime object) to the number of seconds since a given epoch. It can also do the reverse. =head1 METHODS =over 4 =item * new( ... ) Constructor of the formatter/parser object. It can take the following parameters: "epoch", "unit", "type", "skip_leap_seconds", "start_at", "local_epoch" and "dhms". The epoch parameter is the only required parameter. It should be a DateTime object (or at least, it has to be convertible to a DateTime object). This datetime is the starting point of the day count, and is usually numbered 0. If you want to start at a different value, you can use the start_at parameter. The unit parameter can be "seconds", "milliseconds, "microseconds" or "nanoseconds". The default is "seconds". If you need any other unit, you must specify the number of units per second. If you specify a number of units per second below 1, the unit will be longer than a second. In this way, you can count days: unit => 1/86_400. The type parameter specifies the type of the return value. It can be "int" (returns integer value), "float" (returns floating point value), or "bigint" (returns Math::BigInt value). The default is either "int" (if the unit is "seconds"), or "bigint" (if the unit is nanoseconds). The default behaviour of this module is to skip leap seconds. This is what (most versions of?) UNIX do. If you want to include leap seconds, set skip_leap_seconds to false. Some operating systems use an epoch defined in the local timezone of the computer. If you want to use such an epoch in this module, you have two options. The first is to submit a DateTime object with the appropriate timezone. The second option is to set the local_epoch parameter to a true value. In this case, you should submit an epoch with a floating timezone. The exact epoch used in C will then depend on the timezone of the object you pass to C. Most often, the time since an epoch is given in seconds. In some circumstances however it is expressed as a number of days, hours, minutes and seconds. This is done by NASA, for the so called Mission Elapsed Time. For example, 2/03:45:18 MET means it has been 2 days, 3 hours, 45 minutes, and 18 seconds since liftoff. If you set the dhms parameter to true, format_datetime returns a four element list, containing the number of days, hours, minutes and seconds, and parse_datetime accepts the same four element list. =item * format_datetime($datetime) Given a DateTime object, this method returns the number of seconds since the epoch. =item * parse_datetime($secs) Given a number of seconds, this method returns the corresponding DateTime object. =back =head1 BUGS I think there's a problem when you define a count that does not skip leap seconds, and uses the local timezone. Don't do that. =head1 SUPPORT Support for this module is provided via the datetime@perl.org email list. See http://lists.perl.org/ for more details. =head1 AUTHOR Eugene van der Pijll =head1 COPYRIGHT Copyright (c) 2003-2006 Eugene van der Pijll. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 SEE ALSO L datetime@perl.org mailing list =cut DateTime-Format-Epoch-0.13/lib/DateTime/Format/Epoch000755000000000000 011435047726 22503 5ustar00unknownunknown000000000000DateTime-Format-Epoch-0.13/lib/DateTime/Format/Epoch/ActiveDirectory.pm000444000000000000 506311435047526 26300 0ustar00unknownunknown000000000000package DateTime::Format::Epoch::ActiveDirectory; use strict; use vars qw($VERSION @ISA); $VERSION = '0.13'; use DateTime; use DateTime::Format::Epoch; @ISA = qw/DateTime::Format::Epoch/; my $epoch = DateTime->new( year => 1601, month => 1, day => 1, time_zone => 'floating' ); sub new { my $class = shift; return $class->SUPER::new( epoch => $epoch, unit => 1e7, type => 'bigint', local_epoch => undef, skip_leap_seconds => 1 ); } 1; __END__ =head1 NAME DateTime::Format::Epoch::ActiveDirectory - Active Directory epoch seconds =head1 SYNOPSIS use DateTime::Format::Epoch::ActiveDirectory; my $dt = DateTime::Format::Epoch::ActiveDirectory ->parse_datetime( 1051488000 ); DateTime::Format::Epoch::ActiveDirectory->format_datetime($dt); # 1051488000 my $formatter = DateTime::Format::Epoch::ActiveDirectory->new(); my $dt2 = $formatter->parse_datetime( 1051488000 ); $formatter->format_datetime($dt2); =head1 DESCRIPTION This module can convert a DateTime object (or any object that can be converted to a DateTime object) to the number of seconds since the epoch used in Microsoft Active Directory. Note that this epoch is defined in the I time zone. This means that these two pieces of code will print the same number of seconds, even though they represent two datetimes 6 hours apart: $dt = DateTime->new( year => 2003, month => 5, day => 2, time_zone => 'Europe/Amsterdam' ); print $formatter->format_datetime($dt); $dt = DateTime->new( year => 2003, month => 5, day => 2, time_zone => 'America/Chicago' ); print $formatter->format_datetime($dt); =head1 METHODS Most of the methods are the same as those in L. The only difference is the constructor. =over 4 =item * new() Constructor of the formatter/parser object. It has no parameters. =back =head1 SUPPORT Support for this module is provided via the datetime@perl.org email list. See http://lists.perl.org/ for more details. =head1 AUTHOR Eugene van der Pijll =head1 COPYRIGHT Copyright (c) 2004 Eugene van der Pijll. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 SEE ALSO L datetime@perl.org mailing list =cut DateTime-Format-Epoch-0.13/lib/DateTime/Format/Epoch/DotNet.pm000444000000000000 476011435047534 24377 0ustar00unknownunknown000000000000package DateTime::Format::Epoch::DotNet; use strict; use vars qw($VERSION @ISA); $VERSION = '0.13'; use DateTime; use DateTime::Format::Epoch; @ISA = qw/DateTime::Format::Epoch/; my $epoch = DateTime->new( year => 1, month => 1, day => 1, time_zone => 'floating' ); sub new { my $class = shift; return $class->SUPER::new( epoch => $epoch, unit => 1e7, type => 'bigint', local_epoch => 1, skip_leap_seconds => 1 ); } 1; __END__ =head1 NAME DateTime::Format::Epoch::DotNet - Convert DateTimes to/from .NET epoch seconds =head1 SYNOPSIS use DateTime::Format::Epoch::DotNet; my $dt = DateTime::Format::Epoch::DotNet->parse_datetime( 1051488000 ); DateTime::Format::Epoch::DotNet->format_datetime($dt); # 1051488000 my $formatter = DateTime::Format::Epoch::DotNet->new(); my $dt2 = $formatter->parse_datetime( 1051488000 ); $formatter->format_datetime($dt2); =head1 DESCRIPTION This module can convert a DateTime object (or any object that can be converted to a DateTime object) to the number of seconds since the epoch defined in the .NET Framework SDK. Note that this epoch is defined in the I time zone. This means that these two pieces of code will print the same number of seconds, even though they represent two datetimes 6 hours apart: $dt = DateTime->new( year => 2003, month => 5, day => 2, time_zone => 'Europe/Amsterdam' ); print $formatter->format_datetime($dt); $dt = DateTime->new( year => 2003, month => 5, day => 2, time_zone => 'America/Chicago' ); print $formatter->format_datetime($dt); =head1 METHODS Most of the methods are the same as those in L. The only difference is the constructor. =over 4 =item * new() Constructor of the formatter/parser object. It has no parameters. =back =head1 SUPPORT Support for this module is provided via the datetime@perl.org email list. See http://lists.perl.org/ for more details. =head1 AUTHOR Eugene van der Pijll =head1 COPYRIGHT Copyright (c) 2003 Eugene van der Pijll. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 SEE ALSO L datetime@perl.org mailing list =cut DateTime-Format-Epoch-0.13/lib/DateTime/Format/Epoch/JD.pm000444000000000000 667111435047541 23500 0ustar00unknownunknown000000000000package DateTime::Format::Epoch::JD; use strict; use vars qw($VERSION @ISA); $VERSION = '0.13'; use DateTime; use DateTime::Format::Epoch; @ISA = qw/DateTime::Format::Epoch/; my $epoch = DateTime->new( year => -4713, month => 11, day => 24, hour => 12 ); sub new { my $class = shift; return $class->SUPER::new( epoch => $epoch, unit => 1/86400, type => 'float', skip_leap_seconds => 1 ); } 1; __END__ =head1 NAME DateTime::Format::Epoch::JD - Convert DateTimes to/from Julian Days =head1 SYNOPSIS use DateTime::Format::Epoch::JD; my $dt = DateTime::Format::Epoch::JD->parse_datetime( 2453244.5 ); # 2004-08-27T00:00:00 DateTime::Format::Epoch::JD->format_datetime($dt); # 2453244.5 my $formatter = DateTime::Format::Epoch::JD->new(); my $dt2 = $formatter->parse_datetime( 2453244.5 ); # 2004-08-27T00:00:00 $formatter->format_datetime($dt2); # 2453244.5 =head1 DESCRIPTION This module can convert a DateTime object (or any object that can be converted to a DateTime object) to the Julian Day number. This is the number of days since noon U.T.C. on January 1, 4713 B.C. (Julian calendar). This time scale was originally proposed by John Herschel, and is often used in astronomical calculations. Similar modules are: =over 4 =item * DateTime::Format::Epoch::MJD Implements the "modified Julian Day", starting at midnight U.T.C., November 17, 1858. This number is always 2,400,000.5 lower than the JD, and this count only uses five digits to specify a date between 1859 and about 2130. =item * DateTime::Format::Epoch::RJD Implements the "reduced Julian Day", starting at noon U.T.C., November 16, 1858. This number is always 2,400,000 lower than the JD. =item * DateTime::Format::Epoch::TJD Implements the "truncated Julian Day", starting at midnight U.T.C., May 24, 1968. This number is always 2,440,000,5 lower than the JD. Actually, there is another version of the TJD, defined as JD modulo 10,000. But that one is a bit harder to implement, so you'll have to do with this version of TJD. Or don't use TJD's at all. =item * DateTime::Format::Epoch::RataDie Implements the Rata Die count, starting at January 1, 1 (Gregorian). This count is used by DateTime::Calendar programmers. =item * DateTime::Format::Epoch::Lilian Implements the Lilian count, named after Aloysius Lilian (a 16th century physician) and first used by IBM (a 19th century punched card machine manufacturer). This counts the number of days since the adoption of the Gregorian calendar. Only days are counted, and October 15, 1584 is day 1. =back =head1 METHODS Most of the methods are the same as those in L. The only difference is the constructor. =over 4 =item * new() Constructor of the formatter/parser object. It has no parameters. =back =head1 SUPPORT Support for this module is provided via the datetime@perl.org email list. See http://lists.perl.org/ for more details. =head1 AUTHOR Eugene van der Pijll =head1 COPYRIGHT Copyright (c) 2004 Eugene van der Pijll. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 SEE ALSO L datetime@perl.org mailing list =cut DateTime-Format-Epoch-0.13/lib/DateTime/Format/Epoch/Lilian.pm000444000000000000 366311435047545 24415 0ustar00unknownunknown000000000000package DateTime::Format::Epoch::Lilian; use strict; use vars qw($VERSION @ISA); $VERSION = '0.13'; use DateTime; use DateTime::Format::Epoch; @ISA = qw/DateTime::Format::Epoch/; my $epoch = DateTime->new( year => 1582, month => 10, day => 14 ); sub new { my $class = shift; return $class->SUPER::new( epoch => $epoch, unit => 1/86400, type => 'int', skip_leap_seconds => 1 ); } 1; __END__ =head1 NAME DateTime::Format::Epoch::Lilian - Convert DateTimes to/from Lilian Days =head1 SYNOPSIS use DateTime::Format::Epoch::Lilian; my $dt = DateTime::Format::Epoch::Lilian->parse_datetime( 53244.5 ); # 2004-08-27T00:00:00 DateTime::Format::Epoch::Lilian->format_datetime($dt); # 53244.5 my $formatter = DateTime::Format::Epoch::Lilian->new(); my $dt2 = $formatter->parse_datetime( 53244.5 ); # 2004-08-27T00:00:00 $formatter->format_datetime($dt2); # 53244.5 =head1 DESCRIPTION This module can convert a DateTime object (or any object that can be converted to a DateTime object) to the Modified Julian Day number. See L for a description. =head1 METHODS Most of the methods are the same as those in L. The only difference is the constructor. =over 4 =item * new() Constructor of the formatter/parser object. It has no parameters. =back =head1 SUPPORT Support for this module is provided via the datetime@perl.org email list. See http://lists.perl.org/ for more details. =head1 AUTHOR Eugene van der Pijll =head1 COPYRIGHT Copyright (c) 2004 Eugene van der Pijll. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 SEE ALSO L datetime@perl.org mailing list =cut DateTime-Format-Epoch-0.13/lib/DateTime/Format/Epoch/MacOS.pm000444000000000000 515111435047550 24135 0ustar00unknownunknown000000000000package DateTime::Format::Epoch::MacOS; use strict; use vars qw($VERSION @ISA); $VERSION = '0.13'; use DateTime; use DateTime::Format::Epoch; @ISA = qw/DateTime::Format::Epoch/; my $epoch = DateTime->new( year => 1904, month => 1, day => 1, time_zone => 'floating' ); sub new { my $class = shift; return $class->SUPER::new( epoch => $epoch, unit => 'seconds', type => 'int', local_epoch => 1, skip_leap_seconds => 1 ); } 1; __END__ =head1 NAME DateTime::Format::Epoch::MacOS - Convert DateTimes to/from Mac OS epoch seconds =head1 SYNOPSIS use DateTime::Format::Epoch::MacOS; my $dt = DateTime::Format::Epoch::MacOS->parse_datetime( 1051488000 ); DateTime::Format::Epoch::MacOS->format_datetime($dt); # 1051488000 my $formatter = DateTime::Format::Epoch::MacOS->new(); my $dt2 = $formatter->parse_datetime( 1051488000 ); $formatter->format_datetime($dt2); # 1051488000 =head1 DESCRIPTION This module can convert a DateTime object (or any object that can be converted to a DateTime object) to the number of seconds since the Mac OS epoch. Note that the Mac OS epoch is defined in the I time zone. This means that these two pieces of code will print the same number of seconds, even though they represent two datetimes 6 hours apart: $dt = DateTime->new( year => 2003, month => 5, day => 2, time_zone => 'Europe/Amsterdam' ); print $formatter->format_datetime($dt); $dt = DateTime->new( year => 2003, month => 5, day => 2, time_zone => 'America/Chicago' ); print $formatter->format_datetime($dt); Mac OS X is a Unix system, and uses the Unix epoch (1970-01-01T00:00:00). Use DateTime::Format::Epoch::Unix instead. =head1 METHODS Most of the methods are the same as those in L. The only difference is the constructor. =over 4 =item * new() Constructor of the formatter/parser object. It has no parameters. =back =head1 SUPPORT Support for this module is provided via the datetime@perl.org email list. See http://lists.perl.org/ for more details. =head1 AUTHOR Eugene van der Pijll =head1 COPYRIGHT Copyright (c) 2003 Eugene van der Pijll. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 SEE ALSO L datetime@perl.org mailing list =cut DateTime-Format-Epoch-0.13/lib/DateTime/Format/Epoch/MJD.pm000444000000000000 364411435047556 23620 0ustar00unknownunknown000000000000package DateTime::Format::Epoch::MJD; use strict; use vars qw($VERSION @ISA); $VERSION = '0.13'; use DateTime; use DateTime::Format::Epoch; @ISA = qw/DateTime::Format::Epoch/; my $epoch = DateTime->new( year => 1858, month => 11, day => 17 ); sub new { my $class = shift; return $class->SUPER::new( epoch => $epoch, unit => 1/86400, type => 'float', skip_leap_seconds => 1 ); } 1; __END__ =head1 NAME DateTime::Format::Epoch::MJD - Convert DateTimes to/from Modified Julian Days =head1 SYNOPSIS use DateTime::Format::Epoch::MJD; my $dt = DateTime::Format::Epoch::MJD->parse_datetime( 53244 ); # 2004-08-27T00:00:00 DateTime::Format::Epoch::MJD->format_datetime($dt); # 53244 my $formatter = DateTime::Format::Epoch::MJD->new(); my $dt2 = $formatter->parse_datetime( 53244 ); # 2004-08-27T00:00:00 $formatter->format_datetime($dt2); # 53244 =head1 DESCRIPTION This module can convert a DateTime object (or any object that can be converted to a DateTime object) to the Modified Julian Day number. See L for a description. =head1 METHODS Most of the methods are the same as those in L. The only difference is the constructor. =over 4 =item * new() Constructor of the formatter/parser object. It has no parameters. =back =head1 SUPPORT Support for this module is provided via the datetime@perl.org email list. See http://lists.perl.org/ for more details. =head1 AUTHOR Eugene van der Pijll =head1 COPYRIGHT Copyright (c) 2004 Eugene van der Pijll. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 SEE ALSO L datetime@perl.org mailing list =cut DateTime-Format-Epoch-0.13/lib/DateTime/Format/Epoch/RataDie.pm000444000000000000 354411435047561 24512 0ustar00unknownunknown000000000000package DateTime::Format::Epoch::RataDie; use strict; use vars qw($VERSION @ISA); $VERSION = '0.13'; use DateTime; use DateTime::Format::Epoch; @ISA = qw/DateTime::Format::Epoch/; my $epoch = DateTime->new( year => 0, month => 12, day => 31 ); sub new { my $class = shift; return $class->SUPER::new( epoch => $epoch, unit => 1/86400, type => 'float', skip_leap_seconds => 1 ); } 1; __END__ =head1 NAME DateTime::Format::Epoch::RataDie - Convert DateTimes to/from Rata Die =head1 SYNOPSIS use DateTime::Format::Epoch::RataDie; my $dt = DateTime::Format::Epoch::RataDie->parse_datetime( $count ); DateTime::Format::Epoch::RataDie->format_datetime($dt); # $count my $formatter = DateTime::Format::Epoch::RataDie->new(); my $dt2 = $formatter->parse_datetime( $count ); $formatter->format_datetime($dt2); =head1 DESCRIPTION This module can convert a DateTime object (or any object that can be converted to a DateTime object) to the Rata Die count. See L for a description. =head1 METHODS Most of the methods are the same as those in L. The only difference is the constructor. =over 4 =item * new() Constructor of the formatter/parser object. It has no parameters. =back =head1 SUPPORT Support for this module is provided via the datetime@perl.org email list. See http://lists.perl.org/ for more details. =head1 AUTHOR Eugene van der Pijll =head1 COPYRIGHT Copyright (c) 2004 Eugene van der Pijll. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 SEE ALSO L datetime@perl.org mailing list =cut DateTime-Format-Epoch-0.13/lib/DateTime/Format/Epoch/RJD.pm000444000000000000 372411435047565 23624 0ustar00unknownunknown000000000000package DateTime::Format::Epoch::RJD; use strict; use vars qw($VERSION @ISA); $VERSION = '0.13'; use DateTime; use DateTime::Format::Epoch; @ISA = qw/DateTime::Format::Epoch/; my $epoch = DateTime->new( year => 1858, month => 11, day => 16, hour => 12 ); sub new { my $class = shift; return $class->SUPER::new( epoch => $epoch, unit => 1/86400, type => 'float', skip_leap_seconds => 1 ); } 1; __END__ =head1 NAME DateTime::Format::Epoch::RJD - Convert DateTimes to/from Reduced Julian Days =head1 SYNOPSIS use DateTime::Format::Epoch::RJD; my $dt = DateTime::Format::Epoch::RJD->parse_datetime( 53244.5 ); # 2004-08-27T00:00:00 DateTime::Format::Epoch::RJD->format_datetime($dt); # 53244.5 my $formatter = DateTime::Format::Epoch::RJD->new(); my $dt2 = $formatter->parse_datetime( 53244.5 ); # 2004-08-27T00:00:00 $formatter->format_datetime($dt2); # 53244.5 =head1 DESCRIPTION This module can convert a DateTime object (or any object that can be converted to a DateTime object) to the Reduced Julian Day number. See L for a description. =head1 METHODS Most of the methods are the same as those in L. The only difference is the constructor. =over 4 =item * new() Constructor of the formatter/parser object. It has no parameters. =back =head1 SUPPORT Support for this module is provided via the datetime@perl.org email list. See http://lists.perl.org/ for more details. =head1 AUTHOR Eugene van der Pijll =head1 COPYRIGHT Copyright (c) 2004 Eugene van der Pijll. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 SEE ALSO L datetime@perl.org mailing list =cut DateTime-Format-Epoch-0.13/lib/DateTime/Format/Epoch/TAI64.pm000444000000000000 730711435047572 23773 0ustar00unknownunknown000000000000package DateTime::Format::Epoch::TAI64; use strict; use vars qw($VERSION @ISA); $VERSION = '0.13'; use DateTime; use DateTime::Format::Epoch; use Params::Validate qw/validate/; use Math::BigInt ('lib' => $^O eq 'MSWin32' ? 'Pari,FastCalc' : 'GMP,Pari,FastCalc'); @ISA = qw/DateTime::Format::Epoch/; # Epoch is 1970-01-01 00:00:00 TAI, is 1969-12-31T23:59:50 'utc' my $epoch = DateTime->new( year => 1969, month => 12, day => 31, hour => 23, minute => 59, second => 50 ); my $start = Math::BigInt->new(1) << 62; sub new { my $class = shift; my %p = validate( @_, { format => { regex => qr/^string|number$/, default => 'number' }, }); my $self = $class->SUPER::new( epoch => $epoch, unit => 'seconds', type => 'bigint', skip_leap_seconds => 0, start_at => $start ); $self->{is_string} = ($p{format} eq 'string'); return $self; } sub format_datetime { my ($self, $dt) = @_; my $n = $self->SUPER::format_datetime($dt); if ($self->{is_string}) { my $str = $n->as_hex; my ($hex) = $str =~ /^0x(\w+)$/ or die "Unknown BigInt format '$str'\n"; my $retval = pack "H*", $hex; $n = "0" x (8 - length$retval) . $retval; } return $n; } sub parse_datetime { my ($self, $n) = @_; if ($self->{is_string}) { my $hexstr = '0x' . unpack 'H*', $n; $n = Math::BigInt->new($hexstr); } return $self->SUPER::parse_datetime($n); } 1; __END__ =head1 NAME DateTime::Format::Epoch::TAI64 - Convert DateTimes to/from TAI64 values =head1 SYNOPSIS use DateTime::Format::Epoch::TAI64; my $dt = DateTime::Format::Epoch::TAI64 ->parse_datetime( '4611686019483526367' ); # 2003-06-20T19:49:59 DateTime::Format::Epoch::TAI64->format_datetime($dt); # 4611686019483526367 my $formatter = DateTime::Format::Epoch::TAI64->new(); $dt = $formatter->parse_datetime( '4611686019483526367' ); # 2003-06-20T19:49:59 $formatter->format_datetime($dt); # 4611686019483526367 my $str_frmt = DateTime::Format::Epoch::TAI64->new( format => 'string' ); $dt = $str_frmt->parse_datetime( "\x40\0\0\0\x3e\xf3\x69\x6a" ); # 2003-06-20T19:49:59 $str_frmt->format_datetime($dt); # "\x40\0\0\0\x3e\xf3\x69\x6a" =head1 DESCRIPTION This module can convert a DateTime object (or any object that can be converted to a DateTime object) to a TAI64 value. The TAI64 timescale covers the entire expected lifespan of the universe (at least, if you expect the universe to be closed). =head1 METHODS Most of the methods are the same as those in L. The only difference is the constructor. =over 4 =item * new( [format => 'string'] ) Constructor of the formatter/parser object. If the optional format parameter is set to 'string', TAI64 values will be expected to be 8 byte strings. =back =head1 SUPPORT Support for this module is provided via the datetime@perl.org email list. See http://lists.perl.org/ for more details. =head1 AUTHOR Eugene van der Pijll =head1 COPYRIGHT Copyright (c) 2003, 2004 Eugene van der Pijll. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 SEE ALSO L datetime@perl.org mailing list http://cr.yp.to/time.html =cut DateTime-Format-Epoch-0.13/lib/DateTime/Format/Epoch/TJD.pm000444000000000000 360511435047576 23626 0ustar00unknownunknown000000000000package DateTime::Format::Epoch::TJD; use strict; use vars qw($VERSION @ISA); $VERSION = '0.13'; use DateTime; use DateTime::Format::Epoch; @ISA = qw/DateTime::Format::Epoch/; my $epoch = DateTime->new( year => 1968, month => 5, day => 24 ); sub new { my $class = shift; return $class->SUPER::new( epoch => $epoch, unit => 1/86400, type => 'float', skip_leap_seconds => 1 ); } 1; __END__ =head1 NAME DateTime::Format::Epoch::TJD - Convert DateTimes to/from Truncated Julian Days =head1 SYNOPSIS use DateTime::Format::Epoch::TJD; my $dt = DateTime::Format::Epoch::TJD->parse_datetime( 13244.5 ); # 2004-08-27T00:00:00 DateTime::Format::Epoch::TJD->format_datetime($dt); # 13244.5 my $formatter = DateTime::Format::Epoch::TJD->new(); my $dt2 = $formatter->parse_datetime( 13244.5 ); $formatter->format_datetime($dt2); =head1 DESCRIPTION This module can convert a DateTime object (or any object that can be converted to a DateTime object) to the Truncated Julian Day number. See L for a description. =head1 METHODS Most of the methods are the same as those in L. The only difference is the constructor. =over 4 =item * new() Constructor of the formatter/parser object. It has no parameters. =back =head1 SUPPORT Support for this module is provided via the datetime@perl.org email list. See http://lists.perl.org/ for more details. =head1 AUTHOR Eugene van der Pijll =head1 COPYRIGHT Copyright (c) 2004 Eugene van der Pijll. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 SEE ALSO L datetime@perl.org mailing list =cut DateTime-Format-Epoch-0.13/lib/DateTime/Format/Epoch/Unix.pm000444000000000000 354511435047601 24120 0ustar00unknownunknown000000000000package DateTime::Format::Epoch::Unix; use strict; use vars qw($VERSION @ISA); $VERSION = '0.13'; use DateTime; use DateTime::Format::Epoch; @ISA = qw/DateTime::Format::Epoch/; my $epoch = DateTime->new( year => 1970, month => 1, day => 1 ); sub new { my $class = shift; return $class->SUPER::new( epoch => $epoch, unit => 'seconds', type => 'int', skip_leap_seconds => 1 ); } 1; __END__ =head1 NAME DateTime::Format::Epoch::Unix - Convert DateTimes to/from Unix epoch seconds =head1 SYNOPSIS use DateTime::Format::Epoch::Unix; my $dt = DateTime::Format::Epoch::Unix->parse_datetime( 1051488000 ); # 2003-04-28T00:00:00 DateTime::Format::Epoch::Unix->format_datetime($dt); # 1051488000 my $formatter = DateTime::Format::Epoch::Unix->new(); my $dt2 = $formatter->parse_datetime( 1051488000 ); $formatter->format_datetime($dt2); =head1 DESCRIPTION This module can convert a DateTime object (or any object that can be converted to a DateTime object) to the number of seconds since the Unix epoch. =head1 METHODS Most of the methods are the same as those in L. The only difference is the constructor. =over 4 =item * new() Constructor of the formatter/parser object. It has no parameters. =back =head1 SUPPORT Support for this module is provided via the datetime@perl.org email list. See http://lists.perl.org/ for more details. =head1 AUTHOR Eugene van der Pijll =head1 COPYRIGHT Copyright (c) 2003 Eugene van der Pijll. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 SEE ALSO L datetime@perl.org mailing list =cut DateTime-Format-Epoch-0.13/t000755000000000000 011435047726 16216 5ustar00unknownunknown000000000000DateTime-Format-Epoch-0.13/t/001_load.t000444000000000000 45111434566146 20020 0ustar00unknownunknown000000000000# t/001_load.t - check module loading use Test::More tests => 1; BEGIN { use_ok( 'DateTime::Format::Epoch' ); } diag("==> DateTime version = $DateTime::VERSION"); diag("==> Math::BigInt version = $Math::BigInt::VERSION"); diag("==> Math::BigInt lib = ".Math::BigInt->config()->{lib}); DateTime-Format-Epoch-0.13/t/002_format.t000444000000000000 177411434544356 20422 0ustar00unknownunknown000000000000use strict; BEGIN { $^W = 1 } use Test::More tests => 7; use DateTime; use DateTime::Format::Epoch; my $dt = DateTime->new( year => 1970, month => 1, day => 1 ); my $f = DateTime::Format::Epoch->new( epoch => $dt ); my $f_float = DateTime::Format::Epoch->new( epoch => $dt, type => 'float' ); isa_ok($f, 'DateTime::Format::Epoch' ); is($f->format_datetime($dt), 0, 'Epoch = 0'); $dt->set( hour => 1 ); is($f->format_datetime($dt), 3600, 'Epoch + 1hour'); $dt->set( day => 2, hour => 0 ); is($f->format_datetime($dt), 24*3600, 'Epoch + 1day'); $dt = DateTime->new( year => 2003, month => 4, day => 27, hour => 21, minute => 9, second => 57, nanosecond => 8e8, time_zone => 'Europe/Amsterdam' ); is($f->format_datetime($dt), 1051470597, '"now"'); is($f_float->format_datetime($dt), 1051470597.8, '"now" (float)'); $dt = DateTime->new( year => 1969, month => 12, day => 22 ); is($f->format_datetime($dt), -10*24*3600, 'Epoch - 10days'); DateTime-Format-Epoch-0.13/t/003_bigint.t000444000000000000 167711434544356 20411 0ustar00unknownunknown000000000000use strict; BEGIN { $^W = 1 } use Test::More tests => 7; use DateTime; use DateTime::Format::Epoch; my $dt = DateTime->new( year => 1970, month => 1, day => 1 ); my $f = DateTime::Format::Epoch->new( epoch => $dt, type => 'bigint' ); isa_ok($f, 'DateTime::Format::Epoch' ); is($f->format_datetime($dt) + 0, 0, 'Epoch = 0'); isa_ok($f->format_datetime($dt), 'Math::BigInt'); $dt->set( hour => 1 ); is($f->format_datetime($dt) + 0, 3600, 'Epoch + 1hour'); $dt->set( day => 2, hour => 0 ); is($f->format_datetime($dt) + 0, 24*3600, 'Epoch + 1day'); $dt = DateTime->new( year => 2003, month => 4, day => 27, hour => 21, minute => 9, second => 57, nanosecond => 8e8, time_zone => 'Europe/Amsterdam' ); is($f->format_datetime($dt) + 0, 1051470597, '"now"'); $dt = DateTime->new( year => 1969, month => 12, day => 22 ); is($f->format_datetime($dt), -10*24*3600, 'Epoch - 10days'); DateTime-Format-Epoch-0.13/t/004_nano.t000444000000000000 262011434544356 20056 0ustar00unknownunknown000000000000use strict; BEGIN { $^W = 1 } use Test::More tests => 10; use DateTime; use DateTime::Format::Epoch; my $dt = DateTime->new( year => 1970, month => 1, day => 1 ); my $f = DateTime::Format::Epoch->new( epoch => $dt, unit => 'nanoseconds' ); my $f_m = DateTime::Format::Epoch->new( epoch => $dt, unit => 'milliseconds' ); my $f_mu = DateTime::Format::Epoch->new( epoch => $dt, unit => 'microseconds' ); my $f_d = DateTime::Format::Epoch->new( epoch => $dt, unit => 10 ); isa_ok($f, 'DateTime::Format::Epoch' ); is($f->format_datetime($dt) + 0, 0*1e9, 'Epoch = 0'); isa_ok($f->format_datetime($dt), 'Math::BigInt'); $dt->set( hour => 1 ); is($f->format_datetime($dt) + 0, 3600*1e9, 'Epoch + 1hour'); $dt->set( day => 2, hour => 0 ); is($f->format_datetime($dt) + 0, 24*3600*1e9, 'Epoch + 1day'); $dt = DateTime->new( year => 2003, month => 4, day => 27, hour => 21, minute => 9, second => 57, nanosecond => 8e8, time_zone => 'Europe/Amsterdam' ); like($f->format_datetime($dt), qr/^\+?1051470597800000000/, '"now"'); is($f_m->format_datetime($dt), 1051470597800, '"now" (milli)'); is($f_mu->format_datetime($dt), 1051470597800000, '"now" (micro)'); is($f_d->format_datetime($dt), 10514705978, '"now" (deci)'); $dt = DateTime->new( year => 1969, month => 12, day => 22 ); is($f->format_datetime($dt), -10*24*3600*1e9, 'Epoch - 10days'); DateTime-Format-Epoch-0.13/t/005_leap.t000444000000000000 436511434544356 20055 0ustar00unknownunknown000000000000use strict; BEGIN { $^W = 1 } use Test::More tests => 10; use DateTime; use DateTime::Format::Epoch; my $dt = DateTime->new( year => 1970, month => 1, day => 1 ); my $f_with_leap = DateTime::Format::Epoch->new( epoch => $dt, skip_leap_seconds => 0 ); my $f_skip_leap = DateTime::Format::Epoch->new( epoch => $dt, skip_leap_seconds => 1 ); isa_ok($f_with_leap, 'DateTime::Format::Epoch' ); is($f_with_leap->format_datetime($dt), 0, 'Epoch = 0'); $dt->set( hour => 1 ); is($f_with_leap->format_datetime($dt), 3600, 'Epoch + 1hour'); $dt->set( day => 2, hour => 0 ); is($f_with_leap->format_datetime($dt), 24*3600, 'Epoch + 1day'); $dt = DateTime->new( year => 2003, month => 4, day => 27, hour => 21, minute => 9, second => 57, time_zone => 'Europe/Amsterdam' ); is($f_with_leap->format_datetime($dt) - $f_skip_leap->format_datetime($dt), 22, '22 leap seconds until 2003'); $dt = DateTime->new( year => 1994, month => 6, day => 30, hour => 23, minute => 59 ); my $dt2 = DateTime->new( year => 1994, month => 7, day => 1, hour => 0, minute => 1 ); is($f_with_leap->format_datetime($dt2) - $f_with_leap->format_datetime($dt), 121, '121 secs in 2 minutes'); is($f_skip_leap->format_datetime($dt2) - $f_skip_leap->format_datetime($dt), 120, '120 secs counted in 2 minutes'); $dt2 = DateTime->new( year => 1994, month => 6, day => 30, hour => 23, minute => 59, second => 60, time_zone => 'UTC' ); is($f_with_leap->format_datetime($dt2) - $f_with_leap->format_datetime($dt), 60, 'correct value at leap second'); # (epoch count at leap second is not specified if skip_leap_seconds is # true, so not tested) # epoch is leap second my $f = DateTime::Format::Epoch->new( epoch => $dt2, skip_leap_seconds => 0 ); is($f->format_datetime($dt), -60, 'epoch -60 before leap second'); $dt = DateTime->new( year => 1994, month => 7, day => 1, hour => 0, minute => 1 ); is($f->format_datetime($dt), 61, 'epoch 61 after leap second'); DateTime-Format-Epoch-0.13/t/006_local.t000444000000000000 210011434544356 20210 0ustar00unknownunknown000000000000use strict; BEGIN { $^W = 1 } use Test::More tests => 7; use DateTime; use DateTime::Format::Epoch; my $dt = DateTime->new( year => 1970, month => 1, day => 1 ); my $f = DateTime::Format::Epoch->new( epoch => $dt, local_epoch => 1 ); isa_ok($f, 'DateTime::Format::Epoch' ); is($f->format_datetime($dt), 0, 'Epoch = 0'); $dt->set_time_zone( 'Europe/Amsterdam' ); is($f->format_datetime($dt), 0, 'Epoch (tz) = 0'); $dt->set( hour => 1 ); is($f->format_datetime($dt), 3600, 'Epoch + 1hour'); $dt->set( day => 2, hour => 0 ); is($f->format_datetime($dt), 24*3600, 'Epoch + 1day'); $dt = DateTime->new( year => 2003, month => 4, day => 27, hour => 21, minute => 9, second => 57, nanosecond => 8e8, time_zone => 'Europe/Amsterdam' ); is($f->format_datetime($dt), 1051470597 + 2*3600, '"now"'); $dt = DateTime->new( year => 1969, month => 12, day => 22, time_zone => 'America/Chicago' ); is($f->format_datetime($dt), -10*24*3600, 'Epoch - 10days'); DateTime-Format-Epoch-0.13/t/007_parse.t000444000000000000 134611434544356 20244 0ustar00unknownunknown000000000000use strict; BEGIN { $^W = 1 } use Test::More tests => 3; use DateTime; use DateTime::Format::Epoch; my $dt = DateTime->new( year => 1970, month => 1, day => 1 ); my $f = DateTime::Format::Epoch->new( epoch => $dt ); is($f->parse_datetime(0)->datetime, $dt->datetime, '0 = Epoch'); $dt = DateTime->new( year => 2003, month => 4, day => 27, hour => 21, minute => 9, second => 57, nanosecond => 8e8, time_zone => 'Europe/Amsterdam' ); is($f->parse_datetime(1051470597)->datetime, '2003-04-27T19:09:57', '"now"'); $dt = DateTime->new( year => 1969, month => 12, day => 22 ); is($f->parse_datetime(-10*24*3600)->datetime, '1969-12-22T00:00:00', 'Epoch - 10days'); DateTime-Format-Epoch-0.13/t/008_dhms.t000444000000000000 167011434544356 20066 0ustar00unknownunknown000000000000use strict; BEGIN { $^W = 1 } use Test::More tests => 6; use DateTime; use DateTime::Format::Epoch; my $dt = DateTime->new( year => 1970, month => 1, day => 1 ); my $f = DateTime::Format::Epoch->new( epoch => $dt, dhms => 1, skip_leap_seconds => 0 ); isa_ok($f, 'DateTime::Format::Epoch' ); ok(eq_array([$f->format_datetime($dt)], [0,0,0,0]), 'Epoch = 0/0:0:0'); $dt->set( hour => 1 ); ok(eq_array([$f->format_datetime($dt)], [0,1,0,0]), 'Epoch + 1hour'); $dt->set( day => 2, hour => 0 ); ok(eq_array([$f->format_datetime($dt)], [1,0,0,0]), 'Epoch + 1 day'); $dt = DateTime->new( year => 1973, month => 1, day => 2 ); ok(eq_array([$f->format_datetime($dt)], [365*2+366+1,0,0,2]), 'Leap second counted'); $dt = DateTime->new( year => 1969, month => 12, day => 22, hour => 22 ); ok(eq_array([$f->format_datetime($dt)], [-9, -2, 0, 0]), 'Epoch - 9days 2hours'); DateTime-Format-Epoch-0.13/t/101_load.t000444000000000000 17511434544356 20023 0ustar00unknownunknown000000000000# t/001_load.t - check module loading use Test::More tests => 1; BEGIN { use_ok( 'DateTime::Format::Epoch::Unix' ); } DateTime-Format-Epoch-0.13/t/102_format.t000444000000000000 240311434544356 20411 0ustar00unknownunknown000000000000use strict; BEGIN { $^W = 1 } use Test::More tests => 11; use DateTime; use DateTime::Format::Epoch::Unix; my $f = DateTime::Format::Epoch::Unix->new(); isa_ok($f, 'DateTime::Format::Epoch::Unix' ); my $dt = DateTime->new( year => 1970, month => 1, day => 1 ); is($f->format_datetime($dt), 0, 'Epoch = 0'); is(DateTime::Format::Epoch::Unix->format_datetime($dt), 0, 'Epoch = 0'); $dt->set( hour => 1 ); is($f->format_datetime($dt), 3600, 'Epoch + 1hour'); is(DateTime::Format::Epoch::Unix->format_datetime($dt), 3600, 'Epoch + 1hour'); $dt->set( day => 2, hour => 0 ); is($f->format_datetime($dt), 24*3600, 'Epoch + 1day'); is(DateTime::Format::Epoch::Unix->format_datetime($dt), 24*3600, 'Epoch + 1day'); $dt = DateTime->new( year => 2003, month => 4, day => 27, hour => 21, minute => 9, second => 57, nanosecond => 8e8, time_zone => 'Europe/Amsterdam' ); is($f->format_datetime($dt), 1051470597, '"now"'); is(DateTime::Format::Epoch::Unix->format_datetime($dt), 1051470597, '"now"'); $dt = DateTime->new( year => 1969, month => 12, day => 22 ); is($f->format_datetime($dt), -10*24*3600, 'Epoch - 10days'); is(DateTime::Format::Epoch::Unix->format_datetime($dt), -10*24*3600, 'Epoch - 10days'); DateTime-Format-Epoch-0.13/t/201_load.t000444000000000000 17611434544356 20025 0ustar00unknownunknown000000000000# t/001_load.t - check module loading use Test::More tests => 1; BEGIN { use_ok( 'DateTime::Format::Epoch::MacOS' ); } DateTime-Format-Epoch-0.13/t/202_format.t000444000000000000 205311434544356 20413 0ustar00unknownunknown000000000000use strict; BEGIN { $^W = 1 } use Test::More tests => 19; use DateTime; use DateTime::Format::Epoch::MacOS; my $f = DateTime::Format::Epoch::MacOS->new(); isa_ok($f, 'DateTime::Format::Epoch::MacOS' ); my $dt = DateTime->new( year => 1904, month => 1, day => 1 ); is($f->format_datetime($dt), 0, 'Epoch = 0'); is(DateTime::Format::Epoch::MacOS->format_datetime($dt), 0, 'Epoch = 0'); $dt->set( hour => 1 ); is($f->format_datetime($dt), 3600, 'Epoch + 1hour'); is(DateTime::Format::Epoch::MacOS->format_datetime($dt), 3600, 'Epoch + 1hour'); $dt->set( day => 2, hour => 0 ); is($f->format_datetime($dt), 24*3600, 'Epoch + 1day'); is(DateTime::Format::Epoch::MacOS->format_datetime($dt), 24*3600, 'Epoch + 1day'); for my $tz (qw[ UTC floating America/Chicago Europe/Amsterdam Australia/Melbourne +1200 ]) { $dt = DateTime->new( year => 2003, month => 7, day => 1 ); is($f->format_datetime($dt), 3139862400, "tz: $tz"); is(DateTime::Format::Epoch::MacOS->format_datetime($dt), 3139862400, "tz: $tz"); } DateTime-Format-Epoch-0.13/t/301_load.t000444000000000000 17611434544356 20026 0ustar00unknownunknown000000000000# t/301_load.t - check module loading use Test::More tests => 1; BEGIN { use_ok( 'DateTime::Format::Epoch::TAI64' ); } DateTime-Format-Epoch-0.13/t/302_format.t000444000000000000 105311434544356 20413 0ustar00unknownunknown000000000000use strict; BEGIN { $^W = 1 } use Test::More tests => 2; use DateTime; use DateTime::Format::Epoch::TAI64; my $f = DateTime::Format::Epoch::TAI64->new( format => 'string' ); isa_ok($f, 'DateTime::Format::Epoch::TAI64' ); # example from http://cr.yp.to/proto/tai64.txt my $dt = DateTime->new( year => 1997, month => 10, day => 3, hour => 18, minute => 14, second => 48, time_zone => 'UTC' ); is(unpack("H*", $f->format_datetime($dt)), "4000000034353637", '1997-10-3 as string'); DateTime-Format-Epoch-0.13/t/303_parse.t000444000000000000 61711434544356 20223 0ustar00unknownunknown000000000000use strict; BEGIN { $^W = 1 } use Test::More tests => 2; use DateTime; use DateTime::Format::Epoch::TAI64; my $f = DateTime::Format::Epoch::TAI64->new( format => 'string' ); isa_ok($f, 'DateTime::Format::Epoch::TAI64' ); # example from http://cr.yp.to/proto/tai64.txt is($f->parse_datetime("\x40\0\0\0\x34\x35\x36\x37")->datetime, '1997-10-03T18:14:48', '1997-10-3 as string'); DateTime-Format-Epoch-0.13/t/401_load.t000444000000000000 17711434544356 20030 0ustar00unknownunknown000000000000# t/001_load.t - check module loading use Test::More tests => 1; BEGIN { use_ok( 'DateTime::Format::Epoch::DotNet' ); } DateTime-Format-Epoch-0.13/t/402_format.t000444000000000000 174611434566417 20427 0ustar00unknownunknown000000000000use strict; BEGIN { $^W = 1 } use Test::More tests => 9; use DateTime; use DateTime::Format::Epoch::DotNet; my $f = DateTime::Format::Epoch::DotNet->new(); isa_ok($f, 'DateTime::Format::Epoch::DotNet' ); my $dt = DateTime->new( year => 1, month => 1, day => 1 ); is($f->format_datetime($dt), 0, 'Epoch = 0'); is(DateTime::Format::Epoch::DotNet->format_datetime($dt), 0, 'Epoch = 0'); $dt->set( hour => 1 ); is($f->format_datetime($dt), 3600*1e7, 'Epoch + 1hour'); is(DateTime::Format::Epoch::DotNet->format_datetime($dt), 3600*1e7, 'Epoch + 1hour'); $dt->set( day => 2, hour => 0 ); is($f->format_datetime($dt), 24*3600*1e7, 'Epoch + 1day'); is(DateTime::Format::Epoch::DotNet->format_datetime($dt), 24*3600*1e7, 'Epoch + 1day'); $dt = DateTime->new( year => 100, month => 1, day => 1 ); is($f->format_datetime($dt) - 31241376000000000, 0, '100 AD (object)'); is(DateTime::Format::Epoch::DotNet->format_datetime($dt) - 31241376000000000, 0, '100 AD (class)'); DateTime-Format-Epoch-0.13/t/502_format.t000444000000000000 167211434544356 20424 0ustar00unknownunknown000000000000use strict; BEGIN { $^W = 1 } use Test::More qw/no_plan/; use DateTime; use DateTime::Format::Epoch::JD; use DateTime::Format::Epoch::MJD; use DateTime::Format::Epoch::TJD; use DateTime::Format::Epoch::RJD; use DateTime::Format::Epoch::Lilian; use DateTime::Format::Epoch::RataDie; my $dt = DateTime->new( year => 2004, month => 8, day => 28 ); my %dates = ( JD => 2453245.5, MJD => 53245, TJD => 13245, RJD => 53245.5, Lilian => 154086, RataDie => 731821 ); while (my ($timescale, $value) = each %dates) { #no strict 'refs'; is( ("DateTime::Format::Epoch::$timescale")->format_datetime($dt), $value, $timescale ); is( ("DateTime::Format::Epoch::$timescale")->new->format_datetime($dt), $value, $timescale ); is( ("DateTime::Format::Epoch::$timescale")->parse_datetime($value) ->datetime, $dt->datetime, "parse $timescale" ); } DateTime-Format-Epoch-0.13/t/601_load.t000444000000000000 21011434544356 20016 0ustar00unknownunknown000000000000# t/001_load.t - check module loading use Test::More tests => 1; BEGIN { use_ok( 'DateTime::Format::Epoch::ActiveDirectory' ); } DateTime-Format-Epoch-0.13/t/pod.t000444000000000000 20511434544356 17277 0ustar00unknownunknown000000000000use Test::More; eval "use Test::Pod 1.00"; plan skip_all => "Test::Pod 1.00 required for testing POD" if $@; all_pod_files_ok();