summaryrefslogblamecommitdiffstats
path: root/dozentenmodul/src/main/java/org/openslx/dozmod/util/DateLabelFormatter.java
blob: 3e6b70435f575923fb71cdce71efac4dda6c4327 (plain) (tree)































                                                                                                   
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());
	}

}