Skip to content

Support v3.0 for nesbot/carbon. - #6591

Merged
limingxinleo merged 23 commits into
hyperf:3.2from
huangdijia:support-carbon-3.x
Jul 22, 2025
Merged

limingxinleo merged 23 commits into
hyperf:3.2from
huangdijia:support-carbon-3.x

Conversation

@huangdijia

@huangdijia huangdijia commented Mar 13, 2024 •

Copy link
Copy Markdown
Member

@huangdijia
huangdijia requested a review from limingxinleo March 13, 2024 08:20
@huangdijia
huangdijia marked this pull request as ready for review March 13, 2024 08:20
@limingxinleo limingxinleo added this to the v3.2 milestone Mar 13, 2024
@huangdijia
huangdijia marked this pull request as draft March 13, 2024 10:06
@limingxinleo

Copy link
Copy Markdown
Member

https://carbon.nesbot.com/docs/#api-carbon-3

v3.2 版本时,进行挨个比对

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before:

$res = $now->clone()->addSeconds(30)->diffInRealSeconds();
$this->assertSame(30, $res);

After:

$res = $now->clone()->addSeconds(30)->floatDiffInRealSeconds();
$this->assertEquals(30, abs(round($res)));

Some issues with the change:

  • Method floatDiffInRealSeconds() is not in Carbon 3.x. According to release note of 3.0.0:
    • diffIn* will use the floatDiffInReal* behavior.
    • floatDiffInReal*() methods were removed.
  • Hard to read.

Suggested change:

$this->assertSame(30, (int) $now->diffInSeconds($now->clone()->addSeconds(30), false));

or

$this->assertEqualsWithDelta(30, $now->diffInSeconds($now->clone()->addSeconds(30), false), 0.001);

@kingIZZZY

Copy link
Copy Markdown
Contributor

+1 we need this fix for Laravel-Hyperf

  • In PHP 8.4 getting exception about Implicitly marking parameter $weekStartsAt as nullable is deprecated, the explicit nullable type must be used instead which would be fixed with Carbon v3 Upgrade nesbot/carbon ^3.0 #7230 (comment)

Suggested Additions

Can you please also update this for hyperf/validation

And should probably do the same update for the rest of the codebase?

@huangdijia

Copy link
Copy Markdown
Member Author

@kingIZZZY There are a lot of break changes between Carbon 2.0 and 3.0, and Hyperf will incorporate this PR in the next major release.

@kingIZZZY

kingIZZZY commented Jan 1, 2025 •

Copy link
Copy Markdown
Contributor

Is it not good enough to implement @deminy 's suggested fixes above? Or are there definitely other tests which would fail with carbon 3?

So far I just forked my own hyperf/validation & hyperf/crontab & hyperf/database to use carbon 3 in Laravel-Hyperf and it seems to be working so far, but maybe I haven't encountered all code paths using carbon yet..

@huangdijia
huangdijia changed the base branch from master to 3.2 February 5, 2025 12:44
@huangdijia
huangdijia marked this pull request as ready for review February 5, 2025 13:05
Comment thread composer.json Outdated
Comment thread src/crontab/composer.json Outdated
Comment thread .github/workflows/test-components.yml Outdated
Comment thread src/database/composer.json Outdated
Comment thread src/crontab/src/Strategy/Executor.php
@limingxinleo limingxinleo changed the title Added caron 3.x support Support v3.0 for nesbot/carbon. Jul 22, 2025
@limingxinleo
limingxinleo merged commit 53c1f3b into hyperf:3.2 Jul 22, 2025
@huangdijia
huangdijia deleted the support-carbon-3.x branch July 22, 2025 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants