Class DateTimeProvider

java.lang.Object
com.helixframework.time.provider.DateTimeProvider

public final class DateTimeProvider extends Object
Mockable provider of date and time information.
  • Constructor Details

    • DateTimeProvider

      public DateTimeProvider()
      Constructs a DateTimeProvider with the system UTC clock.
    • DateTimeProvider

      public DateTimeProvider(Clock clock)
      Constructs a DateTimeProvider with the specified clock.
      Parameters:
      clock - clock to use
    • DateTimeProvider

      public DateTimeProvider(ZoneId zoneId)
      Constructs a DateTimeProvider with the system clock for the given zone.
      Parameters:
      zoneId - zone to use
  • Method Details

    • getClock

      public Clock getClock()
      Exposes the underlying clock used by this provider.
      Returns:
      the clock
    • getZone

      public ZoneId getZone()
      Returns the provider's zone.
      Returns:
      zoneId of the underlying clock
    • getCurrentDate

      public Date getCurrentDate()
      Gets the current date.
      Returns:
      current date
    • getCurrentLocalDate

      public LocalDate getCurrentLocalDate()
      Gets the current local date in the provider's zone.
      Returns:
      current local date
    • getCurrentLocalDateTime

      public LocalDateTime getCurrentLocalDateTime()
      Gets the current local date-time in the provider's zone.
      Returns:
      current local date-time
    • getCurrentOffsetTime

      public OffsetTime getCurrentOffsetTime()
      Gets the current time and offset in the provider's zone.
      Returns:
      current time with offset
    • getCurrentOffsetDateTime

      public OffsetDateTime getCurrentOffsetDateTime()
      Gets the current date-time and offset in the provider's zone.
      Returns:
      current offset date-time
    • getCurrentZonedDateTime

      public ZonedDateTime getCurrentZonedDateTime()
      Gets the current date-time in the provider's timezone.
      Returns:
      current zoned date-time
    • getCurrentZonedDateTime

      public ZonedDateTime getCurrentZonedDateTime(ZoneId zoneId)
      Gets the current date and time in the specified timezone.
      Parameters:
      zoneId - timezone
      Returns:
      current date and time in a specified timezone
    • getCurrentZonedDateTimeUTC

      public ZonedDateTime getCurrentZonedDateTimeUTC()
      Gets the current date and time in UTC.
      Returns:
      current date and time in UTC
    • getCurrentEpochSecond

      public long getCurrentEpochSecond()
      Gets the current epoch second.
      Returns:
      epoch second
    • getCurrentEpochMillisecond

      public long getCurrentEpochMillisecond()
      Gets the current epoch millisecond.
      Returns:
      epoch millisecond
    • getCurrentInstant

      public Instant getCurrentInstant()
      Get current instant.
      Returns:
      current instant
    • withZone

      public DateTimeProvider withZone(ZoneId zoneId)
      Creates a new DateTimeProvider using the specified time zone. This method configures the provider to use the given ZoneId, altering the underlying clock to operate within the specified time zone.
      Parameters:
      zoneId - the time zone to use, must not be null
      Returns:
      a new DateTimeProvider instance with the specified time zone
    • withFixedInstant

      public DateTimeProvider withFixedInstant(Instant instant)
      Creates a new DateTimeProvider using a fixed instant. This method configures the provider to use a static Instant, effectively freezing the time to the specified instant while retaining the current zone of the underlying clock.
      Parameters:
      instant - the fixed instant to use, must not be null
      Returns:
      a new DateTimeProvider instance with the specified fixed instant
    • withOffset

      public DateTimeProvider withOffset(Duration offset)
      Creates a new DateTimeProvider with the specified offset applied to the underlying clock. The offset adjusts the current time of the clock by the given duration.
      Parameters:
      offset - the duration to offset the clock, must not be null
      Returns:
      a new DateTimeProvider instance with the specified offset applied
    • tick

      public DateTimeProvider tick(Duration tick)
      Creates a new DateTimeProvider that applies a ticking behavior to the underlying clock. The ticking behavior rounds the clock to the specified duration, effectively adjusting the clock to tick at fixed intervals defined by the duration.
      Parameters:
      tick - the duration to define the ticking interval, must not be null
      Returns:
      a new DateTimeProvider configured with a tick-adjusted clock