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

fix: Time::getAge() calculation #6159

Merged
merged 5 commits into from
Jun 21, 2022

Conversation

kenjis
Copy link
Member

@kenjis kenjis commented Jun 19, 2022

Description

  • fix Time::getAge() calculation
  • fix test case

Returns the age, in years, of between the Time’s instance and the current time. Perfect for checking the age of someone based on their birthday:
https://codeigniter4.github.io/CodeIgniter4/libraries/time.html#getage

There are a few ways to calculate human age.
However, the current implementation does not seem to be common.

E.g.:

  • birthdate: December 31, 2020
  • now: January 1, 2022
  • age: 2

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

kenjis added 4 commits June 20, 2022 07:41
The magic property cannot find the test cases from the source of the Time::getAge() definition on IDE.
@kenjis kenjis added the bug Verified issues on the current code behavior or pull requests that will fix them label Jun 19, 2022
Copy link
Member

@MGatner MGatner left a comment

Choose a reason for hiding this comment

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

Why not use Time::difference()? Or it's underlying method:

   return $time->fieldDifference($this->testTime, IntlCalendar::FIELD_YEAR);

@kenjis kenjis requested a review from MGatner June 21, 2022 06:55
@kenjis
Copy link
Member Author

kenjis commented Jun 21, 2022

Refactored.

Copy link
Member

@MGatner MGatner left a comment

Choose a reason for hiding this comment

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

Test failures seemed to be due to CloudFlare's outage affecting Coveralls, not a problem.

@samsonasik samsonasik merged commit 0180479 into codeigniter4:develop Jun 21, 2022
@samsonasik
Copy link
Member

Thank you @kenjis

@kenjis kenjis deleted the fix-Time-getAget branch June 21, 2022 21:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants