| |
| Posted by Jonathan M Davis in reply to Steven Schveighoffer | PermalinkReply |
|
Jonathan M Davis
| On Saturday, February 10, 2024 7:31:47 PM MST Steven Schveighoffer via Digitalmars-d-learn wrote:
> On Saturday, 10 February 2024 at 23:48:56 UTC, Jonathan M Davis
>
> wrote:
> > If I understand correctly, he cares about how far into the
> > month the dates
> > are, whereas diffMonths ignores the smaller units, meaning that
> > you get the
> > same result no matter when in the month the dates are. So,
> > 2000-05-10 - 1990-05-09 would give 10, whereas 2000-05-10 -
> > 1990-05-30
> > would give 9. diffMonths / 12 would give 10 in both cases.
>
> I thought `diffMonths` was actually already taking this into account...
>
> Looking at the impl, it's pretty simple.
>
> Would it make sense to have an overload that takes into account the day as well as the month/year? This kind of stuff is sometimes tricky to get right.
Possibly. Given the trickiness involved, there probably should be a function in std.datetime to handle it, but I'll have to think about what the best way to do it would be in terms of the API.
It is kind of similar to how some functions behave differently depending on how you want to treat the end of the month (e.g. whether adding a month to May 31st gives you June 30th or July 1st), but it's also not quite the same. So, the enum related to that wouldn't be appropriate, but it's yet another edge case where sometimes you want one behavior, and at other times, you want the other behavior.
- Jonathan M Davis
|