emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] /srv/bzr/emacs/trunk r108116: Do not limit current-time-st


From: Paul Eggert
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r108116: Do not limit current-time-string to years 1000..9999.
Date: Thu, 03 May 2012 13:04:29 -0700
User-agent: Bazaar (2.3.1)

------------------------------------------------------------
revno: 108116
committer: Paul Eggert <address@hidden>
branch nick: trunk
timestamp: Thu 2012-05-03 13:04:29 -0700
message:
  Do not limit current-time-string to years 1000..9999.
  
  * 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.
modified:
  doc/lispref/ChangeLog
  doc/lispref/os.texi
  etc/ChangeLog
  etc/NEWS
  src/ChangeLog
  src/editfns.c
=== modified file 'doc/lispref/ChangeLog'
--- a/doc/lispref/ChangeLog     2012-05-02 13:00:29 +0000
+++ b/doc/lispref/ChangeLog     2012-05-03 20:04:29 +0000
@@ -1,3 +1,8 @@
+2012-05-03  Paul Eggert  <address@hidden>
+
+       * os.texi (Time of Day): Do not limit current-time-string
+       to years 1000..9999.
+
 2012-05-02  Chong Yidong  <address@hidden>
 
        * display.texi (Font Lookup):

=== modified file 'doc/lispref/os.texi'
--- a/doc/lispref/os.texi       2012-04-24 17:56:30 +0000
+++ b/doc/lispref/os.texi       2012-05-03 20:04:29 +0000
@@ -1196,11 +1196,14 @@
 
 @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 @@
 @item :urgency @var{urgency}
 The urgency level.  It can be @code{low}, @code{normal}, or @code{critical}.
 
address@hidden :action-items 
address@hidden :action-items
 When this keyword is given, the @var{title} string of the actions is
 interpreted as icon name.
 

=== modified file 'etc/ChangeLog'
--- a/etc/ChangeLog     2012-04-27 06:08:14 +0000
+++ b/etc/ChangeLog     2012-05-03 20:04:29 +0000
@@ -1,3 +1,7 @@
+2012-05-03  Paul Eggert  <address@hidden>
+
+       * NEWS: Do not limit current-time-string to years 1000..9999.
+
 2012-04-27  Jambunathan K  <address@hidden>
 
        * org/OrgOdtStyles.xml (OrgDescriptionList): Modify style.  With

=== modified file 'etc/NEWS'
--- a/etc/NEWS  2012-05-02 17:41:21 +0000
+++ b/etc/NEWS  2012-05-03 20:04:29 +0000
@@ -197,6 +197,12 @@
 
 *** 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.
 
 * Changes in Emacs 24.2 on non-free operating systems
 

=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2012-05-02 23:25:46 +0000
+++ b/src/ChangeLog     2012-05-03 20:04:29 +0000
@@ -1,3 +1,11 @@
+2012-05-03  Paul Eggert  <address@hidden>
+
+       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  <address@hidden>
 
        Fix race conditions involving setenv, gmtime, localtime, asctime.

=== modified file 'src/editfns.c'
--- a/src/editfns.c     2012-05-02 23:25:46 +0000
+++ b/src/editfns.c     2012-05-03 20:04:29 +0000
@@ -73,13 +73,6 @@
 
 #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 @@
 {
   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.


reply via email to

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