mareg / rough-date
Rough date object allowing dates like `Jan 2005` or `2006`
Installs: 1 048
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 1
Open Issues: 0
pkg:composer/mareg/rough-date
Requires
- php: ^7.2, <7.5
Requires (Dev)
- phpspec/phpspec: ^6.1.1
README
Needed to store a "rough date" in one of my project, may be useful for otheres.
Installation
Execute from shell the following command:
$ composer require mareg/rough-date
Or add "mareg/rough-date": "^1.0" to your composer.json:
"require": { "mareg/rough-date": "^1.0" },
Usage
Create a RoughDate object from the string:
$roughDate = RoughDate::fromString('May 2005'); echo $roughDate->format();
Or from a DateTime date object:
$date = new \DateTime(); $roughDate = RoughDate::fromDateTime($date); echo $roughDate->format();
Accepted date formats
When creating an object through RoughDate::fromString():
Y-m-d, e.g.2015-02-22, but also2013-05-00and2013-00-00are correctY/m/dandY.m.dare acceptedj. M Y, e.g.13. May 2005M Y, e.g.May 1985Y, e.g.1978
Output date formats
When calling RoughDate::format():
- For a full date output accepts all variables as in date() method
- For other dates only available variables will be substituded and unavailable ones will be removed, e.g.:
- for date
2015-02-00and formatj M Yyou'll getFeb 2015 - for date
1978-00-00and formatj M Yyou'll get1978