Skip to content

Commit

Permalink
Fixing various dateTime bugs across the system
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelfolaron committed Aug 23, 2024
1 parent c64f09c commit 0538d68
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 15 deletions.
9 changes: 9 additions & 0 deletions app/Core/Support/DateTimeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,19 @@ public function __construct($time = null, $tz = null)
*/
public function parseUserDateTime(string $userDate, string $userTime = ""): CarbonImmutable
{

if (!$this->isValidDateString($userDate)) {
throw new InvalidDateException("The string is not a valid date time string to parse as user datetime string", $userDate);
}

//Check if provided date is iso8601 (from API)
try{
$this->datetime = CarbonImmutable::createFromFormat(DateTime::ISO8601, $userDate);
return $this->datetime;
} catch (\Exception $e) {
//Do nothing
}

if ($userTime == "start") {
$this->datetime = CarbonImmutable::createFromLocaleFormat("!" . $this->userDateFormat, substr($this->userLanguage, 0, 2), trim($userDate), $this->userTimezone)
->startOfDay();
Expand Down
2 changes: 1 addition & 1 deletion app/Domain/Auth/Services/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ public function setUsersession(mixed $user, bool $isLdap = false)
"twoFAVerified" => false,
"twoFASecret" => $user['twoFASecret'] ?? '',
"isLdap" => $isLdap,
"createdOn" => dtHelper()->parseDbDateTime($user['createdOn']) ?? dtHelper()->userNow(),
"createdOn" => !empty($user['createdOn']) ? dtHelper()->parseDbDateTime($user['createdOn']) : dtHelper()->userNow(),
"modified" => !empty($user['modified']) ? dtHelper()->parseDbDateTime($user['modified']) : dtHelper()->userNow()
);

Expand Down
4 changes: 0 additions & 4 deletions app/Domain/Canvas/Repositories/Canvas.php
Original file line number Diff line number Diff line change
Expand Up @@ -866,10 +866,6 @@ public function getSingleCanvasItem($id): mixed
}
}

/**
* @param $values
* @return false|string
*/
/**
* @param $values
* @return false|string
Expand Down
6 changes: 3 additions & 3 deletions app/Domain/Goalcanvas/Controllers/EditCanvasItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,13 +280,13 @@ public function post($params): Response
'canvasId' => $params['canvasId'],
'parent' => $params['parent'] ?? null,
'kpi' => $params['kpi'] ?? '',
'startDate' => format(value: $params['startDate'], fromFormat: FromFormat::UserDateStartOfDay)->isoDateTime(),
'endDate' => format(value: $params['endDate'], fromFormat: FromFormat::UserDateEndOfDay)->isoDateTime(),
'startDate' => format(value: $params['startDate'] ?? '', fromFormat: FromFormat::UserDateStartOfDay)->isoDateTime(),
'endDate' => format(value: $params['endDate'] ?? '', fromFormat: FromFormat::UserDateEndOfDay)->isoDateTime(),
'setting' => $params['setting'] ?? '',
'metricType' => $params['metricType'],
'assignedTo' => $params['assignedTo'] ?? '',
);
$id = $this->canvasRepo->addCanvasItem($canvasItem);
$id = $this->canvasRepo->addCanvasItem($canvasItem);
$canvasTypes = $this->canvasRepo->getCanvasTypes();

$this->tpl->setNotification($canvasTypes[$params['box']]['title'] . ' successfully created', 'success', "goal_item_created");
Expand Down
6 changes: 4 additions & 2 deletions app/Domain/Ideas/Controllers/IdeaDialog.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ public function get($params)
}
$comments = $this->commentsRepo->getComments('idea', $canvasItem['id']);
$this->tpl->assign('numComments', $this->commentsRepo->countComments('ideas', $canvasItem['id']));

} else {

$type = $params['type'] ?? "idea";

$canvasItem = array(
Expand Down Expand Up @@ -169,8 +171,8 @@ public function post($params)
$milestone = array();
$milestone['headline'] = $params['newMilestone'];
$milestone['tags'] = "#ccc";
$milestone['editFrom'] = date("Y-m-d");
$milestone['editTo'] = date("Y-m-d", strtotime("+1 week"));
$milestone['editFrom'] = dtHelper()->userNow()->formatDateForUser();
$milestone['editTo'] = dtHelper()->userNow()->addDays(7)->formatDateForUser();
$id = $this->ticketService->quickAddMilestone($milestone);
if ($id !== false) {
$canvasItem['milestoneId'] = $id;
Expand Down
15 changes: 10 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
},
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true,
"metasyntactical/composer-plugin-license-check": true
"metasyntactical/composer-plugin-license-check": true,
"php-http/discovery": true
}
},
"authors": [
Expand All @@ -26,14 +27,14 @@
}
],
"require": {
"php": "^8.1",
"php": "^8.2",
"ext-ldap": "*",
"ext-pdo": "*",
"ext-zip": "*",
"ext-fileinfo": "*",

"guzzlehttp/guzzle": "7.4.5",
"aws/aws-sdk-php": "3.219.0",
"guzzlehttp/guzzle": "^7.9.2",
"aws/aws-sdk-php": "^3.314",
"phpmailer/phpmailer": "6.6.0",
"robthree/twofactorauth": "1.8.2",
"endroid/qr-code": "3.9.7",
Expand Down Expand Up @@ -77,7 +78,11 @@
"spatie/icalendar-generator": "^2.6",
"carbon-cli/carbon-cli": "^1.2",

"metasyntactical/composer-plugin-license-check": "^2.1"
"metasyntactical/composer-plugin-license-check": "^2.1",

"ext-fileinfo": "*",
"sentry/sdk": "^3.5",
"predis/predis": "^2.2"
},
"require-dev": {
"squizlabs/php_codesniffer": "^3.8",
Expand Down

0 comments on commit 0538d68

Please sign in to comment.