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.enforceValid
- multiple declarations
Function enforceValid
void enforceValid(string units)
(
int value,
string file = __FILE__,
size_t line = __LINE__
) pure @safe
if (units == "months" || units == "hours" || units == "minutes" || units == "seconds");
Parameters
Name | Description |
---|---|
units | The units of time to validate. |
value | The number to validate. |
file | The file that the DateTimeException will list if thrown. |
line | The line number that the DateTimeException will list if
thrown. |
Throws
DateTimeException
if valid!units(value)
is false.
Example
import std .exception : assertThrown, assertNotThrown;
assertNotThrown(enforceValid!"months"(10));
assertNotThrown(enforceValid!"seconds"(40));
assertThrown!DateTimeException(enforceValid!"months"(0));
assertThrown!DateTimeException(enforceValid!"hours"(24));
assertThrown!DateTimeException(enforceValid!"minutes"(60));
assertThrown!DateTimeException(enforceValid!"seconds"(60));
Function enforceValid
Because the validity of the day number depends on both on the year and month of which the day is occurring, take all three variables to validate the day.
void enforceValid(string units)
(
int year,
Month month,
int day,
string file = __FILE__,
size_t line = __LINE__
) pure @safe
if (units == "days");
Parameters
Name | Description |
---|---|
units | The units of time to validate. |
year | The year of the day to validate. |
month | The month of the day to validate. |
day | The day to validate. |
file | The file that the DateTimeException will list if thrown. |
line | The line number that the DateTimeException will list if
thrown. |
Throws
DateTimeException
if valid!"days"(year, month, day)
is false.
Example
import std .exception : assertThrown, assertNotThrown;
assertNotThrown(enforceValid!"days"(2000, Month .jan, 1));
// leap year
assertNotThrown(enforceValid!"days"(2000, Month .feb, 29));
assertThrown!DateTimeException(enforceValid!"days"(2001, Month .feb, 29));
assertThrown!DateTimeException(enforceValid!"days"(2000, Month .jan, 32));
assertThrown!DateTimeException(enforceValid!"days"(2000, Month .apr, 31));
Authors
License
Copyright © 1999-2018 by the D Language Foundation | Page generated by ddox.