DateTime-Format-RFC3339-v1.8.0/0000700060175106017510000000000014553311740014513 5ustar ikegaikegaDateTime-Format-RFC3339-v1.8.0/.gitignore0000644060175106017510000000024314543051675016523 0ustar ikegaikega*.bak *~ .releaserc blib/ cover_db Makefile Makefile.old META.* MYMETA.* pm_to_blib pod2htmd.tmp pod2htmi.tmp DateTime-Format-RFC3339-* DateTime-Format-RFC3339-*/ DateTime-Format-RFC3339-v1.8.0/Changes0000644060175106017510000000205614553311570016024 0ustar ikegaikegaRevision history for DateTime-Format-RFC3339 1.8.0 2024-01-21 - Added missing Perl v5.10 requirement. - Updated the version of ExtUtils::MakeMaker that's required. 1.6.0 2024-01-01 - Fix bug in POD. 1.4.0 2024-01-01 - Added `decimals` option. - Added `sep` and `sep_re` options. - Documented `uc_only` option. - Fixed bug tracker information. - Misc internal improvements. 1.2.0 2015-10-09 No functional changes. Updated to adopt the conventions used by my other modules. A few tests were added, and a repository information was added. 1.0.5 2011-03-28 Specified license more explicitly. 1.0.4 2010-10-10 Switch to UTC rather than rounding when dealing with timezone offsets of non-integral minutes. 1.0.3 2010-10-07 Leave timezone unchanged when formatting. 1.0.2 2009-10-13 Fixed handling of fractional seconds. 1.0.1 2009-01-07 Documentation formatting fixes. 1.0.0 2009-01-05 Initial version DateTime-Format-RFC3339-v1.8.0/lib/0000700060175106017510000000000014553311735015265 5ustar ikegaikegaDateTime-Format-RFC3339-v1.8.0/lib/DateTime/0000700060175106017510000000000014553311735016761 5ustar ikegaikegaDateTime-Format-RFC3339-v1.8.0/lib/DateTime/Format/0000700060175106017510000000000014553311735020211 5ustar ikegaikegaDateTime-Format-RFC3339-v1.8.0/lib/DateTime/Format/RFC3339.pm0000644060175106017510000001674014553311614021521 0ustar ikegaikega package DateTime::Format::RFC3339; use strict; use warnings; use version; our $VERSION = qv( 'v1.8.0' ); use Carp qw( croak ); use DateTime qw( ); use constant FIRST_IDX => 0; use constant IDX_FORMAT => FIRST_IDX + 0; use constant IDX_DECIMALS => FIRST_IDX + 1; use constant IDX_SEP => FIRST_IDX + 2; use constant IDX_SEP_RE => FIRST_IDX + 3; use constant IDX_UC_ONLY => FIRST_IDX + 4; use constant NEXT_IDX => FIRST_IDX + 5; my $default_self; sub new { my $class = shift; my %opts = @_; my $decimals = delete( $opts{ decimals } ); my $sep = delete( $opts{ sep } ); my $sep_re = delete( $opts{ sep_re } ); my $uc_only = delete( $opts{ uc_only } ); $sep //= "T"; $sep_re //= quotemeta( $sep ); $uc_only = $uc_only ? 1 : 0; my $self = bless( [], $class ); #$self->[ IDX_FORMAT ] = undef; $self->[ IDX_DECIMALS ] = $decimals; $self->[ IDX_SEP ] = $sep; $self->[ IDX_SEP_RE ] = $sep_re; $self->[ IDX_UC_ONLY ] = $uc_only; return $self; } sub parse_datetime { my $self = shift; my $str = shift; $self = $default_self //= $self->new() if !ref( $self ); $str = uc( $str ) if !$self->[ IDX_UC_ONLY ]; my ( $Y, $M, $D ) = $str =~ s/^([0-9]{4})-([0-9]{2})-([0-9]{2})// ? ( 0+$1, 0+$2, 0+$3 ) : () or croak( "Incorrectly formatted date" ); $str =~ s/^$self->[ IDX_SEP_RE ]// or croak( "Incorrectly formatted datetime" ); my ( $h, $m, $s ) = $str =~ s/^([0-9]{2}):([0-9]{2}):([0-9]{2})// ? ( 0+$1, 0+$2, 0+$3 ) : () or croak( "Incorrectly formatted time" ); my $ns = $str =~ s/^\.([0-9]{1,9})[0-9]*// ? 0+substr( $1.( '0' x 8 ), 0, 9 ) : 0; my $tz; if ( $str =~ s/^Z// ) { $tz = 'UTC'; } elsif ( $str =~ s/^([+-])([0-9]{2}):([0-9]{2})// ) { $tz = "$1$2$3"; } else { croak( "Incorrect or missing time zone offset" ); } $str =~ /^\z/ or croak( "Incorrectly formatted datetime" ); return DateTime->new( year => $Y, month => $M, day => $D, hour => $h, minute => $m, second => $s, nanosecond => $ns, time_zone => $tz, formatter => $self, ); } sub format_datetime { my $self = shift; my $dt = shift; $self = $default_self //= $self->new() if !ref( $self ); my $format = $self->[ IDX_FORMAT ]; if ( !$format ) { my $decimals = $self->[ IDX_DECIMALS ]; my $sep = $self->[ IDX_SEP ]; $sep = "%%" if $sep eq "%"; if ( defined( $decimals ) ) { if ( $decimals ) { $self->[ IDX_FORMAT ] = $format = "%Y-%m-%d${sep}%H:%M:%S.%${decimals}N"; } else { $self->[ IDX_FORMAT ] = $format = "%Y-%m-%d${sep}%H:%M:%S"; } } else { if ( $dt->nanosecond() ) { $format = "%Y-%m-%d${sep}%H:%M:%S.%9N"; } else { $format = "%Y-%m-%d${sep}%H:%M:%S"; } } } my $tz; if ( $dt->time_zone()->is_utc() ) { $tz = 'Z'; } else { my $secs = $dt->offset(); # TODO Maybe we could cache this. # There are only so many offests, and most # programs probably only uses one or two. my $sign = $secs < 0 ? '-' : '+'; $secs = abs( $secs ); my $mins = int( $secs / 60 ); $secs %= 60; my $hours = int( $mins / 60 ); $mins %= 60; if ( $secs ) { ( $dt = $dt->clone() ) ->set_time_zone( 'UTC' ); $tz = 'Z'; } else { $tz = sprintf( '%s%02d:%02d', $sign, $hours, $mins ); } } return $dt->strftime( $format ) . $tz; } 1; __END__ =head1 NAME DateTime::Format::RFC3339 - Parse and format RFC3339 datetime strings =head1 VERSION Version 1.8.0 =head1 SYNOPSIS use DateTime::Format::RFC3339; my $format = DateTime::Format::RFC3339->new(); my $dt = $format->parse_datetime( '2002-07-01T13:50:05Z' ); # 2002-07-01T13:50:05Z say $format->format_datetime( $dt ); =head1 DESCRIPTION This module understands the RFC3339 date/time format, an ISO 8601 profile, defined at L. It can be used to parse these formats in order to create the appropriate objects. =head1 CONSTRUCTOR =head2 new my $format = DateTime::Format::RFC3339->new(); my $format = DateTime::Format::RFC3339->new( %options ); A number of options are supported: =over =item * decimals decimals => undef [default] decimals => $decimals Date-time strings generated by will have this many decimals (an integer from zero to nine). If C, zero will be used if the date-time has no decimals, nine otherwise. =item * sep sep => "T" [default] sep => $sep =item * sep_re sep_re => $sep_re The spec allows for a separator other than "C" to be used between the date and the time. The string provided to the C option is used when formatting date-time objects into strings, and the regex pattern provided to the C option is used when parsing strings into date-time objects. The default for C is a regex pattern that matches the separator (which is "C" by default). =item * uc_only uc_only => 0 [default] uc_only => 1 Only an uppercase date and time separator and an uppercase timezone offset "Z" will be accepted by C when this option is true. =back =head1 METHODS =head2 parse_datetime my $dt = DateTime::Format::RFC3339->parse_datetime( $string ); my $dt = $format->parse_datetime( $string ); Given a RFC3339 datetime string, this method will return a new L object. If given an improperly formatted string, this method will croak. For a more flexible parser, see L. =head2 format_datetime my $string = DateTime::Format::RFC3339->format_datetime( $dt ); my $string = $format->format_datetime( $dt ); Given a L object, this methods returns a RFC3339 datetime string. =head1 SEE ALSO =over 4 =item * L =item * L =item * L, "Date and Time on the Internet: Timestamps" =back =head1 DOCUMENTATION AND SUPPORT You can find documentation for this module with the perldoc command. perldoc DateTime::Format::RFC3339 You can also find it online at this location: =over =item * L =back If you need help, the following are great resources: =over =item * L =item * L =item * You may also contact the author directly. =back =head1 BUGS Please report any bugs or feature requests using L. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. =head1 REPOSITORY =over =item * Web: L =item * git: L =back =head1 AUTHOR Eric Brine, C<< >> =head1 COPYRIGHT & LICENSE No rights reserved. The author has dedicated the work to the Commons by waiving all of his or her rights to the work worldwide under copyright law and all related or neighboring legal rights he or she had in the work, to the extent allowable by law. Works under CC0 do not require attribution. When citing the work, you should not imply endorsement by the author. =cut DateTime-Format-RFC3339-v1.8.0/LICENSE.txt0000644060175106017510000001564314543046126016363 0ustar ikegaikegaCreative Commons Legal Code CC0 1.0 Universal CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED HEREUNDER. Statement of Purpose The laws of most jurisdictions throughout the world automatically confer exclusive Copyright and Related Rights (defined below) upon the creator and subsequent owner(s) (each and all, an "owner") of an original work of authorship and/or a database (each, a "Work"). Certain owners wish to permanently relinquish those rights to a Work for the purpose of contributing to a commons of creative, cultural and scientific works ("Commons") that the public can reliably and without fear of later claims of infringement build upon, modify, incorporate in other works, reuse and redistribute as freely as possible in any form whatsoever and for any purposes, including without limitation commercial purposes. These owners may contribute to the Commons to promote the ideal of a free culture and the further production of creative, cultural and scientific works, or to gain reputation or greater distribution for their Work in part through the use and efforts of others. For these and/or other purposes and motivations, and without any expectation of additional consideration or compensation, the person associating CC0 with a Work (the "Affirmer"), to the extent that he or she is an owner of Copyright and Related Rights in the Work, voluntarily elects to apply CC0 to the Work and publicly distribute the Work under its terms, with knowledge of his or her Copyright and Related Rights in the Work and the meaning and intended legal effect of CC0 on those rights. 1. Copyright and Related Rights. A Work made available under CC0 may be protected by copyright and related or neighboring rights ("Copyright and Related Rights"). Copyright and Related Rights include, but are not limited to, the following: i. the right to reproduce, adapt, distribute, perform, display, communicate, and translate a Work; ii. moral rights retained by the original author(s) and/or performer(s); iii. publicity and privacy rights pertaining to a person's image or likeness depicted in a Work; iv. rights protecting against unfair competition in regards to a Work, subject to the limitations in paragraph 4(a), below; v. rights protecting the extraction, dissemination, use and reuse of data in a Work; vi. database rights (such as those arising under Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, and under any national implementation thereof, including any amended or successor version of such directive); vii. and other similar, equivalent or corresponding rights throughout the world based on applicable law or treaty, and any national implementations thereof. 2. Waiver. To the greatest extent permitted by, but not in contravention of, applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and unconditionally waives, abandons, and surrenders all of Affirmer's Copyright and Related Rights and associated claims and causes of action, whether now known or unknown (including existing as well as future claims and causes of action), in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each member of the public at large and to the detriment of Affirmer's heirs and successors, fully intending that such Waiver shall not be subject to revocation, rescission, cancellation, termination, or any other legal or equitable action to disrupt the quiet enjoyment of the Work by the public as contemplated by Affirmer's express Statement of Purpose. 3. Public License Fallback. Should any part of the Waiver for any reason be judged legally invalid or ineffective under applicable law, then the Waiver shall be preserved to the maximum extent permitted taking into account Affirmer's express Statement of Purpose. In addition, to the extent the Waiver is so judged Affirmer hereby grants to each affected person a royalty-free, non transferable, non sublicensable, non exclusive, irrevocable and unconditional license to exercise Affirmer's Copyright and Related Rights in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "License"). The License shall be deemed effective as of the date CC0 was applied by Affirmer to the Work. Should any part of the License for any reason be judged legally invalid or ineffective under applicable law, such partial invalidity or ineffectiveness shall not invalidate the remainder of the License, and in such case Affirmer hereby affirms that he or she will not (i) exercise any of his or her remaining Copyright and Related Rights in the Work or (ii) assert any associated claims and causes of action with respect to the Work, in either case contrary to Affirmer's express Statement of Purpose. 4. Limitations and Disclaimers. a. No trademark or patent rights held by Affirmer are waived, abandoned, surrendered, licensed or otherwise affected by this document. b. Affirmer offers the Work as-is and makes no representations or warranties of any kind concerning the Work, express, implied, statutory or otherwise, including without limitation warranties of title, merchantability, fitness for a particular purpose, non infringement, or the absence of latent or other defects, accuracy, or the present or absence of errors, whether or not discoverable, all to the greatest extent permissible under applicable law. c. Affirmer disclaims responsibility for clearing rights of other persons that may apply to the Work or any use thereof, including without limitation any person's Copyright and Related Rights in the Work. Further, Affirmer disclaims responsibility for obtaining any necessary consents, permissions or other rights required for any use of the Work. d. Affirmer understands and acknowledges that Creative Commons is not a party to this document and has no duty or obligation with respect to this CC0 or use of the Work. DateTime-Format-RFC3339-v1.8.0/Makefile.PL0000755060175106017510000000361114553307726016514 0ustar ikegaikega#!/usr/bin/env perl use strict; use warnings; use ExtUtils::MakeMaker qw( WriteMakefile ); WriteMakefile( NAME => 'DateTime::Format::RFC3339', AUTHOR => 'Eric Brine ', VERSION_FROM => 'lib/DateTime/Format/RFC3339.pm', ABSTRACT_FROM => 'lib/DateTime/Format/RFC3339.pm', dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz' }, clean => { FILES => 'DateTime-Format-RFC3339-*' }, BUILD_REQUIRES => {}, META_MERGE => { 'meta-spec' => { version => 2 }, license => [ 'unrestricted' ], prereqs => { configure => { requires => { 'ExtUtils::MakeMaker' => 6.68, }, }, runtime => { requires => { 'perl' => 5.010, 'strict' => 0, 'version' => 0, 'warnings' => 0, 'DateTime' => 0, }, }, test => { requires => { 'Test::More' => 0, }, recommends => { 'Test::Pod' => 1.22, }, }, develop => { requires => { 'Pod::Coverage' => 0.18, 'Test::Pod::Coverage' => 1.08, }, }, }, resources => { homepage => 'https://metacpan.org/dist/DateTime-Format-RFC3339', license => [ 'http://creativecommons.org/publicdomain/zero/1.0/' ], bugtracker => { web => 'https://github.com/ikegami/perl-DateTime-Format-RFC3339/issues', }, repository => { type => 'git', url => 'https://github.com/ikegami/perl-DateTime-Format-RFC3339.git', web => 'https://github.com/ikegami/perl-DateTime-Format-RFC3339', }, }, }, ); DateTime-Format-RFC3339-v1.8.0/MANIFEST0000644060175106017510000000071214553311740015656 0ustar ikegaikega.gitignore Changes lib/DateTime/Format/RFC3339.pm LICENSE.txt Makefile.PL MANIFEST MANIFEST.SKIP README.txt t/00_load.t t/01_devel_mark_check.t t/02_devel_version_check.t t/03_devel_whitespace.t t/04_devel_permissions.t t/05_pod.t t/06_devel_pod_coverage.t t/07_parsing.t t/08_formatting.t META.yml Module YAML meta-data (added by MakeMaker) META.json Module JSON meta-data (added by MakeMaker) DateTime-Format-RFC3339-v1.8.0/MANIFEST.SKIP0000644060175106017510000000023414543051626016425 0ustar ikegaikega^.git/ ^.gitignore$ .bak$ ~$ .releaserc ^blib/ cover_db ^Makefile$ ^Makefile.old$ MYMETA.* ^pm_to_blib$ pod2htmd.tmp pod2htmi.tmp ^DateTime-Format-RFC3339- DateTime-Format-RFC3339-v1.8.0/META.json0000600060175106017510000000351214553311740016137 0ustar ikegaikega{ "abstract" : "Parse and format RFC3339 datetime strings", "author" : [ "Eric Brine " ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 7.64, CPAN::Meta::Converter version 2.150010", "license" : [ "unknown", "unrestricted" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "DateTime-Format-RFC3339", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : {} }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "6.68" } }, "develop" : { "requires" : { "Pod::Coverage" : "0.18", "Test::Pod::Coverage" : "1.08" } }, "runtime" : { "requires" : { "DateTime" : "0", "perl" : "5.01", "strict" : "0", "version" : "0", "warnings" : "0" } }, "test" : { "recommends" : { "Test::Pod" : "1.22" }, "requires" : { "Test::More" : "0" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/ikegami/perl-DateTime-Format-RFC3339/issues" }, "homepage" : "https://metacpan.org/dist/DateTime-Format-RFC3339", "license" : [ "http://creativecommons.org/publicdomain/zero/1.0/" ], "repository" : { "type" : "git", "url" : "https://github.com/ikegami/perl-DateTime-Format-RFC3339.git", "web" : "https://github.com/ikegami/perl-DateTime-Format-RFC3339" } }, "version" : "v1.8.0", "x_serialization_backend" : "JSON::PP version 4.07" } DateTime-Format-RFC3339-v1.8.0/META.yml0000600060175106017510000000163014553311736015773 0ustar ikegaikega--- abstract: 'Parse and format RFC3339 datetime strings' author: - 'Eric Brine ' build_requires: Test::More: '0' configure_requires: ExtUtils::MakeMaker: '6.68' dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 7.64, CPAN::Meta::Converter version 2.150010' license: unknown meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: DateTime-Format-RFC3339 no_index: directory: - t - inc requires: DateTime: '0' perl: '5.01' strict: '0' version: '0' warnings: '0' resources: bugtracker: https://github.com/ikegami/perl-DateTime-Format-RFC3339/issues homepage: https://metacpan.org/dist/DateTime-Format-RFC3339 license: http://creativecommons.org/publicdomain/zero/1.0/ repository: https://github.com/ikegami/perl-DateTime-Format-RFC3339.git version: v1.8.0 x_serialization_backend: 'CPAN::Meta::YAML version 0.018' DateTime-Format-RFC3339-v1.8.0/README.txt0000644060175106017510000000217114544625774016243 0ustar ikegaikegaDateTime-Format-RFC3339 DateTime::Format::RFC3339 parses and formats RFC3339 datetime strings. INSTALLATION To install this module, run the following commands: perl Makefile.PL make make test make install DEPENDENCIES This module requires these other modules and libraries: ExtUtils::MakeMaker 6.52 (For installation only) Software::License::CC0_1_0 (For installation only) Test::More (For testing only) DateTime strict version warnings DOCUMENTATION After installing, you can find documentation for this module with the perldoc command. perldoc DateTime::Format::RFC3339 You can also find it online at this location: https://metacpan.org/dist/DateTime-Format-RFC3339 COPYRIGHT AND LICENCE No rights reserved. The author has dedicated the work to the Commons by waiving all of his or her rights to the work worldwide under copyright law and all related or neighboring legal rights he or she had in the work, to the extent allowable by law. Works under CC0 do not require attribution. When citing the work, you should not imply endorsement by the author. DateTime-Format-RFC3339-v1.8.0/t/0000700060175106017510000000000014553311735014762 5ustar ikegaikegaDateTime-Format-RFC3339-v1.8.0/t/00_load.t0000755060175106017510000000055414544623433016407 0ustar ikegaikega#!perl use strict; use warnings; use Test::More tests => 1; BEGIN { require_ok( 'DateTime::Format::RFC3339' ); } diag( "Testing DateTime::Format::RFC3339 $DateTime::Format::RFC3339::VERSION" ); diag( "Using Perl $]" ); for ( sort grep /\.pm\z/, keys %INC ) { s{\.pm\z}{}; s{/}{::}g; eval { diag( join( ' ', $_, $_->VERSION || '' ) ) }; } DateTime-Format-RFC3339-v1.8.0/t/01_devel_mark_check.t0000755060175106017510000000137614543616222020737 0ustar ikegaikega#!perl # Expected to be run from ../ (make test) or ../blib/ (make disttest) use strict; use warnings; use Test::More; BEGIN { $ENV{ DEVEL_TESTS } or plan skip_all => "Mark checks are only performed when DEVEL_TESTS=1"; } sub slurp_file { my $qfn = shift; open( my $fh, '<', $qfn ) or die( "Can't open \"$qfn\": $!\n" ); local $/; return <$fh>; } sub read_manifest { open( my $fh, '<', 'MANIFEST' ) or die( "Can't open \"MANIFEST\": $!\n" ); my @manifest = <$fh>; s/\s.*//s for @manifest; return @manifest; } { my @qfns = read_manifest(); plan tests => 0+@qfns; for my $qfn ( @qfns ) { my $file = slurp_file( $qfn ); ok( $file !~ /~{3}|&{3}/, "$qfn - Has no developer bookmarks" ); } } DateTime-Format-RFC3339-v1.8.0/t/02_devel_version_check.t0000755060175106017510000000216714543616222021472 0ustar ikegaikega#!perl # Expected to be run from ../ (make test) or ../blib/ (make disttest) use strict; use warnings; use Test::More; BEGIN { if ( $ENV{ DEVEL_TESTS } ) { plan tests => 3; } else { plan skip_all => "Version checks are only performed when DEVEL_TESTS=1"; } } sub slurp_file { my $qfn = shift; open( my $fh, '<', $qfn ) or die( "Can't open \"$qfn\": $!\n" ); local $/; return <$fh>; } { my $base_file = slurp_file( 'lib/DateTime/Format/RFC3339.pm' ); my $changes_file = slurp_file( 'Changes' ); my ( $version ) = $base_file =~ /\bqv\(\s*'v([^']*)'\s*\)/ or die( "Can't find version\n" ); my @parts = split( /\./, $version ); my ( $pod_version ) = $base_file =~ /^Version (\S+)/m or die( "Can't find version in POD\n" ); my ( $changes_version ) = $changes_file =~ /^([0-9]\S*)/m or die( "Can't find version in Changes file\n" ); is( $pod_version, $version, "Version in POD matches actual version" ); ok( $parts[1] % 2 == 0, "Version is a release version" ); is( $changes_version, $version, "Version in Changes file matches actual version" ); } DateTime-Format-RFC3339-v1.8.0/t/03_devel_whitespace.t0000755060175106017510000000201414543616222020774 0ustar ikegaikega#!perl # Expected to be run from ../ (make test) or ../blib/ (make disttest) use strict; use warnings; use Test::More; BEGIN { $ENV{ DEVEL_TESTS } or plan skip_all => "Whitespace checks are only performed when DEVEL_TESTS=1"; } sub slurp_file { my $qfn = shift; open( my $fh, '<', $qfn ) or die( "Can't open \"$qfn\": $!\n" ); local $/; return <$fh>; } sub read_manifest { open( my $fh, '<', 'MANIFEST' ) or die( "Can't open \"MANIFEST\": $!\n" ); my @manifest = <$fh>; s/\s.*//s for @manifest; return @manifest; } { my @qfns = read_manifest(); plan tests => 2*@qfns; for my $qfn ( @qfns ) { my $file = slurp_file( $qfn ); my $rev_file = reverse( $file ); if ( $^O eq 'MSWin32' ) { ok( $file !~ /\r(?!\n)/ && $rev_file !~ /\n(?!\r)/, "$qfn - Windows line endings" ); } else { ok( $file !~ /\r/, "$qfn - Unix line endings" ); } ok( $rev_file !~ /\n(?:\r[^\S\n]|[^\S\r\n])/, "$qfn - No trailing whitespace" ); } } DateTime-Format-RFC3339-v1.8.0/t/04_devel_permissions.t0000755060175106017510000000211114544623703021215 0ustar ikegaikega#!perl # Expected to be run from ../ (make test) or ../blib/ (make disttest) use strict; use warnings; use Test::More; BEGIN { $ENV{ DEVEL_TESTS } or plan skip_all => "Permission checks are only performed when DEVEL_TESTS=1"; $^O ne 'Win32' or plan skip_all => "Permission checks can't be performed on Win32"; } sub read_manifest { open( my $fh, '<', 'MANIFEST' ) or die( "Can't open \"MANIFEST\": $!\n" ); my @manifest = <$fh>; s/\s.*//s for @manifest; return @manifest; } { my @qfns = read_manifest(); plan tests => 3*@qfns; for my $qfn ( @qfns ) { my @stat = stat( $qfn ) or die( "Can't stat \"$qfn\": $!\n" ); my $mode = $stat[2]; is( sprintf( "%04o", $mode & 0400 ), '0400', "$qfn is readable" ); is( sprintf( "%04o", $mode & 0002 ), '0000', "$qfn isn't world writable" ); if ( $qfn =~ /\.(?:t|pl|PL)\z/ ) { is( sprintf( "%04o", $mode & 0100 ), '0100', "$qfn is executable" ); } else { is( sprintf( "%04o", $mode & 0111 ), '0000', "$qfn isn't executable" ); } } } DateTime-Format-RFC3339-v1.8.0/t/05_pod.t0000755060175106017510000000051014543616222016244 0ustar ikegaikega#!perl # Expected to be run from ../ (make test) or ../blib/ (make disttest) use strict; use warnings; use Test::More; BEGIN { # Ensure a recent version of Test::Pod my $min_tp = 1.22; eval( "use Test::Pod $min_tp; 1" ) or plan skip_all => "Test::Pod $min_tp required for testing POD"; } all_pod_files_ok(); DateTime-Format-RFC3339-v1.8.0/t/06_devel_pod_coverage.t0000755060175106017510000000140214543616222021300 0ustar ikegaikega#!perl # Expected to be run from ../ (make test) or ../blib/ (make disttest) use strict; use warnings; use Test::More; BEGIN { $ENV{ DEVEL_TESTS } or plan skip_all => "Pod coverage is only tested when DEVEL_TESTS=1"; # Ensure a recent version of Test::Pod::Coverage my $min_tpc = 1.08; eval( "use Test::Pod::Coverage $min_tpc; 1" ) or plan skip_all => "Test::Pod::Coverage $min_tpc required for testing POD coverage"; # Test::Pod::Coverage doesn't require a minimum Pod::Coverage version, # but older versions don't recognize some common documentation styles my $min_pc = 0.18; eval( "use Pod::Coverage $min_pc; 1" ) or plan skip_all => "Pod::Coverage $min_pc required for testing POD coverage"; } all_pod_coverage_ok(); DateTime-Format-RFC3339-v1.8.0/t/07_parsing.t0000755060175106017510000000452014544611245017135 0ustar ikegaikega#!perl use strict; use warnings; use Test::More; use DateTime qw( ); use DateTime::Format::RFC3339 qw( ); my @tests; my $default_format = 'DateTime::Format::RFC3339'; push @tests, ( [ undef, $default_format, '2002-07-01T13:50:05Z', DateTime->new( year => 2002, month => 7, day => 1, hour => 13, minute => 50, second => 5, time_zone => 'UTC' ), ], [ undef, $default_format, '2002-07-01T13:50:05.123Z', DateTime->new( year => 2002, month => 7, day => 1, hour => 13, minute => 50, second => 5, nanosecond => 123000000, time_zone => 'UTC' ), ], ); my $dt = DateTime->new( year => 2023, month => 12, day => 31, hour => 23, minute => 59, second => 59, time_zone => 'UTC' ); push @tests, ( [ undef, $default_format, '2023-12-31T23:59:59Z', $dt, ], [ undef, $default_format, '2023/12/31T23:59:59Z', qr/^Incorrectly formatted date\b/, ], [ undef, $default_format, '2023-12-31T23-59-59Z', qr/^Incorrectly formatted time\b/, ], [ undef, $default_format, '2023-12-31T23:59:59Y', qr/^Incorrect or missing time zone offset\b/, ], [ undef, $default_format, '2023-12-31T23:59:59ZZ', qr/^Incorrectly formatted datetime\b/, ], ); push @tests, ( [ "sep => undef, sep_re => undef", DateTime::Format::RFC3339->new( sep => undef, sep_re => undef ), '2023-12-31T23:59:59Z', $dt, ], [ "sep => 'T', sep_re => undef", DateTime::Format::RFC3339->new( sep => 'T', sep_re => undef ), '2023-12-31T23:59:59Z', $dt, ], [ "sep => ' ', sep_re => undef", DateTime::Format::RFC3339->new( sep => ' ', sep_re => undef ), '2023-12-31 23:59:59Z', $dt, ], [ "sep => ' ', sep_re => qr/\\s/", DateTime::Format::RFC3339->new( sep => ' ', sep_re => qr/\s/ ), "2023-12-31\t23:59:59Z", $dt, ], ); plan tests => 0+@tests; for ( @tests ) { my ( $name, $format, $str, $expected_dt ) = @$_; $name //= $str; my $actual_dt = eval { $format->parse_datetime( $str ) }; my $e = $@; if ( ref( $expected_dt ) eq 'DateTime' ) { is( $actual_dt, $expected_dt, $name ); diag( "Exception: $e" ) if $e; } else { like( $e, $expected_dt, $name ) } } DateTime-Format-RFC3339-v1.8.0/t/08_formatting.t0000755060175106017510000000542314544610531017645 0ustar ikegaikega#!perl use strict; use warnings; use DateTime qw( ); use DateTime::Format::RFC3339 qw( ); use Test::More; my @tests; my $default_format = 'DateTime::Format::RFC3339'; push @tests, ( [ 'UTC', $default_format, DateTime->new( year => 2002, month => 7, day => 1, hour => 13, minute => 50, second => 5, time_zone => 'UTC' ), '2002-07-01T13:50:05Z', ], [ 'Positive offset', $default_format, DateTime->new( year => 2002, month => 7, day => 1, hour => 13, minute => 50, second => 5, time_zone => 'Europe/London' ), '2002-07-01T13:50:05+01:00', ], [ 'Zero offset', $default_format, DateTime->new( year => 2002, month => 1, day => 1, hour => 13, minute => 50, second => 5, time_zone => 'Europe/London' ), '2002-01-01T13:50:05+00:00', ], [ 'Negative offset', $default_format, DateTime->new( year => 2002, month => 1, day => 1, hour => 13, minute => 50, second => 5, time_zone => 'America/New_York' ), '2002-01-01T13:50:05-05:00', ], [ 'Offset with non-integral minutes', $default_format, DateTime->new( year => 1880, month => 1, day => 1, hour => 0, minute => 0, second => 0, time_zone => 'America/New_York' ), '1880-01-01T04:56:02Z', ], ); my $dt = DateTime->new( year => 2023, month => 12, day => 31, hour => 23, minute => 59, second => 59, time_zone => 'UTC' ); { my $format = DateTime::Format::RFC3339->new( decimals => undef ); push @tests, ( [ 'decimals => undef - No nanoseconds', $format, $dt->clone()->set_nanosecond( 0 ), '2023-12-31T23:59:59Z', ], [ 'decimals => undef - With nanoseconds', $format, $dt->clone()->set_nanosecond( 123_000 ), '2023-12-31T23:59:59.000123000Z', ], ); } for my $decimals ( 0 .. 9 ) { my $format = DateTime::Format::RFC3339->new( decimals => $decimals ); push @tests, ( [ "decimals => $decimals", $format, $dt->clone()->set_nanosecond( 987_654_321 ), ( $decimals ? sprintf( '2023-12-31T23:59:59.%sZ', substr( '987654321', 0, $decimals ) ) : '2023-12-31T23:59:59Z' ), ], ); } for ( [ "sep => undef", undef, '2023-12-31T23:59:59Z' ], [ "sep => 'T'", 'T', '2023-12-31T23:59:59Z' ], [ "sep => ' '", ' ', '2023-12-31 23:59:59Z' ], ) { my ( $name, $sep, $expected_str ) = @$_; my $format = DateTime::Format::RFC3339->new( sep => $sep ); push @tests, [ $name, $format, $dt, $expected_str ]; } plan tests => 0+@tests; for ( @tests ) { my ( $name, $format, $dt, $expected_str ) = @$_; ( $dt = $dt->clone ) ->set_formatter( $format ); my $actual_str = "$dt"; is( $actual_str, $expected_str, $name ); }