diff options
Diffstat (limited to 'dozentenmodul/src/main/java/org/openslx/dozmod/util/DateLabelFormatter.java')
-rw-r--r-- | dozentenmodul/src/main/java/org/openslx/dozmod/util/DateLabelFormatter.java | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/util/DateLabelFormatter.java b/dozentenmodul/src/main/java/org/openslx/dozmod/util/DateLabelFormatter.java new file mode 100644 index 00000000..3e6b7043 --- /dev/null +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/util/DateLabelFormatter.java @@ -0,0 +1,32 @@ +package org.openslx.dozmod.util; + +import java.text.ParseException; +import java.util.Calendar; + +import javax.swing.JFormattedTextField.AbstractFormatter; + +import org.joda.time.format.DateTimeFormat; +import org.joda.time.format.DateTimeFormatter; + +@SuppressWarnings("serial") +public class DateLabelFormatter extends AbstractFormatter { + + private static final DateTimeFormatter formatter = DateTimeFormat.forPattern("dd.MM.yyyy"); + + @Override + public Object stringToValue(String text) throws ParseException { + try { + return formatter.parseDateTime(text); + } catch (Exception e) { + throw new ParseException(e.getMessage(), -1); + } + } + + @Override + public String valueToString(Object value) throws ParseException { + if (value == null) + return ""; + return formatter.print(((Calendar) value).getTimeInMillis()); + } + +} |