FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Support `v3.0` for `nesbot/carbon`. by huangdijia · Pull Request #6591 · hyperf/hyperf · GitHub

/ hyperf Public

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

Support v3.0 for nesbot/carbon.#6591
limingxinleo merged 23 commits into
hyperf:3.2from
huangdijia:support-carbon-3.x

Conversation

huangdijia commented Mar 13, 2024
edited by limingxinleo
Loading

Copy link
Copy Markdown
Member

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

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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);

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?

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 commented Jan 1, 2025
edited
Loading

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 changed the base branch from master to 3.2 February 5, 2025 12:44
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
limingxinleo changed the title Added caron 3.x support Support v3.0 for nesbot/carbon. Jul 22, 2025
limingxinleo merged commit 53c1f3b into hyperf:3.2 Jul 22, 2025
67 checks passed
huangdijia deleted the support-carbon-3.x branch July 22, 2025 13:44
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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


Back | FazBrowse Home | New Git URL