Skip to content
Merged
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
8 changes: 5 additions & 3 deletions src/Forms/Submission.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ public function id($id = null)
{
return $this->fluentlyGetOrSet('id')
->getter(function ($id) {
return $this->id = $id ?: str_replace(',', '.', microtime(true));
$micro = Carbon::now()->timestamp + Carbon::now()->micro / 1000000;

return $this->id = $id ?: str_replace(',', '.', $micro);
})
->args(func_get_args());
}
Expand Down Expand Up @@ -101,7 +103,7 @@ public function columns()
*/
public function date()
{
return Carbon::createFromTimestamp($this->id(), config('app.timezone'));
return Carbon::createFromTimestamp($this->id());
}

/**
Expand All @@ -111,7 +113,7 @@ public function date()
*/
public function formattedDate()
{
return $this->date()->format(
return $this->date()->tz(config('app.timezone'))->format(
$this->form()->dateFormat()
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Resources/CP/Submissions/ListedSubmission.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function toArray($request)
return [
'id' => $this->resource->id(),
$this->merge($this->values([
'datestamp' => $this->resource->date()->format($form->dateFormat()),
'datestamp' => $this->resource->date()->tz(config('app.timezone'))->format($form->dateFormat()),
])),
'url' => cp_route('forms.submissions.show', [$form->handle(), $this->resource->id()]),
'deleteable' => User::current()->can('delete', $this->resource),
Expand Down
24 changes: 24 additions & 0 deletions tests/Forms/SubmissionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

namespace Tests\Forms;

use Carbon\Carbon;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Event;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use Statamic\Events\SubmissionCreated;
use Statamic\Events\SubmissionCreating;
Expand Down Expand Up @@ -49,6 +51,28 @@ public function generated_ids_dont_have_commas()
setlocale(LC_TIME, $originalLocale);
}

#[Test]
#[DataProvider('utcProvider')]
public function the_date_is_utc($tz, $expectedFormatted)
{
config(['app.timezone' => $tz]);

Carbon::setTestNow(Carbon::parse('2025-03-12 02:13:25', 'UTC'));

$submission = Form::make('test')->makeSubmission();

$this->assertEquals('2025-03-12T02:13:25+00:00', $submission->date()->toIso8601String());
$this->assertEquals($expectedFormatted, $submission->formattedDate());
}

public static function utcProvider()
{
return [
'utc' => ['UTC', 'March 12th, 2025 02:13'],
'not utc' => ['America/New_York', 'March 11th, 2025 22:13'],
];
}

#[Test]
public function it_sets_and_gets_data()
{
Expand Down