Commit Graph

32 Commits

Author SHA1 Message Date
kre
de1e0dfd01 parsedate.y: meaningless KNF of a comment (no code changes)
parsedate.3:  add an item in BUGS noting the weirdness of "next"

The real purpose of this commit is to supply the following message
which should be used for the immediately previous commit, replacing
its commit message (the two are similar, but definitely not the
same).   With thanks to gdt@ for pointing out one of the (many) errors
in the previous message (and noting others I had already seen).

    ----

Make parsedate handle "12 noon" and "12 midnight" (including when the
time given is "12:00" or "12:00:00") - but only for exactly 12 o'clock.
"12:00:01" is am or pm, not noon or midnight.

"12 am" remains as an alias for "12 midnight", and "12 pm" for noon,
though both are strictly (pedanticly) invalid (and meaningless.)

Note that "12 midnight" (or "12 am") means 00:00:00 (ie: midnight at
the start of the day, not at the end.)
2017-03-22 18:17:42 +00:00
kre
e9cfba3947 Make parsedate handle "12 noon" and "12 midnight" (including when
the time is "12:00" or "12:00:00) - but only for exactly 12 o'clock.
"12:00:01" is am or pm, not noon or midnight.

"12 am" remains as an alias for "12 midnight", and "12 pm" for midnight,
though both are strictly invalid (and meaningless.)

Note that "12 pm" means 00:00:00 (ie: midnight at the start of the
day, not at the end.)
2017-03-22 01:49:36 +00:00
kre
b717517d3c Fix PR lib/52101 -- 12:30 am is 00:30:00 and 12:30 pm is 12:30:00 2017-03-22 00:59:06 +00:00
kre
0a924e39aa Remove dawn/sunup/sunset/sundown (sunrise was never there...)
If 06:00 or 18:00 are wanted, just say "06:00" (etc).  If these
are ever added back, they really should determine location, and
calculate actual sunrise/sunset times for the location and date.
That's not likely to happen...
2016-06-26 07:09:24 +00:00
kre
3060c9b9b9 Make relative date changes ("+ 2 months") etc, work a little more sanely.
OK christos@
2016-05-03 18:14:54 +00:00
dholland
4f3e8539c0 When computing relative months, use mktime() directly and don't call
our Convert(). And check it for failure. This fixes three sets of
problems:

  (1) depending on the passed-in value of Timezone it might
      disassemble the time in one timezone and reassemble it in
      another, causing mysterious offsets of a few hours;

  (2) with the previous set of changes to this file, Convert() fails
      if it ends up normalizing a date, so e.g. going three months
      forward from March 31 would fail;

  (3) previously if Convert() failed we passed -1 on to DSTcorrect(),
      which made a mess.

PR 50574.
2015-12-31 10:52:06 +00:00
dholland
2213a9c409 Always use localtime_r; I don't think any of this code is tripping
itself up, but it's still good practice for library functions to not
trash static libc state. Might be relevant to PR 50574.
2015-12-31 10:31:07 +00:00
dholland
4c7b8eec63 Reformat grammar part according to my standards for yacc grammars. 2015-12-31 09:12:57 +00:00
christos
5fd02f85b5 preserve a copy of the tm so we can check later. 2015-12-08 12:51:04 +00:00
christos
5e2a9cf1aa - Add support for "midnight" "noon", dawn etc.
- Add validation to date/time strings by checking that mktime did not change
  the fields of struct tm from the ones requested
- Allow the format "year monthname day".
From kre
2015-12-07 20:55:49 +00:00
christos
640422f86c Fix west australia offset, from kre 2015-12-06 14:43:59 +00:00
christos
51dbeaccf4 Patch from kre:
- fix missing/inconsistent abbreviations
- set dst only if we are using localtime.
- properly check for errors where there were missing checks
- handle errno properly including saving and restoring.
2015-11-26 01:00:02 +00:00
apb
82cbb6b06d Improved handling of local times.
* A magic value USE_LOCAL_TIME (defined as 99999) may be passed as the
  Timezone to Convert(), instructing it to use mktime() to work
  in the local time zone, instead of using mktime_z to work in UTC
  (and then adding the specified timezone offset).
* Some old code is removed now that there's no need to find the local
  timezone offset.
* Allow either one or both of the now and zone arguments to
  parsedate() to be NULL, treating them independently.  Previously,
  if either one was NULL, the other was ignored.
* If the zone argument is specified, then the current date is calculated
  in the specified zone, not in local time.

Also add some disabled debug code.

This should fix PR lib/47916.
2014-10-08 17:38:28 +00:00
apb
bb7c1cf124 Add a new non-terminal "time_numericzone" for a time with
a numeric timezone.  Move some productions from "time" to "time_numericzone".
Increment yyHaveZone when encountering one of these.

Previously, input of the form "HH:MM:SS +ZZZZ" would not have set the
yyhaveZone flag.
2014-10-08 14:43:48 +00:00
apb
7ab26473da A time like HH:MM:SS.sss says nothing about whether DST is on or off. 2014-10-08 14:32:29 +00:00
apb
a777540768 Some years don't need the "maybe add 1900 or 2000" adjustment
that was designed for handling two-digit abbreviated years.
For example, "1/2/70" still refers to the year 1970, as before,
but "70-01-02" now refers to the year 70.

* Add a new yyHaveFullYear member to struct dateinfo, to record whether
  or not the year needs to be adjusted.
* Code that parses years sets yyHaveFullYear=1 if they know that the
  year should not be adjusted (as is the case for ISO 8601 dates), or if
  they perform their own adjustment (as is the case for CVS timestamps).
* Move the year adjustment code into a new function, AdjustYear,
  instead of inline in Convert().
* Make Convert() assume the year doesn't need to be adjusted,
  and make Convert's callers first call AdjustYear() if appropriate.
2014-10-07 22:27:14 +00:00
yamt
32786d7c5c fix timezone bugs in rev.1.11 and rev.1.13. PR/47916. 2013-06-12 01:46:07 +00:00
yamt
fbfa30e437 add rcsid 2013-06-12 01:31:24 +00:00
apb
6b80497831 Distinguish between a non-error result of (time_t)-1 and an error result.
Modernise the test code inside #ifdef TEST.
2013-01-19 15:23:33 +00:00
apb
b156ae6a25 mktime(3) works in local time, and trying to trick it by
setting tm_gmtoff doesn't work.  Instead, call mktime_z(3)
with a null timezone (so it works in UTC) and adjust the
result afterwards.  Now "date -d @0" correctly
prints the local equivalent of 1970-01-01 00:00:00 UTC.
2013-01-19 09:27:32 +00:00
joerg
ed602fb487 Don't use const foo const as type, one const is enough. 2012-09-13 21:44:49 +00:00
apb
f93996848b Use mktime(3) instead of hand-coded equivalent.
Don't treat negative results as errors (we should be able
to handle years before 1970).

XXX: This still fails on 1969-12-31 23:59:59.
2011-12-17 19:14:10 +00:00
christos
6ef213c85c restore lost overlow check fix. 2010-12-24 15:47:39 +00:00
christos
5448347830 make this thread-safe. We could use localtime_tz and make it even better,
but not now.
2010-12-24 03:37:37 +00:00
christos
a504543f04 fix incorrect overflow check from Nicholas Joly 2010-12-21 18:13:02 +00:00
christos
2e63e08217 - fix off by one in comparison with 69 (it should be 70)
- add aliases for 1 (one), 2 (two), etc.
- allow parsing of HH:MM:SS.sss as the man page mentions, and ignore sss
2010-12-21 00:14:10 +00:00
christos
49f71b9cd5 PR/42549: Izumi Tsutsui: parsedate does not work after 2038.
Fix multiple issues:
- Remove bogus 2038 check and add overflow checks in the appropriate places.
- Correct incomplete leap year calculation that broke things after 2100.
- Check localtime return values
- Change int calculations to time_t to avoid oveflow.
- Consistently check/return -1 and remove bogus comment about not being
  able to return -1.

Now:
$ date -d 20991201
Tue Dec  1 00:00:00 EST 2099
$ date -d 40991201
Tue Dec  1 00:00:00 EST 4099
$ date -d 10000000991201
Tue Dec  1 00:00:00 EST 1000000099
TIME=0:04.48 CPU=117.8% (5.288u 0.000s) SWAPS=0 (0+95)pf (0i+0o) (0Kc+0Kd)
$ date -d 100000000991201
date: Cannot parse `100000000991201'
TIME=0:53.48 CPU=99.2% (53.086u 0.000s) SWAPS=0 (0+96)pf (0i+0o) (0Kc+0Kd)
Exit 1
2010-12-12 18:39:57 +00:00
tron
90493f6f08 Add support for parsing the data format "@<seconds since epoch>" e.g.
"@735275209" for "Tue Apr 20 03:06:49 UTC 1993". This change was inspired
by coreutil's "date" utility.
2010-08-21 16:17:40 +00:00
christos
50728e7823 merge christos-time_t 2009-01-11 02:57:17 +00:00
drochner
1914237fbe include <stdlib.h> explicitely, for exit(), getprogname() etc.
(it happens to be pulled in by the yacc skeleton, but we shouldn't
rely on this)
2008-07-17 16:24:55 +00:00
christos
af4b090320 From Anon Ymous:
- add __unused
- remove __GNUC__ hack
2006-12-20 16:47:13 +00:00
christos
61261c8531 rename getdate to parsedate to avoid conflict with posix function 2006-11-20 20:33:02 +00:00