1

I see that there is an operator -= on year_month_day, but this:

auto tp = zoned_time{current_zone(), now}.get_local_time();
auto dp = floor<days>(tp);
year_month_day ymd(dp);
ymd -= 1d; // this is not possible ?!

the overloaded operator seems implemented only for months and years. Why it is so?

AndrewBloom
  • 2,171
  • 20
  • 30
  • just do the arithmetic on `tp` before converting to `year_month_day` – Alan Birtles Mar 21 '23 at 12:39
  • I'm not sure why it was designed this way, but from cppreference: *An implicit conversion to and from std::chrono::sys_days allows std::chrono::days-oriented arithmetic to be performed efficiently.* – NathanOliver Mar 21 '23 at 12:40
  • 2
    @NathanOliver this link from the duplicate explains it https://github.com/HowardHinnant/date/wiki/FAQ#day_arithmetic – Richard Critten Mar 21 '23 at 12:45
  • @AlanBirtles just to say yesterday i tried to push a date forward adding 1 month to now like you're proposing and it changed the time too.... I'm not sure what kind of weird behaviours can come out doing that... – AndrewBloom Mar 21 '23 at 12:46
  • @RichardCritten thanks, the link seems full of explanations, I wish those were already copied on the usual cpp documentations online! – AndrewBloom Mar 21 '23 at 12:55
  • cppreference is an editable wiki, if you think the documentation is lacking something then edit it in – Alan Birtles Mar 21 '23 at 13:55

0 Answers0