Class TimeUtil

java.lang.Object
org.summerboot.jexpress.util.TimeUtil

public class TimeUtil extends Object
Author:
Changski Tie Zheng Zhang 张铁铮, 魏泽北, 杜旺财, 杜富贵
  • Field Details

    • ISO_ZONED_DATE_TIME3

      public static DateTimeFormatter ISO_ZONED_DATE_TIME3
    • ISO8601_OFFSET_DATE_TIME

      public static final DateTimeFormatter ISO8601_OFFSET_DATE_TIME
    • ISO8601_ZONED_DATE_TIME

      public static final DateTimeFormatter ISO8601_ZONED_DATE_TIME
    • UTC_DATE_TIME_FORMATTER

      public static DateTimeFormatter UTC_DATE_TIME_FORMATTER
    • ZONE_ID_ONTARIO

      public static ZoneId ZONE_ID_ONTARIO
    • RANDOM

      protected static Random RANDOM
    • MINUTES60

      protected static final BigDecimal MINUTES60
    • DAYS7

      protected static final BigDecimal DAYS7
  • Constructor Details

    • TimeUtil

      public TimeUtil()
  • Method Details

    • getSecondsSinceMidnight

      public static long getSecondsSinceMidnight(Calendar c)
    • getSecondsTillMidnight

      public static long getSecondsTillMidnight(Calendar c)
    • seconds2DHMS

      public static int[] seconds2DHMS(long totalSeconds)
    • seconds2DHMSString

      public static String seconds2DHMSString(long totalSeconds)
    • utcDateTimeToLocalDateTime

      public static String utcDateTimeToLocalDateTime(String utcTime, ZoneId zoneId)
      Maps the UTC time to an ET format.
      Parameters:
      utcTime - UTC time to be formatted.
      zoneId -
      Returns:
      ET formatted time.
    • toLocalDateTime

      public static LocalDateTime toLocalDateTime(long epochTs)
    • toLocalDateTime

      public static LocalDateTime toLocalDateTime(long epochTs, ZoneId zoneId)
    • toOffsetDateTime

      public static OffsetDateTime toOffsetDateTime(long epochTs, ZoneId zoneId)
    • toZonedDateTime

      public static ZonedDateTime toZonedDateTime(ZoneId zoneId, long epochSec, int days, int hourOfDay, int minuteOfHour, int secondOfMinute)
    • toOffsetDateTime

      public static OffsetDateTime toOffsetDateTime(LocalDate localDate, ZoneId zoneId)
    • toZonedDateTime

      public static ZonedDateTime toZonedDateTime(LocalDate localDate, ZoneId zoneId)
    • 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 retry
      truncatedMaxRetry - stop(truncate) exponential backoff when after truncatedMax retry
      Returns:
      the expected backoff slots
    • cronExpression4JobSkippedWhenDSTStarts

      public static String cronExpression4JobSkippedWhenDSTStarts(int hour, int minute)
      Use system default ZoneId Not working for Israel: Friday before last Sunday
      Parameters:
      hour -
      minute -
      Returns:
    • getZoneOffsetTransitionInfo

      public static TimeUtil.ZoneOffsetTransitionInfo getZoneOffsetTransitionInfo(ZoneId zoneId)
    • 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

      public static ZoneOffsetTransition[] getDSTChangeInfo(ZoneId zoneId, ZonedDateTime zdt)
      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

      public static void print(ZoneOffsetTransition transition)
    • toDurationHours

      public static int toDurationHours(long durationMinutes)
    • buildCronDSTDayOfWeekOption

      public static String buildCronDSTDayOfWeekOption(ZoneId zoneId, int dayOfWeek, int dayOfMonth)
      Not working for Israel: Friday before last Sunday
      Parameters:
      zoneId -
      dayOfWeek -
      dayOfMonth -
      Returns: