Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New core functions: toDate and toDateTime #17743

Merged
merged 27 commits into from
Aug 2, 2024
Merged

Conversation

jamisonbryant
Copy link
Contributor

Adds two new global functions: toDate() and toDateTime() which accept mixed values and attempt to convert them to the native Chronos object. This is the first part of a series of PRs to make type-safe request data available to users.

@jamisonbryant jamisonbryant changed the base branch from 5.x to 5.next July 17, 2024 13:06
@jamisonbryant jamisonbryant marked this pull request as ready for review July 17, 2024 13:26
src/Core/functions.php Outdated Show resolved Hide resolved
src/Core/functions.php Outdated Show resolved Hide resolved
src/Core/functions.php Outdated Show resolved Hide resolved
src/Core/functions.php Outdated Show resolved Hide resolved
tests/TestCase/Core/FunctionsTest.php Outdated Show resolved Hide resolved
tests/TestCase/Core/FunctionsTest.php Outdated Show resolved Hide resolved
src/Core/functions.php Outdated Show resolved Hide resolved
jamisonbryant and others added 2 commits July 30, 2024 15:59
Switch to PHPUnit annotations for data providers

Co-authored-by: ADmad <[email protected]>
@jamisonbryant
Copy link
Contributor Author

I just realized also that some tests are failing on PHP8.4 specifically that are passing on 8.3 and below:

DateRangeError: DateTimeImmutable::createFromTimestamp(): Argument #1 ($timestamp) must be a finite 
  number between -9223372036854775808 and 9223372036854775807.999999, NAN given
// (same for -INF)
// (same for INF)

I tried work around this by simply adding |\DateRangeError to the try-catch block but this class is only available in PHP8.3 and up, and composer.json is currently set at >=8.1. So I changed the exception to catch Throwable instead. I've never written try-catch blocks this 'broad' before so if this the wrong approach I would love to get some feedback.

Alternatively, we can remove the tests for NAN/INF and assume users will not try to pass these values to the functions, which I think is semi-reasonable.

src/I18n/functions.php Outdated Show resolved Hide resolved
src/I18n/functions.php Outdated Show resolved Hide resolved
src/I18n/functions.php Outdated Show resolved Hide resolved
jamisonbryant and others added 3 commits August 1, 2024 12:13
Language correction and remove link that no longer applies

Co-authored-by: ADmad <[email protected]>
CI often has slow machines that can have a long delay between data
providers and tests run.
@markstory markstory merged commit 0815bab into 5.next Aug 2, 2024
9 of 10 checks passed
@markstory markstory deleted the feature/to-date-to-datetime branch August 2, 2024 18:59
markstory added a commit to cakephp/docs that referenced this pull request Aug 2, 2024
@ADmad ADmad added this to the 5.1.0 milestone Aug 5, 2024
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.

3 participants