Missed Team ’24? Catch up on announcements here.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Parse date from param

Pablo Gomez Justicia March 8, 2017

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

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
Pablo Gomez Justicia March 8, 2017

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);
0 votes
Alexey Dorofeyev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 8, 2017

Use Joda Time:

DateTimeFormatter formatter = DateTimeFormat.forPattern("dd/MM/yy hh:mm");
Date startDate = formatter.parseDateTime(ParameterUtils.getStringParam(params, "startDate")).toDate();
TAGS
AUG Leaders

Atlassian Community Events