Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i want to fetch average of data between a date range on a portal.... if days between that date range is greater than 20 days and less than 60 so display average of data in weekly format(average data of each week) if it is more than 60 days so display in monthly format

What I have tried:

public void getweeklyVoilations(KeyValueDto key,String startDate , String endDate) {

LocalDate startDate1 = LocalDate.parse(startDate);
LocalDate endDate1 = LocalDate.parse(endDate);

Period period = Period.between(startDate1, endDate1);

int days = period.getDays();
int voilation[];
float value;
if(days>20 && days<60) {
for((days%7)=0;(days%7)<7;days++) {
value= value+voilation[i]

}
Posted
Updated 26-Aug-21 6:27am
Comments
Richard MacCutchan 26-Aug-21 12:08pm    
What is the problem?

1 solution

First off, why are you passing strings containing dates? If they fail to parse, there is no way to be "graceful" about it, or specific in what problem gets reported to the user.

Assuming that the strings are user entered dates, you need to parse them to a Date value as soon as possible, before you code loses any direct contact with the user settings. At that point you can report problems and get them fixed before going any further. From that point on, you are using native date values and all your code gets simpler.

Then, how do you expect a reasonable value when violation has no elements, or values, and i is not declared or changed in any way ...

To be honest, that looks like it was thrown together with no thought at all in the hope that somebody - anybody - would do the actual task for you ...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900