Branch
Hash :
4393ea5a
Author :
Date :
2025-07-15T11:19:10
nstrftime: Add support for non-Gregorian calendars. * lib/calendars.h: New file. * lib/calendar-thai.h: New file. * lib/calendar-persian.h: New file. * lib/calendar-ethiopian.h: New file. * lib/strftime.h (nstrftime): Document which directives don't work with non-Gregorian calendars. * lib/strftime.c (SUPPORT_NON_GREG_CALENDARS_IN_STRFTIME): New macro. Include localcharset.h, localename.h, calendars.h. (CAL_ARGS): New macro. (my_strftime): Recognize locales with non-Gregorian calendars. Pass cal and caldate down to __strftime_internal. (__strftime_internal): Accept additional parameters cal, caldate. Remove rejection of modifier 'O' for directive 'Y' and allow a non-ASCII alternate digits base. Produce calendar-aware output for the directives 'b', 'h', 'B', 'x', 'd', 'e', 'm', 'Y'. * modules/nstrftime (Files): Add the calendar files. (Depends-on): Add localcharset. (Link): New section. * modules/fprintftime (Link): New section. * tests/test-nstrftime-DE.c: New file. * tests/test-nstrftime-TH.c: New file. * tests/test-nstrftime-IR.c: New file. * tests/test-nstrftime-ET.c: New file. * modules/nstrftime-tests (Files): Add them. (Depends-on): Add localcharset, setenv. (Makefile.am): Link test-nstrftime with $(INTL_MACOSX_LIBS). Arrange to compile and run test-nstrftime-DE, test-nstrftime-TH, test-nstrftime-IR, test-nstrftime-ET.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
/* declarations for strftime.c
Copyright (C) 2002, 2004, 2008-2025 Free Software Foundation, Inc.
This file is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This file is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */
#include <time.h>
#ifdef __cplusplus
extern "C" {
#endif
/* Format the broken-down time *__TP, with additional __NS nanoseconds,
into the buffer __S of size __MAXSIZE, according to the rules of the
LC_TIME category of the current locale.
Use the time zone __TZ.
If *__TP represents local time, __TZ should be set to
tzalloc (getenv ("TZ")).
If *__TP represents universal time (a.k.a. GMT), __TZ should be set to
(timezone_t) 0.
The format string __FORMAT, including GNU extensions, is described in
the GNU libc's strftime() documentation:
<https://www.gnu.org/software/libc/manual/html_node/Formatting-Calendar-Time.html>
Additionally, the following conversion is supported:
%N The number of nanoseconds, passed as __NS argument.
Here's a summary of the available conversions (= format directives):
literal characters %n %t %%
date:
century %C
year %Y %y
week-based year %G %g
month (in year) %m %B %b %h
week in year %U %W %V
day in year %j
day (in month) %d %e
day in week %u %w %A %a
year, month, day %x %F %D
time:
half-day %p %P
hour %H %k %I %l
minute (in hour) %M
hour, minute %R
second (in minute) %S
hour, minute, second %r %T %X
second (since epoch) %s
date and time: %c
time zone: %z %Z
nanosecond %N
In locales with non-Gregorian calendars, the following conversions don't
apply in the expected way:
date:
century %C
year %y
week-based year %G %g
week in year %U %W %V
day in year %j
year, month, day %D
Store the result, as a string with a trailing NUL character, at the
beginning of the array __S[0..__MAXSIZE-1] and return the length of
that string, not counting the trailing NUL, and without changing errno.
If unsuccessful, possibly change the array __S, set errno, and return 0;
errno == ERANGE means the string didn't fit.
This function is like strftime, but with two more arguments:
* __TZ instead of the local timezone information,
* __NS as the number of nanoseconds in the %N directive.
*/
size_t nstrftime (char *restrict __s, size_t __maxsize,
char const *__format,
struct tm const *__tp, timezone_t __tz, int __ns);
/* Like nstrftime, except that it uses the "C" locale instead of the
current locale. */
size_t c_nstrftime (char *restrict __s, size_t __maxsize,
char const *__format,
struct tm const *__tp, timezone_t __tz, int __ns);
#ifdef __cplusplus
}
#endif