Skip to content

Add ZonedDateTimeStrategy for controlling ZonedDateTime generation ranges #65

Description

@MessiasLima

Description

The library currently generates ZonedDateTime values across the entire Instant range with a random ZoneId. This works for general fixtures, but tests often need values constrained to specific or realistic time windows, or pinned to a specific time zone. Add a ZonedDateTimeStrategy that lets users choose from predefined generation windows or supply their own exact min/max bounds and optional zone, while keeping the existing full-range behavior as the default.

Scope

  • In scope:
    • Create a new ZonedDateTimeStrategy sealed interface in dev.appoutlet.some.config.
    • Add the following variants:
      • Default — current behavior, spanning the full Instant range.
      • NearPast — from 10 years before now until now.
      • NearFuture — from now until 10 years after now.
      • DistantPast — from Instant.MIN until now.
      • DistantFuture — from now until Instant.MAX.
      • Range(val min: Instant, val max: Instant, val zoneId: ZoneId? = null) — user-defined bounds, where min <= generated instant <= max. If zoneId is null, a random available JVM ZoneId is used.
    • Update JavaZonedDateTimeResolver to read the active ZonedDateTimeStrategy and generate values within the selected window.
    • Register ZonedDateTimeStrategy.default in SomeConfig.defaultStrategies().
    • Add unit tests covering each strategy variant and the strategy registration path.
  • Out of scope:
    • Strategies for other date/time types such as Instant, LocalDateTime, or Kotlin kotlinx.datetime types.
    • Zone ID customization for variants other than Range.

Acceptance criteria

  • GIVEN no explicit ZonedDateTimeStrategy is configured, WHEN a ZonedDateTime value is generated, THEN it behaves like today (random instant between Instant.MIN and Instant.MAX, random ZoneId).
  • GIVEN ZonedDateTimeStrategy.NearPast is configured, WHEN a ZonedDateTime value is generated, THEN its instant falls between 10 years before now and now.
  • GIVEN ZonedDateTimeStrategy.NearFuture is configured, WHEN a ZonedDateTime value is generated, THEN its instant falls between now and 10 years after now.
  • GIVEN ZonedDateTimeStrategy.DistantPast is configured, WHEN a ZonedDateTime value is generated, THEN its instant falls between Instant.MIN and now.
  • GIVEN ZonedDateTimeStrategy.DistantFuture is configured, WHEN a ZonedDateTime value is generated, THEN its instant falls between now and Instant.MAX.
  • GIVEN ZonedDateTimeStrategy.Range(min, max) is configured with min <= max, WHEN a ZonedDateTime value is generated, THEN its instant falls between min and max (inclusive) and its ZoneId is random.
  • GIVEN ZonedDateTimeStrategy.Range(min, max, zoneId) is configured, WHEN a ZonedDateTime value is generated, THEN its ZoneId equals the supplied zoneId.
  • GIVEN ZonedDateTimeStrategy.Range(min, max) is configured with min > max, THEN construction fails with a clear error.
  • GIVEN the strategy is registered via someSetup { strategy(ZonedDateTimeStrategy.Range(min, max, zoneId)) }, WHEN a ZonedDateTime value is generated, THEN the configured range and zone are respected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    Status
    Ready

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions