Skip to content

Commit 74893d6

Browse files
committed
Revert "Augment dates using display_timezone config"
This reverts commit a133e51.
1 parent f34c61d commit 74893d6

File tree

3 files changed

+5
-55
lines changed

3 files changed

+5
-55
lines changed

config/system.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -74,21 +74,6 @@
7474

7575
'date_format' => 'F jS, Y',
7676

77-
/*
78-
|--------------------------------------------------------------------------
79-
| Display Timezone
80-
|--------------------------------------------------------------------------
81-
|
82-
| Dates and times are stored in UTC. This setting allows you to determine which
83-
| timezone dates and times are displayed in. For a full list of supported timezones,
84-
| please see the PHP documentation.
85-
|
86-
| https://www.php.net/manual/en/timezones.php
87-
|
88-
*/
89-
90-
'display_timezone' => 'UTC',
91-
9277
/*
9378
|--------------------------------------------------------------------------
9479
| Default Character Set

src/Fieldtypes/Date.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ public function augment($value)
311311
}
312312

313313
if ($value instanceof Carbon) {
314-
return $value->setTimezone(config('statamic.system.display_timezone'));
314+
return $value;
315315
}
316316

317317
if ($this->config('mode') === 'range') {
@@ -321,8 +321,7 @@ public function augment($value)
321321
];
322322
}
323323

324-
$date = $this->parseSaved($value)
325-
->setTimezone(config('statamic.system.display_timezone'));
324+
$date = $this->parseSaved($value);
326325

327326
if (! $this->config('time_enabled')) {
328327
$date->startOfDay();
@@ -350,7 +349,7 @@ public function toQueryableValue($value)
350349
private function parseSaved($value)
351350
{
352351
try {
353-
return Carbon::createFromFormat($this->saveFormat(), $value, 'UTC');
352+
return Carbon::createFromFormat($this->saveFormat(), $value);
354353
} catch (InvalidFormatException|InvalidArgumentException $e) {
355354
return Carbon::parse($value);
356355
}

tests/Fieldtypes/DateTest.php

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,8 @@ public function setUp(): void
2626

2727
#[Test]
2828
#[DataProvider('augmentProvider')]
29-
public function it_augments(string $displayTimezone, array $config, string $value, string $expected)
29+
public function it_augments($config, $value, $expected)
3030
{
31-
config()->set('statamic.system.display_timezone', $displayTimezone);
32-
3331
$augmented = $this->fieldtype($config)->augment($value);
3432

3533
$this->assertInstanceOf(Carbon::class, $augmented);
@@ -40,52 +38,35 @@ public static function augmentProvider()
4038
{
4139
return [
4240
'date' => [
43-
'UTC',
4441
[],
4542
'2012-01-04',
4643
'2012 Jan 04 00:00:00',
4744
],
4845
'date with custom format' => [
49-
'UTC',
5046
['format' => 'Y--m--d'],
5147
'2012--01--04',
5248
'2012 Jan 04 00:00:00',
5349
],
54-
'date with display timezone' => [
55-
'America/New_York',
56-
[],
57-
'2012-01-04',
58-
'2012 Jan 04 00:00:00',
59-
],
6050

6151
// The time and seconds configs are important, otherwise
62-
// when parsing dates without times, the time would inherit from "now".
52+
// when when parsing dates without times, the time would inherit from "now".
6353
// We need to rely on the configs to know when or when not to reset the time.
6454

6555
'date with time' => [
66-
'UTC',
6756
['time_enabled' => true],
6857
'2012-01-04 15:32',
6958
'2012 Jan 04 15:32:00',
7059
],
7160
'date with time but seconds disabled' => [
72-
'UTC',
7361
['time_enabled' => true],
7462
'2012-01-04 15:32:54',
7563
'2012 Jan 04 15:32:00',
7664
],
7765
'date with time and seconds' => [
78-
'UTC',
7966
['time_enabled' => true, 'time_seconds_enabled' => true],
8067
'2012-01-04 15:32:54',
8168
'2012 Jan 04 15:32:54',
8269
],
83-
'date with time and display timezone' => [
84-
'America/New_York',
85-
['time_enabled' => true],
86-
'2012-01-04 15:32',
87-
'2012 Jan 04 10:32:00', // -5 hours
88-
],
8970
];
9071
}
9172

@@ -108,21 +89,6 @@ public function it_augments_a_carbon_instance()
10889
$this->assertSame($instance, $augmented);
10990
}
11091

111-
#[Test]
112-
public function it_augments_a_carbon_instance_using_display_timezone_config()
113-
{
114-
// Could happen if you are using the date fieldtype to augment a manually provided value.
115-
116-
config()->set('statamic.system.display_timezone', 'America/New_York'); // -5 hours
117-
118-
$instance = new Carbon('2025-01-01 12:00:00');
119-
$augmented = $this->fieldtype()->augment($instance);
120-
121-
$this->assertInstanceOf(Carbon::class, $augmented);
122-
$this->assertEquals('America/New_York', $augmented->getTimezone()->getName());
123-
$this->assertEquals(7, $instance->hour); // 12pm in UTC is 7am in New York
124-
}
125-
12692
#[Test]
12793
public function it_augments_a_range()
12894
{

0 commit comments

Comments
 (0)