EDTF PHP is a small library for parsing, representing and working with the Extended Date/Time Format specification.
EDTF PHP was created by and is maintained by Professional.Wiki. Initial development was funded by the Luxembourg Ministry of Culture. It is an open source project, and contributions are welcome!
$parser = \EDTF\EdtfFactory::newParser();
$parsingResult = $parser->parse('1985-04-12T23:20:30');
$parsingResult->isValid(); // true
$parsingResult->getEdtfValue(); // \EDTF\EdtfValue
$parsingResult->getInput(); // '1985-04-12T23:20:30'
$validator = \EDTF\EdtfFactory::newValidator();
$validator->isValidEdtf('1985-04-12T23:20:30'); // true
$humanizer = \EDTF\EdtfFactory::newHumanizerForLanguage( 'en' );
$humanizer->humanize($edtfValue); // string
$edtfValue->getMax(); // int
$edtfValue->getMin(); // int
$edtfValue->covers(\EDTF\EdtfValue $anotherValue); // bool
$edtfDate->getYear(); // int
$edtfDate->isOpenInterval(); // bool
$edtfDate->getQualification(); // \EDTF\Qualification
All level 0, 1 and 2 EDTF formats can be parsed and represented, except for:
..2004-06-01/2004-06-20
(This is supported: ../2004-06-20
)Humanization has more limits:
1950S2
(some year between 1900 and 1999, estimated to be 1950)2004-06~-11
(year and month approximate)?2004-06-~11
(year uncertain; month known; day approximate)1XXX-1X
(October, November, or December during the 1000s)To use the EDTF library in your project, simply add a dependency on professional-wiki/edtf
to your project's composer.json
file. Here is a minimal example of a composer.json
file that just defines a dependency on EDTF 1.x:
{
"require": {
"professional-wiki/edtf": "~1.0"
}
}
Start by installing the project dependencies by executing
composer update
You can run the tests by executing
make test
You can run style checks and static analysis by executing
make cs
To run all CI checks, execute
make
You can also invoke PHPUnit directly to pass it arguments, as follows
vendor/bin/phpunit --filter SomeClassNameOrFilter
Functional changes:
Breaking API changes:
ExtDate::uncertain
ExtDate::approximate
FrenchStrategy
to DefaultStrategy
Qualification
constructor arguments requiredFurther API changes:
ExtDate::uncertain
in favour of ExtDate::isUncertain
ExtDate::approximate
in favour of ExtDate::isApproximate
Qualification::newFullyKnown
Qualification::isFullyKnown
Qualification::dayIsKnown
Qualification::monthIsKnown
Qualification::yearIsKnown
Qualification::isUncertain
, replacing Qualification::uncertain
Qualification::dayIsUncertain
Qualification::monthIsUncertain
Qualification::yearIsUncertain
Qualification::isApproximate
, replacing Qualification::approximate
Qualification::dayIsApproximate
Qualification::monthIsApproximate
Qualification::yearIsApproximate
Qualification::isUniform
Qualification::monthAndYearHaveTheSameQualification
ExtDate::isUniformlyQualified
?
is no longer recognized as valid date1000-01-01..2000-12-30
2000..2010
Set
class
hasOpenStart
and hasOpenEnd
isSingleElement
Set::isEmpty
Set::getElements
SetElement
interface with implementations
OpenSetElement
RangeSetElement
SingleDateSetElement
ExtDate::precision
and Season::precision
are now guaranteed to return an integerprecisionAsString
in ExtDate
and Season
is now guaranteed to return a non-empty string{ ..2021}
(thanks @chaudbak)ExtDate::iso8601
and ExtDateTime::iso8601
(thanks @seth-shaw-unlv)ParsingResult::getErrorMessage
StructuredHumanizer
service