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

Age method calculates the age incorrectly #181

Closed
tlou80 opened this issue Aug 28, 2023 · 12 comments
Closed

Age method calculates the age incorrectly #181

tlou80 opened this issue Aug 28, 2023 · 12 comments
Labels
Bug Report a reproducible bug or regression

Comments

@tlou80
Copy link

tlou80 commented Aug 28, 2023

carbon2.2.0版本使用Age方法计算年龄错误,譬如2023-08-28计算出生日期为1938-09-02的人年龄计算出来的是85岁,实际应该是84岁,2.2.0之前的版本计算是正确的

@tlou80 tlou80 added the Bug Report a reproducible bug or regression label Aug 28, 2023
@Issues-translate-bot
Copy link
Collaborator

The issue body's language is not English, translate it automatically, please use English next time. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


The carbon2.2.0 version uses the Age method to calculate the age incorrectly. For example, the calculated age of a person whose birth date is 1938-09-02 on 2023-08-28 is calculated to be 85 years old, but the actual age should be 84 years old. The version before 2.2.0 calculated the age as The correct

@Issues-translate-bot Issues-translate-bot changed the title Age方法计算年龄不正确 Age method calculates the age incorrectly Aug 28, 2023
@gouguoyin
Copy link
Collaborator

Fixed in version 2.2.6

@tlou80
Copy link
Author

tlou80 commented Sep 20, 2023

difference.go 第18行

判断条件应该由dd < 0 || dm < 0改成dm < 0 || (dm == 0 && dd < 0)

现在的判断条件只判断天数差小于0就减一年而没有判断月份,导致大量的年龄计算错误。例:当前是2023-09-21,正常出生日期为2019-09-22至2020-09-21的人应该是3岁,现在这种判断条件会导致2020年1月到8月每个月21号之后出生的人会被计算成2岁。 @gouguoyin

@Issues-translate-bot
Copy link
Collaborator

The issue body's language is not English, translate it automatically, please use English next time. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


difference.go line 18

The judgment condition should be changed from dd < 0 || dm < 0 to dm < 0 || (dm == 0 && dd < 0).

The current judgment condition only judges that the difference in days is less than 0 and then subtracts one year without judging the month, resulting in a large number of age calculation errors. Example: The current date is 2023-09-21. A person with a normal birth date from 2019-09-22 to 2020-09-21 should be 3 years old. Now this judgment condition will result in 21 for each month from January to August 2020. People born after the number will be counted as 2 years old. @gouguoyin

@gouguoyin
Copy link
Collaborator

image

@gouguoyin gouguoyin reopened this Sep 26, 2023
@tlou80
Copy link
Author

tlou80 commented Sep 26, 2023

你在2023-09-26号应该测试2023年1月-8月中的27号及以后的日期,在2023-09-27号应该测试2023年1月-8月中的28号及以后的日期,同理2023-10-01号的时候1-9月除了1号那天正确,其他的日期都会小一岁 @gouguoyin

@Issues-translate-bot
Copy link
Collaborator

The issue body's language is not English, translate it automatically, please use English next time. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


You should test the 27th and later dates from January to August 2023 on 2023-09-26, and the 28th and later dates from January to August 2023 on 2023-09-27. , in the same way, when 2023-10-01 is the correct day from January to September, except the 1st, the other dates will be one year younger @gouguoyin

@gouguoyin
Copy link
Collaborator

Please give an example,assuming the current time is "2023-09-27"

@tlou80
Copy link
Author

tlou80 commented Sep 27, 2023

image
[email protected]

@tlou80
Copy link
Author

tlou80 commented Sep 27, 2023

比如当前日期是2023-09-27,那么你计算2020-01-28至2020-01-31、2020-02-28至2020-02-31 ···· 一直到2020-08-28至2020-08-31这些日期都会比实际的小一岁。出现原因在于difference.go 第18行的条件判断有问题,应该把dd < 0 || dm < 0改成dm < 0 || (dm == 0 && dd < 0) @gouguoyin

@Issues-translate-bot
Copy link
Collaborator

The issue body's language is not English, translate it automatically, please use English next time. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


For example, if the current date is 2023-09-27, then you calculate 2020-01-28 to 2020-01-31, 2020-02-28 to 2020-02-31... until 2020-08-28 to 2020- 08-31 These dates will be one year younger than the actual date. The reason is that there is a problem with the conditional judgment in line 18 of difference.go. You should change dd < 0 || dm < 0 to dm < 0 || (dm == 0 && dd < 0)

@gouguoyin
Copy link
Collaborator

Fixed in v2.2.9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Report a reproducible bug or regression
Projects
None yet
Development

No branches or pull requests

3 participants