DateTime.opBinary

Gives the result of adding or subtracting a core.time.Duration from this DateTime.

The legal types of arithmetic for DateTime using this operator are

DateTime+Duration-->DateTime
DateTime-Duration-->DateTime
  1. DateTime opBinary(Duration duration)
    struct DateTime
    const @safe pure nothrow @nogc
    opBinary
    (
    string op
    )
    (
    Duration duration
    )
    if (
    op == "+" ||
    op == "-"
    )
  2. Duration opBinary(DateTime rhs)

Parameters

duration Duration

The core.time.Duration to add to or subtract from this DateTime.

Examples

import core.time : hours, seconds;

assert(DateTime(2015, 12, 31, 23, 59, 59) + seconds(1) ==
       DateTime(2016, 1, 1, 0, 0, 0));

assert(DateTime(2015, 12, 31, 23, 59, 59) + hours(1) ==
       DateTime(2016, 1, 1, 0, 59, 59));

assert(DateTime(2016, 1, 1, 0, 0, 0) - seconds(1) ==
       DateTime(2015, 12, 31, 23, 59, 59));

assert(DateTime(2016, 1, 1, 0, 59, 59) - hours(1) ==
       DateTime(2015, 12, 31, 23, 59, 59));

Meta