View source code
Display the source code in std/datetime/date.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone.

std.datetime.date.Date.opBinary - multiple declarations

Function Date.opBinary

Gives the result of adding or subtracting a Duration from

Date opBinary(string op) (
  Duration duration
) const pure nothrow @nogc @safe
if (op == "+" || op == "-");

The legal types of arithmetic for Date using this operator are

Date + Duration --> Date
Date - Duration --> Date

Parameters

NameDescription
duration The Duration to add to or subtract from this Date.

Example

import core.time : days;

writeln(Date(2015, 12, 31) + days(1)); // Date(2016, 1, 1)
writeln(Date(2004, 2, 26) + days(4)); // Date(2004, 3, 1)

writeln(Date(2016, 1, 1) - days(1)); // Date(2015, 12, 31)
writeln(Date(2004, 3, 1) - days(4)); // Date(2004, 2, 26)

Function Date.opBinary

Gives the difference between two Dates.

Duration opBinary(string op) (
  Date rhs
) const pure nothrow @nogc @safe
if (op == "-");

The legal types of arithmetic for Date using this operator are

Date - Date --> duration

Authors

Jonathan M Davis

License

Boost License 1.0.