TimeOfDay.roll

Adds the given number of units to this TimeOfDay, 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 TimeOfDay one hours's worth of minutes gets the exact same TimeOfDay.

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

  1. TimeOfDay roll(long value)
    struct TimeOfDay
    ref @safe pure nothrow @nogc
    roll
    (
    string units
    )
    (
    long value
    )
    if (
    units == "hours"
    )
  2. TimeOfDay roll(long value)

Parameters

units

The units to add.

value long

The number of units to add to this TimeOfDay.

Return Value

Type: TimeOfDay

A reference to the TimeOfDay (this).

Examples

auto tod1 = TimeOfDay(7, 12, 0);
tod1.roll!"hours"(1);
assert(tod1 == TimeOfDay(8, 12, 0));

auto tod2 = TimeOfDay(7, 12, 0);
tod2.roll!"hours"(-1);
assert(tod2 == TimeOfDay(6, 12, 0));

auto tod3 = TimeOfDay(23, 59, 0);
tod3.roll!"minutes"(1);
assert(tod3 == TimeOfDay(23, 0, 0));

auto tod4 = TimeOfDay(0, 0, 0);
tod4.roll!"minutes"(-1);
assert(tod4 == TimeOfDay(0, 59, 0));

auto tod5 = TimeOfDay(23, 59, 59);
tod5.roll!"seconds"(1);
assert(tod5 == TimeOfDay(23, 59, 0));

auto tod6 = TimeOfDay(0, 0, 0);
tod6.roll!"seconds"(-1);
assert(tod6 == TimeOfDay(0, 0, 59));

Meta