DateTime.opBinaryRight

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
Duration+DateTime-->DateTime
struct DateTime
const @safe pure nothrow @nogc
opBinaryRight
(
string op
)
(
Duration duration
)
if (
op == "+"
)

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));

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

Meta