Mercurial > stress-tester
changeset 561:d836ea2aefed
DateUtils
author | Devel 2 |
---|---|
date | Thu, 21 Sep 2017 15:18:34 +0200 |
parents | f373af509300 |
children | dcd36403d61d |
files | stress-tester/src/main/java/com/passus/st/utils/DateUtils.java |
diffstat | 1 files changed, 44 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/stress-tester/src/main/java/com/passus/st/utils/DateUtils.java Thu Sep 21 15:18:34 2017 +0200 @@ -0,0 +1,44 @@ +package com.passus.st.utils; + +import static com.passus.data.type.DateTimeType.TIME_FORMAT; +import com.passus.data.type.Type; +import org.joda.time.format.DateTimeFormat; +import org.joda.time.format.DateTimeFormatter; + +/** + * + * @author Mirosław Hawrot + */ +public class DateUtils { + + public static final String DATE_FORMAT = "YYYY-MM-dd"; + + public static final String DEFAULT_TIME_FORMAT = "HH:mm:ss"; + + public static final String DATETIME_FORMAT = DATE_FORMAT + " " + TIME_FORMAT; + + public static final DateTimeFormatter DEFAULT_TIME_FORMATTER = DateTimeFormat.forPattern(DEFAULT_TIME_FORMAT); + + public static final DateTimeFormatter DEFAULT_DATETIME_FORMATTER = DateTimeFormat.forPattern(DATETIME_FORMAT); + + private DateUtils() { + } + + public static String formatTime(Object obj) { + try { + return Type.DATETIME.convert(obj).toString(DEFAULT_TIME_FORMATTER); + } catch (Exception e) { + } + + return ""; + } + + public static String formatDateTime(Object obj) { + try { + return Type.DATETIME.convert(obj).toString(DEFAULT_DATETIME_FORMATTER); + } catch (Exception e) { + } + + return ""; + } +}