| 1 | package DateTime::Format::EXIF; | ||||||||||||||
| 2 | 1 | $DateTime::Format::EXIF::VERSION = '0.002'; | |||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | |||||||||||||||
| 6 | # ABSTRACT: DateTime parser for EXIF timestamps | ||||||||||||||
| 7 | |||||||||||||||
| 8 | |||||||||||||||
| 9 | |||||||||||||||
| 10 | 1 | ▶ | sub _make_regex { | ||||||||||||
|
Subroutine
_make_regex: called CC=1 SCAR=0.0
| |||||||||||||||
| 11 | 1 | my $date_re = '(\d{4}) : (\d{2}) : (\d{2})'; | |||||||||||||
| 12 | 1 | my $time_re = '(\d{2}) : (\d{2}) : (\d{2} (?: \. \d{1,9})?)'; | |||||||||||||
| 13 | 1 | my $tz_re = '(Z | [\+\-] \d{2} : \d{2})'; | |||||||||||||
| 14 | 1 | return qr/^ $date_re \s $time_re $tz_re? $/xms; | |||||||||||||
| 15 | } | ||||||||||||||
| 16 | |||||||||||||||
| 17 | |||||||||||||||
| 18 | 1 | ▶ | use DateTime::Format::Builder ( | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 19 | 1 | parsers => { | |||||||||||||
| 20 | parse_datetime => [ | ||||||||||||||
| 21 | { | ||||||||||||||
| 22 | params => [ qw( year month day hour minute second time_zone ) ], | ||||||||||||||
| 23 | regex => _make_regex(), | ||||||||||||||
| 24 | postprocess => \&_postprocess, | ||||||||||||||
| 25 | }, | ||||||||||||||
| 26 | ], | ||||||||||||||
| 27 | }, | ||||||||||||||
| 28 | 1 | ); | |||||||||||||
| 29 | |||||||||||||||
| 30 | |||||||||||||||
| 31 | 7 | ▶ | sub _postprocess { | ||||||||||||
|
Subroutine
_postprocess: called CC=4 SCAR=13.9
| |||||||||||||||
| 32 | 7 | my %args = @_; | |||||||||||||
| 33 | 7 | my ($date, $p) = @args{qw( input parsed )}; | |||||||||||||
| 34 | |||||||||||||||
| 35 | # timezone | ||||||||||||||
| 36 | 7 | ▶ | if (!$p->{time_zone}) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 37 | 3 | $p->{time_zone} = 'floating'; | |||||||||||||
| 38 | } | ||||||||||||||
| 39 | elsif ($p->{time_zone} eq 'Z') { | ||||||||||||||
| 40 | 2 | $p->{time_zone} = 'UTC'; | |||||||||||||
| 41 | } | ||||||||||||||
| 42 | |||||||||||||||
| 43 | # nanoseconds | ||||||||||||||
| 44 | 7 | my ($s, $fs) = split /(?=\.)/x => $p->{second}; | |||||||||||||
| 45 | 7 | $p->{second} = $s; | |||||||||||||
| 46 | 7 | ▶ | $p->{nanosecond} = int($fs * 1e9) if $fs; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 47 | |||||||||||||||
| 48 | 7 | return $date; | |||||||||||||
| 49 | } | ||||||||||||||
| 50 | |||||||||||||||
| 51 | |||||||||||||||
| 52 | 1 | 1; | |||||||||||||
| 53 | |||||||||||||||
| 54 | __END__ | ||||||||||||||