Skip to content

Commit 9c9b03a

Browse files
committed
Ensures precise datetime boundaries for range calculations
Updates datetime handling to set explicit start and end times, including microseconds for greater precision. Improves consistency across range computations, addressing potential inaccuracies in datetime scopes such as 'yesterday', 'current_month', and others.
1 parent b7dede8 commit 9c9b03a

File tree

2 files changed

+30
-38
lines changed

2 files changed

+30
-38
lines changed

.openapi-generator/templates/Statementor.mustache

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -174,43 +174,35 @@ class Statementor extends \Ease\Sand
174174
switch ($scope) {
175175
case 'yesterday':
176176
$this->since = (new \DateTime('yesterday'))->setTime(0, 0);
177-
$this->until = (new \DateTime('yesterday'))->setTime(23, 59);
178-
177+
$this->until = (new \DateTime('yesterday'))->setTime(23, 59, 59, 999);
179178
break;
180179
case 'current_month':
181-
$this->since = new \DateTime('first day of this month');
182-
$this->until = new \DateTime();
183-
180+
$this->since = (new \DateTime('first day of this month'))->setTime(0, 0);
181+
$this->until = (new \DateTime())->setTime(23, 59, 59, 999);
184182
break;
185183
case 'last_month':
186-
$this->since = new \DateTime('first day of last month');
187-
$this->until = new \DateTime('last day of last month');
188-
184+
$this->since = (new \DateTime('first day of last month'))->setTime(0, 0);
185+
$this->until = (new \DateTime('last day of last month'))->setTime(23, 59, 59, 999);
189186
break;
190187
case 'last_week':
191-
$this->since = new \DateTime('first day of last week');
192-
$this->until = new \DateTime('last day of last week');
193-
188+
$this->since = (new \DateTime('monday last week'))->setTime(0, 0);
189+
$this->until = (new \DateTime('sunday last week'))->setTime(23, 59, 59, 999);
194190
break;
195191
case 'last_two_months':
196-
$this->since = (new \DateTime('first day of last month'))->modify('-1 month');
197-
$this->until = (new \DateTime('last day of last month'));
198-
192+
$this->since = (new \DateTime('first day of -2 months'))->setTime(0, 0);
193+
$this->until = (new \DateTime('last day of last month'))->setTime(23, 59, 59, 999);
199194
break;
200195
case 'previous_month':
201-
$this->since = new \DateTime('first day of -2 month');
202-
$this->until = new \DateTime('last day of -2 month');
203-
196+
$this->since = (new \DateTime('first day of -2 months'))->setTime(0, 0);
197+
$this->until = (new \DateTime('last day of -2 months'))->setTime(23, 59, 59, 999);
204198
break;
205199
case 'two_months_ago':
206-
$this->since = new \DateTime('first day of -3 month');
207-
$this->until = new \DateTime('last day of -3 month');
208-
200+
$this->since = (new \DateTime('first day of -3 months'))->setTime(0, 0);
201+
$this->until = (new \DateTime('last day of -3 months'))->setTime(23, 59, 59, 999);
209202
break;
210203
case 'this_year':
211-
$this->since = new \DateTime('first day of January '.date('Y'));
212-
$this->until = new \DateTime('last day of December'.date('Y'));
213-
204+
$this->since = (new \DateTime('first day of January '.date('Y')))->setTime(0, 0);
205+
$this->until = (new \DateTime('last day of December '.date('Y')))->setTime(23, 59, 59, 999);
214206
break;
215207
case 'January': // 1
216208
case 'February': // 2

lib/Statementor.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -175,42 +175,42 @@ public function setScope(string $scope): \DatePeriod
175175
switch ($scope) {
176176
case 'yesterday':
177177
$this->since = (new \DateTime('yesterday'))->setTime(0, 0);
178-
$this->until = (new \DateTime('yesterday'))->setTime(23, 59);
178+
$this->until = (new \DateTime('yesterday'))->setTime(23, 59, 59, 999);
179179

180180
break;
181181
case 'current_month':
182-
$this->since = new \DateTime('first day of this month');
183-
$this->until = new \DateTime();
182+
$this->since = (new \DateTime('first day of this month'))->setTime(0, 0);
183+
$this->until = (new \DateTime())->setTime(23, 59, 59, 999);
184184

185185
break;
186186
case 'last_month':
187-
$this->since = new \DateTime('first day of last month');
188-
$this->until = new \DateTime('last day of last month');
187+
$this->since = (new \DateTime('first day of last month'))->setTime(0, 0);
188+
$this->until = (new \DateTime('last day of last month'))->setTime(23, 59, 59, 999);
189189

190190
break;
191191
case 'last_week':
192-
$this->since = new \DateTime('first day of last week');
193-
$this->until = new \DateTime('last day of last week');
192+
$this->since = (new \DateTime('monday last week'))->setTime(0, 0);
193+
$this->until = (new \DateTime('sunday last week'))->setTime(23, 59, 59, 999);
194194

195195
break;
196196
case 'last_two_months':
197-
$this->since = (new \DateTime('first day of last month'))->modify('-1 month');
198-
$this->until = (new \DateTime('last day of last month'));
197+
$this->since = (new \DateTime('first day of -2 months'))->setTime(0, 0);
198+
$this->until = (new \DateTime('last day of last month'))->setTime(23, 59, 59, 999);
199199

200200
break;
201201
case 'previous_month':
202-
$this->since = new \DateTime('first day of -2 month');
203-
$this->until = new \DateTime('last day of -2 month');
202+
$this->since = (new \DateTime('first day of -2 months'))->setTime(0, 0);
203+
$this->until = (new \DateTime('last day of -2 months'))->setTime(23, 59, 59, 999);
204204

205205
break;
206206
case 'two_months_ago':
207-
$this->since = new \DateTime('first day of -3 month');
208-
$this->until = new \DateTime('last day of -3 month');
207+
$this->since = (new \DateTime('first day of -3 months'))->setTime(0, 0);
208+
$this->until = (new \DateTime('last day of -3 months'))->setTime(23, 59, 59, 999);
209209

210210
break;
211211
case 'this_year':
212-
$this->since = new \DateTime('first day of January '.date('Y'));
213-
$this->until = new \DateTime('last day of December'.date('Y'));
212+
$this->since = (new \DateTime('first day of January '.date('Y')))->setTime(0, 0);
213+
$this->until = (new \DateTime('last day of December '.date('Y')))->setTime(23, 59, 59, 999);
214214

215215
break;
216216
case 'January': // 1

0 commit comments

Comments
 (0)