Skip to content
Merged
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
18 changes: 9 additions & 9 deletions tests/Unit/TimeUtilityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ public function testFormatInterval(): void
$this->assertSame('1 minute', Time::formatInterval(60));
$this->assertSame('1 minute ago', Time::formatInterval(-60));
$this->assertSame('1m 1s', Time::formatInterval(61, true));
$this->assertSame('1 hour', Time::formatInterval(60*60));
$this->assertSame('1 day', Time::formatInterval(24*60*60));
$this->assertSame('2 weeks 3 days 24 minutes 16 seconds', Time::formatInterval(17*24*60*60+1456));
$this->assertSame('2 weeks 3 days', Time::formatInterval(17*24*60*60+1456, parts: 2));
$this->assertSame('1 hour', Time::formatInterval(60 * 60));
$this->assertSame('1 day', Time::formatInterval(24 * 60 * 60));
$this->assertSame('2 weeks 3 days 24 minutes 16 seconds', Time::formatInterval(17 * 24 * 60 * 60 + 1456));
$this->assertSame('2 weeks 3 days', Time::formatInterval(17 * 24 * 60 * 60 + 1456, parts: 2));

// different months could change this
$this->travelTo(Carbon::createFromTimestamp(30042), function () {
$this->assertSame('1 month 1 week 2 days 24 minutes', Time::formatInterval(39*24*60*60+1456));
$this->assertSame('1mo 1w 2d 24m 16s', Time::formatInterval(39*24*60*60+1456, true, 5));
$this->assertSame('1 month 1 week 2 days 24 minutes', Time::formatInterval(39 * 24 * 60 * 60 + 1456));
$this->assertSame('1mo 1w 2d 24m 16s', Time::formatInterval(39 * 24 * 60 * 60 + 1456, true, 5));
});

// calculate if there is a leap year (could freeze time, try this instead)
Expand All @@ -38,9 +38,9 @@ public function testFormatInterval(): void
$days = Carbon::now()->subYear()->isLeapYear() ? 366 : 365;
}

$this->assertSame('1 year', Time::formatInterval($days*24*60*60));
$this->assertSame('1 year ago', Time::formatInterval(-$days*24*60*60));
$this->assertSame('1 year', Time::formatInterval($days * 24 * 60 * 60));
$this->assertSame('1 year ago', Time::formatInterval(-$days * 24 * 60 * 60));

$this->assertSame('4 years', Time::formatInterval(1461*24*60*60));
$this->assertSame('4 years', Time::formatInterval(1461 * 24 * 60 * 60));
}
}
Loading