Hello,
I wrote a simple patch to GNU "date" (based on sh-utils 2.0) to change the
formatting slightly.
Basically, if the environmental variable DATE_DEFAULT_FORMAT is unset, then
the behaviour is as normal. If DATE_DEFAULT_FORMAT is set, then that format
will be used instead of the default one if date has no arguments given to
it.
The reason this is useful is because it's otherwise rather hard to get this
behavior. One can make an shell alias, but then you break trying to give
date an explicit format, like `date +"%s"`
The patch is very simple, a 54 line unified diff (about 1 new line and 4
changed lines), and I have put it into the public domain. Hopefully it's
short enough that if you want to include it in sh-utils, copyright transfer
forms will not be required.
Regards,
Jack
--- date-orig.c Sun Aug 1 06:59:22 1999
+++ date.c Tue Oct 9 14:49:17 2001
@@ -305,6 +305,7 @@
time_t when;
int set_date = 0;
char *format;
+ char *default_format;
char *batch_file = NULL;
char *reference = NULL;
struct stat refstats;
@@ -360,6 +361,8 @@
+ (batch_file ? 1 : 0)
+ (reference ? 1 : 0));
+ default_format = getenv("DATE_DEFAULT_FORMAT");
+
if (option_specified_date > 1)
{
error (0, 0,
@@ -397,7 +400,7 @@
if (batch_file != NULL)
{
status = batch_convert (batch_file,
- (n_args == 1 ? argv[optind] + 1 : NULL));
+ (n_args == 1 ? argv[optind] + 1 : default_format));
}
else
{
@@ -413,14 +416,14 @@
datestr = argv[optind];
when = posixtime (datestr,
PDS_TRAILING_YEAR | PDS_CENTURY | PDS_SECONDS);
- format = NULL;
+ format = default_format;
}
else
{
/* Prepare to print the current date/time. */
datestr = _("undefined");
time (&when);
- format = (n_args == 1 ? argv[optind] + 1 : NULL);
+ format = (n_args == 1 ? argv[optind] + 1 : default_format);
}
}
else
@@ -437,7 +440,7 @@
when = get_date (datestr, NULL);
}
- format = (n_args == 1 ? argv[optind] + 1 : NULL);
+ format = (n_args == 1 ? argv[optind] + 1 : default_format);
}
if (when == -1)