Reccomendation from the mentor : "The isDateOdd() method returns an incorrect value. Test it with different dates."
Can you help to identify where I am doing wrong? Thank you :)
package com.codegym.task.task08.task0827;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.time.temporal.ChronoUnit;
import java.util.Locale;
/*
Working with dates
*/
public class Solution {
public static void main(String[] args) {
System.out.println(isDateOdd("MAY 1 2013"));
}
static int startMonth = 1;
static int startDay = 1;
public static boolean isDateOdd(String date) {
//convert input string date to formatted date object
DateTimeFormatter formatter = new DateTimeFormatterBuilder()
.parseCaseInsensitive()
.appendPattern("MMM d yyyy")
.toFormatter(Locale.getDefault());
LocalDate formattedDate = LocalDate.parse(date, formatter);
//Calculate the elapsed days from the start of the year.
LocalDate start = LocalDate.of( formattedDate.getYear() , startMonth , startDay ) ;
LocalDate stop = LocalDate.of( formattedDate.getYear() , formattedDate.getMonth() , formattedDate.getDayOfMonth() ) ;
int daysBetween = (int) ChronoUnit.DAYS.between( start , stop );
//Find if the int daysBetween is odd or even and return the value.
if ( (daysBetween % 2) == 0) {
return false;
}
else {
return true;
}
}
}