ebene7/php-dateparser

There is no license information available for the latest version (v1.1.0) of this package.

E7 PHP Date Parser

v1.1.0 2020-07-09 18:08 UTC

This package is auto-updated.

Last update: 2024-11-10 03:41:21 UTC


README

Provides a simple parser for (date-)strings.

Installation

composer require ebene7/php-dateparser

Usage

DateParser

<?php

use E7\DateParser\DateParser;

// Setup by yourself
$parser = DateParser();
$parser->addResolver($resolver);

// or use factory method
$parser = DateParser::create();

$result = $parser->parse($query);

The Parser supports...

  • Single patterns e.g. 2020-05, depending on added Resolvers
  • Pattern ranges e.g. 2020-05..2020-10
  • Autocorrection for twisted ranges e.g. 2020-10..2020-05

DayResolver

<?php

use E7\DateParser\Resolver\DayResolver;

$resolver = new DayResolver();
$result = $resolver->resolve($query);

Supported patterns:

  • 2020-05-15
  • today
  • yesterday
  • tommorrow
  • [next|last] <dayofweek>

WeekResolver

Supported patterns:

  • w05-2020
  • week
  • lastweek
  • nextweek

MonthResolver

Supported patterns:

  • 2020-05
  • month
  • lastmonth
  • nextmonth

YearResolver

Supported patterns:

  • 2020
  • year
  • lastyear
  • nextyear