Adding days to std.datetime.Date

Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Dec 6 14:32:54 PST 2014


On Tuesday, December 02, 2014 14:14:58 Steven Schveighoffer via Digitalmars-d-learn wrote:
> On 12/2/14 2:00 PM, H. S. Teoh via Digitalmars-d-learn wrote:
> > On Tue, Dec 02, 2014 at 06:49:54PM +0000, via Digitalmars-d-learn wrote:
> >>> But still, why this method
> >>> http://dlang.org/phobos/std_datetime.html#.Date.add only supports "month"
> >>> or "years" while this one
> >>> http://dlang.org/phobos/std_datetime.html#.Date.roll does ?
> >>
> >> But still, why this method
> >> http://dlang.org/phobos/std_datetime.html#.Date.add only supports
> >> "month" or "years" while this one
> >> http://dlang.org/phobos/std_datetime.html#.Date.roll does support days
> >> ?*
> >
> > Hmm. Looks like an oversight. File a bug?
>
> Not an oversight.
>
> Date.add and Date.roll are for adding units that are variable.
>
> For example, how many days are in a month? Answer: depends on the month.
> How many days in a year? Answer: depends on the year.
>
> But days are NOT variable, there are exactly 24 hours in a day. So to
> add a day, you just add a day with +=.

Exactly. add wouldn't even exist if it weren't for the fact that Duration
doesn't work with units greater than weeks because of they depend on what
date you're talking about.

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list