Errors and Translations
Every error of the package is a Derafu\Date\Exception\DateException, which extends TranslatableInvalidArgumentException of derafu/translation. Catching DateException, or PHP’s InvalidArgumentException, catches all of them.
| Exception | When |
|---|---|
InvalidDateException |
A text is not a date, a date is not valid in its format, a time unit does not exist, or a number of the working day is less than 1. |
InvalidMonthException |
A month, a text AAAA-MM or a number AAAAMM is not a month, or a move leaves the years 1 to 9999. |
InvalidPeriodException |
The end of a period is before its start, a quarter or a semester does not exist, a number of units is less than 1, or a period must be in a single year and it is not. |
The last two extend DateException, like the first one.
try {
Month::fromInt(202513);
} catch (InvalidMonthException $e) {
$e->getMessage(); // Invalid month period: 202513.
}
Translations
The messages of the exceptions (domain errors) and the names and phrases of the dates (domain date) are translatable, and the Spanish translations ship with the package. To have them in your translator, import its services (or add DateTranslationResourceProvider to the resource providers of the translator):
imports:
- { resource: '../vendor/derafu/date/resources/config/date-services.yaml' }
The same file registers DateFormatterInterface and a SystemClock for Psr\Clock\ClockInterface.
With the translator, the message of the example above is El período 202513 no es un mes, debe escribirse AAAAMM.