Package com.helixframework.time.provider
Class DateTimeProvider
java.lang.Object
com.helixframework.time.provider.DateTimeProvider
Mockable provider of date and time information.
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a DateTimeProvider with the system UTC clock.DateTimeProvider(Clock clock) Constructs a DateTimeProvider with the specified clock.DateTimeProvider(ZoneId zoneId) Constructs a DateTimeProvider with the system clock for the given zone. -
Method Summary
Modifier and TypeMethodDescriptiongetClock()Exposes the underlying clock used by this provider.Gets the current date.longGets the current epoch millisecond.longGets the current epoch second.Get current instant.Gets the current local date in the provider's zone.Gets the current local date-time in the provider's zone.Gets the current date-time and offset in the provider's zone.Gets the current time and offset in the provider's zone.Gets the current date-time in the provider's timezone.getCurrentZonedDateTime(ZoneId zoneId) Gets the current date and time in the specified timezone.Gets the current date and time in UTC.getZone()Returns the provider's zone.Creates a newDateTimeProviderthat applies a ticking behavior to the underlying clock.withFixedInstant(Instant instant) Creates a newDateTimeProviderusing a fixed instant.withOffset(Duration offset) Creates a newDateTimeProviderwith the specified offset applied to the underlying clock.Creates a newDateTimeProviderusing the specified time zone.
-
Constructor Details
-
DateTimeProvider
public DateTimeProvider()Constructs a DateTimeProvider with the system UTC clock. -
DateTimeProvider
Constructs a DateTimeProvider with the specified clock.- Parameters:
clock- clock to use
-
DateTimeProvider
Constructs a DateTimeProvider with the system clock for the given zone.- Parameters:
zoneId- zone to use
-
-
Method Details
-
getClock
Exposes the underlying clock used by this provider.- Returns:
- the clock
-
getZone
Returns the provider's zone.- Returns:
- zoneId of the underlying clock
-
getCurrentDate
Gets the current date.- Returns:
- current date
-
getCurrentLocalDate
Gets the current local date in the provider's zone.- Returns:
- current local date
-
getCurrentLocalDateTime
Gets the current local date-time in the provider's zone.- Returns:
- current local date-time
-
getCurrentOffsetTime
Gets the current time and offset in the provider's zone.- Returns:
- current time with offset
-
getCurrentOffsetDateTime
Gets the current date-time and offset in the provider's zone.- Returns:
- current offset date-time
-
getCurrentZonedDateTime
Gets the current date-time in the provider's timezone.- Returns:
- current zoned date-time
-
getCurrentZonedDateTime
Gets the current date and time in the specified timezone.- Parameters:
zoneId- timezone- Returns:
- current date and time in a specified timezone
-
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
Get current instant.- Returns:
- current instant
-
withZone
Creates a newDateTimeProviderusing the specified time zone. This method configures the provider to use the givenZoneId, 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
DateTimeProviderinstance with the specified time zone
-
withFixedInstant
Creates a newDateTimeProviderusing a fixed instant. This method configures the provider to use a staticInstant, 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
DateTimeProviderinstance with the specified fixed instant
-
withOffset
Creates a newDateTimeProviderwith 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
DateTimeProviderinstance with the specified offset applied
-
tick
Creates a newDateTimeProviderthat 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
DateTimeProviderconfigured with a tick-adjusted clock
-