Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanmcclean committed Feb 25, 2025
1 parent 95abd27 commit 373f3ed
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 61 deletions.
6 changes: 3 additions & 3 deletions tests/Modifiers/DaysAgoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ public static function dateProvider()
{
return [
'same time' => ['2025-02-20 00:00', 0.0],
'less than a day ago' => ['2025-02-19 11:00', 0.0],
'less than a day ago' => ['2025-02-19 11:00', 1.0],
'1 day ago' => ['2025-02-19 00:00', 1.0],
'2 days ago' => ['2025-02-18 00:00', 2.0],

'one day from now' => ['2025-02-21 00:00', -1.0],
'less than a day from now' => ['2025-02-20 13:00', -0.0],
'more than a day from now' => ['2025-02-21 13:00', -1.0],
'less than a day from now' => ['2025-02-20 13:00', -1.0],
'more than a day from now' => ['2025-02-21 13:00', -2.0],
];
}

Expand Down
18 changes: 7 additions & 11 deletions tests/Modifiers/HoursAgoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,14 @@ public function it_outputs_minutes_ago($input, $expected)
public static function dateProvider()
{
return [
// Carbon 3 would return floats but to preserve backwards compatibility
// with Carbon 2 we will cast to integers.
'same time' => ['2025-02-20 13:10:00', 0], // 0.0
'less than a hour ago' => ['2025-02-20 13:00:00', 0], // 0.17
'1 hour ago' => ['2025-02-20 12:10:00', 1], // 1.0
'2 hours ago' => ['2025-02-20 11:10:00', 2], // 2.0
'same time' => ['2025-02-20 13:10:00', 0.0], // 0.0
'less than a hour ago' => ['2025-02-20 13:00:00', 0.0], // 0.17
'1 hour ago' => ['2025-02-20 12:10:00', 1.0], // 1.0
'2 hours ago' => ['2025-02-20 11:10:00', 2.0], // 2.0

// Future dates would return negative numbers in Carbon 3 but to preserve
// backwards compatibility with Carbon 2, we keep them positive.
'one hour from now' => ['2025-02-20 14:10:00', 1], // -1.0
'less than a hour from now' => ['2025-02-20 13:30:00', 0], // -0.33
'more than a hour from now' => ['2025-02-20 15:10:00', 2], // -2.0
'one hour from now' => ['2025-02-20 14:10:00', -1.0], // -1.0
'less than a hour from now' => ['2025-02-20 13:30:00', -0.0], // -0.33
'more than a hour from now' => ['2025-02-20 15:10:00', -2.0], // -2.0
];
}

Expand Down
20 changes: 8 additions & 12 deletions tests/Modifiers/MinutesAgoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,20 @@ public function it_outputs_minutes_ago($input, $expected)
{
Carbon::setTestNow(Carbon::parse('2025-02-20 13:10:00'));

$this->assertSame($expected, $this->modify(Carbon::parse($input)));
$this->assertSame($expected, round($this->modify(Carbon::parse($input))));
}

public static function dateProvider()
{
return [
// Carbon 3 would return floats but to preserve backwards compatibility
// with Carbon 2 we will cast to integers.
'same time' => ['2025-02-20 13:10:00', 0], // 0.0
'less than a minute ago' => ['2025-02-20 13:09:30', 0], // 0.5
'1 minute ago' => ['2025-02-20 13:09:00', 1], // 1.0
'2 minutes ago' => ['2025-02-20 13:08:00', 2], // 2.0
'same time' => ['2025-02-20 13:10:00', 0.0], // 0.0
'less than a minute ago' => ['2025-02-20 13:09:30', 1.0], // 0.5
'1 minute ago' => ['2025-02-20 13:09:00', 1.0], // 1.0
'2 minutes ago' => ['2025-02-20 13:08:00', 2.0], // 2.0

// Future dates would return negative numbers in Carbon 3 but to preserve
// backwards compatibility with Carbon 2, we keep them positive.
'one minute from now' => ['2025-02-20 13:11:00', 1], // -1.0
'less than a minute from now' => ['2025-02-20 13:10:30', 0], // -0.5
'more than a minute from now' => ['2025-02-20 13:11:30', 1], // -1.5
'one minute from now' => ['2025-02-20 13:11:00', -1.0], // -1.0
'less than a minute from now' => ['2025-02-20 13:10:30', -1.0], // -0.5
'more than a minute from now' => ['2025-02-20 13:11:30', -2.0], // -1.5
];
}

Expand Down
20 changes: 8 additions & 12 deletions tests/Modifiers/MonthsAgoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,20 @@ public function it_outputs_months_ago($input, $expected)
{
Carbon::setTestNow(Carbon::parse('2025-02-20'));

$this->assertSame($expected, $this->modify(Carbon::parse($input)));
$this->assertSame($expected, round($this->modify(Carbon::parse($input))));
}

public static function dateProvider()
{
return [
// Carbon 3 would return floats but to preserve backwards compatibility
// with Carbon 2 we will cast to integers.
'same month' => ['2025-02-20', 0], // 0.0
'less than a month ago' => ['2025-02-10', 0], // 0.36
'1 month ago' => ['2025-01-20', 1], // 1.0
'2 months ago' => ['2024-12-20', 2], // 2.0
'same month' => ['2025-02-20', 0.0], // 0.0
'less than a month ago' => ['2025-02-10', 0.0], // 0.36
'1 month ago' => ['2025-01-20', 1.0], // 1.0
'2 months ago' => ['2024-12-20', 2.0], // 2.0

// Future dates would return negative numbers in Carbon 3 but to preserve
// backwards compatibility with Carbon 2, we keep them positive.
'one month from now' => ['2025-03-20', 1], // -1.0
'less than a month from now' => ['2025-02-25', 0], // -0.18
'more than a month from now' => ['2025-04-20', 2], // -2.0
'one month from now' => ['2025-03-20', -1.0], // -1.0
'less than a month from now' => ['2025-02-25', -0.0], // -0.18
'more than a month from now' => ['2025-04-20', -2.0], // -2.0
];
}

Expand Down
16 changes: 6 additions & 10 deletions tests/Modifiers/SecondsAgoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,18 @@ public function it_outputs_seconds_ago($input, $expected)
{
Carbon::setTestNow(Carbon::parse('2025-02-20 13:10:30'));

$this->assertSame($expected, $this->modify(Carbon::parse($input)));
$this->assertSame($expected, round($this->modify(Carbon::parse($input))));
}

public static function dateProvider()
{
return [
// Carbon 3 would return floats but to preserve backwards compatibility
// with Carbon 2 we will cast to integers.
'same second' => ['2025-02-20 13:10:30', 0], // 0.0
'1 second ago' => ['2025-02-20 13:10:29', 1], // 1.0
'2 seconds ago' => ['2025-02-20 13:10:28', 2], // 2.0
'same second' => ['2025-02-20 13:10:30', 0.0], // 0.0
'1 second ago' => ['2025-02-20 13:10:29', 1.0], // 1.0
'2 seconds ago' => ['2025-02-20 13:10:28', 2.0], // 2.0

// Future dates would return negative numbers in Carbon 3 but to preserve
// backwards compatibility with Carbon 2, we keep them positive.
'one second from now' => ['2025-02-20 13:10:31', 1], // -1.0
'two seconds from now' => ['2025-02-20 13:10:32', 2], // -2.0
'one second from now' => ['2025-02-20 13:10:31', -1.0], // -1.0
'two seconds from now' => ['2025-02-20 13:10:32', -2.0], // -2.0
];
}

Expand Down
22 changes: 9 additions & 13 deletions tests/Modifiers/WeeksAgoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,21 @@ public function it_outputs_weeks_ago($input, $expected)
{
Carbon::setTestNow(Carbon::parse('2025-02-20'));

$this->assertSame($expected, $this->modify(Carbon::parse($input)));
$this->assertSame($expected, round($this->modify(Carbon::parse($input))));
}

public static function dateProvider()
{
return [
// Carbon 3 would return floats but to preserve backwards compatibility
// with Carbon 2 we will cast to integers.
'same day' => ['2025-02-20', 0], // 0.0
'same week' => ['2025-02-19', 0], // 0.14
'less than a week ago' => ['2025-02-17', 0], // 0.43
'1 week ago' => ['2025-02-13', 1], // 1.0
'2 weeks ago' => ['2025-02-06', 2], // 2.0
'same day' => ['2025-02-20', 0.0], // 0.0
'same week' => ['2025-02-19', 0.0], // 0.14
'less than a week ago' => ['2025-02-17', 0.0], // 0.43
'1 week ago' => ['2025-02-13', 1.0], // 1.0
'2 weeks ago' => ['2025-02-06', 2.0], // 2.0

// Future dates would return negative numbers in Carbon 3 but to preserve
// backwards compatibility with Carbon 2, we keep them positive.
'one week from now' => ['2025-02-27', 1], // -1.0
'less than a week from now' => ['2025-02-22', 0], // -0.29
'more than a week from now' => ['2025-03-08', 2], // -2.29
'one week from now' => ['2025-02-27', -1.0], // -1.0
'less than a week from now' => ['2025-02-22', -0.0], // -0.29
'more than a week from now' => ['2025-03-08', -2.0], // -2.29
];
}

Expand Down

0 comments on commit 373f3ed

Please sign in to comment.