How to use DateTimeFormatterFactory to get date parameter

In this “Creating Jira report tutorial” there’s this line of code that gets date parameter from UI:

Date startDate = ParameterUtils.getDateParam(params, "startDate", i18nBean.getLocale());

But getDateParam method is deprecated and the documentation recommends using DateTimeFormatterFactory instead. But I can’t understand how to use it to get date param? I suspect it’s something like getting a date string and using DateTimeFormatterFactory to get a date object. What is the preferred way of doing this?

BTW, it’s a bane to unit test the generateReportHtml method as we need to mock static ParameterUtils.getblablaParam method. I ended up using PowerMock which screwed the test.

I think the following could work, but I have not tried it, and looks too long:

dateTimeFormatterFactory.formatter().withStyle(DateTimeStyle.DATE_PICKER).parse(ParameterUtils.getStringParam(params, "startDate"));

See also for possibly related problem.

1 Like

Yes, that’s exactly what I wanted. I can’t understand how I couldn’t think of this. It’s so simple.