]> git.eshelyaron.com Git - emacs.git/commitdiff
Do not limit current-time-string to years 1000..9999.
authorPaul Eggert <eggert@cs.ucla.edu>
Thu, 3 May 2012 20:04:29 +0000 (13:04 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Thu, 3 May 2012 20:04:29 +0000 (13:04 -0700)
* src/editfns.c (TM_YEAR_IN_ASCTIME_RANGE): Remove.
(Fcurrent_time_string): Support any year that is supported by the
underlying localtime representation.  Don't use asctime, as it
has undefined behavior for years outside the range -999..9999.
* doc/lispref/os.texi (Time of Day): Do not limit current-time-string
to years 1000..9999.
* etc/NEWS: Do not limit current-time-string to years 1000..9999.

doc/lispref/ChangeLog
doc/lispref/os.texi
etc/ChangeLog
etc/NEWS
src/ChangeLog
src/editfns.c

index c3eadfc85584cc4c29edf46de9bc0fe7be431985..3be41afe97552f88d41e917de20ce55ef913a702 100644 (file)
@@ -1,3 +1,8 @@
+2012-05-03  Paul Eggert  <eggert@cs.ucla.edu>
+
+       * os.texi (Time of Day): Do not limit current-time-string
+       to years 1000..9999.
+
 2012-05-02  Chong Yidong  <cyd@gnu.org>
 
        * display.texi (Font Lookup):
index d825a3f18c4b6f59941480f9f84219c39b9c3718..0fdb3e206943b140050e3140309c6fd1cb085985 100644 (file)
@@ -1196,11 +1196,14 @@ sections.
 
 @defun current-time-string &optional time-value
 This function returns the current time and date as a human-readable
-string.  The format of the string is unvarying; the number of
-characters used for each part is always the same, so you can reliably
-use @code{substring} to extract pieces of it.  You should count
+string.  The format does not vary for the initial part of the string,
+which contains the day of week, month, day of month, and time of day
+in that order: the number of characters used for these fields is
+always the same, so you can reliably
+use @code{substring} to extract them.  You should count
 characters from the beginning of the string rather than from the end,
-as additional information may some day be added at the end.
+as the year might not have exactly four digits, and additional
+information may some day be added at the end.
 
 The argument @var{time-value}, if given, specifies a time to format
 (represented as a list of integers), instead of the current time.
@@ -2301,7 +2304,7 @@ the notification never expires.  Default value is -1.
 @item :urgency @var{urgency}
 The urgency level.  It can be @code{low}, @code{normal}, or @code{critical}.
 
-@item :action-items 
+@item :action-items
 When this keyword is given, the @var{title} string of the actions is
 interpreted as icon name.
 
index f34e5d6d6885809c6b8662ce9dc6e7f8e8968c82..2a6cd7192204ef7d6f80851f3cfa614791c01365 100644 (file)
@@ -1,3 +1,7 @@
+2012-05-03  Paul Eggert  <eggert@cs.ucla.edu>
+
+       * NEWS: Do not limit current-time-string to years 1000..9999.
+
 2012-04-27  Jambunathan K  <kjambunathan@gmail.com>
 
        * org/OrgOdtStyles.xml (OrgDescriptionList): Modify style.  With
index cd15273c3dbfab346440c6be78258aaf6b2c1e2f..a9e4a7832edcf26aa33676f3d2c130d8df1ac7f9 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -197,6 +197,12 @@ in the presence of quoting, such as file completion in shell buffers.
 
 *** New function `completion-table-subvert' to use an existing completion
 table, but with a different prefix.
+
+** Time
+
+*** `current-time-string' no longer requires that its argument's year
+must be in the range 1000..9999.  It now works with any year supported
+by the underlying C implementation.
 \f
 * Changes in Emacs 24.2 on non-free operating systems
 
index bf297616e8234b5b08edb9cb227878ce93994740..2c2902e937ac70252de2e8b5bb8e54bd07f7d6cd 100644 (file)
@@ -1,3 +1,11 @@
+2012-05-03  Paul Eggert  <eggert@cs.ucla.edu>
+
+       Do not limit current-time-string to years 1000..9999.
+       * editfns.c (TM_YEAR_IN_ASCTIME_RANGE): Remove.
+       (Fcurrent_time_string): Support any year that is supported by the
+       underlying localtime representation.  Don't use asctime, as it
+       has undefined behavior for years outside the range -999..9999.
+
 2012-05-02  Paul Eggert  <eggert@cs.ucla.edu>
 
        Fix race conditions involving setenv, gmtime, localtime, asctime.
index b52bc0c2a9979e500c0d8f59f4ae22e77c5b5ba9..d266ca9951d4df831003efd4bef3a4fcf2108bb8 100644 (file)
@@ -73,13 +73,6 @@ extern char **environ;
 
 #define TM_YEAR_BASE 1900
 
-/* Nonzero if TM_YEAR is a struct tm's tm_year value that causes
-   asctime to have well-defined behavior.  */
-#ifndef TM_YEAR_IN_ASCTIME_RANGE
-# define TM_YEAR_IN_ASCTIME_RANGE(tm_year) \
-    (1000 - TM_YEAR_BASE <= (tm_year) && (tm_year) <= 9999 - TM_YEAR_BASE)
-#endif
-
 #ifdef WINDOWSNT
 extern Lisp_Object w32_get_internal_run_time (void);
 #endif
@@ -1943,29 +1936,37 @@ but this is considered obsolete.  */)
 {
   time_t value;
   struct tm *tm;
-  char *tem = NULL;
-  char buf[sizeof "Mon Apr 30 12:49:17 2012" - 1];
+  char buf[sizeof "Mon Apr 30 12:49:17 " + INT_STRLEN_BOUND (int) + 1];
+  int len IF_LINT (= 0);
 
   if (! lisp_time_argument (specified_time, &value, NULL))
     error ("Invalid time specification");
 
-  /* Convert to a string, checking for out-of-range time stamps.
-     Omit the trailing newline.
-     Don't use 'ctime', as that might dump core if VALUE is out of
-     range.  */
+  /* Convert to a string in ctime format, except without the trailing
+     newline, and without the 4-digit year limit.  Don't use asctime
+     or ctime, as they might dump core if the year is outside the
+     range -999 .. 9999.  */
   BLOCK_INPUT;
   tm = localtime (&value);
-  if (tm && TM_YEAR_IN_ASCTIME_RANGE (tm->tm_year))
+  if (tm)
     {
-      tem = asctime (tm);
-      if (tem)
-       memcpy (buf, tem, sizeof buf);
+      static char const wday_name[][4] =
+       { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
+      static char const mon_name[][4] =
+       { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
+         "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
+      printmax_t year_base = TM_YEAR_BASE;
+
+      len = sprintf (buf, "%s %s%3d %02d:%02d:%02d %"pMd,
+                    wday_name[tm->tm_wday], mon_name[tm->tm_mon], tm->tm_mday,
+                    tm->tm_hour, tm->tm_min, tm->tm_sec,
+                    tm->tm_year + year_base);
     }
   UNBLOCK_INPUT;
-  if (! tem)
+  if (! tm)
     time_overflow ();
 
-  return make_unibyte_string (buf, sizeof buf);
+  return make_unibyte_string (buf, len);
 }
 
 /* Yield A - B, measured in seconds.