I have a class that implements a report and has this code:
Date startDate = ParameterUtils.getDateParam(params, "startDate", i18nBean.getLocale());
Now the method getDateParam is deprecated and I need to remake this code. I tried this:
DateTimeFormatterFactory dateTimeFormatterFactory = ComponentAccessor.getComponent(DateTimeFormatterFactory.class); DateTimeFormatter userFormatter = dateTimeFormatterFactory.formatter().forLoggedInUser(); String startDateStr = ParameterUtils.getStringParam(params, "startDate"); Date startDate = userFormatter.parse(startDateStr);
But it throws a UnsupportedOperationException. In one execution I have checked that the date param is: 07/11/16 15:09 and the format hint is dd/MM/yy hh:mm, that is, the appropriate format.
Can someone tell me what the problem is or offer me an alternative??
Thank you
Community moderators have prevented the ability to post new answers.
I found this page that I do not see fit to use Joda Time, because it is necessay to identify the correct time zone.
https://confluence.atlassian.com/jira/plugin-developer-notes-for-jira-4-4-235667482.html
I have solved the problem adding withStyle method. This no longer throws the UnsupportedOperationException.
DateTimeFormatterFactory dateTimeFormatterFactory = ComponentAccessor.getComponent(DateTimeFormatterFactory.class); DateTimeFormatter userFormatter = dateTimeFormatterFactory.formatter().withStyle(DateTimeStyle.DATE_TIME_PICKER).forLoggedInUser(); String startDateStr = ParameterUtils.getStringParam(reqParams, "startDate"); Date startDate = userFormatter.parse(startDateStr);
Use Joda Time:
DateTimeFormatter formatter = DateTimeFormat.forPattern("dd/MM/yy hh:mm"); Date startDate = formatter.parseDateTime(ParameterUtils.getStringParam(params, "startDate")).toDate();
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.