diff options
author | Joey Hess <joey@kodama.kitenet.net> | 2008-04-12 20:37:28 -0400 |
---|---|---|
committer | Joey Hess <joey@kodama.kitenet.net> | 2008-04-12 20:37:28 -0400 |
commit | decdf6ec49194e5c02fa42c3a235bdefee224175 (patch) | |
tree | 5a7508ea50ac5cfcf865d0222ab99d23d131363e /ts | |
parent | c525af9d17aacb226d72495d1bd401ce001b03f6 (diff) | |
download | moreutils-decdf6ec49194e5c02fa42c3a235bdefee224175.tar.gz |
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.
Diffstat (limited to 'ts')
-rwxr-xr-x | ts | 10 |
1 files changed, 8 insertions, 2 deletions
@@ -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 $_; |