summaryrefslogtreecommitdiff
path: root/unixtime.pl
diff options
context:
space:
mode:
authorLuke Bratch <luke@bratch.co.uk>2017-07-12 16:18:51 +0100
committerLuke Bratch <luke@bratch.co.uk>2017-07-12 16:18:51 +0100
commit98f8672608b600524a5abf360d9b65fdcb4e1cbd (patch)
treeb0ed1bffcc2920bc5fc2027d9d45c84e30e5a046 /unixtime.pl
parent347936a79b7e326083559ec8614df1c26a829558 (diff)
parent140c8fc8020f677c9326103a7cb718ae482e0226 (diff)
Merge branch 'irc-input-fix' into 'master' HEADmaster
Irc input fix Handles IRC input where the arguments are received as a single string, regardless of spaces. If there is one argument it will split it on spaces. See merge request !2
Diffstat (limited to 'unixtime.pl')
-rwxr-xr-xunixtime.pl19
1 files changed, 13 insertions, 6 deletions
diff --git a/unixtime.pl b/unixtime.pl
index f47cf9f..e75a786 100755
--- a/unixtime.pl
+++ b/unixtime.pl
@@ -2,21 +2,28 @@
use POSIX qw( strftime );
use Time::HiRes qw( gettimeofday );
-if (defined $ARGV[0]) {
- if ($ARGV[1] eq "ms") {
+#Handle IRC input, multiple words is received as one argument
+if (@ARGV eq 1) {
+ @args = split(/ /, $ARGV[0]);
+} else {
+ @args = @ARGV;
+}
+
+if (defined $args[0] and $args[0] ne "") {
+ if ($args[1] eq "ms") {
#Convert from timestamp in milliseconds to date
- $seconds = substr $ARGV[0], 0, 10;
- $milliseconds = substr $ARGV[0], 10, 3;
+ $seconds = substr $args[0], 0, -3;
+ $milliseconds = substr $args[0], -3;
$date = strftime('%a %b %e %H:%M:%S:' . $milliseconds . ' %Z %Y', localtime( $seconds ) ) . "\n";
print $date;
- } elsif ($ARGV[0] eq "ms") {
+ } elsif ($args[0] eq "ms") {
#Print current millisecond unix timestamp
($seconds, $microseconds) = gettimeofday;
$milliseconds = substr $microseconds, 0, 3;
print $seconds . $milliseconds . "\n";
} else {
#Convert standard unix timestamp to date
- print strftime('%a %b %e %H:%M:%S %Z %Y', localtime( $ARGV[0] ) ) . "\n";
+ print strftime('%a %b %e %H:%M:%S %Z %Y', localtime( $args[0] ) ) . "\n";
}
} else {
#Print current standard unix timestamp