From bb190ff90f192cb50c086abec11459ab09c205f1 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 1 Apr 2011 14:36:03 -0400 Subject: [PATCH] ts: Support %.s for seconds sinch epoch with subsecond resolution. Closes: #619764 --- debian/changelog | 7 +++++++ ts | 11 ++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/debian/changelog b/debian/changelog index d908784..3b4069c 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +moreutils (0.45) UNRELEASED; urgency=low + + * ts: Support %.s for seconds sinch epoch with subsecond resolution. + Closes: #619764 + + -- Joey Hess Fri, 01 Apr 2011 14:34:15 -0400 + moreutils (0.44) unstable; urgency=low * pee: Propigate exit status of commands run. diff --git a/ts b/ts index 042cc18..c3755f4 100755 --- a/ts +++ b/ts @@ -14,8 +14,9 @@ ts adds a timestamp to the beginning of each line of input. The optional format parameter controls how the timestamp is formatted, as used by L. The default format is "%b %d %H:%M:%S". In -addition to the regular strftime conversion specifications, "%.S" is -expanded to fractional seconds (ie, "30.00001"). +addition to the regular strftime conversion specifications, "%.S" and "%.s" +are like "%S" and "%s", but provide subsecond resolution +(ie, "30.00001" and "1301682593.00001"). If the -r switch is passed, it instead converts existing timestamps in the input to relative times, such as "15m5s ago". Many common timestamp @@ -61,9 +62,9 @@ my $use_format=@ARGV; my $format="%b %d %H:%M:%S"; $format=shift if @ARGV; -# For fractional seconds, Time::HiRes is needed. +# For subsecond resolution, Time::HiRes is needed. my $hires=0; -if ($format=~/\%\.S/) { +if ($format=~/\%\.[Ss]/) { require Time::HiRes; $hires=1; } @@ -74,7 +75,7 @@ while (<>) { my $f=$format; my ($seconds, $microseconds) = Time::HiRes::gettimeofday(); my $s=sprintf("%06i", $microseconds); - $f=~s/\%\.S/%S.$s/g; + $f=~s/\%\.([Ss])/%$1.$s/g; print strftime($f, localtime($seconds)); } else { -- 2.39.5