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.valid
- multiple declarations
Function valid
Returns whether the given value is valid for the given unit type when in a time point. Naturally, a duration is not held to a particular range, but the values in a time point are (e.g. a month must be in the range of 1 - 12 inclusive).
bool valid(string units)
(
int value
) pure nothrow @nogc @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. |
Example
assert(valid!"hours"(12));
assert(!valid!"hours"(32));
assert(valid!"months"(12));
assert(!valid!"months"(13));
Function valid
Returns whether the given day is valid for the given year and month.
bool valid(string units)
(
int year,
int month,
int day
) pure nothrow @nogc @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 (January is 1). |
day | The day to validate. |
Example
assert(valid!"days"(2016, 2, 29));
assert(!valid!"days"(2016, 2, 30));
assert(valid!"days"(2017, 2, 20));
assert(!valid!"days"(2017, 2, 29));
Authors
License
Copyright © 1999-2018 by the D Language Foundation | Page generated by ddox.