Download the PHP package mareg/rough-date without Composer
On this page you can find all versions of the php package mareg/rough-date. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mareg/rough-date
More information about mareg/rough-date
Files in mareg/rough-date
Package rough-date
Short Description Rough date object allowing dates like `Jan 2005` or `2006`
License GPL-3.0-only
Informations about the package rough-date
Rough Date
Needed to store a "rough date" in one of my project, may be useful for otheres.
Installation
Execute from shell the following command:
Or add "mareg/rough-date": "^1.0" to your composer.json:
Usage
Create a RoughDate object from the string:
Or from a DateTime date object:
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 accepted, as long as the same separator is used throughoutY-m,Y/mandY.m, e.g.2013-05j M Yandj F Y, with an optional dot after the day, e.g.13. May 2005,23 September 1925M j, YandF j, Y, e.g.May 13, 2005M YandF Y, e.g.May 1985Y, e.g.1978
Unknown parts are written as 00, and precision is truncated from the right: an
unknown month means the day is unknown too. Anything else is rejected with an
UnrecognizedDateFormat exception, including:
- impossible calendar dates, e.g.
2015-02-30and1993-02-29 - a month outside
01–12, e.g.1993-13 - a known day inside an unknown month, e.g.
1993-00-15 - mixed separators, e.g.
1993/09-05
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
- for date
Removed variables leave the literals around them in place, which is why the
examples above keep the spaces that separated them. Literals escaped with a
backslash are always kept, so \Y\e\a\r Y gives Year 1978.

