Skip to content

Commit 0538d68

Browse files
committed
Fixing various dateTime bugs across the system
1 parent c64f09c commit 0538d68

File tree

6 files changed

+27
-15
lines changed

6 files changed

+27
-15
lines changed

app/Core/Support/DateTimeHelper.php

+9
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,19 @@ public function __construct($time = null, $tz = null)
7373
*/
7474
public function parseUserDateTime(string $userDate, string $userTime = ""): CarbonImmutable
7575
{
76+
7677
if (!$this->isValidDateString($userDate)) {
7778
throw new InvalidDateException("The string is not a valid date time string to parse as user datetime string", $userDate);
7879
}
7980

81+
//Check if provided date is iso8601 (from API)
82+
try{
83+
$this->datetime = CarbonImmutable::createFromFormat(DateTime::ISO8601, $userDate);
84+
return $this->datetime;
85+
} catch (\Exception $e) {
86+
//Do nothing
87+
}
88+
8089
if ($userTime == "start") {
8190
$this->datetime = CarbonImmutable::createFromLocaleFormat("!" . $this->userDateFormat, substr($this->userLanguage, 0, 2), trim($userDate), $this->userTimezone)
8291
->startOfDay();

app/Domain/Auth/Services/Auth.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ public function setUsersession(mixed $user, bool $isLdap = false)
325325
"twoFAVerified" => false,
326326
"twoFASecret" => $user['twoFASecret'] ?? '',
327327
"isLdap" => $isLdap,
328-
"createdOn" => dtHelper()->parseDbDateTime($user['createdOn']) ?? dtHelper()->userNow(),
328+
"createdOn" => !empty($user['createdOn']) ? dtHelper()->parseDbDateTime($user['createdOn']) : dtHelper()->userNow(),
329329
"modified" => !empty($user['modified']) ? dtHelper()->parseDbDateTime($user['modified']) : dtHelper()->userNow()
330330
);
331331

app/Domain/Canvas/Repositories/Canvas.php

-4
Original file line numberDiff line numberDiff line change
@@ -866,10 +866,6 @@ public function getSingleCanvasItem($id): mixed
866866
}
867867
}
868868

869-
/**
870-
* @param $values
871-
* @return false|string
872-
*/
873869
/**
874870
* @param $values
875871
* @return false|string

app/Domain/Goalcanvas/Controllers/EditCanvasItem.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -280,13 +280,13 @@ public function post($params): Response
280280
'canvasId' => $params['canvasId'],
281281
'parent' => $params['parent'] ?? null,
282282
'kpi' => $params['kpi'] ?? '',
283-
'startDate' => format(value: $params['startDate'], fromFormat: FromFormat::UserDateStartOfDay)->isoDateTime(),
284-
'endDate' => format(value: $params['endDate'], fromFormat: FromFormat::UserDateEndOfDay)->isoDateTime(),
283+
'startDate' => format(value: $params['startDate'] ?? '', fromFormat: FromFormat::UserDateStartOfDay)->isoDateTime(),
284+
'endDate' => format(value: $params['endDate'] ?? '', fromFormat: FromFormat::UserDateEndOfDay)->isoDateTime(),
285285
'setting' => $params['setting'] ?? '',
286286
'metricType' => $params['metricType'],
287287
'assignedTo' => $params['assignedTo'] ?? '',
288288
);
289-
$id = $this->canvasRepo->addCanvasItem($canvasItem);
289+
$id = $this->canvasRepo->addCanvasItem($canvasItem);
290290
$canvasTypes = $this->canvasRepo->getCanvasTypes();
291291

292292
$this->tpl->setNotification($canvasTypes[$params['box']]['title'] . ' successfully created', 'success', "goal_item_created");

app/Domain/Ideas/Controllers/IdeaDialog.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ public function get($params)
6767
}
6868
$comments = $this->commentsRepo->getComments('idea', $canvasItem['id']);
6969
$this->tpl->assign('numComments', $this->commentsRepo->countComments('ideas', $canvasItem['id']));
70+
7071
} else {
72+
7173
$type = $params['type'] ?? "idea";
7274

7375
$canvasItem = array(
@@ -169,8 +171,8 @@ public function post($params)
169171
$milestone = array();
170172
$milestone['headline'] = $params['newMilestone'];
171173
$milestone['tags'] = "#ccc";
172-
$milestone['editFrom'] = date("Y-m-d");
173-
$milestone['editTo'] = date("Y-m-d", strtotime("+1 week"));
174+
$milestone['editFrom'] = dtHelper()->userNow()->formatDateForUser();
175+
$milestone['editTo'] = dtHelper()->userNow()->addDays(7)->formatDateForUser();
174176
$id = $this->ticketService->quickAddMilestone($milestone);
175177
if ($id !== false) {
176178
$canvasItem['milestoneId'] = $id;

composer.json

+10-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
},
1111
"allow-plugins": {
1212
"dealerdirect/phpcodesniffer-composer-installer": true,
13-
"metasyntactical/composer-plugin-license-check": true
13+
"metasyntactical/composer-plugin-license-check": true,
14+
"php-http/discovery": true
1415
}
1516
},
1617
"authors": [
@@ -26,14 +27,14 @@
2627
}
2728
],
2829
"require": {
29-
"php": "^8.1",
30+
"php": "^8.2",
3031
"ext-ldap": "*",
3132
"ext-pdo": "*",
3233
"ext-zip": "*",
3334
"ext-fileinfo": "*",
3435

35-
"guzzlehttp/guzzle": "7.4.5",
36-
"aws/aws-sdk-php": "3.219.0",
36+
"guzzlehttp/guzzle": "^7.9.2",
37+
"aws/aws-sdk-php": "^3.314",
3738
"phpmailer/phpmailer": "6.6.0",
3839
"robthree/twofactorauth": "1.8.2",
3940
"endroid/qr-code": "3.9.7",
@@ -77,7 +78,11 @@
7778
"spatie/icalendar-generator": "^2.6",
7879
"carbon-cli/carbon-cli": "^1.2",
7980

80-
"metasyntactical/composer-plugin-license-check": "^2.1"
81+
"metasyntactical/composer-plugin-license-check": "^2.1",
82+
83+
"ext-fileinfo": "*",
84+
"sentry/sdk": "^3.5",
85+
"predis/predis": "^2.2"
8186
},
8287
"require-dev": {
8388
"squizlabs/php_codesniffer": "^3.8",

0 commit comments

Comments
 (0)