Image-Synchronize

 view release on metacpan or  search on metacpan

t/Image-Synchronize-Timestamp.t  view on Meta::CPAN

#!/usr/bin/perl
use Modern::Perl;

use Scalar::Util qw(refaddr looks_like_number);
use Test::More;
use Time::Local qw(timegm_modern timelocal_modern);
use Image::Synchronize::Timestamp;

sub parse_components_ {
  Image::Synchronize::Timestamp::parse_components_(@_);
}

# test unrecognized timestamp

foreach my $test
  (
   undef,                       # undefined
   '',                          # empty
   '2001-02-03',                # date only
   'some text',
   ' 2001-02-03T04:05:06',      # whitespace prefix
 )
{
  my $et = Image::Synchronize::Timestamp->new($test);
  ok(not(defined $et), 'unrecognized timestamp: ' . ($test // 'undef'));
}

my $chosen_time = 981180000;
my $chosen_time_iso = '2001-02-03T06:00:00Z';
is_deeply([gmtime($chosen_time)],
          # sec,min,hr,mday,mon,year,wday,yday,isdst
          [   0,  0, 6,   3,  1, 101,   6,  33,    0],
          'check chosen time');

# test various ways of specifying the same instant of time with
# timezone, equivalent to 2001-02-03T06:00:00Z

foreach my $test
  (
   '2001:02:03 14:00:00+08:00', # exif format with timezone
   '2001-02-03 14:00:00+08:00', # - as date separator
   '2001-02-03T14:00:00+08:00', # ISO 8601
   '2001-02-03T14:00:00+08:00:00', # timezone seconds, too
   '2001-02-03T14:00:00+08',    # timezone hours only
   '2001-02-03T14:00+08:00',    # no clock seconds
   '2001-02-03T14+08',          # no minutes or seconds
   '2001-02-03T13+07',          # different timezone, same instant
   '2001-02-03T06+00',          # UTC
   '2001-02-03T06Z',            # UTC
   '2001-02-03T05-01',          # negative timezone offset
   '2001-02-03T05-1',           # single timezone hour digit
   '2001-2-3T7+1',              # omit initial 0s
 )
{
  my $et = Image::Synchronize::Timestamp->new($test);
  is($et->time_utc, $chosen_time, "same instant with tz: $test");
}

# test epoch
{
  my $et = Image::Synchronize::Timestamp->new('1970-01-01T00+00');
  is($et->time_utc, 0, 'epoch');



( run in 0.695 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )