Skip to content

Commit

Permalink
Merge pull request #3847 from bachmeil/change-datetime
Browse files Browse the repository at this point in the history
Documentation: Added example to DateTime opBinary and reference to core.time.Duration
  • Loading branch information
Hackerpilot committed Dec 2, 2015
2 parents 4a12bd6 + 0f23dba commit ef45b5e
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions std/datetime.d
Original file line number Diff line number Diff line change
Expand Up @@ -6173,7 +6173,7 @@ public:
)

Params:
duration = The duration to add to or subtract from this
duration = The $(CXREF time, Duration) to add to or subtract from this
$(LREF SysTime).
+/
SysTime opBinary(string op, D)(in D duration) @safe const pure nothrow
Expand All @@ -6194,6 +6194,14 @@ public:
return retval;
}

///
unittest
{
auto oldYear = SysTime(DateTime(2015, 12, 31, 23, 59, 59));
auto newYear = oldYear + 1.seconds;
assert(newYear == SysTime(DateTime(2016, 1, 1, 0, 0, 0)));
}

unittest
{
auto st = SysTime(DateTime(1999, 7, 6, 12, 30, 33), hnsecs(2_345_678));
Expand Down Expand Up @@ -16151,7 +16159,7 @@ public:
)

Params:
duration = The duration to add to or subtract from this
duration = The $(CXREF time, Duration) to add to or subtract from this
$(LREF DateTime).
+/
DateTime opBinary(string op, D)(in D duration) @safe const pure nothrow
Expand All @@ -16171,6 +16179,14 @@ public:
mixin(format(`return retval._addSeconds(convert!("hnsecs", "seconds")(%shnsecs));`, op));
}

///
unittest
{
auto oldYear = DateTime(2015, 12, 31, 23, 59, 59);
auto newYear = oldYear + 1.seconds;
assert(newYear == DateTime(2016, 1, 1, 0, 0, 0));
}

unittest
{
auto dt = DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33));
Expand Down

0 comments on commit ef45b5e

Please sign in to comment.