summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoey Hess <joey@kitenet.net>2011-04-01 14:36:03 -0400
committerJoey Hess <joey@kitenet.net>2011-04-01 14:36:03 -0400
commitbb190ff90f192cb50c086abec11459ab09c205f1 (patch)
tree02be03c33ec08e18c1b45da0080ebee318b5a6e0
parentc27365c4f2a7e42841aef3f53b9316b4aaab730a (diff)
downloadmoreutils-bb190ff90f192cb50c086abec11459ab09c205f1.tar.gz
ts: Support %.s for seconds sinch epoch with subsecond resolution. Closes: #619764
-rw-r--r--debian/changelog7
-rwxr-xr-xts11
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 <joeyh@debian.org> 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<strftime(3)>. 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 {