Git Product home page Git Product logo

age-calc-cs's People

Contributors

faisalman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

age-calc-cs's Issues

Wrong age calculation

For one case it calculates the age wrong. For example:

Start Date: 02/01/2019
End Date: 08/31/2020

It calculates as 1 year, 7 months and 2 days instead of 1 year, 6 months and 30 days.

Wrong calculation

Hi.

Your code is not calculating correctly.

Birthday = 02/23/2022 (MM/dd/yyyy)

Example Dates:
04/28/2022 => 0 Years, 2 Months, 5 Days
04/29/2022 => 0 Years, 2 Months, 6 Days
04/30/2022 => 0 Years, 2 Months, 7 Days
05/01/2022 => 0 Years, 2 Months, 6 Days (should be 8 Days)
05/02/2022 => 0 Years, 2 Months, 7 Days (should be 9 Days)
05/03/2022 => 0 Years, 2 Months, 8 Days (should be 10 Days)

The issue happens because you are calculating the days without considering the months / year. You have to calculate years & months at first and after this the remaining days.

Wrong Age.

this.Months = Cday.Month - (Bday.Month + 1) + Math.Abs(DaysRemain / DaysInBdayMonth);

Bday 26 Nov 2020
Cday 25 Dec 2020

Run.
DaysRemain = 25+ (30- 26) = 29
this.Months = 12 - (11+1) + Math.Abs(29 /30)
Math.Abs(29 / 30) >> 0.999
this.Months = 12 - (11+1) + 0.999
this.Months = 1 (int) Wrong!

Age 1 month 29 days

add Math.Truncate()
this.Months = Cday.Month - (Bday.Month + 1) + Math.Truncate(Math.Abs(DaysRemain / DaysInBdayMonth));

Age 29 days

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.