Skip to content

Commit

Permalink
Show unix time along with formatted date
Browse files Browse the repository at this point in the history
  • Loading branch information
hoytech committed Oct 11, 2013
1 parent 6bd746c commit d3e333d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
1 change: 1 addition & 0 deletions Changes
@@ -1,4 +1,5 @@
* Fix bug in date formatting (thanks Mike R)
* Show unix time along with formatted date

0.310 2013-09-01
* Don't die on log lines that don't start with JSON
Expand Down
18 changes: 9 additions & 9 deletions bin/log-defer-viz
Expand Up @@ -226,31 +226,31 @@ sub handle_entry {
}

if ($opt->{date}) {
my $datetime = '';
my $formatted = '';

if ($opt->{'since-now'}) {
require Date::Calc;

my $elapsed = int(time - $entry->{start});

if ($elapsed <= 0) {
$datetime = abs($elapsed) . " seconds in the future.. clock is wrong?";
$formatted = abs($elapsed) . " seconds in the future.. clock is wrong?";
} else {
my ($Dd,$Dh,$Dm,$Ds) = Date::Calc::Normalize_DHMS(0, 0, 0, int(time - $entry->{start}));
$datetime .= "$Dd days " if $Dd;
$datetime .= "$Dh hours " if $Dh;
$datetime .= "$Dm minutes " if $Dm;
$datetime .= "$Ds seconds " if $Ds;
$formatted .= "$Dd days " if $Dd;
$formatted .= "$Dh hours " if $Dh;
$formatted .= "$Dm minutes " if $Dm;
$formatted .= "$Ds seconds " if $Ds;

$datetime .= "ago";
$formatted .= "ago";
}
} else {
require Date::Format;

$datetime = Date::Format::time2str("%Y-%m-%d %a %H:%M:%S$millis %Z", $entry->{start});
$formatted = Date::Format::time2str("%Y-%m-%d %a %H:%M:%S$millis %Z", $entry->{start});
}

my $date_header = "------ " . $datetime . " ------";
my $date_header = "------ $formatted ($entry->{start}) ------";

$date_header = colored($date_header, 'black on_white') if $opt->{colour};

Expand Down

0 comments on commit d3e333d

Please sign in to comment.