Skip to content

Commit 0dd0562

Browse files
authored
Merge pull request #238 from datamweb/fix-datatime-if-defaultLocale-fa
fix: datetime for defaultLocale set fa
2 parents 0e1f378 + e929fc8 commit 0dd0562

6 files changed

Lines changed: 27 additions & 5 deletions

File tree

src/Authentication/Authenticators/AccessTokens.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public function check(array $credentials): Result
124124
]);
125125
}
126126

127-
$token->last_used_at = Time::now()->toDateTimeString();
127+
$token->last_used_at = Time::now()->format('Y-m-d H:i:s');
128128
$identityModel->save($token);
129129

130130
// Ensure the token is set as the current token

src/Authorization/Traits/Authorizable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ private function saveGroupsOrPermissions(string $type, $model, array $cache): vo
367367
$inserts[] = [
368368
'user_id' => $this->id,
369369
$type => $item,
370-
'created_at' => Time::now()->toDateTimeString(),
370+
'created_at' => Time::now()->format('Y-m-d H:i:s'),
371371
];
372372
}
373373

src/Controllers/MagicLinkController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function loginAction()
8585
'user_id' => $user->id,
8686
'type' => Session::ID_TYPE_MAGIC_LINK,
8787
'secret' => $token,
88-
'expires' => Time::now()->addSeconds(setting('Auth.magicLinkLifetime'))->toDateTimeString(),
88+
'expires' => Time::now()->addSeconds(setting('Auth.magicLinkLifetime'))->format('Y-m-d H:i:s'),
8989
]);
9090

9191
// Send the user an email with the code

src/Models/LoginModel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function fake(Generator &$faker): Login
9191
'id_type' => Session::ID_TYPE_EMAIL_PASSWORD,
9292
'identifier' => $faker->email,
9393
'user_id' => null,
94-
'date' => Time::parse('-1 day')->toDateTimeString(),
94+
'date' => Time::parse('-1 day')->format('Y-m-d H:i:s'),
9595
'success' => true,
9696
]);
9797
}

src/Models/TokenLoginModel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function fake(Generator &$faker): Login
2222
'ip_address' => $faker->ipv4,
2323
'identifier' => 'token: ' . random_string('crypto', 64),
2424
'user_id' => fake(UserModel::class)->id,
25-
'date' => Time::parse('-1 day')->toDateTimeString(),
25+
'date' => Time::parse('-1 day')->format('Y-m-d H:i:s'),
2626
'success' => true,
2727
]);
2828
}

tests/Authorization/AuthorizableTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use CodeIgniter\Shield\Authorization\AuthorizationException;
77
use CodeIgniter\Shield\Models\UserModel;
88
use CodeIgniter\Test\DatabaseTestTrait;
9+
use Locale;
910
use Tests\Support\FakeUser;
1011
use Tests\Support\TestCase;
1112

@@ -295,4 +296,25 @@ public function testCanCascadesToGroupsWithWildcards(): void
295296

296297
$this->assertTrue($this->user->can('admin.access'));
297298
}
299+
300+
/**
301+
* @see https://github.com/codeigniter4/shield/pull/238
302+
*/
303+
public function testCreatedAtIfDefaultLocaleSetFaWithAddGroup(): void
304+
{
305+
$currentLocale = Locale::getDefault();
306+
Locale::setDefault('fa');
307+
308+
Time::setTestNow('March 10, 2017', 'America/Chicago');
309+
310+
$this->user->addGroup('admin');
311+
312+
$this->seeInDatabase('auth_groups_users', [
313+
'user_id' => $this->user->id,
314+
'group' => 'admin',
315+
'created_at' => '2017-03-10 00:00:00',
316+
]);
317+
318+
Locale::setDefault($currentLocale);
319+
}
298320
}

0 commit comments

Comments
 (0)