in reply to Re^2: Detecting whether DateTime object has a time component or not? (updated)
in thread Detecting whether DateTime object has a time component or not?
Yup, I ended up looking at the original data, which fortunately are also available.
That's good! Here's how I might have done it:
use warnings; use strict; use DateTime::Format::Strptime; my $strp = DateTime::Format::Strptime->new(on_error=>'croak', pattern=>'%Y%m%dT%H:%M:%S', time_zone=>'UTC'); while (<DATA>) { chomp; my $dt; if ($_ eq 'today') { $dt = DateTime->now->truncate( to => 'day' ) ->set( hour=>23, minute=>59, second=>59 ) } elsif ($_ eq 'now') { $dt = DateTime->now } else { $_ .= "T23:59:59" if /^\d{8}$/; $dt = $strp->parse_datetime($_) } print "$_ => ",$dt->strftime('%Y-%m-%d %H:%M:%S %Z'),"\n"; } __DATA__ 20170616T15:30:53 20170616 now today
|
|---|