Skip to content

Commit

Permalink
Merge pull request #138 from ihackcode/develop
Browse files Browse the repository at this point in the history
Convert user time to Server time on saving items
  • Loading branch information
mambax7 authored Jul 4, 2020
2 parents baf0804 + d6cea93 commit 17794f5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
2 changes: 1 addition & 1 deletion class/Form/ItemForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public function createElements($obj)
if (!\is_object($GLOBALS['xoopsUser'])) {
$group = [XOOPS_GROUP_ANONYMOUS];
$currentUid = 0;
$timeoffset = 0;
$timeoffset = null;
} else {
$group = $GLOBALS['xoopsUser']->getGroups();
$currentUid = $GLOBALS['xoopsUser']->uid();
Expand Down
24 changes: 11 additions & 13 deletions class/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -1050,7 +1050,11 @@ public function setVarsFromRequest()
//Required fields
// if (!empty($categoryid = Request::getInt('categoryid', 0, 'POST'))) {
// $this->setVar('categoryid', $categoryid);}

if (\is_object($GLOBALS['xoopsUser'])) {
$userTimeoffset = $GLOBALS['xoopsUser']->getVar('timezone_offset');
}else{
$userTimeoffset = null;
}
$this->setVar('categoryid', Request::getInt('categoryid', 0, 'POST'));
$this->setVar('title', Request::getString('title', '', 'POST'));
$this->setVar('body', Request::getText('body', '', 'POST'));
Expand Down Expand Up @@ -1101,13 +1105,10 @@ public function setVarsFromRequest()
// } else {
$resDate = Request::getArray('datesub', [], 'POST');
$resTime = Request::getArray('datesub', [], 'POST');
$dateTimeObj = \DateTime::createFromFormat(_SHORTDATESTRING, $resDate['date'],
new \DateTimeZone($GLOBALS['xoopsUser']->getVar('timezone_offset')));
$dateTimeObj = \DateTime::createFromFormat(_SHORTDATESTRING, $resDate['date']);
$dateTimeObj->setTime(0, 0, (int)$resTime['time']);
$dateTimeObj->setTimezone(new \DateTimeZone('GMT'));
$gmtTimestamp = $dateTimeObj->getTimestamp();
//always store the time as GMT/UTC Time
$this->setVar('datesub', $gmtTimestamp);
$serverTimestamp = userTimeToServerTime($dateTimeObj->getTimestamp(), $userTimeoffset);
$this->setVar('datesub', $serverTimestamp);
// }
} elseif ($this->isNew()) {
$this->setVar('datesub', \time());
Expand All @@ -1118,13 +1119,10 @@ public function setVarsFromRequest()
if ('' !== Request::getString('dateexpire', '', 'POST')) {
$resExDate = Request::getArray('dateexpire', [], 'POST');
$resExTime = Request::getArray('dateexpire', [], 'POST');
$dateTimeObj = \DateTime::createFromFormat(_SHORTDATESTRING, $resExDate['date'],
new \DateTimeZone($GLOBALS['xoopsUser']->getVar('timezone_offset')));
$dateTimeObj = \DateTime::createFromFormat(_SHORTDATESTRING, $resExDate['date']);
$dateTimeObj->setTime(0, 0, (int)$resExTime['time']);
$dateTimeObj->setTimezone(new \DateTimeZone('GMT'));
$gmtTimestamp = $dateTimeObj->getTimestamp();
//always store the time as GMT/UTC Time
$this->setVar('dateexpire', $gmtTimestamp);
$serverTimestamp = userTimeToServerTime($dateTimeObj->getTimestamp(), $userTimeoffset);
$this->setVar('dateexpire', $serverTimestamp);
}
} else {
$this->setVar('dateexpire', 0);
Expand Down

0 comments on commit 17794f5

Please sign in to comment.