professional-wiki/edtf
Composer 安装命令:
composer require professional-wiki/edtf
包简介
PHP library to parse, represent and work with dates that follow the Extended Date/Time Format specification.
README 文档
README
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->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:
- Open ranges with a date (Level 2: Qualification):
..2004-06-01/2004-06-20(This is supported:../2004-06-20)
Humanization has more limits:
- Significant digits (EDTF level 2):
1950S2(some year between 1900 and 1999, estimated to be 1950) - Group Qualification (EDTF level 2):
2004-06~-11(year and month approximate) - Qualification of Individual Component (EDTF level 2):
?2004-06-~11(year uncertain; month known; day approximate) - Level 2 Unspecified Digit:
1XXX-1X(October, November, or December during the 1000s)
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.1.0 - 2025-09-23
- Added support for installation with a newer version of a used date time library (
nesbot/carbon3.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
FrenchStrategytoDefaultStrategy - Made
Qualificationconstructor arguments required
Further API changes:
- Deprecated
ExtDate::uncertainin favour ofExtDate::isUncertain - Deprecated
ExtDate::approximatein favour ofExtDate::isApproximate - Added
Qualification::newFullyKnown - Added
Qualification::isFullyKnown - Added
Qualification::dayIsKnown - Added
Qualification::monthIsKnown - Added
Qualification::yearIsKnown - Added
Qualification::isUncertain, replacingQualification::uncertain - Added
Qualification::dayIsUncertain - Added
Qualification::monthIsUncertain - Added
Qualification::yearIsUncertain - Added
Qualification::isApproximate, replacingQualification::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
Setclass- Constructor signature changed
- Removed
hasOpenStartandhasOpenEnd - Removed
isSingleElement
- Added
Set::isEmpty - Added
Set::getElements - Added
SetElementinterface with implementationsOpenSetElementRangeSetElementSingleDateSetElement
ExtDate::precisionandSeason::precisionare now guaranteed to return an integerprecisionAsStringinExtDateandSeasonis 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::iso8601andExtDateTime::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
StructuredHumanizerservice - 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
professional-wiki/edtf 适用场景与选型建议
professional-wiki/edtf 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 462.66k 次下载、GitHub Stars 达 10, 最近一次更新时间为 2020 年 11 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 professional-wiki/edtf 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 professional-wiki/edtf 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 462.66k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 10
- 点击次数: 35
- 依赖项目数: 4
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0-or-later
- 更新时间: 2020-11-12