Class TimeProvider

java.lang.Object
org.apache.juneau.commons.time.TimeProvider

public class TimeProvider extends Object
Provides access to system time and timezone information.

This class abstracts time-related operations to allow for easier testing and customization. By default, it delegates to the system's time and timezone, but can be extended or replaced for testing purposes (e.g., using a custom implementation that provides fixed times).

Usage:

// Use the default instance ZoneId zone = TimeProvider.INSTANCE.getSystemDefaultZoneId(); ZonedDateTime now = TimeProvider.INSTANCE.now(); // Or create a custom implementation for testing TimeProvider testProvider = new FakeTimeProvider(); ZonedDateTime fixedTime = testProvider.now();

See Also:
  • Field Details

    • INSTANCE

      public static final TimeProvider INSTANCE
      The default instance that uses the system's time and timezone.
  • Constructor Details

  • Method Details

    • getSystemDefaultZoneId

      Returns the system default timezone.
      Returns:
      The system default ZoneId.
    • now

      public ZonedDateTime now()
      Returns the current date and time in the system default timezone.
      Returns:
      The current ZonedDateTime in the system default timezone.
    • now

      public ZonedDateTime now(ZoneId zoneId)
      Returns the current date and time in the specified timezone.
      Parameters:
      zoneId - The timezone to use. Must not be null.
      Returns:
      The current ZonedDateTime in the specified timezone.