diff options
author | Joey Hess <joeyh@joeyh.name> | 2017-10-31 13:02:48 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2017-10-31 13:02:48 -0400 |
commit | 3d31d550ffc75f7eada0d6cb624a98423b54bbd2 (patch) | |
tree | ad554bfc1c1fe67c0e9fd6206bd0219cf6f5ff5c | |
parent | c5a0deb4fbca8d95a63374e2b2ef1ac0f87520c1 (diff) | |
download | moreutils-3d31d550ffc75f7eada0d6cb624a98423b54bbd2.tar.gz |
make -m start at current time
The mono clock is relative to some arbitrary start time, which led to a
display of a date typically close to the epoch. Fix that by getting the
current time at startup, and applying the delta between that and the
mono time.
-rwxr-xr-x | ts | 8 |
1 files changed, 5 insertions, 3 deletions
@@ -93,11 +93,13 @@ if ($format=~/\%\.[Ss]/ || $mono) { my $lastseconds = 0; my $lastmicroseconds = 0; +my $monodelta; if ($mono) { my $raw_time = Time::HiRes::clock_gettime(CLOCK_MONOTONIC); - $lastseconds = int($raw_time); - $lastmicroseconds = int(1000000 * ($raw_time - $lastseconds)); + $lastseconds = time; + $lastmicroseconds = int(1000000 * ($raw_time - int($raw_time))); + $monodelta = time - int($raw_time); } elsif ($hires) { ($lastseconds, $lastmicroseconds) = Time::HiRes::gettimeofday(); @@ -116,7 +118,7 @@ while (<>) { if ($mono) { my $raw_time = Time::HiRes::clock_gettime(CLOCK_MONOTONIC); - $seconds = int($raw_time); + $seconds = $monodelta + int($raw_time); $microseconds = int(1000000 * ($raw_time - $seconds)); } else { |