Package io.openems.common.utils
Class DateUtils
java.lang.Object
io.openems.common.utils.DateUtils
-
Field Summary
Modifier and TypeFieldDescriptionstatic final DateTimeFormatter
Day-Month-Year with dots separatedDateTimeFormatter
.static final DateTimeFormatter
DateTimeFormatter
with inclusively 24:00 which is converted to 00:00. -
Method Summary
Modifier and TypeMethodDescriptionstatic void
assertSameTimezone
(ZonedDateTime date1, ZonedDateTime date2) Asserts that both dates are in the same timezone.static LocalDate
parseLocalDateOrError
(String date) Parses a string to anLocalDate
or throws an error.static LocalDate
parseLocalDateOrError
(String date, DateTimeFormatter formatter) Parses a string to anLocalDate
or throws an error.static LocalDate
parseLocalDateOrNull
(String date) Parses a string to anLocalDate
or returns null.static LocalDate
parseLocalDateOrNull
(String date, DateTimeFormatter formatter) Parses a string to anLocalDate
or returns null.static LocalDateTime
parseLocalDateTimeOrError
(String dateTime) Parses a string to anLocalDateTime
or throws an error.static LocalDateTime
parseLocalDateTimeOrError
(String dateTime, DateTimeFormatter formatter) Parses a string to anLocalDateTime
or throws an error.static LocalDateTime
parseLocalDateTimeOrNull
(String dateTime) Parses a string to anLocalDateTime
or returns null.static LocalDateTime
parseLocalDateTimeOrNull
(String dateTime, DateTimeFormatter formatter) Parses a string to anLocalDateTime
or returns null.static LocalTime
parseLocalTimeOrError
(String time) Parses a string to anLocalTime
or throws an error.static LocalTime
parseLocalTimeOrError
(String time, DateTimeFormatter formatter) Parses a string to anLocalTime
or throws an error.static LocalTime
parseLocalTimeOrNull
(String time) Parses a string to anLocalTime
or returns null.static LocalTime
parseLocalTimeOrNull
(String time, DateTimeFormatter formatter) Parses a string to anLocalTime
or returns null.static ZonedDateTime
Parses a string to anZonedDateTime
or throws an error.static ZonedDateTime
parseZonedDateTimeOrError
(String date, DateTimeFormatter formatter) Parses a string to anZonedDateTime
or throws an error.static ZonedDateTime
Parses a string to anZonedDateTime
or returns null.static ZonedDateTime
parseZonedDateTimeOrNull
(String date, DateTimeFormatter formatter) Parses a string to anZonedDateTime
or returns null.static ZonedDateTime
roundDownToMinutes
(ZonedDateTime d, int minutes) Rounds aZonedDateTime
down to given minutes.static ZonedDateTime
Rounds aZonedDateTime
down to next quarter (15 minutes).
-
Field Details
-
DMY_FORMATTER
Day-Month-Year with dots separatedDateTimeFormatter
. -
TIME_FORMATTER
DateTimeFormatter
with inclusively 24:00 which is converted to 00:00.
-
-
Method Details
-
roundDownToMinutes
Rounds aZonedDateTime
down to given minutes.- Parameters:
d
- theZonedDateTime
minutes
- the minutes to round down to; max 59- Returns:
- the rounded result
-
roundDownToQuarter
Rounds aZonedDateTime
down to next quarter (15 minutes).- Parameters:
d
- theZonedDateTime
- Returns:
- the rounded result
-
assertSameTimezone
public static void assertSameTimezone(ZonedDateTime date1, ZonedDateTime date2) throws OpenemsException Asserts that both dates are in the same timezone.- Parameters:
date1
- the first Datedate2
- the second Date- Throws:
OpenemsException
- if dates are not in the same timezone
-
parseZonedDateTimeOrNull
Parses a string to anZonedDateTime
or returns null.- Parameters:
date
- the string value- Returns:
- a
ZonedDateTime
or null
-
parseZonedDateTimeOrNull
Parses a string to anZonedDateTime
or returns null.- Parameters:
date
- the string valueformatter
- the formatter to use, not null- Returns:
- a
ZonedDateTime
or null
-
parseZonedDateTimeOrError
Parses a string to anZonedDateTime
or throws an error.- Parameters:
date
- the string value- Returns:
- a
ZonedDateTime
- Throws:
OpenemsException
- on error
-
parseZonedDateTimeOrError
public static ZonedDateTime parseZonedDateTimeOrError(String date, DateTimeFormatter formatter) throws OpenemsException Parses a string to anZonedDateTime
or throws an error.- Parameters:
date
- the string valueformatter
- the formatter to use, not null- Returns:
- a
ZonedDateTime
- Throws:
OpenemsException
- on error
-
parseLocalDateOrNull
Parses a string to anLocalDate
or returns null.- Parameters:
date
- the string value- Returns:
- a
LocalDate
or null
-
parseLocalDateOrNull
Parses a string to anLocalDate
or returns null.- Parameters:
date
- the string valueformatter
- the formatter to use, not null- Returns:
- a
LocalDate
or null
-
parseLocalDateOrError
Parses a string to anLocalDate
or throws an error.- Parameters:
date
- the string value- Returns:
- a
LocalDate
- Throws:
OpenemsException
- on error
-
parseLocalDateOrError
public static LocalDate parseLocalDateOrError(String date, DateTimeFormatter formatter) throws OpenemsException Parses a string to anLocalDate
or throws an error.- Parameters:
date
- the string valueformatter
- the formatter to use, not null- Returns:
- a
LocalDate
- Throws:
OpenemsException
- on error
-
parseLocalDateTimeOrNull
Parses a string to anLocalDateTime
or returns null.- Parameters:
dateTime
- date the string value- Returns:
- a
LocalDateTime
or null
-
parseLocalDateTimeOrNull
Parses a string to anLocalDateTime
or returns null.- Parameters:
dateTime
- date the string valueformatter
- the formatter to use, not null- Returns:
- a
LocalDateTime
or null
-
parseLocalDateTimeOrError
Parses a string to anLocalDateTime
or throws an error.- Parameters:
dateTime
- date the string value- Returns:
- a
LocalDateTime
- Throws:
OpenemsException
- on error
-
parseLocalDateTimeOrError
public static LocalDateTime parseLocalDateTimeOrError(String dateTime, DateTimeFormatter formatter) throws OpenemsException Parses a string to anLocalDateTime
or throws an error.- Parameters:
dateTime
- date the string valueformatter
- the formatter to use, not null- Returns:
- a
LocalDateTime
- Throws:
OpenemsException
- on error
-
parseLocalTimeOrNull
Parses a string to anLocalTime
or returns null.- Parameters:
time
- the string value- Returns:
- a
LocalTime
or null
-
parseLocalTimeOrNull
Parses a string to anLocalTime
or returns null.- Parameters:
time
- the string valueformatter
- the formatter to use, not null- Returns:
- a
LocalTime
or null
-
parseLocalTimeOrError
Parses a string to anLocalTime
or throws an error.- Parameters:
time
- the string value- Returns:
- a
LocalTime
- Throws:
OpenemsException
- on error
-
parseLocalTimeOrError
public static LocalTime parseLocalTimeOrError(String time, DateTimeFormatter formatter) throws OpenemsException Parses a string to anLocalTime
or throws an error.- Parameters:
time
- the string valueformatter
- the formatter to use, not null- Returns:
- a
LocalTime
- Throws:
OpenemsException
- on error
-