Design comparison
Community feedback
- @arturasmckwczPosted about 1 year ago
Hey Enitan,
Thanks for reviewing my Age calculator app. I noticed that you calculated the age in years, months, and days between dates, which is a better approach than converting milliseconds. However, I found that your code doesn't produce 100% accurate results. I suggest leveraging JavaScript's Date object to handle leap years, the number of days in months, and other factors for more accurate calculations. Wish you the best!
Marked as helpful0@Mastermind390Posted about 1 year ago@arturasmckwcz Thanks for your observation and suggestion.
what you just pointed out came across my mind when I was working on the project but I don't know how to go about it. I will appreciate if you can help me with how to achieve that.
Thanks so much.
0@arturasmckwczPosted about 1 year ago@Mastermind390
The first of all I'd consider the quite obvious rule: if dates differs by years only, then months and days should be 0s, for example 10 years 0 month 0 days are between 09.09.2013 and 09.09.2023 right? Regarding leveraging Date object I'd use constructor
Date(year, month, day)
where args are ofnumber
type and month number is 0 based. It already takes care of a number of days in a month and if a year is leap. For examplenew Date(2023,1,29)
will return 2023-03-01, so I used that to check if a date is correct bynew Date(year, month-1, day).getDate() === day
, etc.Marked as helpful0@Mastermind390Posted about 1 year ago@arturasmckwcz thanks for this I will check it out.
0@arturasmckwczPosted about 1 year ago@Mastermind390
you're welcome! now it does calc much better, however I figured that for dates from the next day year ago like 22.09.2022 (today 21.09.2023) to the end of that year (2022) it prints all zeros, which isn't correct
0
Please log in to post a comment
Log in with GitHubJoin our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord