ProfessionalWiki / EDTF

PHP library to parse, represent and work with dates that follow the Extended Date/Time Format specification.
https://wikibase.consulting/wikibase-edtf
GNU General Public License v2.0
10 stars 7 forks source link
date-time edtf edtf-php parser php

EDTF PHP Library

GitHub Workflow Status Type Coverage 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.

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!

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->isOpenInterval(); // bool
$edtfDate->getQualification(); // \EDTF\Qualification

EDTF support and limits

All level 0, 1 and 2 EDTF formats can be parsed and represented, except for:

Humanization has more limits:

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

{
    "require": {
        "professional-wiki/edtf": "~1.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.0.1 - 2024-05-03

Version 3.0.0 - 2023-01-18

Functional changes:

Breaking API changes:

Further API changes:

Version 2.0.2 - 2022-04-29

Version 2.0.1 - 2022-02-19

Version 2.0.0 - 2021-04-28

Version 1.3.0 - 2021-04-26

Version 1.2.0 - 2021-04-16

Version 1.1.0 - 2021-03-20

Version 1.0.0 - 2021-03-19