| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Data::Sah::Format::perl::iso8601_datetime; | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | our $DATE = '2016-06-17'; # DATE | 
| 4 |  |  |  |  |  |  | our $VERSION = '0.002'; # VERSION | 
| 5 |  |  |  |  |  |  |  | 
| 6 | 1 |  |  | 1 |  | 22 | use 5.010001; | 
|  | 1 |  |  |  |  | 2 |  | 
| 7 | 1 |  |  | 1 |  | 4 | use strict; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 16 |  | 
| 8 | 1 |  |  | 1 |  | 3 | use warnings; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 126 |  | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | sub format { | 
| 11 | 5 |  |  | 5 | 0 | 9 | my %args = @_; | 
| 12 |  |  |  |  |  |  |  | 
| 13 | 5 |  |  |  |  | 5 | my $dt    = $args{data_term}; | 
| 14 | 5 |  | 100 |  |  | 18 | my $fargs = $args{args} // {}; | 
| 15 |  |  |  |  |  |  |  | 
| 16 | 5 |  | 100 |  |  | 14 | my $format_datetime   = $fargs->{format_datetime} // 1; | 
| 17 | 5 |  | 100 |  |  | 12 | my $format_timemoment = $fargs->{format_timemoment} // 1; | 
| 18 |  |  |  |  |  |  |  | 
| 19 | 5 |  |  |  |  | 5 | my $res = {}; | 
| 20 |  |  |  |  |  |  |  | 
| 21 | 5 | 100 |  |  |  | 26 | $res->{expr} = join( | 
|  |  | 100 |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | "", | 
| 23 |  |  |  |  |  |  | "$dt =~ /\\A\\d+(\\.\\d+)?\\z/ ? do { my \@t = gmtime($dt); sprintf('%04d-%02d-%02dT%02d:%02d:%02dZ', \$t[5]+1900, \$t[4]+1, \$t[3], \$t[2], \$t[1], \$t[0]) } : ", | 
| 24 |  |  |  |  |  |  | ($format_datetime ? | 
| 25 |  |  |  |  |  |  | # convert to UTC first | 
| 26 |  |  |  |  |  |  | "ref($dt) eq 'DateTime' ? DateTime->from_epoch(epoch => $dt\->epoch)->iso8601 . 'Z' : " : ""), | 
| 27 |  |  |  |  |  |  | ($format_timemoment ? | 
| 28 |  |  |  |  |  |  | "ref($dt) eq 'Time::Moment' ? $dt\->at_utc->strftime('%Y-%m-%dT%H:%M:%SZ') : " : ""), | 
| 29 |  |  |  |  |  |  | $dt, | 
| 30 |  |  |  |  |  |  | ); | 
| 31 |  |  |  |  |  |  |  | 
| 32 | 5 |  |  |  |  | 12 | $res; | 
| 33 |  |  |  |  |  |  | } | 
| 34 |  |  |  |  |  |  |  | 
| 35 |  |  |  |  |  |  | 1; | 
| 36 |  |  |  |  |  |  | # ABSTRACT: Format date as ISO8601 datetime (e.g. 2016-06-13T03:08:00Z) | 
| 37 |  |  |  |  |  |  |  | 
| 38 |  |  |  |  |  |  | __END__ |