Skip to content

Open-source social media scheduler built for AI agents and the teams behind them. Create, schedule and publish posts to every network through MCP or the REST API, or write them yourself in a composer your team will love.

Read stored time zones as their canonical identifier, and cover every place a zone enters (#488)

Paulo Castellanoe1c984d405a4
diff --git a/app/Models/SocialAccount.php b/app/Models/SocialAccount.php
index 370a57ca3..b3f61fc9b 100644
--- a/app/Models/SocialAccount.php
+++ b/app/Models/SocialAccount.php
@@ -20,6 +20,7 @@ use App\Models\Scopes\SocialAccountOrderScope;
use App\Observers\ComposerVersionObserver;
use App\Observers\SocialAccountObserver;
use App\Support\GoogleBusinessResourceName;
+use App\Support\Timezone;
use Database\Factories\SocialAccountFactory;
use Illuminate\Contracts\Cache\LockTimeoutException;
use Illuminate\Database\Eloquent\Attributes\ObservedBy;
@@ -53,6 +54,13 @@ class SocialAccount extends Model
/** The X verification types that show a badge: blue (paid), business (gold) and government (gray). */
public const array X_VERIFIED_BADGES = ['blue', 'business', 'government'];
+ /**
+ * @var array<string, mixed>
+ */
+ protected $attributes = [
+ 'timezone' => Timezone::DEFAULT,
+ ];
+
protected $fillable = [
'workspace_id',
'platform',
@@ -360,6 +368,17 @@ class SocialAccount extends Model
|| ($this->platform->extendsAccessTokenOnRefresh() && $this->is_token_expiring_soon);
}
+ /**
+ * The stored zone read as its canonical identifier, so an alias the tz
+ * database renamed after it was saved never reaches Carbon.
+ */
+ protected function timezone(): Attribute
+ {
+ return Attribute::make(
+ get: fn (string $value): string => Timezone::usable($value),
+ );
+ }
+
protected function avatarUrl(): Attribute
{
return Attribute::make(
diff --git a/app/Models/User.php b/app/Models/User.php
index b978a960e..62c42cb71 100644
--- a/app/Models/User.php
+++ b/app/Models/User.php
@@ -18,9 +18,11 @@ use App\Models\Traits\HasAccount;
use App\Models\Traits\HasMedia;
use App\Models\Traits\HasWorkspace;
use App\Models\Traits\SyncsStripeCustomer;
+use App\Support\Timezone;
use Database\Factories\UserFactory;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Contracts\Translation\HasLocalePreference;
+use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasMany;
@@ -77,6 +79,7 @@ class User extends Authenticatable implements HasLocalePreference, MustVerifyEma
* @var array<string, mixed>
*/
protected $attributes = [
+ 'timezone' => Timezone::DEFAULT,
'theme' => Theme::DEFAULT->value,
'time_format' => TimeFormat::DEFAULT->value,
'week_starts_on' => WeekStart::DEFAULT->value,
@@ -144,6 +147,17 @@ class User extends Authenticatable implements HasLocalePreference, MustVerifyEma
];
}
+ /**
+ * The stored zone read as its canonical identifier, so an alias the tz
+ * database renamed after it was saved never reaches Carbon.
+ */
+ protected function timezone(): Attribute
+ {
+ return Attribute::make(
+ get: fn (string $value): string => Timezone::usable($value),
+ );
+ }
+
public function preferredLocale(): string
{
return $this->locale->value;
diff --git a/app/Support/Timezone.php b/app/Support/Timezone.php
index fa9edd4f4..5ac2aa483 100644
--- a/app/Support/Timezone.php
+++ b/app/Support/Timezone.php
@@ -6,6 +6,7 @@ namespace App\Support;
use DateTimeImmutable;
use DateTimeZone;
+use Illuminate\Support\Collection;
use IntlTimeZone;
class Timezone
@@ -14,21 +15,27 @@ class Timezone
public static function normalize(?string $value): string
{
- if (! is_string($value)) {
+ if (blank($value)) {
return self::DEFAULT;
}
- $canonical = DateTimeZone::listIdentifiers();
+ $canonical = once(fn (): Collection => collect(DateTimeZone::listIdentifiers())->flip());
- if (in_array($value, $canonical, true)) {
- return $value;
- }
+ return collect([$value, IntlTimeZone::getIanaID($value)])
+ ->first(fn (mixed $zone): bool => is_string($zone) && $canonical->has($zone), self::DEFAULT);
+ }
- $mapped = IntlTimeZone::getIanaID($value);
+ /**
+ * A stored zone made safe to compute with: its canonical identifier, or the
+ * zone itself when PHP knows it without one (Etc/GMT+10), so a zone PHP
+ * understands never shifts to UTC; only one it does not know is replaced.
+ */
+ public static function usable(string $value): string
+ {
+ $known = once(fn (): Collection => collect(DateTimeZone::listIdentifiers(DateTimeZone::ALL_WITH_BC))->flip());
+ $normalized = self::normalize($value);
- return is_string($mapped) && in_array($mapped, $canonical, true)
- ? $mapped
- : self::DEFAULT;
+ return $normalized === self::DEFAULT && $known->has($value) ? $value : $normalized;
}
/**
diff --git a/tests/Browser/PostComposerDialogTest.php b/tests/Browser/PostComposerDialogTest.php
index fbaf98df6..6a5c83ec4 100644
--- a/tests/Browser/PostComposerDialogTest.php
+++ b/tests/Browser/PostComposerDialogTest.php
@@ -577,8 +577,9 @@ test('a label created from the empty label picker of the global composer is list
->click('@composer-label-empty-create');
waitForComposerReady($page, 'composer-label-new-name');
$page->fill('@composer-label-new-name', 'Launch')
- ->click('@submit-composer-label-new')
- ->assertSeeIn('@composer-tags-trigger', 'Launch')
+ ->click('@submit-composer-label-new');
+ waitForText($page, '@composer-tags-trigger', 'Launch');
+ $page->assertSeeIn('@composer-tags-trigger', 'Launch')
->assertValue("@composer-caption-{$account->id}", 'Draft text');
$label = $workspace->labels()->sole();
@@ -608,8 +609,9 @@ test('a label created while editing a post on the publish page is listed and sel
->click('@composer-label-empty-create');
waitForComposerReady($page, 'composer-label-new-name');
$page->fill('@composer-label-new-name', 'Launch')
- ->click('@submit-composer-label-new')
- ->assertSeeIn('@composer-tags-trigger', 'Launch')
+ ->click('@submit-composer-label-new');
+ waitForText($page, '@composer-tags-trigger', 'Launch');
+ $page->assertSeeIn('@composer-tags-trigger', 'Launch')
->assertValue("@composer-caption-{$account->id}", 'Edited text')
->assertNoJavaScriptErrors();
});
diff --git a/tests/Browser/PostNotesTest.php b/tests/Browser/PostNotesTest.php
index 8db381df3..ff45d78a6 100644
--- a/tests/Browser/PostNotesTest.php
+++ b/tests/Browser/PostNotesTest.php
@@ -95,6 +95,7 @@ test('the note composer enables send only with text and sends on Enter but not S
$page->keys('@note-input', ['Enter']);
waitFor($page, '@note-body');
+ waitForText($page, "@post-notes-count-{$post->id}", '1');
$page->assertSeeIn('@note-body', 'First line')
->assertValue('@note-input', '')
@@ -196,12 +197,14 @@ test('the notes count follows the thread when it opens and when a note is delete
$page->click("@post-notes-trigger-{$post->id}");
waitFor($page, '@note-body');
waitForCount($page, '@note-item', 2);
+ waitForText($page, "@post-notes-count-{$post->id}", '2');
$page->assertSeeIn("@post-notes-count-{$post->id}", '2');
$page->hover('@note-item')->click('@note-actions');
waitFor($page, '@note-delete');
$page->click('@note-delete');
waitForCount($page, '@note-item', 1);
+ waitForText($page, "@post-notes-count-{$post->id}", '1');
$page->assertSeeIn("@post-notes-count-{$post->id}", '1')->assertNoJavaScriptErrors();
});
@@ -230,6 +233,7 @@ test('notes open, grow, send, edit and fit the card on every tab, on desktop and
$page->keys('@note-input', ['Enter']);
waitFor($page, '@note-body');
+ waitForText($page, "@post-notes-count-{$post->id}", '1');
$page->assertSeeIn("@post-notes-count-{$post->id}", '1')
->assertScript('document.documentElement.scrollWidth <= window.innerWidth', true);
diff --git a/tests/Feature/Analytics/AnalyticsRangePresetTest.php b/tests/Feature/Analytics/AnalyticsRangePresetTest.php
index f12387154..fce46b177 100644
--- a/tests/Feature/Analytics/AnalyticsRangePresetTest.php
+++ b/tests/Feature/Analytics/AnalyticsRangePresetTest.php
@@ -57,6 +57,16 @@ test('custom returns the given dates', function () {
->toBe(['start' => '2026-01-05', 'end' => '2026-02-10']);
});
+test('a viewer stored with an alias missing from PHP\'s list still opens insights', function () {
+ $user = analyticsPresetUserWithSnapshot(now('UTC')->subDay()->toDateString());
+ $user->update(['timezone' => 'Canada/East-Saskatchewan']);
+
+ $this->actingAs($user)
+ ->get(route('app.insights', ['range' => '7d']))
+ ->assertOk()
+ ->assertInertia(fn (Assert $page) => $page->component('insights/Index'));
+});
+
test('an unknown preset is rejected', function () {
$user = analyticsPresetUserWithSnapshot('2026-09-20');
diff --git a/tests/Feature/Auth/SignupPreferencesTest.php b/tests/Feature/Auth/SignupPreferencesTest.php
index 6ffde405b..c6b2cfbbf 100644
--- a/tests/Feature/Auth/SignupPreferencesTest.php
+++ b/tests/Feature/Auth/SignupPreferencesTest.php
@@ -106,6 +106,21 @@ test('github signup with unusable detection values falls back instead of failing
->and($user->time_format)->toBe(TimeFormat::TwelveHour);
});
+test('social signup maps a legacy time zone alias to its canonical identifier', function (string $network, string $driver, string $alias, string $canonical) {
+ $this->get(route("auth.{$network}.redirect", ['timezone' => $alias]));
+ signupPreferencesSocialite($driver, "{$network}-alias", "{$network}[email protected]");
+
+ $this->get(route("auth.{$network}.callback"))->assertRedirect(route('app.welcome', absolute: false));
+
+ expect(User::query()->where('email', "{$network}[email protected]")->sole()->timezone)->toBe($canonical);
+})->with([
+ 'google' => ['google', 'google-auth'],
+ 'github' => ['github', 'github'],
+])->with([
+ 'Calcutta' => ['Asia/Calcutta', 'Asia/Kolkata'],
+ 'missing from PHP\'s list' => ['Canada/East-Saskatchewan', 'America/Regina'],
+]);
+
test('an existing user logging in with google does not leave the detection in the session', function () {
User::factory()->create(['email' => '[email protected]', 'google_id' => 'g-returning', 'timezone' => 'Europe/Lisbon']);
diff --git a/tests/Feature/Channels/ChannelDefaultsTest.php b/tests/Feature/Channels/ChannelDefaultsTest.php
index 210f3af26..f53d79742 100644
--- a/tests/Feature/Channels/ChannelDefaultsTest.php
+++ b/tests/Feature/Channels/ChannelDefaultsTest.php
@@ -63,6 +63,13 @@ test('without an authenticated user the workspace owner time zone is used', func
expect(connectLinkedIn($workspace)->fresh()->timezone)->toBe('Asia/Tokyo');
});
+test('a new channel takes the canonical zone of a connecting user stored with a legacy alias', function () {
+ [, $workspace] = channelDefaultsWorkspace();
+ $this->actingAs(User::factory()->create(['timezone' => 'Canada/East-Saskatchewan']));
+
+ expect(connectLinkedIn($workspace)->fresh()->timezone)->toBe('America/Regina');
+});
+
test('reconnecting keeps a customized schedule, goal and time zone', function () {
[$owner, $workspace] = channelDefaultsWorkspace();
$this->actingAs($owner);
diff --git a/tests/Feature/Mail/MailRenderingTest.php b/tests/Feature/Mail/MailRenderingTest.php
index a27d7b8a2..cc88d1c9e 100644
--- a/tests/Feature/Mail/MailRenderingTest.php
+++ b/tests/Feature/Mail/MailRenderingTest.php
@@ -391,6 +391,18 @@ test('approval emails name the canonical zone of a legacy alias', function () {
expect((new PostApproved($post->id, $approver, $author))->render())->toContain('October 7, 2026 20:30 (Asia/Kolkata)');
});
+test('approval emails name the canonical zone of an alias missing from PHP\'s list', function () {
+ $author = User::factory()->create(['timezone' => 'Canada/East-Saskatchewan', 'time_format' => TimeFormat::TwentyFourHour]);
+ $approver = User::factory()->create(['account_id' => $author->account_id]);
+ $workspace = Workspace::factory()->create(['account_id' => $author->account_id, 'user_id' => $author->id]);
+ $post = approvalEmailPost($workspace, $author, Platform::LinkedIn, 'Acme Inc', [
+ 'status' => PostStatus::Scheduled,
+ 'scheduled_at' => now('UTC')->addDay()->setTime(15, 0),
+ ]);
+
+ expect((new PostApproved($post->id, $approver, $author))->render())->toContain('09:00 (America/Regina)');
+});
+
test('the email layout carries the recipient locale and direction', function (Locale $locale, string $direction) {
$account = Account::factory()->create(['name' => 'Acme Co']);
$invite = Invite::factory()->create([
diff --git a/tests/Feature/Middleware/SharedChannelsPropTest.php b/tests/Feature/Middleware/SharedChannelsPropTest.php
index 0aa87942b..5a5d27456 100644
--- a/tests/Feature/Middleware/SharedChannelsPropTest.php
+++ b/tests/Feature/Middleware/SharedChannelsPropTest.php
@@ -94,6 +94,14 @@ test('shared channels carry their normalized time zone', function () {
->assertInertia(fn ($page) => $page->where('channels.0.timezone', 'Europe/Warsaw'));
});
+test('a shared channel stored with a legacy alias carries its canonical time zone', function () {
+ SocialAccount::factory()->linkedin()->create(['workspace_id' => $this->workspace->id, 'timezone' => 'Canada/East-Saskatchewan']);
+
+ $this->actingAs($this->user)
+ ->get(route('app.workspace.channels'))
+ ->assertInertia(fn ($page) => $page->where('channels.0.timezone', 'America/Regina'));
+});
+
test('a shared channel carries its verified badge', function () {
$channel = SocialAccount::factory()->x()->create(['workspace_id' => $this->workspace->id, 'meta' => ['x_verified_type' => 'blue']]);
diff --git a/tests/Feature/Parity/SchedulingParityTest.php b/tests/Feature/Parity/SchedulingParityTest.php
index 0bb06cad9..feb34cda9 100644
--- a/tests/Feature/Parity/SchedulingParityTest.php
+++ b/tests/Feature/Parity/SchedulingParityTest.php
@@ -732,6 +732,31 @@ test('the recurrence ceiling is checked in the channel time zone on every surfac
expect(schedulingParityRecurrence($post)['interval'])->toBeNull();
});
+test('the recurrence ceiling is checked in the canonical zone of a channel stored with a legacy alias on every surface', function () {
+ $regina = SocialAccount::factory()->create([
+ 'workspace_id' => $this->workspace->id,
+ 'platform' => Platform::LinkedIn,
+ 'timezone' => 'Canada/East-Saskatchewan',
+ ]);
+ $posts = collect(range(1, 3))->map(function () use ($regina) {
+ $post = schedulingParityRecurring($regina, $this->workspace->id, $this->user->id);
+ $post->update(['scheduled_at' => CarbonImmutable::parse('2037-11-30 20:00', 'America/Regina')->utc()]);
+
+ return $post;
+ });
+ $lastMonth = ['interval' => 1, 'frequency' => 'month', 'times' => 1];
+ $expected = ['interval' => 1, 'frequency' => 'month', 'remaining' => 1];
+
+ $this->actingAs($this->user)->patchJson(route('app.posts.recurrence.update', $posts[0]), $lastMonth)->assertRedirect();
+ auth()->forgetGuards();
+ $this->withHeaders(parityApi($this->token))->patchJson(route('api.posts.recurrence.update', $posts[1]), $lastMonth)->assertOk();
+ TryPostServer::actingAs($this->user)->tool(SetPostRecurrenceTool::class, ['post_id' => $posts[2]->id, ...$lastMonth])->assertOk();
+
+ foreach ($posts as $post) {
+ expect(schedulingParityRecurrence($post))->toBe($expected);
+ }
+});
+
test('a post that is not scheduled cannot get a recurrence on any surface', function () {
$draft = schedulingParityRecurring($this->account, $this->workspace->id, $this->user->id, Status::Draft);
$rule = ['interval' => 1, 'frequency' => 'day', 'times' => 2];
@@ -854,6 +879,24 @@ test('updating the posting schedule stores the same schedule and zone on the web
->and($response->json('id'))->toBe($api->id);
});
+test('a legacy time zone alias is refused for a posting schedule on every surface, and nothing is stored', function () {
+ $payload = [
+ 'timezone' => 'Asia/Calcutta',
+ 'posting_goal' => 2,
+ 'posting_schedule' => PostingSchedule::empty()->withTime(2, '11:00')->toArray(),
+ ];
+
+ $this->actingAs($this->user)->putJson(route('app.channels.posting-schedule.update', $this->account), $payload)
+ ->assertUnprocessable()->assertJsonValidationErrors('timezone');
+ auth()->forgetGuards();
+ $this->withHeaders(parityApi($this->token))->putJson(route('api.channels.posting-schedule.update', $this->account), $payload)
+ ->assertUnprocessable()->assertJsonValidationErrors('timezone');
+ auth()->forgetGuards();
+ TryPostServer::actingAs($this->user)->tool(UpdatePostingScheduleTool::class, ['account_id' => $this->account->id, ...$payload])->assertHasErrors();
+
+ expect($this->account->fresh()->timezone)->toBe('UTC');
+});
+
test('an invalid posting schedule is refused with the web messages on every surface', function () {
$payload = ['timezone' => 'Nope/Zone', 'posting_goal' => 99, 'posting_schedule' => [['day' => 1]]];
diff --git a/tests/Feature/Posts/CalendarPageTest.php b/tests/Feature/Posts/CalendarPageTest.php
index 57ee6a794..a99c9e187 100644
--- a/tests/Feature/Posts/CalendarPageTest.php
+++ b/tests/Feature/Posts/CalendarPageTest.php
@@ -104,6 +104,20 @@ test('the tz query re-buckets the calendar and moves the range boundaries', func
->has('posts.2026-10-07', 1));
});
+test('a legacy tz alias shows its canonical zone', function () {
+ $this->actingAs($this->user)
+ ->get(route('app.calendar', ['view' => 'month', 'tz' => 'Canada/East-Saskatchewan']))
+ ->assertInertia(fn (AssertableInertia $page) => $page->where('displayTimezone', 'America/Regina'));
+});
+
+test('a user stored with a legacy alias sees the calendar in its canonical zone', function () {
+ $this->user->update(['timezone' => 'Canada/East-Saskatchewan']);
+
+ $this->actingAs($this->user)
+ ->get(route('app.calendar', ['view' => 'month']))
+ ->assertInertia(fn (AssertableInertia $page) => $page->where('displayTimezone', 'America/Regina'));
+});
+
test('an unknown tz falls back to the user time zone', function () {
$this->actingAs($this->user)
->get(route('app.calendar', ['view' => 'month', 'tz' => 'Mars/Olympus']))
diff --git a/tests/Feature/Posts/PostRecurrenceTest.php b/tests/Feature/Posts/PostRecurrenceTest.php
index d4a3ba186..ab237c195 100644
--- a/tests/Feature/Posts/PostRecurrenceTest.php
+++ b/tests/Feature/Posts/PostRecurrenceTest.php
@@ -298,6 +298,24 @@ test('the series follows the channel time zone across daylight saving changes',
'lisbon, spring forward' => ['Europe/Lisbon', '2027-03-24 10:00', '2027-03-24 10:05', '2027-03-31 10:00'],
]);
+test('the series follows the canonical zone of a channel stored with a legacy alias', function () {
+ $year = now('UTC')->year + 1;
+ $this->channel->update(['timezone' => 'Canada/East-Saskatchewan']);
+ $start = CarbonImmutable::parse("{$year}-01-30 20:00", 'America/Regina');
+ $this->travelTo($start->addMinutes(5));
+ $post = recurringPost($this->channel, $this->user, [
+ 'scheduled_at' => $start->utc(),
+ 'recurrence_interval' => 1,
+ 'recurrence_frequency' => RecurrenceFrequency::Month,
+ 'recurrence_remaining' => 2,
+ ]);
+
+ publishRecurringPost($post);
+
+ expect(nextOccurrence($post)->scheduled_at->setTimezone('America/Regina')->format('Y-m-d H:i'))
+ ->toBe(CarbonImmutable::parse("{$year}-02-01", 'America/Regina')->endOfMonth()->format('Y-m-d').' 20:00');
+});
+
test('the last occurrence carries no rule and ends the series', function () {
$post = recurringPost($this->channel, $this->user, [
'scheduled_at' => now()->subMinute(),
diff --git a/tests/Feature/Posts/PublishPageTest.php b/tests/Feature/Posts/PublishPageTest.php
index 7cd7c46ec..ccdd50560 100644
--- a/tests/Feature/Posts/PublishPageTest.php
+++ b/tests/Feature/Posts/PublishPageTest.php
@@ -449,6 +449,37 @@ test('an invalid time zone and an oversized queue window fall back safely', func
->where('queue.queueDays', 14)));
});
+test('a legacy tz alias and a user stored with one show the canonical zone', function () {
+ $this->actingAs($this->user)
+ ->get(route('app.posts.index', ['tz' => 'Canada/East-Saskatchewan']))
+ ->assertInertia(fn (AssertableInertia $page) => $page->where('displayTimezone', 'America/Regina'));
+
+ $this->user->update(['timezone' => 'Canada/East-Saskatchewan']);
+
+ $this->get(route('app.posts.index'))
+ ->assertInertia(fn (AssertableInertia $page) => $page->where('displayTimezone', 'America/Regina'));
+});
+
+test('the weekly counts of a channel stored with a legacy alias follow its canonical zone', function () {
+ $mondayNight = CarbonImmutable::now('UTC')->next(CarbonImmutable::MONDAY)->setTime(3, 0);
+ $this->travelTo($mondayNight);
+ $this->channel->update(['timezone' => 'Canada/East-Saskatchewan']);
+ $this->user->update(['week_starts_on' => WeekStart::Monday]);
+
+ publishPagePost($this->channel, PostStatus::Published, [], [
+ 'publish_status' => PlatformStatus::Published,
+ 'published_at' => $mondayNight->subHours(15),
+ ]);
+ publishPagePost($this->channel, PostStatus::Scheduled, ['scheduled_at' => $mondayNight->addHours(2)]);
+ publishPagePost($this->channel, PostStatus::Scheduled, ['scheduled_at' => $mondayNight->addHours(4)]);
+
+ $this->actingAs($this->user)
+ ->get(route('app.channels.publish', $this->channel))
+ ->assertInertia(fn (AssertableInertia $page) => $page
+ ->where('channel.sent_this_week', 1)
+ ->where('channel.scheduled_this_week', 1));
+});
+
test('sent this week still counts a post the network deleted afterwards', function () {
foreach ([PlatformStatus::Published, PlatformStatus::Deleted] as $publishStatus) {
publishPagePost($this->channel, PostStatus::Published, [], [
diff --git a/tests/Feature/Settings/UserTimezoneTest.php b/tests/Feature/Settings/UserTimezoneTest.php
index 2b66b1c7c..57f399844 100644
--- a/tests/Feature/Settings/UserTimezoneTest.php
+++ b/tests/Feature/Settings/UserTimezoneTest.php
@@ -2,6 +2,7 @@
declare(strict_types=1);
+use App\Models\SocialAccount;
use App\Models\User;
use App\Support\Timezone;
@@ -45,6 +46,42 @@ test('normalize maps legacy aliases to canonical identifiers', function (string
'Saigon' => ['Asia/Saigon', 'Asia/Ho_Chi_Minh'],
]);
+test('normalize maps an alias missing from PHP\'s time zone list', function (string $alias, string $canonical) {
+ expect(DateTimeZone::listIdentifiers(DateTimeZone::ALL_WITH_BC))->not->toContain($alias)
+ ->and(Timezone::normalize($alias))->toBe($canonical);
+})->with([
+ 'East-Saskatchewan' => ['Canada/East-Saskatchewan', 'America/Regina'],
+ 'Pacific-New' => ['US/Pacific-New', 'America/Los_Angeles'],
+]);
+
+test('a user and a channel stored with an alias missing from PHP\'s list read their canonical zone', function () {
+ $user = User::factory()->create(['timezone' => 'Canada/East-Saskatchewan']);
+ $channel = SocialAccount::factory()->create(['timezone' => 'Canada/East-Saskatchewan']);
+
+ expect($user->fresh()->timezone)->toBe('America/Regina')
+ ->and($channel->fresh()->timezone)->toBe('America/Regina');
+});
+
+test('a user and a channel stored with a zone PHP knows without a canonical name keep it', function () {
+ $user = User::factory()->create(['timezone' => 'Etc/GMT+10']);
+ $channel = SocialAccount::factory()->create(['timezone' => 'Etc/GMT-14']);
+
+ expect($user->fresh()->timezone)->toBe('Etc/GMT+10')
+ ->and($channel->fresh()->timezone)->toBe('Etc/GMT-14');
+});
+
+test('registration maps an alias missing from PHP\'s time zone list', function () {
+ $this->post(route('register.store'), [
+ 'name' => 'Ravi',
+ 'email' => '[email protected]',
+ 'password' => strongPassword(),
+ 'locale' => 'en',
+ 'timezone' => 'Canada/East-Saskatchewan',
+ ]);
+
+ expect(User::query()->where('email', '[email protected]')->value('timezone'))->toBe('America/Regina');
+});
+
test('registration falls back to UTC for a missing or invalid time zone', function (?string $timezone) {
$payload = [
'name' => 'Bo',
@@ -82,6 +119,17 @@ test('changing the time zone rejects invalid identifiers', function () {
expect($user->fresh()->timezone)->toBe('UTC');
});
+test('changing the time zone rejects a legacy alias, whose zone the list offers by its canonical name', function () {
+ $user = User::factory()->create();
+
+ $this->actingAs($user)
+ ->patch(route('app.settings.preferences.update'), ['timezone' => 'Asia/Calcutta'])
+ ->assertSessionHasErrors('timezone');
+
+ expect($user->fresh()->timezone)->toBe('UTC')
+ ->and(collect(Timezone::options())->pluck('value'))->toContain('Asia/Kolkata')->not->toContain('Asia/Calcutta');
+});
+
test('the shared auth user exposes the time zone', function () {
$user = User::factory()->create(['timezone' => 'Asia/Tokyo']);