aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggert2017-10-17 18:25:18 -0700
committerPaul Eggert2017-10-17 18:26:01 -0700
commit8ca6fa585add53db66fb17b151e67029d68cc9ef (patch)
treedff09a39ff2611836ecae7d90a37503701cb87d9
parent2e1b3522b8562f94a98fed07aeddb6b5ba0dbc6c (diff)
downloademacs-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.texi37
-rw-r--r--src/editfns.c11
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
1487This is a synonym for @samp{%x %X}. 1487This is a synonym for @samp{%x %X}.
1488@item %C 1488@item %C
1489This has a locale-specific meaning. In the default locale (named C), it 1489This stands for the century, that is, the year divided by 100,
1490is equivalent to @samp{%A, %B %e, %Y}. 1490truncated toward zero.
1491@item %d 1491@item %d
1492This stands for the day of month, zero-padded. 1492This 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).
1530This is a synonym for @samp{%I:%M:%S %p}. 1530This is a synonym for @samp{%I:%M:%S %p}.
1531@item %R 1531@item %R
1532This is a synonym for @samp{%H:%M}. 1532This is a synonym for @samp{%H:%M}.
1533@item %s
1534This stands for the integer number of seconds since the epoch.
1533@item %S 1535@item %S
1534This stands for the seconds (00--59). 1536This stands for the second (00--59, or 00--60 on platforms
1537that support leap seconds).
1535@item %t 1538@item %t
1536This stands for a tab character. 1539This 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
1562This stands for the time zone abbreviation (e.g., @samp{EST}). 1565This stands for the time zone abbreviation (e.g., @samp{EST}).
1563@item %z 1566@item %z
1564This stands for the time zone numerical offset (e.g., @samp{-0500}). 1567This stands for the time zone numerical offset. The @samp{z} can be
1568preceded 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}
1570stands for @samp{-05:00:00}, and @samp{%:::z} is like @samp{%::z}
1571except it suppresses trailing instances of @samp{:00} so it stands for
1572@samp{-05} in the same example.
1573@item %%
1574This stands for a single @samp{%}.
1565@end table 1575@end table
1566 1576
1577One or more flag characters can appear immediately after the @samp{%}.
1578@samp{0} pads with zeros, @samp{_} pads with blanks, @samp{-}
1579suppresses padding, @samp{^} upper-cases letters, and @samp{#}
1580reverses the case of letters.
1581
1567You can also specify the field width and type of padding for any of 1582You can also specify the field width and type of padding for any of
1568these @samp{%}-sequences. This works as in @code{printf}: you write 1583these @samp{%}-sequences. This works as in @code{printf}: you write
1569the field width as digits in the middle of a @samp{%}-sequences. If you 1584the field width as digits in a @samp{%}-sequence, after any flags.
1570start the field width with @samp{0}, it means to pad with zeros. If you
1571start the field width with @samp{_}, it means to pad with spaces.
1572
1573For example, @samp{%S} specifies the number of seconds since the minute; 1585For 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
1575pad with spaces to 3 positions. Plain @samp{%3S} pads with zeros, 1587pad with spaces to 3 positions. Plain @samp{%3S} pads with zeros,
1576because that is how @samp{%S} normally pads to two positions. 1588because that is how @samp{%S} normally pads to two positions.
1577 1589
1578The characters @samp{E} and @samp{O} act as modifiers when used between 1590The 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 1591any flags and field widths in a @samp{%}-sequence. @samp{E} specifies
1580using the current locale's alternative version of the date and time. 1592using the current locale's alternative version of the date and time.
1581In a Japanese locale, for example, @code{%Ex} might yield a date format 1593In a Japanese locale, for example, @code{%Ex} might yield a date format
1582based on the Japanese Emperors' reigns. @samp{E} is allowed in 1594based 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
1587representation of numbers, instead of the ordinary decimal digits. This 1599representation of numbers, instead of the ordinary decimal digits. This
1588is allowed with most letters, all the ones that output numbers. 1600is allowed with most letters, all the ones that output numbers.
1589 1601
1602To help debug programs, unrecognized @samp{%}-sequences stand for
1603themselves and are output as-is. Programs should not rely on this
1604behavior, as future versions of Emacs may recognize new
1605@samp{%}-sequences as extensions.
1606
1590This function uses the C library function @code{strftime} 1607This 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
1592Manual}) to do most of the work. In order to communicate with that 1609Manual}) 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
2055Finally, %n is a newline, %t is a tab, %% is a literal %. 2055Finally, %n is a newline, %t is a tab, %% is a literal %, and
2056unrecognized %-sequences stand for themselves.
2056 2057
2057Certain flags and modifiers are available with some format controls. 2058Certain flags and modifiers are available with some format controls.
2058The flags are `_', `-', `^' and `#'. For certain characters X, 2059The flags are `_', `-', `^' and `#'. For certain characters X,