summaryrefslogtreecommitdiff
path: root/mdate.pl
diff options
context:
space:
mode:
authorColin Watson <cjwatson@debian.org>2018-03-09 12:27:37 +0000
committerColin Watson <cjwatson@debian.org>2018-03-09 12:30:24 +0000
commit677274dafc5dd5f79f2a6d16270b21d2f5a16c5b (patch)
tree1c69f440e0be58324b76385d630fcf1c87e41586 /mdate.pl
parent459c1ad4e2fd1e0ee220e739cd5530699cf6b6bf (diff)
downloadgroff-git-677274dafc5dd5f79f2a6d16270b21d2f5a16c5b.tar.gz
mdate.sh: rewrite in Perl
groff already requires perl to build. This version is much shorter and easier to understand than the shell/awk version: we don't have to worry about convincing ls to produce output that we can parse, and we don't have to play games with the way that the same field may contain either the year or the time depending on how old the file is. While I'm at it, this version also adds `SOURCE_DATE_EPOCH' support for reproducible builds: when `SOURCE_DATE_EPOCH' is set, files are considered to have been last modified at that time. * mdate.sh: Rewrite in Perl, moving to ... * mdate.pl: ... this new file. * Makefile.am (EXTRA_DIST, .man): Update references.
Diffstat (limited to 'mdate.pl')
-rwxr-xr-xmdate.pl32
1 files changed, 32 insertions, 0 deletions
diff --git a/mdate.pl b/mdate.pl
new file mode 100755
index 000000000..94499e7cf
--- /dev/null
+++ b/mdate.pl
@@ -0,0 +1,32 @@
+#! /usr/bin/env perl
+#
+# Copyright (C) 1991-2017 Free Software Foundation, Inc.
+#
+# This file is part of groff.
+#
+# groff is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# groff is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# Print the modification date of $1 `nicely'.
+
+use warnings;
+use strict;
+use POSIX qw(LC_ALL setlocale strftime);
+
+# Don't want localized dates.
+setlocale(LC_ALL, "C");
+
+my @mtime = gmtime($ENV{SOURCE_DATE_EPOCH} || (stat $ARGV[0])[9]);
+my $mdate = strftime("%e %B %Y", @mtime);
+$mdate =~ s/^ //;
+print "$mdate\n";