aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2011-01-31 23:23:48 -0800
committerPaul Eggert2011-01-31 23:23:48 -0800
commita4180391acf904dde6ec72bd37b8f908f69ac3e8 (patch)
tree414be2d27e23b8ec836d6eac9b0a7d96f2c5671d /src
parentabb97fbbedcd84a13bae7b7b70251514bf97cdbb (diff)
downloademacs-a4180391acf904dde6ec72bd37b8f908f69ac3e8.tar.gz
emacs-a4180391acf904dde6ec72bd37b8f908f69ac3e8.zip
format-time-string now supports subsecond time stamp resolution
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog10
-rw-r--r--src/editfns.c25
2 files changed, 26 insertions, 9 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 2353116c8bd..c0c09875121 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,13 @@
12011-02-01 Paul Eggert <eggert@cs.ucla.edu>
2
3 format-time-string now supports subsecond time stamp resolution
4 * editfns.c (emacs_nmemftime): Renamed from emacs_memftimeu,
5 for consistency with its new argument and with gnulib nstrftime.
6 All callers changed. New argument NS.
7 (Fformat_time_string): Check that the time argument's microseconds
8 component, if any, is in range; this avoids integer overflow and
9 also nstrftime needs this. Document %N.
10
12011-01-31 Andreas Schwab <schwab@linux-m68k.org> 112011-01-31 Andreas Schwab <schwab@linux-m68k.org>
2 12
3 * image.c (DEF_IMGLIB_FN): Add parameter rettype, use it instead 13 * image.c (DEF_IMGLIB_FN): Add parameter rettype, use it instead
diff --git a/src/editfns.c b/src/editfns.c
index 7364a5bcf15..1733580ee32 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -92,8 +92,8 @@ static void find_field (Lisp_Object, Lisp_Object, Lisp_Object,
92 EMACS_INT *, Lisp_Object, EMACS_INT *); 92 EMACS_INT *, Lisp_Object, EMACS_INT *);
93static void update_buffer_properties (EMACS_INT, EMACS_INT); 93static void update_buffer_properties (EMACS_INT, EMACS_INT);
94static Lisp_Object region_limit (int); 94static Lisp_Object region_limit (int);
95static size_t emacs_memftimeu (char *, size_t, const char *, 95static size_t emacs_nmemftime (char *, size_t, const char *,
96 size_t, const struct tm *, int); 96 size_t, const struct tm *, int, int);
97static void general_insert_function (void (*) (const unsigned char *, EMACS_INT), 97static void general_insert_function (void (*) (const unsigned char *, EMACS_INT),
98 void (*) (Lisp_Object, EMACS_INT, 98 void (*) (Lisp_Object, EMACS_INT,
99 EMACS_INT, EMACS_INT, 99 EMACS_INT, EMACS_INT,
@@ -1549,6 +1549,7 @@ or (if you need time as a string) `format-time-string'. */)
1549/* Write information into buffer S of size MAXSIZE, according to the 1549/* Write information into buffer S of size MAXSIZE, according to the
1550 FORMAT of length FORMAT_LEN, using time information taken from *TP. 1550 FORMAT of length FORMAT_LEN, using time information taken from *TP.
1551 Default to Universal Time if UT is nonzero, local time otherwise. 1551 Default to Universal Time if UT is nonzero, local time otherwise.
1552 Use NS as the number of nanoseconds in the %N directive.
1552 Return the number of bytes written, not including the terminating 1553 Return the number of bytes written, not including the terminating
1553 '\0'. If S is NULL, nothing will be written anywhere; so to 1554 '\0'. If S is NULL, nothing will be written anywhere; so to
1554 determine how many bytes would be written, use NULL for S and 1555 determine how many bytes would be written, use NULL for S and
@@ -1557,7 +1558,8 @@ or (if you need time as a string) `format-time-string'. */)
1557 This function behaves like nstrftime, except it allows null 1558 This function behaves like nstrftime, except it allows null
1558 bytes in FORMAT and it does not support nanoseconds. */ 1559 bytes in FORMAT and it does not support nanoseconds. */
1559static size_t 1560static size_t
1560emacs_memftimeu (char *s, size_t maxsize, const char *format, size_t format_len, const struct tm *tp, int ut) 1561emacs_nmemftime (char *s, size_t maxsize, const char *format,
1562 size_t format_len, const struct tm *tp, int ut, int ns)
1561{ 1563{
1562 size_t total = 0; 1564 size_t total = 0;
1563 1565
@@ -1574,7 +1576,7 @@ emacs_memftimeu (char *s, size_t maxsize, const char *format, size_t format_len,
1574 if (s) 1576 if (s)
1575 s[0] = '\1'; 1577 s[0] = '\1';
1576 1578
1577 result = nstrftime (s, maxsize, format, tp, ut, 0); 1579 result = nstrftime (s, maxsize, format, tp, ut, ns);
1578 1580
1579 if (s) 1581 if (s)
1580 { 1582 {
@@ -1620,6 +1622,7 @@ by text that describes the specified date and time in TIME:
1620%p is the locale's equivalent of either AM or PM. 1622%p is the locale's equivalent of either AM or PM.
1621%M is the minute. 1623%M is the minute.
1622%S is the second. 1624%S is the second.
1625%N is the nanosecond, %6N the microsecond, %3N the millisecond, etc.
1623%Z is the time zone name, %z is the numeric form. 1626%Z is the time zone name, %z is the numeric form.
1624%s is the number of seconds since 1970-01-01 00:00:00 +0000. 1627%s is the number of seconds since 1970-01-01 00:00:00 +0000.
1625 1628
@@ -1649,13 +1652,17 @@ For example, to produce full ISO 8601 format, use "%Y-%m-%dT%T%z". */)
1649{ 1652{
1650 time_t value; 1653 time_t value;
1651 int size; 1654 int size;
1655 int usec;
1656 int ns;
1652 struct tm *tm; 1657 struct tm *tm;
1653 int ut = ! NILP (universal); 1658 int ut = ! NILP (universal);
1654 1659
1655 CHECK_STRING (format_string); 1660 CHECK_STRING (format_string);
1656 1661
1657 if (! lisp_time_argument (time, &value, NULL)) 1662 if (! (lisp_time_argument (time, &value, &usec)
1663 && 0 <= usec && usec < 1000000))
1658 error ("Invalid time specification"); 1664 error ("Invalid time specification");
1665 ns = usec * 1000;
1659 1666
1660 format_string = code_convert_string_norecord (format_string, 1667 format_string = code_convert_string_norecord (format_string,
1661 Vlocale_coding_system, 1); 1668 Vlocale_coding_system, 1);
@@ -1678,9 +1685,9 @@ For example, to produce full ISO 8601 format, use "%Y-%m-%dT%T%z". */)
1678 1685
1679 buf[0] = '\1'; 1686 buf[0] = '\1';
1680 BLOCK_INPUT; 1687 BLOCK_INPUT;
1681 result = emacs_memftimeu (buf, size, SSDATA (format_string), 1688 result = emacs_nmemftime (buf, size, SSDATA (format_string),
1682 SBYTES (format_string), 1689 SBYTES (format_string),
1683 tm, ut); 1690 tm, ut, ns);
1684 UNBLOCK_INPUT; 1691 UNBLOCK_INPUT;
1685 if ((result > 0 && result < size) || (result == 0 && buf[0] == '\0')) 1692 if ((result > 0 && result < size) || (result == 0 && buf[0] == '\0'))
1686 return code_convert_string_norecord (make_unibyte_string (buf, result), 1693 return code_convert_string_norecord (make_unibyte_string (buf, result),
@@ -1688,10 +1695,10 @@ For example, to produce full ISO 8601 format, use "%Y-%m-%dT%T%z". */)
1688 1695
1689 /* If buffer was too small, make it bigger and try again. */ 1696 /* If buffer was too small, make it bigger and try again. */
1690 BLOCK_INPUT; 1697 BLOCK_INPUT;
1691 result = emacs_memftimeu (NULL, (size_t) -1, 1698 result = emacs_nmemftime (NULL, (size_t) -1,
1692 SSDATA (format_string), 1699 SSDATA (format_string),
1693 SBYTES (format_string), 1700 SBYTES (format_string),
1694 tm, ut); 1701 tm, ut, ns);
1695 UNBLOCK_INPUT; 1702 UNBLOCK_INPUT;
1696 size = result + 1; 1703 size = result + 1;
1697 } 1704 }