Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Http/Middleware/Localize.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function handle($request, Closure $next)
return $date->forHumans();
}

return $date->setTimezone(Statamic::displayTimezone())->format(Statamic::dateFormat());
return $date->copy()->setTimezone(Statamic::displayTimezone())->format(Statamic::dateFormat());
});

$response = $next($request);
Expand Down
2 changes: 1 addition & 1 deletion src/Modifiers/CoreModifiers.php
Original file line number Diff line number Diff line change
Expand Up @@ -3352,7 +3352,7 @@ private function carbon($value)
}

if (config('statamic.system.localize_dates_in_modifiers')) {
$value->setTimezone(Statamic::displayTimezone());
$value = $value->copy()->setTimezone(Statamic::displayTimezone());
}

return $value;
Expand Down
20 changes: 20 additions & 0 deletions tests/FrontendTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,26 @@ public function it_sets_the_carbon_to_string_format()
$this->assertDefaultCarbonFormat();
}

#[Test]
public function outputting_a_date_does_not_localize_it_for_the_rest_of_the_template()
{
config([
'statamic.system.date_format' => 'H:i',
'statamic.system.display_timezone' => 'Europe/Zurich', // +1 hour
'statamic.system.localize_dates_in_modifiers' => false,
]);

$this->viewShouldReturnRaw('layout', '{{ template_content }}');
$this->viewShouldReturnRaw('some_template', '<p>{{ date }}</p><p>{{ date format="H:i" }}</p>');

tap($this->makeCollection()->dated(true))->save();
tap($this->makePage('about', ['with' => ['template' => 'some_template']])->date(Carbon::parse('2025-01-01 18:25')))->save();

$this->get('/about')
->assertSee('<p>19:25</p>', false)
->assertSee('<p>18:25</p>', false);
}

#[Test]
public function it_sets_the_locale()
{
Expand Down
12 changes: 12 additions & 0 deletions tests/Modifiers/FormatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ public function it_formats_date_and_outputs_in_display_timezone()
$this->assertSame('1st January 2025 4:45pm', $this->modify(Carbon::parse('2025-01-01 15:45'), 'jS F Y g:ia'));
}

#[Test]
public function it_does_not_mutate_the_original_date_when_localizing()
{
config()->set('statamic.system.localize_dates_in_modifiers', true);

$date = Carbon::parse('2025-01-01 15:45');

$this->modify($date, 'g:ia');

$this->assertSame('UTC', $date->timezone->getName());
}

public function modify($value, $format)
{
return Modify::value($value)->format($format)->fetch();
Expand Down
Loading