Skip to content
ProfessionalWikiPublic

About

PHP library to parse, represent and work with dates that follow the Extended Date/Time Format specification.

Topics

Resources

Stars

12 stars

Watchers

9 watching

Forks

Repository files navigation

EDTF PHP Library

GitHub Workflow Status codecov Latest Stable Version Download count License

EDTF PHP is a small library for parsing, representing, and working with the Extended Date/Time Format specification.

Professional Wiki created and maintains EDTF. The Luxembourg Ministry of Culture funded the initial development. This library is an open-source project, so contributions are welcome! You can also commission software development via Professional Wiki.

Usage

Parsing

$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'

Validating

$validator = \EDTF\EdtfFactory::newValidator();
$validator->isValidEdtf('1985-04-12T23:20:30'); // true

Humanizing

$humanizer = \EDTF\EdtfFactory::newHumanizerForLanguage( 'en' );
$humanizer->humanize($edtfValue); // string

Object model

$edtfValue->getMax(); // int
$edtfValue->getMin(); // int
$edtfValue->covers(\EDTF\EdtfValue $anotherValue); // bool
$edtfDate->getYear(); // ?int
$edtfDate->getQualification(); // \EDTF\Model\Qualification

EDTF support and limits

All level 0, 1 and 2 EDTF formats can be parsed and represented.

Humanization has these limits:

  • Unspecified digit before a specified one in a year (EDTF level 2): 19X5 (some year from 1905 to 1995 ending in 5)
  • Qualification of an unspecified month or day (EDTF level 2): 2004-06-?XX (reads as if the whole date were uncertain)

Installation

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 3.x:

{
    "require": {
        "professional-wiki/edtf": "~3.0"
    }
}

Development

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

Release notes

Version 3.3.0 - 2026-12-03

  • Fixed months and days with an unspecified last digit being humanized as one value: 1985-1X is now "October to December 1985" instead of "October 1985"
  • Fixed the number after S being read as the number of insignificant digits: 1950S3 now spans 1950 to 1959 instead of 1000 to 1999, and -1950S2 is no longer rejected
  • Fixed the range of a year with an unspecified digit before a specified one, and of a negative year with unspecified digits: 19X5 now spans 1905 to 1995 instead of 1905 to 1909, and -19XX -1999 to -1900 instead of ending before it starts
  • Changed interval validity to follow these ranges: 19X5/1950 is now invalid, since its start can be as late as 1995, and -XXXX/2000 is now valid
  • Changed the humanization of a year with unspecified last digits: on its own, 197X is now "Some year in the 1970s (decade)" instead of "1970s", and 1XXX "Some year in the 1000s (millennium)" instead of "1000"; elsewhere, such as before Christ or in a season, it always ends in s: -19XX is now "1900s BC" instead of "1900 BC"
  • Added UnspecifiedDigit::monthHasOnlyLastDigitUnspecified, UnspecifiedDigit::dayHasOnlyLastDigitUnspecified and UnspecifiedDigit::yearHasOnlyLastDigitsUnspecified
  • Deprecated UnspecifiedDigit::century and UnspecifiedDigit::decade: use yearHasOnlyLastDigitsUnspecified with getYear, the number of unspecified year digits
  • Improved translations

Version 3.2.0 - 2026-12-02

  • Fixed winter seasons ending before they start: 2010-24 now ends in February 2011
  • Fixed seasons of a partly unspecified year covering only their first year: 19XX-24 now covers the winters of 1900 to 1999 and is humanized as "Winter 1900s" instead of "Winter 1900"
  • Fixed year 0 in dates and seasons: 0000-12 is now December of year 0 instead of a month without a year, and 0000-21 no longer throws a TypeError when parsed or validated
  • Added support for seasons of a fully unspecified year: XXXX-21 covers the spring of every year from 0 to 9999 and is humanized as "Spring of unknown year"
  • Changed the humanization of a fully unspecified year such as XXXX from "Year 0" to "Unknown year"
  • Added Season::getStartYear, Season::getEndYear and Season::getUnspecifiedDigit
  • Improved translations

Version 3.1.0 - 2025-09-23

  • Added support for installation with a newer version of a used date time library (nesbot/carbon 3.x)
  • Improved translations

Version 3.0.2 - 2025-05-12

  • Improved translations

Version 3.0.1 - 2024-05-03

  • Fixed "Undefined array key" warning when combining approximation qualifiers
  • Improved translations

Version 3.0.0 - 2023-01-18

Functional changes:

  • Improved humanization of uncertain and approximate dates
  • Improved capitalization in humanization, especially for French
  • Various translation updates from TranslateWiki, improving humanization for many languages
  • Added support for pluralization in humanization, for use by TranslateWiki

Breaking API changes:

  • Removed parameter of ExtDate::uncertain
  • Removed parameter of ExtDate::approximate
  • Renamed FrenchStrategy to DefaultStrategy
  • Made Qualification constructor arguments required

Further API changes:

  • Deprecated ExtDate::uncertain in favour of ExtDate::isUncertain
  • Deprecated ExtDate::approximate in favour of ExtDate::isApproximate
  • Added Qualification::newFullyKnown
  • Added Qualification::isFullyKnown
  • Added Qualification::dayIsKnown
  • Added Qualification::monthIsKnown
  • Added Qualification::yearIsKnown
  • Added Qualification::isUncertain, replacing Qualification::uncertain
  • Added Qualification::dayIsUncertain
  • Added Qualification::monthIsUncertain
  • Added Qualification::yearIsUncertain
  • Added Qualification::isApproximate, replacing Qualification::approximate
  • Added Qualification::dayIsApproximate
  • Added Qualification::monthIsApproximate
  • Added Qualification::yearIsApproximate
  • Added Qualification::isUniform
  • Added Qualification::monthAndYearHaveTheSameQualification
  • Added ExtDate::isUniformlyQualified

Version 2.0.2 - 2022-04-29

  • Improved translations

Version 2.0.1 - 2022-02-19

  • ? is no longer recognized as valid date

Version 2.0.0 - 2021-04-28

  • Fixed performance issue for sets with large range elements like 1000-01-01..2000-12-30
  • Fixed humanization of sets with more than one element, of which at least one an open range
  • Improved humanization of sets with range elements like 2000..2010
  • Intervals and set ranges with end dates earlier than their start dates are now rejected
  • Various breaking changes to the Set class
    • Constructor signature changed
    • Removed hasOpenStart and hasOpenEnd
    • Removed isSingleElement
  • Added Set::isEmpty
  • Added Set::getElements
  • Added SetElement interface with implementations
    • OpenSetElement
    • RangeSetElement
    • SingleDateSetElement
  • ExtDate::precision and Season::precision are now guaranteed to return an integer
  • precisionAsString in ExtDate and Season is now guaranteed to return a non-empty string

Version 1.3.0 - 2021-04-26

  • Fixed season support in intervals
  • Fixed parsing of open sets with an extra space like { ..2021} (thanks @chaudbak)
  • Added ExtDate::iso8601 and ExtDateTime::iso8601 (thanks @seth-shaw-unlv)
  • Added ParsingResult::getErrorMessage

Version 1.2.0 - 2021-04-16

  • Improved humanization of open sets

Version 1.1.0 - 2021-03-20

  • Added internationalization to the StructuredHumanizer service
  • Fixed handling of "year 0"

Version 1.0.0 - 2021-03-19

  • Initial release with
    • Support for EDTF levels 0, 1 and 2
    • Parsing
    • Object model
    • Internationalized humanization
    • Validation service
    • Example data

About

PHP library to parse, represent and work with dates that follow the Extended Date/Time Format specification.

Topics

Resources

Stars

12 stars

Watchers

9 watching

Forks

Sponsor this project

Used by

Contributors

Languages