aboutsummaryrefslogtreecommitdiff
path: root/src/time/strftime.c (follow)
Commit message (Expand)AuthorAgeFilesLines
* strftime: fix underlying format string in %z format•••the expression (tm->__tm_gmtoff)/3600 has type long. use %+.2ld instead. Daniel Sabogal2018-06-261-1/+1
* adjust strftime + modifier to match apparent intent of POSIX•••it's unclear from the specification whether the word "consumes" in "consumes more than four bytes to represent a year" refers just to significant places or includes leading zeros due to field width padding. however the examples in the rationale indicate that the latter was the intent. in particular, the year 270 is shown being formatted by %+5Y as +0270 rather than 00270. previously '+' prefixing was implemented just by comparing the year against 10000. instead, count the number of significant digits and padding bytes to be added, and use the total to determine whether to apply the '+' prefix. based on testing by Dennis Wölfing. Rich Felker2018-02-061-6/+12
* fix strftime field widths with %F format and zero year•••the code to strip initial sign and leading zeros inadvertently stripped all the zeros and the subsequent '-' separating the month. instead, only strip sign characters from the very first position, and only strip zeros when they are followed by another digit. based on testing by Dennis Wölfing. Rich Felker2018-02-051-1/+2
* implement strftime padding specifier extensions•••notes added by maintainer: the '-' specifier allows default padding to be suppressed, and '_' allows padding with spaces instead of the default (zeros). these extensions seem to be included in several other implementations including FreeBSD and derivatives, and Solaris. while portable software should not depend on them, time format strings are often exposed to the user for configurable time display. reportedly some python programs also use and depend on them. Timo Teräs2017-12-111-8/+14
* fix strftime %y for negative years•••commit 583ea83541dcc6481c7a1bd1a9b485526bad84a1 fixed the case where tm_year is negative but the resulting year (offset by 1900) was still positive, which is always the case for time_t values that fit in 32 bits, but not for arbitrary inputs. based on an earlier patch by Julien Ramseier which was overlooked at the time the previous fix was applied. Rich Felker2017-01-021-2/+2
* fix strftime %y for negative tm_yearSzabolcs Nagy2016-10-061-0/+1
* fix strftime handling of out-of-range struct tm fields•••strftime results are unspecified in this case, but should not invoke undefined behaviour. tm_wday, tm_yday, tm_mon and tm_year fields were used in signed int arithmetic that could overflow. based on patch by Szabolcs Nagy. Rich Felker2015-10-141-8/+12
* match historical behavior for tm_gmtoff member of struct tm•••tm_gmtoff is a nonstandard field, but on historical systems which have this field, it stores the offset of the local time zone from GMT or UTC. this is the opposite of the POSIX extern long timezone object and the offsets used in POSIX-form TZ strings, which represent the offset from local time to UTC. previously we were storing these negated offsets in tm_gmtoff too. programs which only used this field indirectly via strftime were not affected since strftime performed the negation for presentation. however, some programs and libraries accesse tm_gmtoff directly and were obtaining negated time zone offsets. Natanael Copa2015-08-141-2/+2
* properly pass current locale to *_l functions when used internally•••this change is presently non-functional since the callees do not yet use their locale argument for anything. Rich Felker2014-07-021-1/+2
* fix strftime %s not to zero pad with default width=2Szabolcs Nagy2014-05-081-0/+1
* fix off-by-one length failure in strftime/wcsftime and improve error behavior•••these functions were spuriously failing in the case where the buffer size was exactly the number of bytes/characters to be written, including null termination. since these functions do not have defined error conditions other than buffer size, a reasonable application may fail to check the return value when the format string and buffer size are known to be valid; such an application could then attempt to use a non-terminated buffer. in addition to fixing the bug, I have changed the error handling behavior so that these functions always null-terminate the output except in the case where the buffer size is zero, and so that they always write as many characters as possible before failing, rather than dropping whole fields that do not fit. this actually simplifies the logic somewhat anyway. Rich Felker2013-11-261-6/+8
* add the %s (seconds since the epoch) format to strftime•••this is a nonstandard extension but will be required in the next version of POSIX, and it's widely used/useful in shell scripts utilizing the date utility. Rich Felker2013-08-251-0/+4
* fix strftime regression in %e format•••%e pads with spaces instead of zeros. Rich Felker2013-08-241-2/+2
* fix strftime handling of time zone data•••this may need further revision in the future, since POSIX is rather unclear on the requirements, and is designed around the assumption of POSIX TZ specifiers which are not sufficiently powerful to represent real-world timezones (this is why zoneinfo support was added). the basic issue is that strftime gets the string and numeric offset for the timezone from the extra fields in struct tm, which are initialized when calling localtime/gmtime/etc. however, a conforming application might have created its own struct tm without initializing these fields, in which case using __tm_zone (a pointer) could crash. other zoneinfo-based implementations simply check for a null pointer, but otherwise can still crash of the field contains junk. simply ignoring __tm_zone and using tzname[] would "work" but would give incorrect results in time zones with more complex rules. I feel like this would lower the quality of implementation. instead, simply validate __tm_zone: unless it points to one of the zone name strings managed by the timezone system, assume it's invalid. this commit also fixes several other minor bugs with formatting: tm_isdst being negative is required to suppress printing of the zone formats, and %z was using the wrong format specifiers since the type of val was changed, resulting in bogus output. Rich Felker2013-08-241-3/+13
* fix missing string.h in strftime.c (needed by new strftime code)•••this bug was masked by local experimental CFLAGS in my config.mak. Rich Felker2013-08-231-0/+1
* add strftime and wcsftime field widths•••at present, since POSIX requires %F to behave as %+4Y-%m-%d and ISO C requires %F to behave as %Y-%m-%d, the default behavior for %Y has been changed to match %+4Y. this seems to be the only way to conform to the requirements of both standards, and it does not affect years prior to the year 10000. depending on the outcome of interpretations from the standards bodies, this may be adjusted at some point. Rich Felker2013-08-221-3/+32
* simplify strftime and fix integer overflows•••use a long long value so that even with offsets, values cannot overflow. instead of using different format strings for different numeric formats, simply use a per-format width and %0*lld for all of them. this width specifier is not for use with strftime field widths; that will be a separate step in the caller. Rich Felker2013-08-221-28/+12
* strftime cleanup: avoid recomputing strlen when it's knownRich Felker2013-08-221-10/+16
* more strftime refactoring•••make __strftime_fmt_1 return a string (possibly in the caller-provided temp buffer) rather than writing into the output buffer. this approach makes more sense when padding to a minimum field width might be required, and it's also closer to what wcsftime wants. Rich Felker2013-08-221-23/+25
* begin refactoring strftime to make adding field widths easierRich Felker2013-08-221-151/+161
* fix semantically incorrect use of LC_GLOBAL_LOCALE•••LC_GLOBAL_LOCALE refers to the global locale, controlled by setlocale, not the thread-local locale in effect which these functions should be using. neither LC_GLOBAL_LOCALE nor 0 has an argument to the *_l functions has behavior defined by the standard, but 0 is a more logical choice for requesting the callee to lookup the current locale. in the future I may move the current locale lookup the the caller (the non-_l-suffixed wrapper). at this point, all of the locale logic is dummied out, so no harm was done, but it should at least avoid misleading usage. Rich Felker2013-07-281-1/+1
* reorder strftime to eliminate the incorrect indention level•••this change is in preparation for possibly adding support for the field width and padding specifiers added in POSIX 2008. Rich Felker2013-07-271-5/+5
* rework langinfo code for ABI compat and for use by time codeRich Felker2013-07-241-4/+4
* move strftime_l into strftime.c and add __-prefixed version•••the latter is both for ABI purposes, and to facilitate eventually adding LC_TIME support. it's also nice to eliminate an extra source file. Rich Felker2013-07-241-1/+10
* the big time handling overhaul•••this commit has two major user-visible parts: zoneinfo-format time zones are now supported, and overflow handling is intended to be complete in the sense that all functions return a correct result if and only if the result fits in the destination type, and otherwise return an error. also, some noticable bugs in the way DST detection and normalization worked have been fixed, and performance may be better than before, but it has not been tested. Rich Felker2013-07-171-6/+2
* implement week-based-year year numbers in strftime•••in the process, I refactored the week-number code so it can be used by the week-based-year formats to determine year adjustments at the boundary values. this also improves indention/code readability. Rich Felker2013-06-281-27/+34
* fix breakage in last commit to strftime due to missing INT_MAX•••that's what I get for changing a hard-coded threshold to a proper non-magic-number without testing. Rich Felker2013-06-281-0/+1
* implement week numbers and half of the week-based-year logic for strftime•••output for plain week numbers (%U and %W) has been sanity-checked, and output for the week-based-year week numbers (%V) has been checked extensively against known-good data for the full non-negative range of 32-bit time_t. year numbers for week-based years (%g and %G) are not yet implemented. Rich Felker2013-06-281-3/+38
* use restrict everywhere it's required by c99 and/or posix 2008•••to deal with the fact that the public headers may be used with pre-c99 compilers, __restrict is used in place of restrict, and defined appropriately for any supported compiler. we also avoid the form [restrict] since older versions of gcc rejected it due to a bug in the original c99 standard, and instead use the form *restrict. Rich Felker2012-09-061-1/+1
* initial check-in, version 0.5.0Rich Felker2011-02-121-0/+172