The OpenD Programming Language

DateTime.roll

Adds the given number of units to this DateTime, mutating it. A negative number will subtract.

The difference between rolling and adding is that rolling does not affect larger units. For instance, rolling a DateTime one year's worth of days gets the exact same DateTime.

Accepted units are "days", "minutes", "hours", "minutes", and "seconds".

  1. DateTime roll(long value, AllowDayOverflow allowOverflow)
  2. DateTime roll(long value)
  3. DateTime roll(long value)
    struct DateTime
    ref @safe pure nothrow @nogc
    roll
    (
    string units
    )
    (
    long value
    )
    if (
    units == "hours" ||
    units == "minutes"
    ||
    units == "seconds"
    )

Parameters

units

The units to add.

value long

The number of units to add to this DateTime.

Return Value

Type: DateTime

A reference to the DateTime (this).

Examples

auto dt1 = DateTime(2010, 1, 1, 11, 23, 12);
dt1.roll!"days"(1);
assert(dt1 == DateTime(2010, 1, 2, 11, 23, 12));
dt1.roll!"days"(365);
assert(dt1 == DateTime(2010, 1, 26, 11, 23, 12));
dt1.roll!"days"(-32);
assert(dt1 == DateTime(2010, 1, 25, 11, 23, 12));

auto dt2 = DateTime(2010, 7, 4, 12, 0, 0);
dt2.roll!"hours"(1);
assert(dt2 == DateTime(2010, 7, 4, 13, 0, 0));

auto dt3 = DateTime(2010, 1, 1, 0, 0, 0);
dt3.roll!"seconds"(-1);
assert(dt3 == DateTime(2010, 1, 1, 0, 0, 59));

Meta