aboutsummaryrefslogtreecommitdiff
path: root/toys/posix/date.c
AgeCommit message (Collapse)Author
2019-03-26Make touch use xparsedate() (result: -t and -d the same, autodetects format),Rob Landley
and fix tests to pass on host too.
2019-03-24Factor out xparsedate() and xvali_date() into lib.Rob Landley
2019-03-13date: fix various time zone/daylight time issues.Elliott Hughes
Sunday's transition in the US broke a bunch of the tests. Worse, it broke some of the QA folks' scripts. Finally, the boil that is date's handling of time zones and daylight time has come to a head... This patch fixes the newly-failing tests *and* the other tests that were checked in failing to serve as TODOs. I've resolved the test TODOs about whether implied year/century in POSIX format should mean the current year or 1900 in favor of the current year. Both busybox and coreutils agree, and Rob fixed the code recently so toybox agrees too, but without fixing the tests. I've switched tests from Europe/London to Europe/Berlin to avoid disagreements between C libraries about whether to say "GMT" or "UTC" when daylight savings is not in force. The majority of this patch implements what I'd been unsuccessfully trying to explain on the list: that to correctly implement the distinct input and output time zones (as demonstrated in the three failing tests we've been carrying around for a while), we should switch to working with time_t internally rather than struct tm. I've also added the code to temporarily switch to the input time zone (and back again). All the tests now pass.
2019-02-14Use current time for unspecified fields, set weekday to match date.Rob Landley
2019-02-11date: some fixes.Elliott Hughes
Add support for more input formats, primarily the ISO formats used by the AOSP build. I've improved/added to the tests a bit to cover these changes, and to explain the reasons for the various remaining test failures (none of which are regressions caused by this patch).
2018-10-06date: fix some tests.Elliott Hughes
`errno` isn't meaningful here.
2018-08-31Convert option style.Rob Landley
2017-05-19Implement date %N, loosely inspired by Elliott Hughes's patch.Rob Landley
I didn't implement %37N's ability to insert zeroes, so removed those two tests. If you really need it, I can add the divide loop back.
2017-03-28Don't try to implement %s, we have @seconds, strptime() in libc tendsRob Landley
not to have it, and implementing our own means a pattern like "Time %%%s%%" is expensive to handle the corner cases of.
2017-03-28Replace chkmktime() (which produces false positive normalization failures)Rob Landley
with range checks for seconds, minutes, hours, day of month, and month.
2015-11-12Document %s in date(1).Elliott Hughes
2015-11-12Fix year parsing in date(1).Elliott Hughes
Four-digit years were being mangled by the code for two-digit years. Move all the two-digit year code into the "we only saw two digits" case. Add some new tests and fix existing tests.
2015-08-11Fix more date bugs.Elliott Hughes
Correctly and portably check for non-normal dates, and explicitly show the "before" and "after" dates (in the format of the user's choosing). Clear the struct tm in date_main rather than parse_default because on one path the struct tm is actually initialized. Explicitly clear the tm_sec field in parse_default because -- experiment shows -- that should not be preserved. Only do the "what does this 2-digit year mean?" dance if we actually parsed a 2-digit year. Show the right string in the error message if strptime fails. Also add more tests, and use UTC in the tests to avoid flakiness.
2015-08-11Bugfixes from Elliott Hughes: debug code got checked in (oops) andRob Landley
uninitialized trash in struct tm fields could segfault glibc's strftime().
2015-08-08Teach date @unixtime[.fraction], switch -s to be -D (matching busybox andRob Landley
not stomping on gnu's "an extra argument tells it to set the time so let's add -s to do the same thing" extension). Nanoseconds aren't uniformly supported by these apis, so had to stick it in GLOBALS() and pull it out later. Awkward, open to suggestions for a better way. (Also, the setting API is microseconds, not nanoseconds. Collect nano, convert to micro so we can switch APIs later without changing date's external UI again.) Oh, and shrink really_long_name_mktime() with a for() loop (and rename it) although I may go back and redo that for portability to hypothetical libraries if I can convert this mess to struct timespec with proper nanoseconds support. But that needs an extended strptime() which needs an extended struct tm, and between us and that is convincing posix computers got fast enough to care about fractions of a second. (Yes, I'm aware gnu added %N to date without adding it to strptime, implying they reimplemented strptime longhand inside date. I'm not doing that.)
2015-08-08Reject invalid dates in date(1).Elliott Hughes
Humans get upset when date(1) lets mktime(3) work out what the 99th day of the 99th month would be rather than rejecting the invalid date. For the subtly wrong cases, rather than get into the leap year business, let's rely on localtime_r(3).
2015-08-02Mark command-local functions static.Rob Landley
2014-07-03date -r wasn't saving the result in the right variable. (And make date -ur ↵Rob Landley
work.)
2014-05-24Remove debug detritus I didn't mean to to check in, and treat an "this ↵Rob Landley
variable can never actually be used uninitialized but gcc's warning generator can't tell and fails spamwards" warning.
2014-05-22date: add -ds, document +FORMAT escapes.Rob Landley
2014-04-16Revert lots of half-finished local debris I didn't mean to check in with ↵Rob Landley
Isaac's roadmap update. Mercurial's "import" command is still broken, committing local tree changes to files that weren't even touched by the patch because the hg developers inisist, when I point out how stupid it is, that they meant to do that. (hg record can do hunks, but import can't even track _files_.)
2014-04-12roadmap: describe glibc commands.Isaac Dunham
Some glibc commands are irrelevant because they're for functionality that is excluded from musl (mtrace, rpc*, localedef, iconvconfig, nscd). getconf and catchsegv look like candidates for the development toolchain; locale and iconv were already triaged. getent is pretty lame, but it and the timezone stuff (tzselect zic zdump) are the only new possibly interesting commands.
2014-04-10Fix date setting, and fluff out help text a bit.Rob Landley
2012-11-13Reindent to two spaces per level. Remove vi: directives that haven't worked ↵Rob Landley
right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style. The actual code should be the same afterward, this is just cosmetic refactoring.
2012-10-08New build infrastructure to generate FLAG_ macros and TT alias, #define ↵Rob Landley
FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
2012-08-25Regularize command headers, update links to standards documents.Rob Landley
2012-08-25Move commands into "posix", "lsb", and "other" menus/directories.Rob Landley