Skip to content

Commit c084a2c

Browse files
committed
use Carbon::now for fresh timestamps
1 parent 78d7cbd commit c084a2c

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/Jenssegers/Mongodb/Eloquent/Model.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public function getDateFormat()
118118
*/
119119
public function freshTimestamp()
120120
{
121-
return new UTCDateTime(time() * 1000);
121+
return new UTCDateTime(Carbon::now());
122122
}
123123

124124
/**

tests/ModelTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,16 @@ public function testDates(): void
434434
$this->assertEquals((string) $user->getAttribute('entry.date')->format('Y-m-d H:i:s'), $data['entry']['date']);
435435
}
436436

437+
public function testCarbonDateMockingWorks()
438+
{
439+
$fakeDate = \Carbon\Carbon::createFromDate(2000, 01, 01);
440+
441+
Carbon::setTestNow($fakeDate);
442+
$item = Item::create(['name' => 'sword']);
443+
444+
$this->assertEquals($item->created_at, $fakeDate);
445+
}
446+
437447
public function testIdAttribute(): void
438448
{
439449
/** @var User $user */

0 commit comments

Comments
 (0)