The OpenD Programming Language

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.

  1. void enforceValid(int value, string file, size_t line)
  2. void enforceValid(int year, Month month, int day, string file, size_t line)
    @safe pure
    void
    enforceValid
    (
    string units
    )
    (
    int year
    ,,
    int day
    ,
    string file = __FILE__
    ,
    size_t line = __LINE__
    )
    if (
    units == "days"
    )

Parameters

units

The units of time to validate.

year int

The year of the day to validate.

month Month

The month of the day to validate.

day int

The day to validate.

file string

The file that the DateTimeException will list if thrown.

line size_t

The line number that the DateTimeException will list if thrown.

Throws

DateTimeException if valid!"days"(year, month, day) is false.

Examples

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));

Meta