The OpenD Programming Language

YearMonth.add

  1. YearMonth add(long months)
    struct YearMonth
    nothrow deprecated @safe pure nothrow @nogc ref
    add
    (
    string units : "months"
    )
    (
    long months
    )
  2. YearMonth add(long quarters)
  3. YearMonth add(long years)

Examples

auto ym0 = YearMonth(2020, Month.jan);

ym0.add!"months"(1);
assert(ym0.year == 2020);
assert(ym0.month == Month.feb);

auto ym1 = ym0.add!"months"(1);
assert(ym1.year == 2020);
assert(ym1.month == Month.mar);

// also changes ym0
assert(ym0.year == 2020);
assert(ym0.month == Month.mar);

ym1.add!"months"(10);
assert(ym1.year == 2021);
assert(ym1.month == Month.jan);

ym1.add!"months"(-13);
assert(ym1.year == 2019);
assert(ym1.month == Month.dec);

Meta