Bug 438 - Abnormal return value of getDuration() from Plan class
Summary: Abnormal return value of getDuration() from Plan class
Status: CONFIRMED
Alias: None
Product: Group 3
Classification: Unclassified
Component: Personal Finance Mangement (show other bugs)
Version: unspecified
Hardware: PC Mac OS
: --- critical
Assignee: Hsu To-Liang
URL:
Depends on:
Blocks:
 
Reported: 2020-11-22 17:45 HKT by Xavier.edith.lee
Modified: 2020-11-23 20:21 HKT (History)
1 user (show)

See Also:


Attachments
Bug reproduced and located in Plan class as suggested (179.04 KB, image/jpeg)
2020-11-22 18:16 HKT, Xavier.edith.lee
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Xavier.edith.lee 2020-11-22 17:45:47 HKT
When calculateAverage() was called, the result computed obviously was wrong and inconsistent with the expected result from test case. 

After some investigation, it was discovered that the denominator i.e. number of days, was given a wrong value from getDuration() function. May consider studying the implementation of that first.
Comment 1 Xavier.edith.lee 2020-11-22 18:16:51 HKT
Created attachment 49 [details]
Bug reproduced and located in Plan class as suggested

The result after unit testing was indeed caused by the aforementioned function getDuration(). It is suspected that the fault arose from the use of Period class to calculate date difference. 

As discussion from online forum revealed, Period class returns date difference separately in terms of [year, month, day]. Suppose dateDifference = 93 days. Period.getDays() will return 3 days since it is [0 year, 3 months, 3 days].

Alternative method is suggested to replace such erroneous function.
Comment 2 Hsu To-Liang 2020-11-23 20:21:03 HKT
After switching to DAYS.between(startDate, endDate) from ChronoUnit Class. The computation was corrected.