Class TimeUtils
java.lang.Object
de.iip_ecosphere.platform.support.TimeUtils
Test utilities.
- Author:
- Holger Eichelberger, SSE
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classAn abstract basic date converter.static interfacePlugin to extend the date time conversion. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Map<Class<?>, TimeUtils.DateConverter<?>> private static final Map<String, SimpleDateFormat> static final StringPre-defined known format for ISO8601. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static <T> DateconvertToDate(Class<T> cls, Object data) Uses one of the registered data converters to convertdata.static StringFormats a date object to a given format.static SimpleDateFormatgetDateFormatter(String format) Returns a (cached) simple date formatter.static DateParses a date from the givendatafor the specifiedformat.static voidregisterConverter(TimeUtils.DateConverter<?> converter) Registers an additional converter.static voidregisterFormat(String name, String pattern) Registers a default format forSimpleDateFormat.static voidsleep(int ms) Just sleeps for the given amount of milliseconds.static DatetoDate(LocalDateTime date) Converts aLocalDateTimevalue toDateusing instant and the system default time zone.static LocalDateTimetoLocalDateTime(Date date) Converts aDatevalue toLocalDateTimeusing instant and the system default time zone.static booleanA generic function that waits either until thetimeoutis reached or theendConditionreturnstrue.
-
Field Details
-
ISO8601_FORMAT
Pre-defined known format for ISO8601.- See Also:
-
DATE_FORMATTER
-
CONVERTERS
-
-
Constructor Details
-
TimeUtils
private TimeUtils()Preventing external creation.
-
-
Method Details
-
registerConverter
Registers an additional converter.- Parameters:
converter- the converter
-
registerFormat
Registers a default format forSimpleDateFormat.- Parameters:
name- the symbolic name of the formatpattern- the pattern format to apply- Throws:
IllegalArgumentException- ifpatternis illegal
-
format
Formats a date object to a given format.- Parameters:
data- the data/dateformat- the format, may be fromSimpleDateFormatorISO8601_FORMAT- Returns:
- if no format can be constructed
- Throws:
IOException- if formatting is not possible or the format is unknown
-
convertToDate
Uses one of the registered data converters to convertdata.- Type Parameters:
T- the type ofdata- Parameters:
cls- the type ofdatadata- the data (must not be null)- Returns:
- the converted instance, may be null if there is no conversion
-
parse
Parses a date from the givendatafor the specifiedformat.- Parameters:
data- the data (may be null, the the result will be null)format- the format may be fromSimpleDateFormatorISO8601_FORMAT- Returns:
- the parsed date
- Throws:
IOException- if parsing is not possible or the format is unknown
-
getDateFormatter
Returns a (cached) simple date formatter.- Parameters:
format- the format for the requested formatter for a string forSimpleDateFormat- Returns:
- the formatter instance
- Throws:
IOException- ifformatis not valid
-
toLocalDateTime
Converts aDatevalue toLocalDateTimeusing instant and the system default time zone.- Parameters:
date- the date to convert (may be null)- Returns:
- the converted date (may be null)
-
toDate
Converts aLocalDateTimevalue toDateusing instant and the system default time zone.- Parameters:
date- the date to convert (may be null)- Returns:
- the converted date (may be null)
-
sleep
public static void sleep(int ms) Just sleeps for the given amount of milliseconds.- Parameters:
ms- the milliseconds to wait for
-
waitFor
A generic function that waits either until thetimeoutis reached or theendConditionreturnstrue.- Parameters:
continueCondition- function that returnstruewhen waiting go on andfalsewhen waiting shall stoptimeoutMs- timeout from calling in ms, may be negative for endless waitingsleepMs- time between two trials oftimeoutMsandendCondition- Returns:
trueif thecontinueConditionstopped waiting,falseif the timeout caused the end of waiting
-