Phobos: Determining number of hours or minutes or seconds till now

Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jan 20 04:50:18 PST 2017


On Friday, January 20, 2017 08:39:40 Rene Zwanenburg via Digitalmars-d-learn 
wrote:
> On Friday, 20 January 2017 at 03:48:14 UTC, rikki cattermole
>
> wrote:
> > As per the documentation this is wrong for anything beyond a
> > few weeks.
> > Although I have no idea if that's the case implementation wise.
>
> I think the documentation is talking about the units used, not
> length of the duration. The reason Duration makes this
> distinction is because months and everything larger have a
> variable length. I'm not sure though.

Exactly. The conversion from anything smaller than a week up to a week (and
vice versa) is well-defined. A week is 7 days, a day is 24 hours, an hour is
60 minutes, etc. However, then number of days or weeks in a month is
undefined as is the number of days, weeks, or months in a year. And it's
certainly undefined how many hecto-nanoseconds there are in a month or year.
The only way to know is to compare actual dates. A duration type that holds
its value in hecto-nanoseconds (which core.time.Duration does) cannot
possibly deal with units greater than weeks.

When I originally proposed std.datetime, to try and deal with the problem, I
had something like HNDuration, MonthDuration, and JoinerDuration (where
HNDuration was the same as Duration is now, whereas MonthDuration held its
value in months and JoinerDuration held an HNDuration and a MonthDuration).
However, it was deemed way too complicated to be worth it (and at this
point, I'm inclined to agree).

Time is one of those things that seems quite simple at first but tends to
get annoyingly mucky once you get into the finer details.

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list