Skip to content

Commit

Permalink
seconds/millis fix for date input
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaHonchar committed Sep 4, 2018
1 parent eff7a31 commit 9a52207
Showing 1 changed file with 24 additions and 0 deletions.
Expand Up @@ -31,6 +31,7 @@

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

/**
* @author lazyman
Expand Down Expand Up @@ -64,6 +65,29 @@ protected void onUpdate(AjaxRequestTarget target){

}

@Override
public void convertInput() {
super.convertInput();
Date convertedDate = getConvertedInput();
Date modelDate = getModelObject();
if (convertedDate == null || modelDate == null){
return;
}

GregorianCalendar gregorianCalendar = new GregorianCalendar();
gregorianCalendar.setTimeInMillis(modelDate.getTime());

//set seconds and milliseconds only in case when the date input value wasn't changed
if (gregorianCalendar.get(13) > 0 || gregorianCalendar.get(14) > 0){
GregorianCalendar convertedCalendar = new GregorianCalendar();
convertedCalendar.setTimeInMillis(convertedDate.getTime());

convertedCalendar.set(13, gregorianCalendar.get(13));
convertedCalendar.set(14, gregorianCalendar.get(14));
setConvertedInput(convertedCalendar.getTime());
}
}

@Override
protected TextField<Integer> newMinutesTextField(String id, IModel<Integer> model, Class<Integer> type) {
TextField<Integer> textField = super.newMinutesTextField(id, model, type);
Expand Down

0 comments on commit 9a52207

Please sign in to comment.