From decdf6ec49194e5c02fa42c3a235bdefee224175 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sat, 12 Apr 2008 20:37:28 -0400 Subject: [PATCH] ts improvements * ts: Allow both -r and a format to be specified, to parse dates and output in a specified format. * ts: Fix bug in timezone regexp. --- debian/changelog | 3 +++ ts | 10 ++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/debian/changelog b/debian/changelog index d9fdf39..ffa7f5b 100644 --- a/debian/changelog +++ b/debian/changelog @@ -6,6 +6,9 @@ moreutils (0.29) UNRELEASED; urgency=low rather than write(). * sponge: Handle large data sizes by using a temp file rather than by consuming arbitrary amounts of memory. Patch by Brock Noland. + * ts: Allow both -r and a format to be specified, to parse dates and output + in a specified format. + * ts: Fix bug in timezone regexp. -- Joey Hess Thu, 20 Mar 2008 12:56:42 -0400 diff --git a/ts b/ts index d1cbb16..d8d8719 100755 --- a/ts +++ b/ts @@ -20,6 +20,9 @@ the input to relative times, such as "15m5s ago". Many common timestamp formats are supported. Note that the Time::Duration and Date::Parse perl modules are required for this mode to work. +If both -r and a format is passed, the format existing timestamps are +converted to the specified format. + =head1 ENVIRONMENT The standard TZ environment variable controls what time zone dates @@ -51,6 +54,7 @@ if ($rel) { die $@ if $@; } +my $use_format=@ARGV; my $format="%b %d %H:%M:%S"; $format=shift if @ARGV; @@ -73,14 +77,16 @@ while (<>) { (?:\w\w\w,?\s+)? # (optional Day) \d+\s+\w\w\w\s+\d\d+\s+\d\d:\d\d:\d\d # 16 Jun 94 07:29:35 - (?:\s+\w\w\w|\s+-\d\d\d\d)? + (?:\s+\w\w\w|\s[+-]\d\d\d\d)? # (optional timezone) | \w\w\w\s+\w\w\w\s+\d\d\s+\d\d:\d\d # lastlog format )\b }{ - concise(ago(time - str2time($1), 2)) + $use_format + ? strftime($format, localtime(str2time($1))) + : concise(ago(time - str2time($1), 2)) }exg; print $_; -- 2.11.4.GIT