PHPackages                             data-values/time - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. data-values/time

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

data-values/time
================

Time value objects, parsers and formatters

1.2.0(1y ago)10318.6k↑14.9%6[2 issues](https://github.com/wmde/Time/issues)[2 PRs](https://github.com/wmde/Time/pulls)13GPL-2.0-or-laterPHPPHP &gt;=7.4.0

Since Nov 17Pushed 1y ago20 watchersCompare

[ Source](https://github.com/wmde/Time)[ Packagist](https://packagist.org/packages/data-values/time)[ Docs](https://github.com/DataValues/Time)[ RSS](/packages/data-values-time/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (5)Versions (35)Used By (13)

DataValues Time
===============

[](#datavalues-time)

Library containing value objects to represent temporal information, parsers to turn user input into such value objects, and formatters to turn them back into user consumable representations.

It is part of the [DataValues set of libraries](https://github.com/DataValues).

[![Build Status](https://github.com/wmde/Time/actions/workflows/lint-and-test.yaml/badge.svg?branch=master)](https://github.com/wmde/Time/actions/workflows/lint-and-test.yaml)[![Code Coverage](https://camo.githubusercontent.com/2ab6aae38f2bb91244668078d9a8f15c7e34deb2c46a9de4c6dfd448269f2b9e/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f776d64652f54696d652f6261646765732f636f7665726167652e706e673f733d63356462376233373537366465646165646432386432376130653566646132623739653836646136)](https://scrutinizer-ci.com/g/wmde/Time/)[![Scrutinizer Quality Score](https://camo.githubusercontent.com/38160b501daacf6aef59607f5e76b030cc69908785924a510f49947f913523d0/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f776d64652f54696d652f6261646765732f7175616c6974792d73636f72652e706e673f733d33633636646231653539613862663737663965396130383736306139326361396332363533386239)](https://scrutinizer-ci.com/g/wmde/Time/)

On [Packagist](https://packagist.org/packages/data-values/time): [![Latest Stable Version](https://camo.githubusercontent.com/9681de2cd74a148e9db4590303116f292eff97ec9b3fbcebe7e927587cbed443/68747470733a2f2f706f7365722e707567782e6f72672f646174612d76616c7565732f74696d652f76657273696f6e2e706e67)](https://packagist.org/packages/data-values/time)[![Download count](https://camo.githubusercontent.com/f26648c54252113b3200b524411cd800b7702abbd58c1ddaf69d2b7f3bb14fea/68747470733a2f2f706f7365722e707567782e6f72672f646174612d76616c7565732f74696d652f642f746f74616c2e706e67)](https://packagist.org/packages/data-values/time)

Installation
------------

[](#installation)

The recommended way to use this library is via [Composer](http://getcomposer.org/).

### Composer

[](#composer)

To add this package as a local, per-project dependency to your project, simply add a dependency on `data-values/time` to your project's `composer.json` file. Here is a minimal example of a `composer.json` file that just defines a dependency on version 1.x of this package:

```
    {
        "require": {
            "data-values/time": "~1.2"
        }
    }
```

### Manual

[](#manual)

Get the code of this package, either via git, or some other means. Also get all dependencies. You can find a list of the dependencies in the "require" section of the composer.json file. Then take care of autoloading the classes defined in the src directory.

Tests
-----

[](#tests)

This library comes with a set up PHPUnit tests that cover all non-trivial code. You can run these tests using the PHPUnit configuration file found in the root directory. The tests can also be run via TravisCI, as a TravisCI configuration file is also provided in the root directory.

Authors
-------

[](#authors)

DataValues Time has been written by the Wikidata team, as [Wikimedia Germany](https://wikimedia.de/en)employees for the [Wikidata project](https://wikidata.org/).

Release notes
-------------

[](#release-notes)

### 1.2.0 (2024-12-12)

[](#120-2024-12-12)

- Drop support for PHP 7.2, 7.3
- Upgrade codesniffer rules to current `mediawiki/mediawiki-codesniffer` version (45.0.0)
- Make nullable type parameter declarations explicit for compatibility with PHP 8.4

### 1.1.2 (2022-10-24)

[](#112-2022-10-24)

- Allow installation together with data-values/common 1.1.0 and data-values/interfaces 1.x

### 1.1.1 (2022-10-21)

[](#111-2022-10-21)

- Allow installation together with DataValues 3.1

### 1.1.0 (2022-10-21)

[](#110-2022-10-21)

- Improved compatibility with PHP 8.1; in particular, the new `__serialize`/`__unserialize` methods are implemented now (in addition to the still supported `Serializable` interface). Make sure to also use `data-values/data-values` version 3.1.0 (or later) to keep hashes stable.
- Added support for the YYYY-DDD format (DDDth day of the year) added in PHP 8.1.7. (Not supported in earlier PHP versions.)

### 1.0.4 (2021-07-15)

[](#104-2021-07-15)

- Support month+year dates with era

### 1.0.3 (2021-03-18)

[](#103-2021-03-18)

- Update major `data-values/*` versions

### 1.0.2 (2020-08-20)

[](#102-2020-08-20)

- Fixed parsing unicode month names

### 1.0.1 (2018-09-18)

[](#101-2018-09-18)

- Parse and refuse invalid calendar option

### 1.0.0 (2018-08-02)

[](#100-2018-08-02)

- Removed `DATAVALUES_TIME_VERSION` constant
- Allow installation together with DataValues 2.x

### 0.8.6 (2017-09-06)

[](#086-2017-09-06)

- Added whitespace trimming to `YearTimeParser`.
- Fixed `IsoTimestampParser` and `TimeValue` accepting a time of day with no day.
- Fixed `MonthNameUnlocalizer` accidentally replacing already unlocalized numeric months.
- Fixed `PhpDateTimeParser` misinterpreting inputs with only one or two numbers.
- Deprecated `TimeValue::newFromArray`.
- Raised required PHP version from 5.3 to 5.5.

### 0.8.5 (2017-08-09)

[](#085-2017-08-09)

- Removed MediaWiki integration
- Bump data-values/common dependency

### 0.8.4 (2016-04-20)

[](#084-2016-04-20)

- Added `MonthNameProvider` interface.
- Added `MonolingualMonthNameProvider`.
- Added `YearMonthTimeParser`.
- Added `YearTimeParser`.

### 0.8.3 (2016-03-16)

[](#083-2016-03-16)

- Added optional `ParserOptions` parameter to the `YearMonthDayTimeParser` constructor.
- Fixed `YearMonthDayTimeParser` not accepting calendar model and precision options.
- Fixed `IsoTimestampParser` not accepting string precisions.
- Fixed `IsoTimestampParser` not always throwing an exception on invalid precisions.
- Fixed `FORMAT_NAME` constants in parsers.

### 0.8.2 (2015-09-15)

[](#082-2015-09-15)

- Fixed `IsoTimestampParser` and `TimeValue` accepting days with no month.
- Fixed `YearMonthDayTimeParser` rejecting YDM dates.
- `YearMonthDayTimeParser` accepts some more dates where month and day are the same anyway.

### 0.8.1 (2015-08-14)

[](#081-2015-08-14)

#### Additions

[](#additions)

- Added `YearMonthDayTimeParser`.
- `PhpDateTimeParser` now accepts space-separated dates in YMD order.

#### Other changes

[](#other-changes)

- The component can now be installed together with DataValues Interfaces 0.2.x.
- The component can now be installed together with DataValues Common 0.3.x.

### 0.8.0 (2015-06-26)

[](#080-2015-06-26)

#### Breaking changes

[](#breaking-changes)

- `IsoTimestampParser` auto-detects the calendar model and does not default to Gregorian any more
- Removed `IsoTimestampParser::PRECISION_NONE`, use `null` instead
- `TimeValue`s leap second range changed from \[0..62\] to \[0..61\]

#### Additions

[](#additions-1)

- Added `EraParser`
- Added `TimeValue::CALENDAR_GREGORIAN` and `TimeValue::CALENDAR_JULIAN`
- Renamed all `TimeValue::PRECISION_...` constants with lower case letters, e.g. `PRECISION_10a` to `PRECISION_YEAR10`, leaving backwards compatible aliases
- `IsoTimestampParser` now accepts time values with optional colons, per ISO
- `PhpDateTimeParser` now accepts comma separated dates

#### Other changes

[](#other-changes-1)

- Fixed `IsoTimestampParser` not being able to set precision to hour, minute or second on midnight
- Deprecated `IsoTimestampParser::CALENDAR_GREGORIAN` and `IsoTimestampParser::CALENDAR_JULIAN`
- Deprecated `TimeFormatter::CALENDAR_GREGORIAN` and `TimeFormatter::CALENDAR_JULIAN`

### 0.7.0 (2015-04-20)

[](#070-2015-04-20)

#### Breaking changes

[](#breaking-changes-1)

- Renamed `TimeParser` to `IsoTimestampParser`
- Empty strings are now detected as invalid calendar models in the `TimeValue` constructor

#### Additions

[](#additions-2)

- Added `MonthNameUnlocalizer`
- Added `PhpDateTimeParser`
- `IsoTimestampParser` can now parse various YMD ordered timestamp strings resembling ISO 8601
- `CalendarModelParser` now accepts URIs and localized calendar names given via options

#### Other changes

[](#other-changes-2)

- The year in `TimeValue`s is now padded to 4 digits, and additional leading zeros are trimmed
- Major update of the `TimeValue` documentation
- Constructor arguments in `IsoTimestampParser` and `TimeFormatter` are optional now
- Fixed `TimeFormatter` delegating to an ISO timestamp formatter given via option
- `TimeFormatter` does not output the calendar model any more

### 0.6.1 (2014-10-09)

[](#061-2014-10-09)

- Made component installable with DataValues 1.x

### 0.6.0 (2014-06-05)

[](#060-2014-06-05)

- Added TimeValueCalculator
- Removed TimeIsoFormatter interface
- Introduced FORMAT\_NAME class constants on ValueParsers in order to use them as expectedFormat
- Changed ValueParsers to pass rawValue and expectedFormat arguments when constructing a ParseException

### 0.5.2 (2014-04-28)

[](#052-2014-04-28)

- Fix parsing of years ending in zero, defaulting precision to year when year is &lt;= 4000 and &gt;= 4000 BC.

### 0.5.1 (2014-03-24)

[](#051-2014-03-24)

- Fix composer version of DataValues/Common

### 0.5.0 (2014-03-21)

[](#050-2014-03-21)

- Removed TimeParser::SIGN\_PATTERN constant
- Removed TimeParser::TIME\_PATTERN constant
- Fixed [bug 62730](https://bugzilla.wikimedia.org/show_bug.cgi?id=62730). The TimeParser now returns the correct precision when only month and year or year is given

### 0.4.0 (2014-03-14)

[](#040-2014-03-14)

- Corrected spelling errors calender/calander -&gt; calendar

### 0.3.0 (2014-03-13)

[](#030-2014-03-13)

- Renamed CalenderModelParser to CalendarModelParser
- Added Calandar and Precision options to TimeParser

### 0.2.0 (2014-02-11)

[](#020-2014-02-11)

Added features:

- TimeParser
- CalenderModelParser

### 0.1.0 (2013-11-17)

[](#010-2013-11-17)

Initial release with these features:

- TimeValue
- TimeFormatter
- TimeIsoFormatter

Links
-----

[](#links)

- [DataValues Time on Packagist](https://packagist.org/packages/data-values/time)
- [DataValues Time on TravisCI](https://travis-ci.org/wmde/Time)

###  Health Score

50

—

FairBetter than 96% of packages

Maintenance35

Infrequent updates — may be unmaintained

Popularity42

Moderate usage in the ecosystem

Community40

Growing community involvement

Maturity75

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~155 days

Recently: every ~311 days

Total

27

Last Release

522d ago

Major Versions

0.8.6 → 1.0.02018-08-02

PHP version history (4 changes)0.1PHP &gt;=5.3.0

0.8.6PHP &gt;=5.5.9

1.0.3PHP &gt;=7.2.0

1.2.0PHP &gt;=7.4.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/451bd4039d530fed8f9c3da91bfa519233a397d2182cdfdcad700f6cfea19b7f?d=identicon)[Jeroen De Dauw](/maintainers/Jeroen%20De%20Dauw)

![](https://www.gravatar.com/avatar/054adb441e7ee248ec924bc45fa793835c284710eb31627587fa5de21bab9e96?d=identicon)[wmde](/maintainers/wmde)

![](https://www.gravatar.com/avatar/5406ed1d40d50ffc61d67e9f5149914dbfe0b8a52bdf297299f5ccfab0a73d91?d=identicon)[thiemowmde](/maintainers/thiemowmde)

![](https://www.gravatar.com/avatar/fe4220e5a109212ea1a84969fbcb0795ceaf975145c1f0577bd758d0500e6428?d=identicon)[manicki](/maintainers/manicki)

![](https://www.gravatar.com/avatar/8cc7ef1a982b9520bbe19e7699556cda12f528e2fcece72d0d18e79b6457794c?d=identicon)[mariushoch](/maintainers/mariushoch)

![](https://avatars.githubusercontent.com/u/22235?v=4)[Stefan Wasilewski](/maintainers/SMW)[@smw](https://github.com/smw)

![](https://www.gravatar.com/avatar/0c1ddc1309ce2f268d42afc35c3065421f8a6d21e4ca25eb338db3a297cdef1b?d=identicon)[DataValues](/maintainers/DataValues)

![](https://www.gravatar.com/avatar/d6bcf38f15ab0b990ee4f042aa93bfa76e920123b41cc9c62515d5689f6af790?d=identicon)[tobijat](/maintainers/tobijat)

---

Top Contributors

[![thiemowmde](https://avatars.githubusercontent.com/u/6576639?v=4)](https://github.com/thiemowmde "thiemowmde (128 commits)")[![addshore](https://avatars.githubusercontent.com/u/3308769?v=4)](https://github.com/addshore "addshore (53 commits)")[![JeroenDeDauw](https://avatars.githubusercontent.com/u/146040?v=4)](https://github.com/JeroenDeDauw "JeroenDeDauw (47 commits)")[![mariushoch](https://avatars.githubusercontent.com/u/2446964?v=4)](https://github.com/mariushoch "mariushoch (37 commits)")[![lucaswerkmeister](https://avatars.githubusercontent.com/u/2346599?v=4)](https://github.com/lucaswerkmeister "lucaswerkmeister (18 commits)")[![manicki](https://avatars.githubusercontent.com/u/3524114?v=4)](https://github.com/manicki "manicki (14 commits)")[![itamargiv](https://avatars.githubusercontent.com/u/6132917?v=4)](https://github.com/itamargiv "itamargiv (10 commits)")[![tobijat](https://avatars.githubusercontent.com/u/2997252?v=4)](https://github.com/tobijat "tobijat (7 commits)")[![chukarave](https://avatars.githubusercontent.com/u/7420952?v=4)](https://github.com/chukarave "chukarave (7 commits)")[![Ladsgroup](https://avatars.githubusercontent.com/u/5351225?v=4)](https://github.com/Ladsgroup "Ladsgroup (6 commits)")[![adrianheine](https://avatars.githubusercontent.com/u/139208?v=4)](https://github.com/adrianheine "adrianheine (6 commits)")[![rosalieper](https://avatars.githubusercontent.com/u/15235452?v=4)](https://github.com/rosalieper "rosalieper (5 commits)")[![matejsuchanek](https://avatars.githubusercontent.com/u/13053169?v=4)](https://github.com/matejsuchanek "matejsuchanek (4 commits)")[![codders](https://avatars.githubusercontent.com/u/17782?v=4)](https://github.com/codders "codders (4 commits)")[![JonasKress](https://avatars.githubusercontent.com/u/13198391?v=4)](https://github.com/JonasKress "JonasKress (4 commits)")[![JanZerebecki](https://avatars.githubusercontent.com/u/7452727?v=4)](https://github.com/JanZerebecki "JanZerebecki (2 commits)")[![gmelikov](https://avatars.githubusercontent.com/u/3868786?v=4)](https://github.com/gmelikov "gmelikov (2 commits)")[![micgro42](https://avatars.githubusercontent.com/u/7372507?v=4)](https://github.com/micgro42 "micgro42 (2 commits)")[![toban](https://avatars.githubusercontent.com/u/352149?v=4)](https://github.com/toban "toban (1 commits)")[![snaterlicious](https://avatars.githubusercontent.com/u/5755120?v=4)](https://github.com/snaterlicious "snaterlicious (1 commits)")

---

Tags

timewikidatadatavaluesvalueparsersvalueformatters

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/data-values-time/health.svg)

```
[![Health](https://phpackages.com/badges/data-values-time/health.svg)](https://phpackages.com/packages/data-values-time)
```

###  Alternatives

[data-values/number

Numerical value objects, parsers and formatters

18303.0k14](/packages/data-values-number)[symfony/clock

Decouples applications from the system clock

430168.9M205](/packages/symfony-clock)[knplabs/knp-time-bundle

Making your dates and durations look sensible and descriptive

6308.9M39](/packages/knplabs-knp-time-bundle)[data-values/common

Contains common implementations of the interfaces defined by DataValuesInterfaces

11934.5k13](/packages/data-values-common)[league/period

Time range API for PHP

7335.4M21](/packages/league-period)[data-values/geo

Geographical value objects, parsers and formatters

20631.0k18](/packages/data-values-geo)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
