DateTime-Format-Strptime

 view release on metacpan or  search on metacpan

bench  view on Meta::CPAN

package main;

use strict;
use warnings;
use utf8;

use Benchmark qw( timethese );
use DateTime::Format::Strptime;
use Try::Tiny;
use Test::More;
use Test::Fatal;

timethese( 100, { test => \&test } );

sub test {
for my $test ( _tests_from_data() ) {
    subtest(
        qq{$test->{name}},
        sub {
            _utf8_output();

            my $parser;
            is(
                exception {
                    $parser = DateTime::Format::Strptime->new(
                        pattern => $test->{pattern},
                        (
                            $test->{locale}
                            ? ( locale => $test->{locale} )
                            : ()
                        ),
                        on_error => 'croak',
                    );
                },
                undef,
                "no exception building parser for $test->{pattern}"
            ) or return;

            # Thursday changed from "Thu" to "Thu." and December went from
            # "Dec" to "Dec." between CLDR versions.
            $test->{input}
                =~ s/AU_THU/DateTime::Locale->load('en-AU')->day_format_abbreviated->[3]/e;
            $test->{input}
                =~ s/AU_DEC/DateTime::Locale->load('en-AU')->month_format_abbreviated->[11]/e;

            ( my $real_input = $test->{input} ) =~ s/\\n/\n/g;

            my $dt;
            is(
                exception { $dt = $parser->parse_datetime( $real_input ) },
                undef,
                "no exception parsing $test->{input}"
            ) or return;

            _test_dt_methods( $dt, $test->{expect} );

            unless ( $test->{skip_round_trip} ) {
                is(
                    $parser->format_datetime($dt),
                    $real_input,
                    'round trip via strftime produces original input'
                );
            }
        }
    );
}

subtest(
    'parsing whitespace',
    sub {
        my $parser = DateTime::Format::Strptime->new(



( run in 2.442 seconds using v1.01-cache-2.11-cpan-54e63673c56 )