Skip to content

Commit fbba8f4

Browse files
committed
Add more parser options like next-month, this-month, last-month, this-year, etc.
1 parent 8f1a30c commit fbba8f4

File tree

3 files changed

+313
-56
lines changed

3 files changed

+313
-56
lines changed

README.md

Lines changed: 73 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -43,62 +43,82 @@ $dateParser = (new DateParser('today'))->formatTo('Y-m-d H:i:s');
4343
// 2023-07-07 23:59:59
4444
```
4545
46-
## Parsing formats / overview
46+
## Parsing formats
47+
48+
### Supported words
49+
50+
| Word | Description |
51+
|--------------|-------------------------------|
52+
| `tomorrow` | The day tomorrow (`'j' + 1`) |
53+
| `today` | The day today (`'j'`) |
54+
| `yesterday` | The day yesterday (`'j' - 1`) |
55+
| `next-month` | Next month (`'n' + 1`) |
56+
| `this-month` | This month (`'n'`) |
57+
| `last-month` | Last month (`'n' - 1`) |
58+
| `next-year` | Next year (`'Y' + 1`) |
59+
| `this-year` | This year (`'Y'`) |
60+
| `last-year` | Last year (`'Y' - 1`) |
61+
62+
### Overview
4763
4864
* Imagine today would be the: `2023-07-07`
4965
50-
| Given format | description | from | to |
51-
|-----------------------------------------|--------------------------------------------------|--------------------------------------|--------------------------------------|
52-
| <nobr>`"tomorrow"`</nobr> | Returns the date range from tomorrow. | <nobr>`"2023-07-08 00:00:00"`</nobr> | <nobr>`"2023-07-08 23:59:59"`</nobr> |
53-
| <nobr>`"=tomorrow"`</nobr> | Alias of `"tomorrow"`. | <nobr>`"2023-07-08 00:00:00"`</nobr> | <nobr>`"2023-07-08 23:59:59"`</nobr> |
54-
| <nobr>`"today"`</nobr> | Returns the date range from today. | <nobr>`"2023-07-07 00:00:00"`</nobr> | <nobr>`"2023-07-07 23:59:59"`</nobr> |
55-
| <nobr>`"=today"`</nobr> | Alias of `"today"`. | <nobr>`"2023-07-07 00:00:00"`</nobr> | <nobr>`"2023-07-07 23:59:59"`</nobr> |
56-
| <nobr>`"yesterday"`</nobr> | Returns the date range from yesterday. | <nobr>`"2023-07-06 00:00:00"`</nobr> | <nobr>`"2023-07-06 23:59:59"`</nobr> |
57-
| <nobr>`"=yesterday"`</nobr> | Alias of `"yesterday"` | <nobr>`"2023-07-06 00:00:00"`</nobr> | <nobr>`"2023-07-06 23:59:59"`</nobr> |
58-
| <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> |
59-
| <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> |
60-
| - | - | - | - |
61-
| <nobr>`">tomorrow"`</nobr> | Higher than tomorrow<sup>1)</sup> | <nobr>`"2023-07-09 00:00:00"`</nobr> | <nobr>`NULL`</nobr> |
62-
| <nobr>`">=tomorrow"`</nobr> | Higher than tomorrow<sup>2)</sup> | <nobr>`"2023-07-08 00:00:00"`</nobr> | <nobr>`NULL`</nobr> |
63-
| <nobr>`">+tomorrow"`</nobr> | Alias of `">=tomorrow"` | <nobr>`"2023-07-08 00:00:00"`</nobr> | <nobr>`NULL`</nobr> |
64-
| <nobr>`"+tomorrow"`</nobr> | Alias of `">=tomorrow"` | <nobr>`"2023-07-08 00:00:00"`</nobr> | <nobr>`NULL`</nobr> |
65-
| <nobr>`">today"`</nobr> | Higher than today<sup>1)</sup> | <nobr>`"2023-07-08 00:00:00"`</nobr> | <nobr>`NULL`</nobr> |
66-
| <nobr>`">=today"`</nobr> | Higher than today<sup>2)</sup> | <nobr>`"2023-07-07 00:00:00"`</nobr> | <nobr>`NULL`</nobr> |
67-
| <nobr>`">+today"`</nobr> | Alias of `">=today"` | <nobr>`"2023-07-07 00:00:00"`</nobr> | <nobr>`NULL`</nobr> |
68-
| <nobr>`"+today"`</nobr> | Alias of `">=today"` | <nobr>`"2023-07-07 00:00:00"`</nobr> | <nobr>`NULL`</nobr> |
69-
| <nobr>`">yesterday"`</nobr> | Higher than yesterday<sup>1)</sup> | <nobr>`"2023-07-07 00:00:00"`</nobr> | <nobr>`NULL`</nobr> |
70-
| <nobr>`">=yesterday"`</nobr> | Higher than yesterday<sup>2)</sup> | <nobr>`"2023-07-06 00:00:00"`</nobr> | <nobr>`NULL`</nobr> |
71-
| <nobr>`">+yesterday"`</nobr> | Alias of `">=yesterday"` | <nobr>`"2023-07-06 00:00:00"`</nobr> | <nobr>`NULL`</nobr> |
72-
| <nobr>`"+yesterday"`</nobr> | Alias of `">=yesterday"` | <nobr>`"2023-07-06 00:00:00"`</nobr> | <nobr>`NULL`</nobr> |
73-
| <nobr>`">2023-07-01"`</nobr> | Higher than the given date<sup>1)</sup> | <nobr>`"2023-07-02 00:00:00"`</nobr> | <nobr>`NULL`</nobr> |
74-
| <nobr>`">=2023-07-01"`</nobr> | Higher than the given date<sup>2)</sup> | <nobr>`"2023-07-01 00:00:00"`</nobr> | <nobr>`NULL`</nobr> |
75-
| <nobr>`">+2023-07-01"`</nobr> | Alias of `">=2023-07-01"` | <nobr>`"2023-07-01 00:00:00"`</nobr> | <nobr>`NULL`</nobr> |
76-
| <nobr>`"+2023-07-01"`</nobr> | Alias of `">=2023-07-01"` | <nobr>`"2023-07-01 00:00:00"`</nobr> | <nobr>`NULL`</nobr> |
77-
| - | - | - | - |
78-
| <nobr>`"<tomorrow"`</nobr> | Lower than tomorrow<sup>1)</sup> | <nobr>`NULL`</nobr> | <nobr>`"2023-07-07 23:59:59"`</nobr> |
79-
| <nobr>`"<=tomorrow"`</nobr> | Lower than tomorrow<sup>2)</sup> | <nobr>`NULL`</nobr> | <nobr>`"2023-07-08 23:59:59"`</nobr> |
80-
| <nobr>`"<+tomorrow"`</nobr> | Alias of `"<=tomorrow"` | <nobr>`NULL`</nobr> | <nobr>`"2023-07-08 23:59:59"`</nobr> |
81-
| <nobr>`"-tomorrow"`</nobr> | Alias of `"<=tomorrow"` | <nobr>`NULL`</nobr> | <nobr>`"2023-07-08 23:59:59"`</nobr> |
82-
| <nobr>`"<today"`</nobr> | Lower than today<sup>1)</sup> | <nobr>`NULL`</nobr> | <nobr>`"2023-07-06 23:59:59"`</nobr> |
83-
| <nobr>`"<=today"`</nobr> | Lower than today<sup>2)</sup> | <nobr>`NULL`</nobr> | <nobr>`"2023-07-07 23:59:59"`</nobr> |
84-
| <nobr>`"<+today"`</nobr> | Alias of `"<=today"` | <nobr>`NULL`</nobr> | <nobr>`"2023-07-07 23:59:59"`</nobr> |
85-
| <nobr>`"-today"`</nobr> | Alias of `"<=today"` | <nobr>`NULL`</nobr> | <nobr>`"2023-07-07 23:59:59"`</nobr> |
86-
| <nobr>`"<yesterday"`</nobr> | Lower than yesterday<sup>1)</sup> | <nobr>`NULL`</nobr> | <nobr>`"2023-07-05 23:59:59"`</nobr> |
87-
| <nobr>`"<=yesterday"`</nobr> | Lower than yesterday<sup>2)</sup> | <nobr>`NULL`</nobr> | <nobr>`"2023-07-06 23:59:59"`</nobr> |
88-
| <nobr>`"<+yesterday"`</nobr> | Alias of `"<=yesterday"` | <nobr>`NULL`</nobr> | <nobr>`"2023-07-06 23:59:59"`</nobr> |
89-
| <nobr>`"-yesterday"`</nobr> | Alias of `"<=yesterday"` | <nobr>`NULL`</nobr> | <nobr>`"2023-07-06 23:59:59"`</nobr> |
90-
| <nobr>`"<2023-07-01"`</nobr> | Lower than the given date<sup>1)</sup> | <nobr>`NULL`</nobr> | <nobr>`"2023-06-30 23:59:59"`</nobr> |
91-
| <nobr>`"<=2023-07-01"`</nobr> | Lower than the given date<sup>2)</sup> | <nobr>`NULL`</nobr> | <nobr>`"2023-07-01 23:59:59"`</nobr> |
92-
| <nobr>`"<+2023-07-01"`</nobr> | Alias of `"<=2023-07-01"` | <nobr>`NULL`</nobr> | <nobr>`"2023-07-01 23:59:59"`</nobr> |
93-
| <nobr>`"-2023-07-01"`</nobr> | Alias of `"<=2023-07-01"` | <nobr>`NULL`</nobr> | <nobr>`"2023-07-01 23:59:59"`</nobr> |
94-
| - | - | - | - |
95-
| <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> |
96-
| <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> |
97-
| <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> |
98-
| <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> |
99-
| <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> |
100-
| - | - | - | - |
101-
| <nobr>`NULL`</nobr> | No range given (infinitive range). | <nobr>`NULL`</nobr> | <nobr>`NULL`</nobr> |
66+
| Given format | Description | From `('Y-m-d H:i:s')` | To `('Y-m-d H:i:s')` |
67+
|-----------------------------------------|---------------------------------------------------------|--------------------------------------|--------------------------------------|
68+
| <nobr>`"tomorrow"`</nobr> | Returns the date range from tomorrow. | <nobr>`"2023-07-08 00:00:00"`</nobr> | <nobr>`"2023-07-08 23:59:59"`</nobr> |
69+
| <nobr>`"=tomorrow"`</nobr> | Alias of `"tomorrow"`. | <nobr>`"2023-07-08 00:00:00"`</nobr> | <nobr>`"2023-07-08 23:59:59"`</nobr> |
70+
| <nobr>`"today"`</nobr> | Returns the date range from today. | <nobr>`"2023-07-07 00:00:00"`</nobr> | <nobr>`"2023-07-07 23:59:59"`</nobr> |
71+
| <nobr>`"=today"`</nobr> | Alias of `"today"`. | <nobr>`"2023-07-07 00:00:00"`</nobr> | <nobr>`"2023-07-07 23:59:59"`</nobr> |
72+
| <nobr>`"yesterday"`</nobr> | Returns the date range from yesterday. | <nobr>`"2023-07-06 00:00:00"`</nobr> | <nobr>`"2023-07-06 23:59:59"`</nobr> |
73+
| <nobr>`"=yesterday"`</nobr> | Alias of `"yesterday"` | <nobr>`"2023-07-06 00:00:00"`</nobr> | <nobr>`"2023-07-06 23:59:59"`</nobr> |
74+
| <nobr>`"this-month"`</nobr> | Date range from first day to last day this month. | <nobr>`"2023-07-01 00:00:00"`</nobr> | <nobr>`"2023-07-31 23:59:59"`</nobr> |
75+
| <nobr>`"=this-month"`</nobr> | Alias of `"this-month"` | <nobr>`"2023-07-01 00:00:00"`</nobr> | <nobr>`"2023-07-31 23:59:59"`</nobr> |
76+
| <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> |
77+
| <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> |
78+
| - | - | - | - |
79+
| <nobr>`">tomorrow"`</nobr> | Higher than tomorrow<sup>1)</sup> | <nobr>`"2023-07-09 00:00:00"`</nobr> | <nobr>`NULL`</nobr> |
80+
| <nobr>`">=tomorrow"`</nobr> | Higher than tomorrow<sup>2)</sup> | <nobr>`"2023-07-08 00:00:00"`</nobr> | <nobr>`NULL`</nobr> |
81+
| <nobr>`">+tomorrow"`</nobr> | Alias of `">=tomorrow"` | <nobr>`"2023-07-08 00:00:00"`</nobr> | <nobr>`NULL`</nobr> |
82+
| <nobr>`"+tomorrow"`</nobr> | Alias of `">=tomorrow"` | <nobr>`"2023-07-08 00:00:00"`</nobr> | <nobr>`NULL`</nobr> |
83+
| <nobr>`">today"`</nobr> | Higher than today<sup>1)</sup> | <nobr>`"2023-07-08 00:00:00"`</nobr> | <nobr>`NULL`</nobr> |
84+
| <nobr>`">=today"`</nobr> | Higher than today<sup>2)</sup> | <nobr>`"2023-07-07 00:00:00"`</nobr> | <nobr>`NULL`</nobr> |
85+
| <nobr>`">+today"`</nobr> | Alias of `">=today"` | <nobr>`"2023-07-07 00:00:00"`</nobr> | <nobr>`NULL`</nobr> |
86+
| <nobr>`"+today"`</nobr> | Alias of `">=today"` | <nobr>`"2023-07-07 00:00:00"`</nobr> | <nobr>`NULL`</nobr> |
87+
| <nobr>`">yesterday"`</nobr> | Higher than yesterday<sup>1)</sup> | <nobr>`"2023-07-07 00:00:00"`</nobr> | <nobr>`NULL`</nobr> |
88+
| <nobr>`">=yesterday"`</nobr> | Higher than yesterday<sup>2)</sup> | <nobr>`"2023-07-06 00:00:00"`</nobr> | <nobr>`NULL`</nobr> |
89+
| <nobr>`">+yesterday"`</nobr> | Alias of `">=yesterday"` | <nobr>`"2023-07-06 00:00:00"`</nobr> | <nobr>`NULL`</nobr> |
90+
| <nobr>`"+yesterday"`</nobr> | Alias of `">=yesterday"` | <nobr>`"2023-07-06 00:00:00"`</nobr> | <nobr>`NULL`</nobr> |
91+
| <nobr>`">2023-07-01"`</nobr> | Higher than the given date<sup>1)</sup> | <nobr>`"2023-07-02 00:00:00"`</nobr> | <nobr>`NULL`</nobr> |
92+
| <nobr>`">=2023-07-01"`</nobr> | Higher than the given date<sup>2)</sup> | <nobr>`"2023-07-01 00:00:00"`</nobr> | <nobr>`NULL`</nobr> |
93+
| <nobr>`">+2023-07-01"`</nobr> | Alias of `">=2023-07-01"` | <nobr>`"2023-07-01 00:00:00"`</nobr> | <nobr>`NULL`</nobr> |
94+
| <nobr>`"+2023-07-01"`</nobr> | Alias of `">=2023-07-01"` | <nobr>`"2023-07-01 00:00:00"`</nobr> | <nobr>`NULL`</nobr> |
95+
| - | - | - | - |
96+
| <nobr>`"<tomorrow"`</nobr> | Lower than tomorrow<sup>1)</sup> | <nobr>`NULL`</nobr> | <nobr>`"2023-07-07 23:59:59"`</nobr> |
97+
| <nobr>`"<=tomorrow"`</nobr> | Lower than tomorrow<sup>2)</sup> | <nobr>`NULL`</nobr> | <nobr>`"2023-07-08 23:59:59"`</nobr> |
98+
| <nobr>`"<+tomorrow"`</nobr> | Alias of `"<=tomorrow"` | <nobr>`NULL`</nobr> | <nobr>`"2023-07-08 23:59:59"`</nobr> |
99+
| <nobr>`"-tomorrow"`</nobr> | Alias of `"<=tomorrow"` | <nobr>`NULL`</nobr> | <nobr>`"2023-07-08 23:59:59"`</nobr> |
100+
| <nobr>`"<today"`</nobr> | Lower than today<sup>1)</sup> | <nobr>`NULL`</nobr> | <nobr>`"2023-07-06 23:59:59"`</nobr> |
101+
| <nobr>`"<=today"`</nobr> | Lower than today<sup>2)</sup> | <nobr>`NULL`</nobr> | <nobr>`"2023-07-07 23:59:59"`</nobr> |
102+
| <nobr>`"<+today"`</nobr> | Alias of `"<=today"` | <nobr>`NULL`</nobr> | <nobr>`"2023-07-07 23:59:59"`</nobr> |
103+
| <nobr>`"-today"`</nobr> | Alias of `"<=today"` | <nobr>`NULL`</nobr> | <nobr>`"2023-07-07 23:59:59"`</nobr> |
104+
| <nobr>`"<yesterday"`</nobr> | Lower than yesterday<sup>1)</sup> | <nobr>`NULL`</nobr> | <nobr>`"2023-07-05 23:59:59"`</nobr> |
105+
| <nobr>`"<=yesterday"`</nobr> | Lower than yesterday<sup>2)</sup> | <nobr>`NULL`</nobr> | <nobr>`"2023-07-06 23:59:59"`</nobr> |
106+
| <nobr>`"<+yesterday"`</nobr> | Alias of `"<=yesterday"` | <nobr>`NULL`</nobr> | <nobr>`"2023-07-06 23:59:59"`</nobr> |
107+
| <nobr>`"-yesterday"`</nobr> | Alias of `"<=yesterday"` | <nobr>`NULL`</nobr> | <nobr>`"2023-07-06 23:59:59"`</nobr> |
108+
| <nobr>`"<2023-07-01"`</nobr> | Lower than the given date<sup>1)</sup> | <nobr>`NULL`</nobr> | <nobr>`"2023-06-30 23:59:59"`</nobr> |
109+
| <nobr>`"<=2023-07-01"`</nobr> | Lower than the given date<sup>2)</sup> | <nobr>`NULL`</nobr> | <nobr>`"2023-07-01 23:59:59"`</nobr> |
110+
| <nobr>`"<+2023-07-01"`</nobr> | Alias of `"<=2023-07-01"` | <nobr>`NULL`</nobr> | <nobr>`"2023-07-01 23:59:59"`</nobr> |
111+
| <nobr>`"-2023-07-01"`</nobr> | Alias of `"<=2023-07-01"` | <nobr>`NULL`</nobr> | <nobr>`"2023-07-01 23:59:59"`</nobr> |
112+
| - | - | - | - |
113+
| <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> |
114+
| <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> |
115+
| <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> |
116+
| <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> |
117+
| <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> |
118+
| <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> |
119+
| <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> |
120+
| - | - | - | - |
121+
| <nobr>`NULL`</nobr> | No range given (infinitive range). | <nobr>`NULL`</nobr> | <nobr>`NULL`</nobr> |
102122
103123
* <sup>1)</sup> - excluding the given one
104124
* <sup>2)</sup> - including the given one

0 commit comments

Comments
 (0)