PHPackages                             heartsentwined/date-time-parser - 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. heartsentwined/date-time-parser

ActiveLibrary

heartsentwined/date-time-parser
===============================

Parse date and time according to the subset of ISO 8601 date/time format used in Vcard \[ISO 6350\].

v2.1.1(9y ago)21.0k1ISCPHPPHP &gt;=5.3.3

Since Sep 6Pushed 9y ago1 watchersCompare

[ Source](https://github.com/heartsentwined/php-date-time-parser)[ Packagist](https://packagist.org/packages/heartsentwined/date-time-parser)[ Docs](https://github.com/yalesov/php-date-time-parser)[ RSS](/packages/heartsentwined-date-time-parser/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependencies (2)Versions (11)Used By (0)

Yalesov\\DateTimeParser
=======================

[](#yalesovdatetimeparser)

[![Build Status](https://camo.githubusercontent.com/4087fbd7ba9b5d9fecc3a0882cf71cc1e316ac03a146f332e396a9d3f287b1c3/68747470733a2f2f7472617669732d63692e6f72672f79616c65736f762f7068702d646174652d74696d652d7061727365722e737667)](https://travis-ci.org/yalesov/php-date-time-parser)

Parse date and time according to the subset of ISO 8601 date/time format used in Vcard \[ISO 6350\].

Installation
============

[](#installation)

[Composer](http://getcomposer.org/):

```
{
  "require": {
    "yalesov/date-time-parser": "2.*"
  }
}
```

Usage
=====

[](#usage)

Parse an ISO-8601 date/time
---------------------------

[](#parse-an-iso-8601-datetime)

```
use Yalesov\DateTimeParser\Parser;

$datetime = Parser::parseDateTime('19961022T140000+0800');
// $datetime['year']     = '1996';
// $datetime['month']    = '10';
// $datetime['day']      = '22';
// $datetime['hour']     = '14';
// $datetime['minute']   = '00';
// $datetime['second']   = '00';
// $datetime['timezone'] = '+0800';

$datetime = Parser::parseDateTime('---22T14');
// $datetime['year']     = null;
// $datetime['month']    = null;
// $datetime['day']      = '22';
// $datetime['hour']     = '14';
// $datetime['minute']   = null;
// $datetime['second']   = null;
// $datetime['timezone'] = null;
```

Full function signature:

```
public static function parseDateTime($datetime)
```

It accepts an ISO-8601 date-and-or-time string and returns an array of datetime units. It will throw an `InvalidArgumentException` if the input is not a valid date/time expression, or if the date/time specified is invalid.

Missing date/time units will be filled with `null`.

Standalone time expressions must be prefixed with `T`.

To parse an ISO-8601 date expression, use:

```
public static function parseDate($date)
```

To parse an ISO-8601 time expression, use:

```
public static function parseTime($time)
```

The return array for these two functions are same as `Parser::parseDateTime()`.

Create an ISO-8601 date/time
----------------------------

[](#create-an-iso-8601-datetime)

```
use Yalesov\DateTimeParser\Parser;

$expr = Parser::createDateTime('1996', '10', '22', '14', '00', '00', '+0800');
// $expr = '19961022T140000+0800';

$expr = Parser::createDateTime(null, null, '22', '14', null, null, null);
// $expr = '---22T14';
```

These are simply reverses of the `parse-()` functions.

Full function signatures:

```
public static function createDateTime(
  $year = null, $month = null, $day = null,
  $hour = null, $minute = null, $second = null, $timezone = null)
```

```
public static function createDate($year = null, $month = null, $day = null)
```

```
public static function createTime($hour = null, $minute = null, $second = null, $timezone = null)
```

Valid ranges:

- Year: (unlimited)
- Month: 01-12
- Day: 01-31
- Hour: 00-23
- Minute: 00-59
- Second: 00-59

Note that `0`-prefixed numbers are different from `0`-prefixed strings. For example, if you mean August, write `8` or `'08'`, not `08`.

Create a timestamp from a complete or partial date/time
-------------------------------------------------------

[](#create-a-timestamp-from-a-complete-or-partial-datetime)

```
public static function createTimestamp(
  $year = null, $month = null, $day = null,
  $hour = null, $minute = null, $second = null, $timezone = null)
```

Accepted arguments are same as the `create-()` series.

`Parser::createTimestamp()` will create a timestamp if at least `year`, `month`, `day` are given (and valid). It will assume `'00'` for `hour`, `minute` and `second` if not given; and script timezone if `timezone` is not given.

Return `null` if failed to create a timestamp.

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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 ~0 days

Total

10

Last Release

3594d ago

Major Versions

1.0.3 → v2.0.02016-07-05

### Community

Maintainers

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

---

Top Contributors

[![yalesov](https://avatars.githubusercontent.com/u/20264293?v=4)](https://github.com/yalesov "yalesov (9 commits)")

---

Tags

datetimevCardiso8601iso-8601

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/heartsentwined-date-time-parser/health.svg)

```
[![Health](https://phpackages.com/badges/heartsentwined-date-time-parser/health.svg)](https://phpackages.com/packages/heartsentwined-date-time-parser)
```

###  Alternatives

[nette/utils

🛠 Nette Utils: lightweight utilities for string &amp; array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password generating etc.

2.1k394.3M1.5k](/packages/nette-utils)[cakephp/chronos

A simple API extension for DateTime.

1.4k47.7M120](/packages/cakephp-chronos)[nesbot/carbon

An API extension for DateTime that supports 281 different languages.

169661.4M4.8k](/packages/nesbot-carbon)[carbonphp/carbon-doctrine-types

Types to use Carbon in Doctrine

213220.4M8](/packages/carbonphp-carbon-doctrine-types)[sabre/vobject

The VObject library for PHP allows you to easily parse and manipulate iCalendar and vCard objects

59623.5M40](/packages/sabre-vobject)[stella-maris/clock

A pre-release of the proposed PSR-20 Clock-Interface

7947.5M2](/packages/stella-maris-clock)

PHPackages © 2026

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