Skip to content

Commit bf3d510

Browse files
authored
Merge pull request #2435 from MiddleSokilAI/middleSokil/2431-date-timezone-roundtrip
fix(core): keep resource date round trips timezone-stable (#2431)
2 parents f630fd2 + 7d8080b commit bf3d510

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

core/src/Core.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5036,7 +5036,7 @@ public function toTimeStamp($str)
50365036
$M = 0;
50375037
$S = 0;
50385038
}
5039-
$timeStamp = mktime($H, $M, $S, $m, $d, $Y);
5039+
$timeStamp = gmmktime($H, $M, $S, $m, $d, $Y);
50405040
$timeStamp = (int) $timeStamp;
50415041
return $timeStamp;
50425042
}

core/tests/Unit/CoreTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,24 @@
7373
Mockery::close();
7474
});
7575

76+
test('date conversion round trips without runtime timezone drift', function () {
77+
$originalTimezone = date_default_timezone_get();
78+
79+
try {
80+
date_default_timezone_set('Asia/Tokyo');
81+
$this->parser->config['datetime_format'] = 'YYYY/mm/dd';
82+
83+
$date = '2026/09/01 10:00:00';
84+
$timestamp = $this->parser->toTimeStamp($date);
85+
86+
expect($this->parser->toDateFormat($timestamp))->toBe($date)
87+
->and($this->parser->toDateFormat($this->parser->toTimeStamp($this->parser->toDateFormat($timestamp))))
88+
->toBe($date);
89+
} finally {
90+
date_default_timezone_set($originalTimezone);
91+
}
92+
});
93+
7694
describe('getTagsFromContent', function () {
7795

7896
test('it extracts basic placeholders correctly', function () {

0 commit comments

Comments
 (0)