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.CmpTimeUnits/cmpTimeUnits
- multiple declarations
Function cmpTimeUnits
Compares two time unit strings. "years"
are the largest units and
"hnsecs"
are the smallest.
int cmpTimeUnits
(
string lhs,
string rhs
) pure @safe;
Returns
this < rhs | < 0 |
this == rhs | 0 |
this > rhs | > 0 |
Throws
DateTimeException
if either of the given strings is not a valid
time unit string.
Example
import std .exception : assertThrown;
writeln(cmpTimeUnits("hours", "hours")); // 0
assert(cmpTimeUnits("hours", "weeks") < 0);
assert(cmpTimeUnits("months", "seconds") > 0);
assertThrown!DateTimeException(cmpTimeUnits("month", "second"));
Enum member CmpTimeUnits
Compares two time unit strings at compile time. "years"
are the largest
units and "hnsecs"
are the smallest.
enum CmpTimeUnits(string lhs, string rhs)
= cmpTimeUnitsCTFE(lhs, rhs);
This template is used instead of cmpTimeUnits
because exceptions
can't be thrown at compile time and cmpTimeUnits
must enforce that
the strings it's given are valid time unit strings. This template uses a
template constraint instead.
Returns
this < rhs | < 0 |
this == rhs | 0 |
this > rhs | > 0 |
Example
static assert(CmpTimeUnits!("years", "weeks") > 0);
static assert(CmpTimeUnits!("days", "days") == 0);
static assert(CmpTimeUnits!("seconds", "hours") < 0);
Authors
License
Copyright © 1999-2018 by the D Language Foundation | Page generated by ddox.