Package org.summerboot.jexpress.util
Class TimeUtil
java.lang.Object
org.summerboot.jexpress.util.TimeUtil
- Author:
- Changski Tie Zheng Zhang 张铁铮, 魏泽北, 杜旺财, 杜富贵
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic class -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final BigDecimalstatic DateTimeFormatterstatic final DateTimeFormatterstatic final DateTimeFormatterprotected static final BigDecimalprotected static Randomstatic DateTimeFormatterstatic ZoneId -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringbuildCronDSTDayOfWeekOption(ZoneId zoneId, int dayOfWeek, int dayOfMonth) Not working for Israel: Friday before last Sundaystatic StringcronExpression4JobSkippedWhenDSTStarts(int hour, int minute) Use system default ZoneId Not working for Israel: Friday before last Sundaystatic StringgetAnnualCompensationForDSTGapCronExpression(ZoneId zoneId, int hour, int minute) Use user specified ZoneId.static ZoneOffsetTransition[]getDSTChangeInfo(ZoneId zoneId, ZonedDateTime zdt) static longstatic longgetZoneOffsetTransitionInfo(ZoneId zoneId) static voidprint(ZoneOffsetTransition transition) static intrandom(int low, int high) static int[]seconds2DHMS(long totalSeconds) static Stringseconds2DHMSString(long totalSeconds) static inttoDurationHours(long durationMinutes) static LocalDateTimetoLocalDateTime(long epochTs) static LocalDateTimetoLocalDateTime(long epochTs, ZoneId zoneId) static OffsetDateTimetoOffsetDateTime(long epochTs, ZoneId zoneId) static OffsetDateTimetoOffsetDateTime(LocalDate localDate, ZoneId zoneId) static ZonedDateTimetoZonedDateTime(LocalDate localDate, ZoneId zoneId) static ZonedDateTimetoZonedDateTime(ZoneId zoneId, long epochSec, int days, int hourOfDay, int minuteOfHour, int secondOfMinute) static doubletruncatedExponentialBackoffSlots(int retry, int truncatedMaxRetry) expected backoff time = random value between (2^n - 1)/2 and (2^n - 1), n should be truncated by max retry.static StringutcDateTimeToLocalDateTime(String utcTime, ZoneId zoneId) Maps the UTC time to an ET format.
-
Field Details
-
ISO_ZONED_DATE_TIME3
-
ISO8601_OFFSET_DATE_TIME
-
ISO8601_ZONED_DATE_TIME
-
UTC_DATE_TIME_FORMATTER
-
ZONE_ID_ONTARIO
-
RANDOM
-
MINUTES60
-
DAYS7
-
-
Constructor Details
-
TimeUtil
public TimeUtil()
-
-
Method Details
-
getSecondsSinceMidnight
-
getSecondsTillMidnight
-
seconds2DHMS
public static int[] seconds2DHMS(long totalSeconds) -
seconds2DHMSString
-
utcDateTimeToLocalDateTime
Maps the UTC time to an ET format.- Parameters:
utcTime- UTC time to be formatted.zoneId-- Returns:
- ET formatted time.
-
toLocalDateTime
-
toLocalDateTime
-
toOffsetDateTime
-
toZonedDateTime
public static ZonedDateTime toZonedDateTime(ZoneId zoneId, long epochSec, int days, int hourOfDay, int minuteOfHour, int secondOfMinute) -
toOffsetDateTime
-
toZonedDateTime
-
random
public static int random(int low, int high) -
truncatedExponentialBackoffSlots
public static double truncatedExponentialBackoffSlots(int retry, int truncatedMaxRetry) expected backoff time = random value between (2^n - 1)/2 and (2^n - 1), n should be truncated by max retry. For the example, E(3) = 3.5 slots, the expected backoff slots should between 3 ~ 7 slots- Parameters:
retry- the (n)th retrytruncatedMaxRetry- stop(truncate) exponential backoff when after truncatedMax retry- Returns:
- the expected backoff slots
-
cronExpression4JobSkippedWhenDSTStarts
Use system default ZoneId Not working for Israel: Friday before last Sunday- Parameters:
hour-minute-- Returns:
-
getZoneOffsetTransitionInfo
-
getAnnualCompensationForDSTGapCronExpression
public static String getAnnualCompensationForDSTGapCronExpression(ZoneId zoneId, int hour, int minute) Use user specified ZoneId.Warning: Not working for Israel: due to Friday before last Sunday in March is not supported by cron syntax yet,
work-around: schedule your job every Friday in March and have some in-job logic to check whether it is actually the second-to-last before going on.
- Parameters:
zoneId-hour-minute-- Returns:
-
getDSTChangeInfo
- Parameters:
zoneId-zdt-- Returns:
- Two elements: array[0] is DST starting info or null if DST is not applied, array[1] is DST ending info or null if DST is not applied
-
print
-
toDurationHours
public static int toDurationHours(long durationMinutes) -
buildCronDSTDayOfWeekOption
Not working for Israel: Friday before last Sunday- Parameters:
zoneId-dayOfWeek-dayOfMonth-- Returns:
-