bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Eternal September support for date


From: Jaakko Kangasharju
Subject: [PATCH] Eternal September support for date
Date: Wed, 25 Jun 2003 22:34:44 +0300
User-agent: Gnus/5.1002 (Gnus v5.10.2) Emacs/21.3 (gnu/linux)

Hello coreutils maintainers,

You may know of a Usenet custom of referring to September 1993 as "the
September that never ended" and sometimes even expressing dates as if
this were true (so today would be the 3585th of September 1993).  To
my surprise, the only program implementing this that I could find was
a simple perl script that did not understand e.g. timezones or output
formats.

To fix the situation, I patched GNU date to have a command-line option
to print the date as if it were September 1993.  I include the patch
(against coreutils 5.0, the latest version I found) below.  I admit
this is a silly feature, but it is also small and non-intrusive, so I
thought it could be included for wider distribution.

I will follow the mailing list through the archives, but since I am
not subscribed to bug-coreutils, please CC me on anything sent to the
list that needs my attention.



diff --unified --recursive coreutils-5.0/src/date.c 
coreutils-5.0.changed/src/date.c
--- coreutils-5.0/src/date.c    2002-12-15 22:47:03.000000000 +0200
+++ coreutils-5.0.changed/src/date.c    2003-06-25 19:45:03.000000000 +0300
@@ -76,7 +76,10 @@
 /* If non-zero, display time in RFC-(2)822 format for mail or news. */
 static int rfc_format = 0;
 
-#define COMMON_SHORT_OPTIONS "Rd:f:r:s:u"
+/* If non-zero, display time according to Usenet custom (in Sep 1993) */
+static int september = 0;
+
+#define COMMON_SHORT_OPTIONS "RSd:f:r:s:u"
 
 static struct option const long_options[] =
 {
@@ -85,6 +88,7 @@
   {"iso-8601", optional_argument, NULL, 'I'},
   {"reference", required_argument, NULL, 'r'},
   {"rfc-822", no_argument, NULL, 'R'},
+  {"september", no_argument, NULL, 'S'},
   {"set", required_argument, NULL, 's'},
   {"uct", no_argument, NULL, 'u'},
   {"utc", no_argument, NULL, 'u'},
@@ -133,6 +137,7 @@
       fputs (_("\
   -r, --reference=FILE      display the last modification time of FILE\n\
   -R, --rfc-822             output RFC-822 compliant date string\n\
+  -S, --september           output date as if September 1993 never ended\n\
   -s, --set=STRING          set time described by STRING\n\
   -u, --utc, --universal    print or set Coordinated Universal Time\n\
 "), stdout);
@@ -334,6 +339,9 @@
       case 'R':
        rfc_format = 1;
        break;
+      case 'S':
+       september = 1;
+       break;
       case 's':
        set_datestr = optarg;
        set_date = 1;
@@ -497,6 +505,35 @@
 
   tm = localtime (&when.tv_sec);
 
+  /* Correct time, if so wanted, according to Usenet custom.  Don't
+     bother if tm is NULL (I understand this is possible, although
+     unlikely. */
+  if (september && tm)
+    {
+      /* This needs to be in order Dec, Jan, Feb, ..., Oct, Nov
+        because mondays[i] is the number of days to add when we go
+        from month i to i-1 (mod 12, of course). */
+      int mondays[] = { 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30 };
+      while (tm->tm_year > 94 || (tm->tm_year == 94 && tm->tm_mon >= 8))
+       {
+         int leapyear = tm->tm_year--;
+         if (tm->tm_mon < 2)
+           leapyear--;
+         tm->tm_mday += 365 + (leapyear % 4 == 0
+                               && (leapyear % 100 != 0
+                                   || (leapyear - 100) % 400 == 0));
+       }
+      if (tm->tm_year == 94)
+       {
+         while (tm->tm_mon >= 0)
+           tm->tm_mday += mondays[tm->tm_mon--];
+         tm->tm_year = 93;
+         tm->tm_mon = 11;
+       }
+      while (tm->tm_mon > 8)
+       tm->tm_mday += mondays[tm->tm_mon--];
+    }
+
   if (format == NULL)
     {
       if (rfc_format)


-- 
Jaakko Kangasharju
A good programmer is worth his weight in salt




reply via email to

[Prev in Thread] Current Thread [Next in Thread]