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

Add parsing methods where missing. #86

Merged
merged 2 commits into from
Oct 2, 2023

Conversation

gnutix
Copy link
Contributor

@gnutix gnutix commented Sep 30, 2023

Fixes #68 by adding :

  • YearWeek::parse('2023-W39');
  • Year::parse('2023');
  • DayOfWeek::parse('06');
  • Month::parse('October');

I was not sure it made sense to add Year::parse(), because it's so close to Year::of((int) $string). But then I realized they do differ for dates (positive and negative) under 1000 / 100 / 10 because of the trailing zeroes :

Year::of((int) '-100'); // works
Year::of((int) '-0100'); // works, interpreted as -100 (PHP, right? :>)
Year::parse('-100'); // should throw an Exception, as the valid ISO is "-0100"
Year::parse('-0100'); // works

Same for DayOfWeek with its leading zero. I know DayOfMonth and Month will be converted into Enums in the next version (0.6), but I still think it doesn't hurt to add these methods on them in the meantime.

@gnutix gnutix force-pushed the year-objects-add-parse-method branch 2 times, most recently from db9d036 to e95ae99 Compare September 30, 2023 10:06
@gnutix gnutix changed the title Add parsing methods for YearWeek and Year. Add parsing methods where missing. Sep 30, 2023
@gnutix gnutix force-pushed the year-objects-add-parse-method branch from 91cfd90 to e95ae99 Compare September 30, 2023 10:35
@gnutix
Copy link
Contributor Author

gnutix commented Sep 30, 2023

Instant and Interval(Instant, Instant) don't have parse methods either. Not sure if it would make sense to add them or not. WDYT ?

@gnutix gnutix marked this pull request as ready for review September 30, 2023 10:40
@BenMorel
Copy link
Member

BenMorel commented Oct 1, 2023

Instant and Interval(Instant, Instant) don't have parse methods either. Not sure if it would make sense to add them or not. WDYT ?

If they're not needed at the moment, I would leave them for now.

Copy link
Member

@BenMorel BenMorel left a comment

Choose a reason for hiding this comment

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

@gnutix I'm OK with Year and YearWeek, but not Month and DayOfWeek for the reasons stated below!

src/DayOfWeek.php Outdated Show resolved Hide resolved
tests/YearTest.php Show resolved Hide resolved
tests/YearWeekTest.php Show resolved Hide resolved
@gnutix gnutix force-pushed the year-objects-add-parse-method branch from d5e5ef8 to 17ba49c Compare October 2, 2023 07:10
@gnutix gnutix requested a review from BenMorel October 2, 2023 07:12
@gnutix
Copy link
Contributor Author

gnutix commented Oct 2, 2023

I'm OK with Year and YearWeek, but not Month and DayOfWeek for the reasons stated below!

Reverted. PR is ready for merge IMHO.

@BenMorel BenMorel force-pushed the year-objects-add-parse-method branch from 17ba49c to 89381c2 Compare October 2, 2023 19:49
@BenMorel BenMorel merged commit 5b6044c into brick:master Oct 2, 2023
8 checks passed
@BenMorel
Copy link
Member

BenMorel commented Oct 2, 2023

Thank you, @gnutix!

To iterate faster and avoid yet another feedback, I took the liberty to update your commits to rename data providers that didn't match the project's standards:

  • providerParseInvalidValues providerParseInvalidYearThrowsException
  • providerParseInvalidValues providerParseInvalidYearWeekThrowsException

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.

Some objects with ISO representations are missing a parse method
2 participants