I'm trying to adjust my method and accept current year or next if the second part of date is next year.
My code:
private static final String PERIOD = "24 Dec-2 Jan";
private static DateRange _period = null;
public static void main(final String[] args)
{
_period = DateRange.parse(PERIOD, new SimpleDateFormat("dd MMM", Locale.US));
}
And the parse method:
public static DateRange parse(final String dateRange, final DateFormat format)
{
final String[] date = dateRange.split("-");
if (date.length == 2)
{
try
{
final Date startDate = format.parse(date[0]);
final Date endDate = format.parse(date[1]);
return new DateRange(startDate, endDate);
}
catch (final ParseException e)
{
_log.log(Level.WARNING, "Invalid Date Format.", e);
}
}
return new DateRange(null, null);
}
So after i execute the code i want to have _startDate to show 24 Dec 2020 and _endDate to show 4 JAN 2021 since is in next year
Edit: Current it print this:
Thu Dec 24 00:00:00 EET 1970
Fri Jan 02 00:00:00 EET 1970
While i need this
Thu Dec 24 00:00:00 EET 2020
Fri Jan 02 00:00:00 EET 2021