Skip to content

Commit afd7d4b

Browse files
committed
Store time/date as unix timestamp
1 parent 84c0a8a commit afd7d4b

File tree

3 files changed

+46
-23
lines changed

3 files changed

+46
-23
lines changed

wcfsetup/install/files/lib/system/condition/provider/UserConditionProvider.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
2121
* @since 6.3
2222
*
23-
* @extends AbstractConditionProvider<IDatabaseObjectListConditionType<UserList>&IObjectConditionType<User>>
23+
* @extends AbstractConditionProvider<IDatabaseObjectListConditionType<UserList, mixed>&IObjectConditionType<User, mixed>>
2424
*/
2525
final class UserConditionProvider extends AbstractConditionProvider
2626
{

wcfsetup/install/files/lib/system/condition/type/user/UserRegistrationDateConditionType.class.php

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
1818
* @since 6.3
1919
*
20-
* @phpstan-type Filter = array{condition: string, value: string}
20+
* @phpstan-type Filter = array{condition: string, value: int}
2121
* @implements IDatabaseObjectListConditionType<UserList<User>, Filter>
2222
* @implements IObjectConditionType<User, Filter>
2323
* @extends AbstractConditionType<Filter>
@@ -48,7 +48,7 @@ public function getLabel(): string
4848
#[\Override]
4949
public function applyFilter(DatabaseObjectList $objectList): void
5050
{
51-
["condition" => $condition, "time" => $time] = $this->getParsedFilter();
51+
["condition" => $condition, "value" => $time] = $this->filter;
5252

5353
$objectList->getConditionBuilder()->add(
5454
"{$objectList->getDatabaseTableAlias()}.registrationDate {$condition} ?",
@@ -59,7 +59,7 @@ public function applyFilter(DatabaseObjectList $objectList): void
5959
#[\Override]
6060
public function match(object $object): bool
6161
{
62-
["condition" => $condition, "time" => $time] = $this->getParsedFilter();
62+
["condition" => $condition, "value" => $time] = $this->filter;
6363

6464
return match ($condition) {
6565
">" => $object->registrationDate > $time,
@@ -70,23 +70,6 @@ public function match(object $object): bool
7070
};
7171
}
7272

73-
/**
74-
* @return array{condition: string, time: int}
75-
*/
76-
private function getParsedFilter(): array
77-
{
78-
$dateTime = \DateTime::createFromFormat(
79-
DateConditionFormField::TIME_FORMAT,
80-
$this->filter["value"],
81-
new \DateTimeZone(TIMEZONE),
82-
);
83-
84-
return [
85-
'condition' => $this->filter["condition"],
86-
'time' => $dateTime->getTimestamp(),
87-
];
88-
}
89-
9073
/**
9174
* @return string[]
9275
*/

wcfsetup/install/files/lib/system/form/builder/field/DateConditionFormField.class.php

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace wcf\system\form\builder\field;
44

55
use wcf\system\form\builder\field\validation\FormFieldValidationError;
6+
use wcf\system\WCF;
7+
use wcf\util\DateUtil;
68

79
/**
810
* @author Olaf Braun
@@ -23,7 +25,7 @@ final class DateConditionFormField extends AbstractConditionFormField implements
2325

2426
public const DATE_FORMAT = 'Y-m-d';
2527

26-
public const TIME_FORMAT = 'Y-m-d\TH:i:sP';
28+
public const TIME_FORMAT = 'Y-m-d\TH:i:s';
2729

2830
/**
2931
* is `true` if not only the date, but also the time can be set
@@ -35,6 +37,30 @@ final class DateConditionFormField extends AbstractConditionFormField implements
3537
*/
3638
protected $templateName = 'shared_dateConditionFormField';
3739

40+
public function __construct()
41+
{
42+
$this->fieldAttribute("data-ignore-timezone", "1");
43+
}
44+
45+
#[\Override]
46+
public function getSaveValue()
47+
{
48+
if ($this->getValue() === null) {
49+
return parent::getSaveValue();
50+
}
51+
52+
$dateTime = \DateTime::createFromFormat(
53+
$this->supportsTime() ? self::TIME_FORMAT : self::DATE_FORMAT,
54+
$this->getValue(),
55+
WCF::getUser()->getTimezone()
56+
);
57+
58+
return [
59+
"condition" => $this->getCondition(),
60+
"value" => $dateTime->getTimestamp(),
61+
];
62+
}
63+
3864
#[\Override]
3965
public function validate()
4066
{
@@ -44,7 +70,7 @@ public function validate()
4470
$dateTime = \DateTime::createFromFormat(
4571
$this->supportsTime() ? self::TIME_FORMAT : self::DATE_FORMAT,
4672
$this->getValue(),
47-
new \DateTimeZone(TIMEZONE)
73+
WCF::getUser()->getTimezone()
4874
);
4975

5076
if ($dateTime === false) {
@@ -58,6 +84,20 @@ public function validate()
5884
}
5985
}
6086

87+
#[\Override]
88+
public function value($value): self
89+
{
90+
parent::value($value);
91+
92+
if ($this->getValue() !== null) {
93+
$dateTime = DateUtil::getDateTimeByTimestamp($this->getValue());
94+
$dateTime->setTimezone(WCF::getUser()->getTimezone());
95+
$this->value["value"] = $dateTime->format($this->supportsTime() ? self::TIME_FORMAT : self::DATE_FORMAT);
96+
}
97+
98+
return $this;
99+
}
100+
61101
/**
62102
* Sets if not only the date, but also the time can be set.
63103
*/

0 commit comments

Comments
 (0)