Commit ab0fa4e4 authored by Paul Eggert's avatar Paul Eggert
Browse files

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.
parent f7ae6719
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):
......
......@@ -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.
......
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
......
......@@ -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.
* Changes in Emacs 24.2 on non-free operating systems
......
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.
......
......@@ -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.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment