blob: 4f9ca8abd01b310263040cf7b4f80a94cf01254c [file] [log] [blame]
/**
*
* Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany)
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation
*
*/
package org.eclipse.osbp.utils.vaadin;
import java.text.DateFormat;
import java.util.Locale;
public class SimpleDateFormatter {
public static DateFormat getFormat(String format, Locale locale) {
DateFormat dateFormat = null;
if (format.equals("SHORTDATE")) {
dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, locale);
}
if (format.equals("MEDIUMDATE")) {
dateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM, locale);
}
if (format.equals("LONGDATE")) {
dateFormat = DateFormat.getDateInstance(DateFormat.LONG, locale);
}
if (format.equals("FULLDATE")) {
dateFormat = DateFormat.getDateInstance(DateFormat.FULL, locale);
}
if (format.equals("SHORTTIME")) {
dateFormat = DateFormat.getTimeInstance(DateFormat.SHORT, locale);
}
if (format.equals("MEDIUMTIME")) {
dateFormat = DateFormat.getTimeInstance(DateFormat.MEDIUM, locale);
}
if (format.equals("LONGTIME")) {
dateFormat = DateFormat.getTimeInstance(DateFormat.LONG, locale);
}
if (format.equals("FULLTIME")) {
dateFormat = DateFormat.getTimeInstance(DateFormat.FULL, locale);
}
if (format.equals("SHORTDATESHORTTIME")) {
dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, locale);
}
if (format.equals("SHORTDATEMEDIUMTIME")) {
dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM, locale);
}
if (format.equals("SHORTDATELONGTIME")) {
dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.LONG, locale);
}
if (format.equals("SHORTDATEFULLTIME")) {
dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.FULL, locale);
}
if (format.equals("MEDIUMDATESHORTTIME")) {
dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT, locale);
}
if (format.equals("MEDIUMDATEMEDIUMTIME")) {
dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, locale);
}
if (format.equals("MEDIUMDATELONGTIME")) {
dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.LONG, locale);
}
if (format.equals("MEDIUMDATEFULLTIME")) {
dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.FULL, locale);
}
if (format.equals("LONGDATESHORTTIME")) {
dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT, locale);
}
if (format.equals("LONGDATEMEDIUMTIME")) {
dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.MEDIUM, locale);
}
if (format.equals("LONGDATELONGTIME")) {
dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
}
if (format.equals("LONGDATEFULLTIME")) {
dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.FULL, locale);
}
if (format.equals("FULLDATESHORTTIME")) {
dateFormat = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.SHORT, locale);
}
if (format.equals("FULLDATEMEDIUMTIME")) {
dateFormat = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.MEDIUM, locale);
}
if (format.equals("FULLDATELONGTIME")) {
dateFormat = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.LONG, locale);
}
if (format.equals("FULLDATEFULLTIME")) {
dateFormat = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, locale);
}
dateFormat.setLenient(false);
return dateFormat;
}
}