Last active
January 18, 2019 00:19
-
-
Save miyagawa/4ec107552f3457236f80f40c202c52b4 to your computer and use it in GitHub Desktop.
Convert local timestamps in text to UTC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use DateTime; | |
use Date::Parse qw(str2time); | |
my $pattern = qr/\d?\d:\d\d(:\d\d)?(?: ?[aApP][mM])?/; | |
while (<>) { | |
s/$pattern/utc(str2time($&), $1)/eg; | |
print; | |
} | |
sub utc { | |
my($epoch, $sec) = @_; | |
my $utc = DateTime->from_epoch( | |
epoch => $epoch, | |
time_zone => "UTC", | |
); | |
$utc->strftime( defined $sec ? "%H:%M:%S" : "%H:%M" ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment