Hello, On Wed, Mar 14, 2018 at 05:22:04PM -0700, Paul Eggert wrote: > On 03/13/2018 06:42 PM, Assaf Gordon wrote: > >Therefore it is always recommended to use noon (12pm) > >as explicit time when adjusting days > > Maybe "date" should default to 12:00 instead of to 00:00 when the time is > not specified? That would avoid this sort of problem, typically.
Technically it's an easy fix (patch attached), but it changes a long-standing behavior. I wonder if it will break some existing scripts that might rely on being 'midnight'? (even implicitly, because the user isn't aware of this nuance). For example, currently '2018-03-15 + 14 hours' is 2pm on March 15th. With this change, it'll result in 2am on March 16th. What do you think? -assaf
>From 364bbe1b8adbb2fd3a67569de412273711162aab Mon Sep 17 00:00:00 2001 From: Assaf Gordon <[email protected]> Date: Thu, 15 Mar 2018 00:59:28 -0600 Subject: [PATCH] parse-datetime: default to noon for dates without time Prefer noon (instead of midnight) to reduce unexpected date shifts with date arithmetics. Discussed in https://bugs.gnu.org/30795#11 * lib/parse-datetime.y (parse_datetime2): Set tm_hour to 12 (noon) instead of 0 (midnight) if time wasn't given. --- ChangeLog | 8 ++++++++ lib/parse-datetime.y | 5 +++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index a9cd4ae..e71935d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2018-03-15 Assaf Gordon <[email protected]> + + parse-datetime: default to noon for dates without time + Prefer noon (instead of midnight) to reduce unexpected date shifts + with date arithmetics. Discussed in https://bugs.gnu.org/30795#11 + * lib/parse-datetime.y (parse_datetime2): Set tm_hour to 12 (noon) + instead of 0 (midnight) if time wasn't given. + 2018-03-08 Paul Eggert <[email protected]> fflush: be more paranoid about libio.h change diff --git a/lib/parse-datetime.y b/lib/parse-datetime.y index f14bb31..7b183d9 100644 --- a/lib/parse-datetime.y +++ b/lib/parse-datetime.y @@ -2019,10 +2019,11 @@ parse_datetime2 (struct timespec *result, char const *p, } else { - tm.tm_hour = tm.tm_min = tm.tm_sec = 0; + tm.tm_hour = 12; + tm.tm_min = tm.tm_sec = 0; pc.seconds.tv_nsec = 0; if (pc.parse_datetime_debug) - dbg_printf ("warning: using midnight as starting time: 00:00:00\n"); + dbg_printf ("warning: using noon as starting time: 12:00:00\n"); } /* Let mktime deduce tm_isdst if we have an absolute timestamp. */ -- 2.7.4
