nextMidnight

Returns a SysTime of the following midnight.

nextMidnight
(
const SysTime now
)

Parameters

now SysTime

A SysTime of the base date from which to proceed to the next midnight.

Return Value

Type: auto

A SysTime of the midnight following the date passed as argument.

Examples

immutable now = Clock.currTime;
immutable midnight = now.nextMidnight;
writeln("Time until next midnight: ", (midnight - now));
import std.datetime : DateTime;
import std.datetime.systime : SysTime;
import std.datetime.timezone : UTC;

immutable utc = UTC();

immutable christmasEve = SysTime(DateTime(2018, 12, 24, 12, 34, 56), utc);
immutable nextDay = christmasEve.nextMidnight;
immutable christmasDay = SysTime(DateTime(2018, 12, 25, 0, 0, 0), utc);
assert(nextDay.toUnixTime() == christmasDay.toUnixTime());

immutable someDay = SysTime(DateTime(2018, 6, 30, 12, 27, 56), utc);
immutable afterSomeDay = someDay.nextMidnight;
immutable afterSomeDayToo = SysTime(DateTime(2018, 7, 1, 0, 0, 0), utc);
assert(afterSomeDay == afterSomeDayToo);

immutable newyearsEve = SysTime(DateTime(2018, 12, 31, 0, 0, 0), utc);
immutable newyearsDay = newyearsEve.nextMidnight;
immutable alsoNewyearsDay = SysTime(DateTime(2019, 1, 1, 0, 0, 0), utc);
assert(newyearsDay == alsoNewyearsDay);

immutable troubleDay = SysTime(DateTime(2018, 6, 30, 19, 14, 51), utc);
immutable afterTrouble = troubleDay.nextMidnight;
immutable alsoAfterTrouble = SysTime(DateTime(2018, 7, 1, 0, 0, 0), utc);
assert(afterTrouble == alsoAfterTrouble);

immutable novDay = SysTime(DateTime(2019, 11, 30, 12, 34, 56), utc);
immutable decDay = novDay.nextMidnight;
immutable alsoDecDay = SysTime(DateTime(2019, 12, 1, 0, 0, 0), utc);
assert(decDay == alsoDecDay);

immutable lastMarch = SysTime(DateTime(2005, 3, 31, 23, 59, 59), utc);
immutable firstApril = lastMarch.nextMidnight;
immutable alsoFirstApril = SysTime(DateTime(2005, 4, 1, 0, 0, 0), utc);
assert(firstApril == alsoFirstApril);