diff options
author | Andreas Gruenbacher <agruen@suse.de> | 2006-02-01 12:28:29 +0000 |
---|---|---|
committer | Andreas Gruenbacher <agruen@suse.de> | 2006-02-01 12:28:29 +0000 |
commit | 882ab0adfcf900abab9aa3df22fb7051df058a22 (patch) | |
tree | c3bcb7752d7ce593decb5fc93bf34b06c56e0e4e /compat | |
parent | 2f9728a96276570abdcf3420f27ce03af0feddea (diff) | |
download | quilt-882ab0adfcf900abab9aa3df22fb7051df058a22.tar.gz |
- configure.ac: Remove uniq -D test; we no longer use it.
- compat/date.in: Compatibility wrapper that emulates the GNU
date features that quilt depends on (with minor cleanups from
Andreas Gruenbacher).
- configure.ac: Add test for date --rfc-822.
Diffstat (limited to 'compat')
-rw-r--r-- | compat/date.in | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/compat/date.in b/compat/date.in new file mode 100644 index 0000000..aaa2c6d --- /dev/null +++ b/compat/date.in @@ -0,0 +1,60 @@ +#! @PERL@ -w + +# This script is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. +# +# See the COPYING and AUTHORS files for more details. + +use strict; +use POSIX qw(strftime); +use Getopt::Long; +use Date::Parse; + +my $spec = '%a %b %e %H:%M:%S %Z %Y'; +my $now = time(); +my $utc = 0; + +sub usage() { + print "Usage: date [OPTION]... [+FORMAT] +Display the current time in the given FORMAT. + + -d, --date=STRING display time described by STRING, not `now' + -f, --file=DATEFILE like --date once for each line of DATEFILE + -R, --rfc-822 output RFC-822 compliant date string + -u, --utc, --universal print or set Coordinated Universal Time + --help display this help and exit +"; + exit 1; +} + +sub parse_utc_secs($) { + my ($now) = @_; + + if ($now =~ / UTC ([0-9]+) seconds$/) { + # This is an heuristic specifically for quilts mail.in invocation: + # date --rfc-822 -d "1970/01/01 UTC nnnnnnnn seconds" + return $1; + } + else { + return str2time($now); + } +} + +Getopt::Long::Configure("gnu_getopt"); + +GetOptions('rfc-822|R' => sub() { $spec = '%a, %d %b %Y %H:%M:%S %z' }, + 'utc|universal|u' => \$utc, + 'date|d=s' => sub() { $now = parse_utc_secs($_[1]) }, + 'help|h' => sub() { usage }) + or usage; + +if (@ARGV == 1 && $ARGV[0] =~ /^\+/) { + $spec = substr($ARGV[0], 1); +} elsif (@ARGV > 1) { + usage; +} + +my @now = $utc ? gmtime($now) : localtime($now); + +print strftime($spec, @now) . "\n"; |