diff options
| author | Paul Eggert | 2017-10-17 18:25:18 -0700 |
|---|---|---|
| committer | Paul Eggert | 2017-10-17 18:26:01 -0700 |
| commit | 8ca6fa585add53db66fb17b151e67029d68cc9ef (patch) | |
| tree | dff09a39ff2611836ecae7d90a37503701cb87d9 | |
| parent | 2e1b3522b8562f94a98fed07aeddb6b5ba0dbc6c (diff) | |
| download | emacs-8ca6fa585add53db66fb17b151e67029d68cc9ef.tar.gz emacs-8ca6fa585add53db66fb17b151e67029d68cc9ef.zip | |
Improve format-time-string doc
* doc/lispref/os.texi (Time Parsing): Fix some errors in the
documentation for format-time-string. Document ^, #, %s, and %z
with colons. Say that unrecognized sequences are output as-is.
* src/editfns.c (Fformat_time_string): %S can stand for 60.
Also mention unrecognized sequences.
| -rw-r--r-- | doc/lispref/os.texi | 37 | ||||
| -rw-r--r-- | src/editfns.c | 11 |
2 files changed, 33 insertions, 15 deletions
diff --git a/doc/lispref/os.texi b/doc/lispref/os.texi index 59c269a3084..0cb9de9f9a8 100644 --- a/doc/lispref/os.texi +++ b/doc/lispref/os.texi | |||
| @@ -1486,8 +1486,8 @@ This stands for the full name of the month. | |||
| 1486 | @item %c | 1486 | @item %c |
| 1487 | This is a synonym for @samp{%x %X}. | 1487 | This is a synonym for @samp{%x %X}. |
| 1488 | @item %C | 1488 | @item %C |
| 1489 | This has a locale-specific meaning. In the default locale (named C), it | 1489 | This stands for the century, that is, the year divided by 100, |
| 1490 | is equivalent to @samp{%A, %B %e, %Y}. | 1490 | truncated toward zero. |
| 1491 | @item %d | 1491 | @item %d |
| 1492 | This stands for the day of month, zero-padded. | 1492 | This stands for the day of month, zero-padded. |
| 1493 | @item %D | 1493 | @item %D |
| @@ -1530,8 +1530,11 @@ This stands for the calendar quarter (1--4). | |||
| 1530 | This is a synonym for @samp{%I:%M:%S %p}. | 1530 | This is a synonym for @samp{%I:%M:%S %p}. |
| 1531 | @item %R | 1531 | @item %R |
| 1532 | This is a synonym for @samp{%H:%M}. | 1532 | This is a synonym for @samp{%H:%M}. |
| 1533 | @item %s | ||
| 1534 | This stands for the integer number of seconds since the epoch. | ||
| 1533 | @item %S | 1535 | @item %S |
| 1534 | This stands for the seconds (00--59). | 1536 | This stands for the second (00--59, or 00--60 on platforms |
| 1537 | that support leap seconds). | ||
| 1535 | @item %t | 1538 | @item %t |
| 1536 | This stands for a tab character. | 1539 | This stands for a tab character. |
| 1537 | @item %T | 1540 | @item %T |
| @@ -1561,22 +1564,31 @@ This stands for the year with century. | |||
| 1561 | @item %Z | 1564 | @item %Z |
| 1562 | This stands for the time zone abbreviation (e.g., @samp{EST}). | 1565 | This stands for the time zone abbreviation (e.g., @samp{EST}). |
| 1563 | @item %z | 1566 | @item %z |
| 1564 | This stands for the time zone numerical offset (e.g., @samp{-0500}). | 1567 | This stands for the time zone numerical offset. The @samp{z} can be |
| 1568 | preceded by one, two, or three colons; if plain @samp{%z} stands for | ||
| 1569 | @samp{-0500}, then @samp{%:z} stands for @samp{-05:00}, @samp{%::z} | ||
| 1570 | stands for @samp{-05:00:00}, and @samp{%:::z} is like @samp{%::z} | ||
| 1571 | except it suppresses trailing instances of @samp{:00} so it stands for | ||
| 1572 | @samp{-05} in the same example. | ||
| 1573 | @item %% | ||
| 1574 | This stands for a single @samp{%}. | ||
| 1565 | @end table | 1575 | @end table |
| 1566 | 1576 | ||
| 1577 | One or more flag characters can appear immediately after the @samp{%}. | ||
| 1578 | @samp{0} pads with zeros, @samp{_} pads with blanks, @samp{-} | ||
| 1579 | suppresses padding, @samp{^} upper-cases letters, and @samp{#} | ||
| 1580 | reverses the case of letters. | ||
| 1581 | |||
| 1567 | You can also specify the field width and type of padding for any of | 1582 | You can also specify the field width and type of padding for any of |
| 1568 | these @samp{%}-sequences. This works as in @code{printf}: you write | 1583 | these @samp{%}-sequences. This works as in @code{printf}: you write |
| 1569 | the field width as digits in the middle of a @samp{%}-sequences. If you | 1584 | the field width as digits in a @samp{%}-sequence, after any flags. |
| 1570 | start the field width with @samp{0}, it means to pad with zeros. If you | ||
| 1571 | start the field width with @samp{_}, it means to pad with spaces. | ||
| 1572 | |||
| 1573 | For example, @samp{%S} specifies the number of seconds since the minute; | 1585 | For example, @samp{%S} specifies the number of seconds since the minute; |
| 1574 | @samp{%03S} means to pad this with zeros to 3 positions, @samp{%_3S} to | 1586 | @samp{%03S} means to pad this with zeros to 3 positions, @samp{%_3S} to |
| 1575 | pad with spaces to 3 positions. Plain @samp{%3S} pads with zeros, | 1587 | pad with spaces to 3 positions. Plain @samp{%3S} pads with zeros, |
| 1576 | because that is how @samp{%S} normally pads to two positions. | 1588 | because that is how @samp{%S} normally pads to two positions. |
| 1577 | 1589 | ||
| 1578 | The characters @samp{E} and @samp{O} act as modifiers when used between | 1590 | The characters @samp{E} and @samp{O} act as modifiers when used after |
| 1579 | @samp{%} and one of the letters in the table above. @samp{E} specifies | 1591 | any flags and field widths in a @samp{%}-sequence. @samp{E} specifies |
| 1580 | using the current locale's alternative version of the date and time. | 1592 | using the current locale's alternative version of the date and time. |
| 1581 | In a Japanese locale, for example, @code{%Ex} might yield a date format | 1593 | In a Japanese locale, for example, @code{%Ex} might yield a date format |
| 1582 | based on the Japanese Emperors' reigns. @samp{E} is allowed in | 1594 | based on the Japanese Emperors' reigns. @samp{E} is allowed in |
| @@ -1587,6 +1599,11 @@ based on the Japanese Emperors' reigns. @samp{E} is allowed in | |||
| 1587 | representation of numbers, instead of the ordinary decimal digits. This | 1599 | representation of numbers, instead of the ordinary decimal digits. This |
| 1588 | is allowed with most letters, all the ones that output numbers. | 1600 | is allowed with most letters, all the ones that output numbers. |
| 1589 | 1601 | ||
| 1602 | To help debug programs, unrecognized @samp{%}-sequences stand for | ||
| 1603 | themselves and are output as-is. Programs should not rely on this | ||
| 1604 | behavior, as future versions of Emacs may recognize new | ||
| 1605 | @samp{%}-sequences as extensions. | ||
| 1606 | |||
| 1590 | This function uses the C library function @code{strftime} | 1607 | This function uses the C library function @code{strftime} |
| 1591 | (@pxref{Formatting Calendar Time,,, libc, The GNU C Library Reference | 1608 | (@pxref{Formatting Calendar Time,,, libc, The GNU C Library Reference |
| 1592 | Manual}) to do most of the work. In order to communicate with that | 1609 | Manual}) to do most of the work. In order to communicate with that |
diff --git a/src/editfns.c b/src/editfns.c index e65bd34da87..f6f5ccc9480 100644 --- a/src/editfns.c +++ b/src/editfns.c | |||
| @@ -2038,11 +2038,11 @@ by text that describes the specified date and time in TIME: | |||
| 2038 | only blank-padded, %l is like %I blank-padded. | 2038 | only blank-padded, %l is like %I blank-padded. |
| 2039 | %p is the locale's equivalent of either AM or PM. | 2039 | %p is the locale's equivalent of either AM or PM. |
| 2040 | %q is the calendar quarter (1–4). | 2040 | %q is the calendar quarter (1–4). |
| 2041 | %M is the minute. | 2041 | %M is the minute (00-59). |
| 2042 | %S is the second. | 2042 | %S is the second (00-59; 00-60 on platforms with leap seconds) |
| 2043 | %N is the nanosecond, %6N the microsecond, %3N the millisecond, etc. | ||
| 2044 | %Z is the time zone name, %z is the numeric form. | ||
| 2045 | %s is the number of seconds since 1970-01-01 00:00:00 +0000. | 2043 | %s is the number of seconds since 1970-01-01 00:00:00 +0000. |
| 2044 | %N is the nanosecond, %6N the microsecond, %3N the millisecond, etc. | ||
| 2045 | %Z is the time zone abbreviation, %z is the numeric form. | ||
| 2046 | 2046 | ||
| 2047 | %c is the locale's date and time format. | 2047 | %c is the locale's date and time format. |
| 2048 | %x is the locale's "preferred" date format. | 2048 | %x is the locale's "preferred" date format. |
| @@ -2052,7 +2052,8 @@ by text that describes the specified date and time in TIME: | |||
| 2052 | %R is like "%H:%M", %T is like "%H:%M:%S", %r is like "%I:%M:%S %p". | 2052 | %R is like "%H:%M", %T is like "%H:%M:%S", %r is like "%I:%M:%S %p". |
| 2053 | %X is the locale's "preferred" time format. | 2053 | %X is the locale's "preferred" time format. |
| 2054 | 2054 | ||
| 2055 | Finally, %n is a newline, %t is a tab, %% is a literal %. | 2055 | Finally, %n is a newline, %t is a tab, %% is a literal %, and |
| 2056 | unrecognized %-sequences stand for themselves. | ||
| 2056 | 2057 | ||
| 2057 | Certain flags and modifiers are available with some format controls. | 2058 | Certain flags and modifiers are available with some format controls. |
| 2058 | The flags are `_', `-', `^' and `#'. For certain characters X, | 2059 | The flags are `_', `-', `^' and `#'. For certain characters X, |