The OpenD Programming Language

SysTime.roll

Adds the given number of years or months to this SysTime. A negative number will subtract.

The difference between rolling and adding is that rolling does not affect larger units. Rolling a SysTime 12 months gets the exact same SysTime. However, the days can still be affected due to the differing number of days in each month.

Because there are no units larger than years, there is no difference between adding and rolling years.

  1. SysTime roll(long value, AllowDayOverflow allowOverflow)
    struct SysTime
    ref @safe nothrow scope
    roll
    (
    string units
    )
    if (
    units == "years"
    )
  2. SysTime roll(long value)

Parameters

units

The type of units to add ("years" or "months").

value long

The number of months or years to add to this SysTime.

allowOverflow AllowDayOverflow

Whether the days should be allowed to overflow, causing the month to increment.

Examples

import std.datetime.date : AllowDayOverflow, DateTime;

auto st1 = SysTime(DateTime(2010, 1, 1, 12, 33, 33));
st1.roll!"months"(1);
assert(st1 == SysTime(DateTime(2010, 2, 1, 12, 33, 33)));

auto st2 = SysTime(DateTime(2010, 1, 1, 12, 33, 33));
st2.roll!"months"(-1);
assert(st2 == SysTime(DateTime(2010, 12, 1, 12, 33, 33)));

auto st3 = SysTime(DateTime(1999, 1, 29, 12, 33, 33));
st3.roll!"months"(1);
assert(st3 == SysTime(DateTime(1999, 3, 1, 12, 33, 33)));

auto st4 = SysTime(DateTime(1999, 1, 29, 12, 33, 33));
st4.roll!"months"(1, AllowDayOverflow.no);
assert(st4 == SysTime(DateTime(1999, 2, 28, 12, 33, 33)));

auto st5 = SysTime(DateTime(2000, 2, 29, 12, 30, 33));
st5.roll!"years"(1);
assert(st5 == SysTime(DateTime(2001, 3, 1, 12, 30, 33)));

auto st6 = SysTime(DateTime(2000, 2, 29, 12, 30, 33));
st6.roll!"years"(1, AllowDayOverflow.no);
assert(st6 == SysTime(DateTime(2001, 2, 28, 12, 30, 33)));

Meta