@@ -5,42 +5,65 @@ DateTime or DateTimeImmutable classes which return the time
55range. Can be used e.g. excellently for command line
66arguments and options to make database queries with.
77
8- ## Usage
8+ ## Examples / Usage
99
1010``` php
1111use Ixnode\PhpDateParser\DateParser;
1212```
1313
14- ### Date parser
14+ ### Date parser ( ` UTC ` )
1515
1616``` php
17- $dateParser = (new DateParser('2023-07-01'))->formatFrom('Y-m-d H:i:s');
17+ print (new DateParser('2023-07-01'))->formatFrom('Y-m-d H:i:s');
1818// 2023-07-01 00:00:00
1919
20- $dateParser = (new DateParser('2023-07-01'))->formatTo('Y-m-d H:i:s');
20+ print (new DateParser('2023-07-01'))->formatTo('Y-m-d H:i:s');
2121// 2023-07-01 23:59:59
2222```
2323
24- ### Word parser
24+ ### Word parser (` UTC ` )
25+
26+ * Imagine that now is the time: ` 2023-07-07 12:34:56 `
2527
2628``` php
27- $dateParser = (new DateParser('today'))->formatFrom('Y-m-d H:i:s');
29+ print (new DateParser('today'))->formatFrom('Y-m-d H:i:s');
2830// 2023-07-07 00:00:00
2931
30- $dateParser = (new DateParser('today'))->formatTo('Y-m-d H:i:s');
32+ print (new DateParser('today'))->formatTo('Y-m-d H:i:s');
3133// 2023-07-07 23:59:59
3234```
3335
3436### Date parser with timezones
3537
38+ * Input: ` America/New_York `
39+ * Output: ` Europe/Berlin `
40+
3641``` php
37- $dateParser = (new DateParser('<2023-07-01 ' , ' America /New_York ' ))->formatFrom(' Y-m-d H:i:s ' , ' Europe /Berlin ' );
42+ /* Parses given date time from timezone America/New_York; Output to timezone Europe/Berlin */
43+ print (new DateParser('<2023-07-01 ' , ' America /New_York ' ))->formatFrom(' Y-m-d H:i:s ' , ' Europe /Berlin ' );
3844// null
3945
40- $dateParser = (new DateParser(' <2023-07-01 ' , ' America /New_York ' ))->formatTo(' Y-m-d H:i:s ' , ' Europe /Berlin ' );
46+ /* Parses given date time from timezone America/New_York; Output to timezone Europe/Berlin */
47+ print (new DateParser(' <2023-07-01 ' , ' America /New_York ' ))->formatTo(' Y-m-d H:i:s ' , ' Europe /Berlin ' );
4148// 2023-07-01 05:59:59
4249```
4350
51+ ### Working with `DateRange` class
52+
53+ ```php
54+ /* Parses given date time from timezone America/New_York */
55+ $dateParser = (new DateParser(' 2023-07-01 ' , ' America /New_York ' ));
56+
57+ /* Sets default output to timezone Asia/Tokyo */
58+ $dateRange = $dateParser->getDateRange(' Asia /Tokyo ' );
59+
60+ print $dateRange->getFrom()?->format(' Y-m-d H:i:s (e) ' );
61+ // 2023-07-01 13:00:00 (Asia/Tokyo)
62+
63+ print $dateRange->getTo()?->format(' Y-m-d H:i:s (e) ' );
64+ // 2023-07-02 12:59:59 (Asia/Tokyo)
65+ ```
66+
4467## Parsing formats
4568
4669### Supported words
@@ -68,7 +91,9 @@ $dateParser = (new DateParser('<2023-07-01', 'America/New_York'))->formatTo('Y-m
6891
6992### Overview
7093
71- * Imagine today would be the: `2023-07-07`
94+ #### Exact time parser (`=datetime`)
95+
96+ * Imagine that now is the time: `2023-07-07 12:34:56`
7297
7398| Given format | Description | From `(' Y-m-d H:i:s ' )` | To `(' Y-m-d H:i:s ' )` |
7499|-----------------------------------------|---------------------------------------------------------|--------------------------------------|--------------------------------------|
@@ -82,7 +107,14 @@ $dateParser = (new DateParser('<2023-07-01', 'America/New_York'))->formatTo('Y-m
82107| <nobr>`"=this-month"`</nobr> | Alias of `"this-month"` | <nobr>`"2023-07-01 00:00:00"`</nobr> | <nobr>`"2023-07-31 23:59:59"`</nobr> |
83108| <nobr>`"2023-07-01"`</nobr> | Exactly the given date. | <nobr>`"2023-07-01 00:00:00"`</nobr> | <nobr>`"2023-07-01 23:59:59"`</nobr> |
84109| <nobr>`"=2023-07-01"`</nobr> | Alias of `"2023-07-01"` | <nobr>`"2023-07-01 00:00:00"`</nobr> | <nobr>`"2023-07-01 23:59:59"`</nobr> |
85- | - | - | - | - |
110+
111+ #### Time is greater than parser (`>from`)
112+
113+ * Imagine that now is the time: `2023-07-07 12:34:56`
114+ * "To" values are `NULL`
115+
116+ | Given format | Description | From `(' Y-m-d H:i:s ' )` | To `(' Y-m-d H:i:s ' )` |
117+ |-----------------------------------------|---------------------------------------------------------|--------------------------------------|--------------------------------------|
86118| <nobr>`">tomorrow"`</nobr> | Later than tomorrow<sup>1)</sup> | <nobr>`"2023-07-09 00:00:00"`</nobr> | <nobr>`NULL`</nobr> |
87119| <nobr>`">=tomorrow"`</nobr> | Later than tomorrow<sup>2)</sup> | <nobr>`"2023-07-08 00:00:00"`</nobr> | <nobr>`NULL`</nobr> |
88120| <nobr>`">+tomorrow"`</nobr> | Alias of `">=tomorrow"` | <nobr>`"2023-07-08 00:00:00"`</nobr> | <nobr>`NULL`</nobr> |
@@ -99,7 +131,14 @@ $dateParser = (new DateParser('<2023-07-01', 'America/New_York'))->formatTo('Y-m
99131| <nobr>`">=2023-07-01"`</nobr> | Later than the given date<sup>2)</sup> | <nobr>`"2023-07-01 00:00:00"`</nobr> | <nobr>`NULL`</nobr> |
100132| <nobr>`">+2023-07-01"`</nobr> | Alias of `">=2023-07-01"` | <nobr>`"2023-07-01 00:00:00"`</nobr> | <nobr>`NULL`</nobr> |
101133| <nobr>`"+2023-07-01"`</nobr> | Alias of `">=2023-07-01"` | <nobr>`"2023-07-01 00:00:00"`</nobr> | <nobr>`NULL`</nobr> |
102- | - | - | - | - |
134+
135+ #### Time is less than parser (`<to`)
136+
137+ * Imagine that now is the time: `2023-07-07 12:34:56`
138+ * "From" values are `NULL`
139+
140+ | Given format | Description | From `(' Y-m-d H:i:s ' )` | To `(' Y-m-d H:i:s ' )` |
141+ |-----------------------------------------|---------------------------------------------------------|--------------------------------------|--------------------------------------|
103142| <nobr>`"<tomorrow"`</nobr> | Before tomorrow<sup>1)</sup> | <nobr>`NULL`</nobr> | <nobr>`"2023-07-07 23:59:59"`</nobr> |
104143| <nobr>`"<=tomorrow"`</nobr> | Before tomorrow<sup>2)</sup> | <nobr>`NULL`</nobr> | <nobr>`"2023-07-08 23:59:59"`</nobr> |
105144| <nobr>`"<+tomorrow"`</nobr> | Alias of `"<=tomorrow"` | <nobr>`NULL`</nobr> | <nobr>`"2023-07-08 23:59:59"`</nobr> |
@@ -116,15 +155,25 @@ $dateParser = (new DateParser('<2023-07-01', 'America/New_York'))->formatTo('Y-m
116155| <nobr>`"<=2023-07-01"`</nobr> | Before the given date<sup>2)</sup> | <nobr>`NULL`</nobr> | <nobr>`"2023-07-01 23:59:59"`</nobr> |
117156| <nobr>`"<+2023-07-01"`</nobr> | Alias of `"<=2023-07-01"` | <nobr>`NULL`</nobr> | <nobr>`"2023-07-01 23:59:59"`</nobr> |
118157| <nobr>`"-2023-07-01"`</nobr> | Alias of `"<=2023-07-01"` | <nobr>`NULL`</nobr> | <nobr>`"2023-07-01 23:59:59"`</nobr> |
119- | - | - | - | - |
158+
159+ #### Range parser (`from|to`)
160+
161+ * Imagine that now is the time: `2023-07-07 12:34:56`
162+
163+ | Given format | Description | From `(' Y-m-d H:i:s ' )` | To `(' Y-m-d H:i:s ' )` |
164+ |-----------------------------------------|---------------------------------------------------------|--------------------------------------|--------------------------------------|
120165| <nobr>`"2023-07-01\|2023-07-03"`</nobr> | Date range from `"2023-07-01"` to `"2023-07-03"` | <nobr>`"2023-07-01 00:00:00"`</nobr> | <nobr>`"2023-07-03 23:59:59"`</nobr> |
121166| <nobr>`"2023-07-01\|tomorrow"`</nobr> | Date range from `"2023-07-01"` to `"tomorrow"` | <nobr>`"2023-07-01 00:00:00"`</nobr> | <nobr>`"2023-07-08 23:59:59"`</nobr> |
122167| <nobr>`"2023-07-01\|today"`</nobr> | Date range from `"2023-07-01"` to `"today"` | <nobr>`"2023-07-01 00:00:00"`</nobr> | <nobr>`"2023-07-07 23:59:59"`</nobr> |
123168| <nobr>`"2023-07-01\|yesterday"`</nobr> | Date range from `"2023-07-01"` to `"yesterday"` | <nobr>`"2023-07-01 00:00:00"`</nobr> | <nobr>`"2023-07-06 23:59:59"`</nobr> |
124169| <nobr>`"yesterday\|today"`</nobr> | Date range from `"yesterday"` to `"today"` | <nobr>`"2023-07-06 00:00:00"`</nobr> | <nobr>`"2023-07-07 23:59:59"`</nobr> |
125170| <nobr>`"yesterday\|this-month"`</nobr> | Date range from `"yesterday"` to last day of this month | <nobr>`"2023-07-06 00:00:00"`</nobr> | <nobr>`"2023-07-31 23:59:59"`</nobr> |
126171| <nobr>`"this-month\|today"`</nobr> | Date range from first day this month to `"today"` | <nobr>`"2023-07-01 00:00:00"`</nobr> | <nobr>`"2023-07-07 23:59:59"`</nobr> |
127- | - | - | - | - |
172+
173+ #### Infinitive range parser (`NULL`)
174+
175+ | Given format | Description | From `(' Y-m-d H:i:s ' )` | To `(' Y-m-d H:i:s ' )` |
176+ |-----------------------------------------|---------------------------------------------------------|--------------------------------------|--------------------------------------|
128177| <nobr>`NULL`</nobr> | No range given (infinitive range). | <nobr>`NULL`</nobr> | <nobr>`NULL`</nobr> |
129178
130179* <sup>1)</sup> - excluding the given one
@@ -155,32 +204,28 @@ vendor/bin/php-date-parser --version
155204```
156205
157206```bash
158- 0.1.8 (2023-07-18 21:24:05 ) - Björn Hempel <bjoern@hempel.li>
207+ 0.1.10 (2023-07-21 21:39:44 ) - Björn Hempel <bjoern@hempel.li>
159208```
160209
161- ## Command line
162-
163- ```bash
164- bin/console pdt --timezone-input=America/New_York --timezone-output=Europe/Berlin "<2023-07-01"
165- ```
210+ ## Command line tool
166211
167- or within your composer project
212+ Used to quickly check a given date time directly in the command line.
168213
169214```bash
170215vendor/bin/php-date-parser pdt --timezone-input=America/New_York --timezone-output=Europe/Berlin "<2023-07-01"
171216```
172217
173218```text
174219
175- Given date time range: "<2023-07-01" (America/New_York)
220+ Given date time range: "<2023-07-01" (America/New_York > Europe/Berlin )
176221
177- +------------------------------------------+------------------+
178- | Value | Given |
179- +------------------------------------------+------------------+
180- | Given date time range (America/New_York) | <2023-07-01 |
181- | Timezone (input) | America/New_York |
182- | Timezone (output) | Europe/Berlin |
183- +------------------------------------------+------------------+
222+ +---------------------------------------------------------- +------------------+
223+ | Value | Given |
224+ +---------------------------------------------------------- +------------------+
225+ | Given date time range (America/New_York > Europe/Berlin ) | <2023-07-01 |
226+ | Timezone (input) | America/New_York |
227+ | Timezone (output) | Europe/Berlin |
228+ +---------------------------------------------------------- +------------------+
184229
185230Parsed from given string (input):
186231
0 commit comments