In java, How to fill the missing date range with data ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

In java, How to fill the missing date range with data ?

Im having two files one with date range and another file with (date range , values) We need to write an output with matching date range and values, default value is given for missing date ranges 1/1/2022 to 4/30/2022 - red 6/30/2022 to 10/31/2022 - blue For the missing date range i need to fill with value green Expected OUTPUT: 1/1/2022 -4/30/2022 = red 5/1/2022 -5/31/2022 = green 6/30/2022 -10/31/2022= blue 11/1/2022 -12/31/2022 = green

12th Jun 2022, 5:43 AM
prasath mohan
prasath mohan - avatar
1 Answer
+ 1
Use java.time.LocalDate.datesUntil() method to define a range of consecutive days, which are represented as Stream<LocalDate> You can compare dates with LocalDate.isBefore, isEqual, isAfter methods. https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/time/LocalDate.html#datesUntil(java.time.LocalDate)
12th Jun 2022, 11:54 AM
Tibor Santa
Tibor Santa - avatar