Kotlin / Reusable behavior and typed boundaries / Lesson 14
JVM instants, offsets, and durations
Compare Kotlin/JVM java.time instants, offsets, and elapsed durations.
On this page
Lesson goals
- Compare instants with explicit offsets.
- Test duration and local-time boundaries.
- Compare fixed offset date-times by their represented instants.
- Separate elapsed durations from local calendar schedules and transition policies.
Define the time contract
An instant, a local calendar time, and an elapsed duration answer different questions. On the JVM, java.time provides types for these distinctions. Specify the intended input format and time zone at the API boundary. A numeric offset can identify an instant when paired with a local time, but it does not contain the future transition rules of a named time zone.
Compare instants
Two offset date-times with different clock readings can identify the same instant. The example parses fixed values and compares their Instant representations, avoiding the machine’s current clock and local zone. Converting to an instant supports consistent comparison, but a recurring local appointment may also need its named zone and an explicit policy for ambiguous or invalid local times.
import java.time.OffsetDateTime
fun main() {
val a = OffsetDateTime.parse("2026-01-01T12:00:00+02:00")
val b = OffsetDateTime.parse("2026-01-01T10:00:00Z")
println(a.toInstant() == b.toInstant())
}
true
Both values identify the same instant.
Measure elapsed time
Duration measures an amount of elapsed time between instants. The second example calculates a fixed one-hour interval and prints sixty minutes. A local calendar day can differ from a fixed 24-hour duration near a clock transition, so model a calendar rule separately. State the units of numeric input and output, and do not infer scheduling intent from a duration alone.
import java.time.Duration
import java.time.Instant
fun main() {
val start = Instant.parse("2026-01-01T10:00:00Z")
val end = Instant.parse("2026-01-01T11:00:00Z")
println(Duration.between(start, end).toMinutes())
}
60
The fixed interval is sixty minutes.
Interpret local time
Parsing external dates requires a format, error policy, and zone interpretation. A local date-time without a zone may be ambiguous or invalid at a transition; reject or resolve it according to documented requirements. Avoid relying on the server’s default time zone for machine-readable records. Handle parsing errors at the boundary and validate application-specific date ranges separately.
Test time boundaries
Test equivalent instants with different offsets, a duration boundary, malformed input, and supported transition cases. Use fixed values or an injected clock rather than waiting for real time. Verify the stored instant and displayed local value when both are part of the contract. A passing UTC-only example does not establish correct recurring local scheduling.
Choose the temporal question first
An Instant identifies a point on the UTC time-line; an OffsetDateTime combines a local date and time with a numeric offset, and can be converted to an instant. A LocalDateTime contains calendar fields without an offset or zone and cannot by itself identify a unique instant. Duration represents an amount of time, not a calendar appointment or a named zone. Pick the type from the question: compare event occurrence using instants, preserve an explicit offset when it is part of an input contract, and use a local date-time plus zone and resolution policy for a human schedule.
Specify parsing format, precision, units and invalid-input behavior at the boundary. A string with Z denotes a UTC offset; a string with +02:00 provides a different offset, not a time-zone region with transition rules. Avoid machine-default zones in machine-readable records because deployment environments can differ. The java.time APIs described here are Java platform APIs used by Kotlin/JVM. They do not establish behavior on Kotlin targets that lack those APIs, and the illustrative snippets are reasoned rather than executed.
Normalize before comparing occurrence
For an offset date-time, subtracting a positive offset from the local clock reading gives the corresponding UTC reading. Thus 12:00 at +02:00 and 10:00 at Z on the same stated date identify the same instant. A negative offset moves the UTC reading in the opposite direction, and the calculation can cross a date boundary. Convert using the API rather than hand-adjusting production timestamps; the hand calculation is a useful independent check for a fixed example.
Compare the property the domain actually cares about. OffsetDateTime equality includes its local date-time and offset, so two differently represented values may not be equal even when they identify the same instant. Comparing their toInstant values or using the appropriate instant-based comparison answers the occurrence question. A local display may still need to retain the original offset or named zone, so normalization need not mean discarding that presentation information. Specify whether an identity key represents an instant or the full offset representation before storing or deduplicating events.
Distinguish elapsed duration from calendar rules
Duration.between(start, end) expresses the elapsed amount from start to end. If end precedes start, the duration is negative; decide whether the application accepts reverse intervals or reports invalid ordering. Fixed examples make the arithmetic reviewable: 10:00Z to 11:00Z is 60 minutes, while equal endpoints give zero. Conversion methods return the documented unit representation, so a whole-minute value can discard a partial minute; do not claim that 61 seconds is exactly one minute merely because a whole-minute conversion returns 1. State whether rounding, truncation or a remainder is required.
A calendar day in a named zone is not always the same as adding a fixed 24-hour duration to an instant. A transition can change the offset between two local midnights, changing elapsed time. For an appointment at the same local time tomorrow, use the calendar and zone rules appropriate to the contract; for a timeout lasting 24 elapsed hours, use a duration. Neither choice is automatically correct for all domains. Test the exact rule with known zone data and retain the applicable time-zone database and runtime context when results matter.
Handle gaps and overlaps by policy
A numeric offset such as +01:00 describes one offset from UTC, but it does not encode a region’s future or historical transition rules. A ZoneId identifies a rule set supplied by the runtime’s time-zone data. When mapping a local date-time through zone rules, an ordinary time usually has one valid offset; a spring-forward gap has no valid offset, and a fall-back overlap commonly has two. The application must decide whether to reject, shift, or choose an offset in those exceptional cases. Library convenience methods can have default resolution behavior, so inspect the specific method rather than assuming it matches the product policy.
For a recurring appointment, retain the local schedule, named zone and gap/overlap policy rather than treating one observed numeric offset as a permanent zone rule. Time-zone databases can be updated, and the same future local schedule may need reevaluation after a rule change. Record the runtime and zone-data context when reproducibility matters. A fixed-offset example demonstrates arithmetic but does not prove behavior for a real region or date. Use actual documented zone rules and controlled tests before making a claim about a particular transition.
Test parsing, boundaries and both representations
A practical test matrix covers equivalent instants with different offsets, an earlier and a later instant, zero and negative durations, a non-whole-minute interval, malformed text, and the exact deadline boundary. Separate a parse error from a parsed date that violates a business range. For local scheduling, test ordinary, gap and overlap inputs against a named zone with a stated policy, and verify both the resolved instant and displayed local value. A synthetic transition trace can teach the decision without claiming that a particular real zone changed on an invented date.
Inject Clock.fixed or fixed values into a JVM test instead of waiting for real time; read one clock snapshot when an operation needs an internally consistent decision. A fake clock does not prove the operating-system clock’s accuracy, network synchronization or production zone-data deployment. Preserve input offset, zone, precision and policy as required by the domain, and avoid logging sensitive event data. The snippets here are unexecuted illustrations: compile complete isolated programs with the declared Kotlin, Java and time-zone data environment before reporting observed results. Structural validation is not a time-zone or runtime test.
20 worked examples
1. Parse a fixed instant
Problem: What UTC point does this string represent?
- The Z suffix states the UTC offset.
- Instant.parse constructs the fixed point at 10:00 UTC on the given date.
val instant = Instant.parse("2026-02-01T10:00:00Z")
println(instant)
This illustration assumes the stated imports and context and was not executed; synthetic transition rules are not a real zone.
Expected result: 2026-02-01T10:00:00Z
Why this result follows: The input contains an explicit UTC representation.
2. Normalize a positive offset
Problem: What instant corresponds to 12:00 at +02:00?
- The local reading is two hours ahead of UTC.
- Subtracting two hours gives 10:00Z on the same date.
val value = OffsetDateTime.parse("2026-02-01T12:00:00+02:00")
println(value.toInstant())
This illustration assumes the stated imports and context and was not executed; synthetic transition rules are not a real zone.
Expected result: 2026-02-01T10:00:00Z
Why this result follows: toInstant expresses the same occurrence on the UTC time-line.
3. Normalize a negative offset
Problem: What instant corresponds to 08:00 at -02:00?
- The local reading is two hours behind UTC.
- Adding two hours gives 10:00Z on the same date.
val value = OffsetDateTime.parse("2026-02-01T08:00:00-02:00")
println(value.toInstant())
This illustration assumes the stated imports and context and was not executed; synthetic transition rules are not a real zone.
Expected result: 2026-02-01T10:00:00Z
Why this result follows: The offset sign determines the direction of normalization.
4. Equivalent representations
Problem: Do these offset values identify the same instant?
- The first value normalizes to 10:00Z.
- The second already represents 10:00Z on the same date.
val a = OffsetDateTime.parse("2026-02-01T12:00:00+02:00")
val b = OffsetDateTime.parse("2026-02-01T10:00:00Z")
println(a.toInstant() == b.toInstant())
This illustration assumes the stated imports and context and was not executed; synthetic transition rules are not a real zone.
Expected result: true
Why this result follows: Different local representations can denote one occurrence.
5. Earlier instant
Problem: Is a earlier than b on the UTC time-line?
- Both values use the same date and UTC representation.
- 09:59 occurs one minute before 10:00.
val a = Instant.parse("2026-02-01T09:59:00Z")
val b = Instant.parse("2026-02-01T10:00:00Z")
println(a.isBefore(b))
This illustration assumes the stated imports and context and was not executed; synthetic transition rules are not a real zone.
Expected result: true
Why this result follows: Instant comparison orders occurrences rather than local display strings.
6. Representation equality versus instant
Problem: How do equality and isEqual differ for these values?
- Their local fields and offsets differ, so OffsetDateTime equality is false.
- They identify the same instant, so isEqual is true.
val a = OffsetDateTime.parse("2026-02-01T12:00:00+02:00")
val b = OffsetDateTime.parse("2026-02-01T10:00:00Z")
println(a == b)
println(a.isEqual(b))
This illustration assumes the stated imports and context and was not executed; synthetic transition rules are not a real zone.
Expected result: false true
Why this result follows: The comparison must match whether representation or occurrence matters.
7. Positive elapsed duration
Problem: How many whole minutes separate these fixed instants?
- The end is thirty minutes after the start.
- Duration.between therefore represents a positive thirty-minute interval.
val start = Instant.parse("2026-02-01T10:00:00Z")
val end = Instant.parse("2026-02-01T10:30:00Z")
println(Duration.between(start, end).toMinutes())
This illustration assumes the stated imports and context and was not executed; synthetic transition rules are not a real zone.
Expected result: 30
Why this result follows: Duration measures the elapsed amount in the stated order.
8. Equal endpoints
Problem: What duration results when both endpoints are identical?
- Start and end are the same instant.
- The elapsed amount between them is zero.
val point = Instant.parse("2026-02-01T10:00:00Z")
println(Duration.between(point, point).isZero)
This illustration assumes the stated imports and context and was not executed; synthetic transition rules are not a real zone.
Expected result: true
Why this result follows: Equal instants give a zero duration.
9. Reverse interval
Problem: What is the signed duration when the end precedes the start?
- The end is thirty minutes before the start.
- The duration from start to end is negative thirty minutes.
val start = Instant.parse("2026-02-01T10:30:00Z")
val end = Instant.parse("2026-02-01T10:00:00Z")
println(Duration.between(start, end).toMinutes())
This illustration assumes the stated imports and context and was not executed; synthetic transition rules are not a real zone.
Expected result: -30
Why this result follows: Argument order determines the sign of the elapsed duration.
10. Whole-minute conversion
Problem: What does toMinutes report for a positive 61-second duration?
- The interval contains one whole minute and one additional second.
- toMinutes returns the whole-minute amount, 1.
val duration = Duration.ofSeconds(61)
println(duration.toMinutes())
This illustration assumes the stated imports and context and was not executed; synthetic transition rules are not a real zone.
Expected result: 1
Why this result follows: The returned integer does not mean the interval was exactly sixty seconds.
11. Add elapsed time
Problem: What instant is fifteen minutes after the fixed start?
- The fixed starting instant is 10:00Z on the stated date.
- Adding a fifteen-minute duration produces 10:15Z.
val start = Instant.parse("2026-02-01T10:00:00Z")
println(start.plus(Duration.ofMinutes(15)))
This illustration assumes the stated imports and context and was not executed; synthetic transition rules are not a real zone.
Expected result: 2026-02-01T10:15:00Z
Why this result follows: A duration advances this instant by the specified elapsed amount.
12. Local time lacks an instant
Problem: Can this local value alone identify one UTC instant?
- The value contains local date and clock fields.
- It has no offset or zone policy from which to resolve a unique instant.
val local = LocalDateTime.parse("2026-02-01T10:00:00")
// no offset or zone supplied
This illustration assumes the stated imports and context and was not executed; synthetic transition rules are not a real zone.
Expected result: instant not determined
Why this result follows: A local date-time is not a complete instant without additional context.
13. Offset is not zone rules
Problem: Does this fixed offset describe future regional transitions?
- The numeric offset states one difference from UTC.
- The fixture supplies no named region or transition rules.
fixed offset = +01:00
recurring event = 09:00 local each week
regional transition rules = not supplied
This illustration assumes the stated imports and context and was not executed; synthetic transition rules are not a real zone.
Expected result: future regional behavior not established
Why this result follows: A recurring local schedule needs a zone and a resolution policy.
14. Gap policy
Problem: What does the stated policy do when no offset is valid?
- The fixture identifies a local time in a synthetic gap.
- The explicit policy rejects rather than inventing an offset.
synthetic local time = 02:30
valid offsets from fixture rules = []
policy = reject
This illustration assumes the stated imports and context and was not executed; synthetic transition rules are not a real zone.
Expected result: rejected gap time
Why this result follows: A gap resolution must follow the application’s documented rule.
15. Overlap policy
Problem: What does the stated policy require for two valid offsets?
- The fixture supplies two possible offsets for one local reading.
- The application requires a choice before resolving an instant.
synthetic local time = 01:30
valid offsets from fixture rules = [+02:00, +01:00]
policy = require explicit choice
This illustration assumes the stated imports and context and was not executed; synthetic transition rules are not a real zone.
Expected result: offset choice required
Why this result follows: An overlap needs a deliberate rule rather than an assumed unique mapping.
16. Ordinary local resolution
Problem: What happens when the fixture provides one valid offset?
- The local reading has exactly one valid offset in this synthetic rule set.
- The policy accepts that offset for resolution.
synthetic local time = 09:00
valid offsets from fixture rules = [+01:00]
policy = accept unique offset
This illustration assumes the stated imports and context and was not executed; synthetic transition rules are not a real zone.
Expected result: unique offset accepted
Why this result follows: Ordinary and exceptional zone cases can follow different policy branches.
17. Malformed instant text
Problem: What happens when this invalid string is parsed as an Instant?
- The string does not match the expected instant format.
- Instant.parse throws DateTimeParseException.
Instant.parse("not-a-time")
This illustration assumes the stated imports and context and was not executed; synthetic transition rules are not a real zone.
Expected result: DateTimeParseException
Why this result follows: Parsing failure is separate from a business-date validation failure.
18. Fixed clock
Problem: What instant does this fixed clock supply?
- Clock.fixed is configured with the stated instant.
- Instant.now reads that fixed value from the supplied clock.
val fixed = Clock.fixed(Instant.parse("2026-02-01T10:00:00Z"), ZoneOffset.UTC)
println(Instant.now(fixed))
This illustration assumes the stated imports and context and was not executed; synthetic transition rules are not a real zone.
Expected result: 2026-02-01T10:00:00Z
Why this result follows: An injected fixed clock makes this test input independent of wall time.
19. Display with an offset
Problem: What local clock time is shown at +02:00?
- The instant is 10:00 at UTC.
- Applying an offset two hours ahead displays 12:00.
val instant = Instant.parse("2026-02-01T10:00:00Z")
val shown = instant.atOffset(ZoneOffset.ofHours(2))
println(shown.toLocalTime())
This illustration assumes the stated imports and context and was not executed; synthetic transition rules are not a real zone.
Expected result: 12:00
Why this result follows: Changing the representation does not change the underlying instant.
20. Calendar day versus duration
Problem: How much elapsed time separates these synthetic local midnights?
- The offset increases by one hour during the local calendar day.
- The UTC interval between the midnights is therefore 23 hours in this fixture.
synthetic zone: offset changes from +01:00 to +02:00 between local midnights
local day: midnight to next midnight
This illustration assumes the stated imports and context and was not executed; synthetic transition rules are not a real zone.
Expected result: 23 elapsed hours
Why this result follows: A local day can differ from a fixed 24-hour duration.
Common errors and fixes
Equivalent instants appear different
- Why it happens
- Their clock readings use different offsets.
- How to fix it
- Compare their Instant values.
- Prevent it next time
- Record offsets explicitly.
A recurring appointment shifts
- Why it happens
- A fixed offset was treated as a zone rule.
- How to fix it
- Use a named zone and transition policy.
- Prevent it next time
- Test local transition cases.
A test depends on current time
- Why it happens
- The clock was read directly.
- How to fix it
- Use fixed values or an injected clock.
- Prevent it next time
- Control time in tests.
20 practice exercises
1. Are 12:00 at +02:00 and 10:00 at UTC the same instant?
Show hint
Normalize the positive offset to UTC before comparing.
Show worked solution
Yes. The first reading corresponds to 10:00 UTC, matching the second.
Subtract two hours from the same-date local reading 12:00+02:00 to obtain 10:00Z. The second value is already 10:00Z, so their Instant representations compare equal even though their offset representations differ.
Check your solution
- Both normalize to 10:00Z on the stated date.
- The comparison is about the instant, not identical offset representation.
2. Why is a fixed offset insufficient for a recurring local appointment?
Show hint
Separate one offset from a region’s rules over time.
Show worked solution
A region can change offsets over time, so the schedule needs a named zone and transition policy.
A fixed offset tells the UTC difference for a representation but does not carry a region’s future transitions. Preserve the local recurrence and named zone, then define how gaps and overlaps are resolved and test those cases using the applicable zone data.
Check your solution
- A named zone is part of the recurring schedule contract.
- Gap and overlap handling is explicit.
3. Three events on the same date are 11:00+02:00, 09:30Z and 07:00-03:00. Normalize and order them by instant.
Show hint
Convert each offset reading to UTC before comparing.
Show worked solution
The events correspond to 09:00Z, 09:30Z and 10:00Z respectively. Their given order is therefore earliest to latest; compare Instant values in code rather than ordering the raw local clock strings.
Check your solution
- The normalized times are 09:00Z, 09:30Z and 10:00Z.
- The first event is earliest and the third is latest.
4. A deduplication key uses OffsetDateTime equality, but the contract considers 12:00+02:00 and 10:00Z the same occurrence. Diagnose and redesign the key.
Show hint
Representation equality and instant equality answer different questions.
Show worked solution
OffsetDateTime equality distinguishes the local fields and offsets, so these representations can become separate keys. Normalize to Instant for an occurrence-based key, while retaining original display information separately if the domain requires it.
Check your solution
- Both representations map to one Instant key.
- The original offset is retained separately when required.
5. An event is recorded at 2026-02-01 00:30+02:00. Determine its UTC date and time and explain why comparing dates alone is unsafe.
Show hint
Subtract the positive offset and account for the date boundary.
Show worked solution
The instant is 2026-01-31 22:30Z, on the previous UTC date. A local calendar date and a UTC date can differ for the same event, so compare the intended instant or explicitly specified calendar context.
Check your solution
- The UTC result is 2026-01-31 22:30Z.
- The date change is included in the explanation.
6. A token expires at 10:00Z and is valid only strictly before expiry. Design checks at 09:59Z, 10:00Z and 10:01Z using a fixed clock.
Show hint
State the equality policy explicitly.
Show worked solution
Inject fixed instants for each case. The token is valid at 09:59 and invalid at 10:00 and 10:01 under the strict rule; assert the decision rather than waiting for wall time.
Check your solution
- The before-expiry case is valid.
- Equality and after-expiry cases are invalid.
7. An API receives start=10:30Z and end=10:00Z but requires nonnegative elapsed time. Explain the Duration result and validation outcome.
Show hint
Duration preserves argument order and sign.
Show worked solution
Duration.between returns negative thirty minutes for this ordering. Because the API forbids reverse intervals, reject the input explicitly rather than silently taking an absolute value or reporting a positive duration.
Check your solution
- The signed duration is -30 minutes.
- The API rejects the reverse interval.
8. A billing rule needs exact elapsed seconds, not whole minutes. Compare a 61-second duration with toMinutes and specify what to record.
Show hint
A whole-unit conversion loses the partial unit.
Show worked solution
toMinutes returns 1 for the positive 61-second interval, but one second remains beyond that whole minute. Record the duration or its exact seconds according to the contract; do not bill it as exactly sixty seconds.
Check your solution
- The whole-minute value is 1.
- The recorded elapsed amount preserves 61 seconds.
9. A user supplies an enormous duration and the application adds it to an instant. Design error handling and a state-safety test for an out-of-range result.
Show hint
Date-time arithmetic can fail at representational bounds.
Show worked solution
Validate the allowed duration against a practical domain limit and handle the documented date-time or arithmetic failure from the chosen operation. Compute before updating stored state, then test that an out-of-range request reports failure and leaves the previous timestamp unchanged.
Check your solution
- An excessive duration is rejected or reported as failure.
- The stored timestamp remains unchanged after the failed operation.
10. An event needs an immutable occurrence time for ordering and the original +02:00 display offset for an audit. Propose stored fields and checks.
Show hint
One normalized instant does not preserve every presentation detail.
Show worked solution
Store the Instant for ordering and retain the original offset or source representation under the audit contract. Test two equivalent instant representations to confirm one occurrence ordering while verifying the recorded display offset remains available.
Check your solution
- Equivalent instants compare as the same occurrence.
- The original offset remains available for the audit.
11. A synthetic zone rule reports no valid offset for local 02:30. The product rejects gaps but offers a user a choice of another time. Design the response and test.
Show hint
The alternative time is a user decision, not an invented automatic offset.
Show worked solution
Return a labeled invalid-local-time outcome and request a replacement time; do not silently claim 02:30 mapped uniquely. Test the gap and a separate ordinary time with one valid offset as a successful control.
Check your solution
- The gap is rejected with a distinct outcome.
- An ordinary local time can be resolved under the stated policy.
12. A synthetic overlap for local 01:30 allows offsets +02:00 and +01:00. Calculate both UTC clock readings and define a choice policy.
Show hint
Resolve each candidate using its own offset.
Show worked solution
On the same stated local date, +02:00 maps to 23:30Z on the previous date and +01:00 maps to 00:30Z on that date. Require an explicit choice or apply a documented earlier-or-later policy; record which was selected.
Check your solution
- The two candidate UTC readings differ by one hour.
- The chosen offset and policy are recorded.
13. A recurring appointment is stored only as 09:00+01:00. The user expects 09:00 local in a region whose offset can change. Explain the defect and redesign.
Show hint
A fixed offset has no regional transition rules.
Show worked solution
The saved offset can preserve a particular offset representation but not the region’s future local schedule. Store the local recurrence, named zone and gap/overlap policy, and resolve each occurrence using the applicable rules.
Check your solution
- The local-time requirement is retained.
- The schedule records a named zone and resolution policy.
14. A future appointment was resolved using one runtime’s zone data; another deployment has updated zone rules. What evidence is needed before claiming identical future instants?
Show hint
Named zones depend on the applicable rule data.
Show worked solution
Record the zone ID, local recurrence, resolution policy and runtime or zone-data version used by each deployment. Resolve representative future occurrences under both configurations and investigate differences rather than assuming a matching zone name guarantees identical data.
Check your solution
- Both rule-data contexts are recorded.
- Representative future results are compared.
15. In a synthetic zone the offset changes from +01:00 to +02:00 between local midnights. Compare the next local midnight with adding 24 elapsed hours to the first instant.
Show hint
The local calendar day lasts 23 elapsed hours in this fixture.
Show worked solution
The next local midnight is 23 elapsed hours after the first; adding 24 hours reaches one hour after that local midnight. Choose according to whether the requirement is a calendar boundary or a fixed elapsed timeout.
Check your solution
- The next local midnight is 23 elapsed hours later.
- The 24-hour instant is one hour after that boundary.
16. A controlled fake clock advances between two reads during a single authorization decision. The contract requires one consistent instant. Design a testable boundary.
Show hint
Capture the time once for the decision.
Show worked solution
Read an injected clock once at the start and pass that Instant through all checks for the operation. Use a fake that would return different instants on successive reads and assert the operation uses one snapshot; another operation may read a newer value.
Check your solution
- The operation performs the intended single clock read.
- All checks in that operation use the same instant.
17. A date input is malformed, while another is syntactically valid but outside the booking window. Design separate outcomes and controls.
Show hint
Parsing and business-range validation are different stages.
Show worked solution
Report a parse error for malformed text, then compare a successfully parsed value against the booking window and report a range rejection if needed. Include an in-window control and avoid converting either failure into a fabricated valid date.
Check your solution
- Malformed and out-of-window inputs are distinguishable.
- An in-window valid input succeeds.
18. A server’s default zone differs between staging and production. A machine-readable event omits an offset. Explain the risk and propose a boundary rule.
Show hint
A local timestamp is not a unique instant.
Show worked solution
The same local text can resolve to different instants if each environment silently applies its default zone. Require an explicit offset or a named zone plus documented resolution policy at the boundary, and test both environments with the same fixture.
Check your solution
- The API does not silently rely on the machine default.
- Both environments resolve the same valid input according to the contract.
19. Design a test matrix for a local scheduling boundary with a named zone. Include ordinary time, gap, overlap, malformed text and an explicit policy for each.
Show hint
Each class of input needs an expected decision.
Show worked solution
Use fixed documented zone-rule fixtures: accept an ordinary time, reject or resolve a gap according to policy, require or select an overlap offset, and reject malformed text. Assert both resolved instant and local display for accepted cases, and record the zone-data environment.
Check your solution
- All four input classes have explicit outcomes.
- Accepted cases verify both instant and local representation.
20. A fixed-clock unit test passes, but no real clock adapter or deployed zone-data test ran. Write a truthful verification report.
Show hint
The fake clock covers only its controlled boundary.
Show worked solution
Report the fixed instant, decisions and observed test result for the unit case. Mark the real clock adapter, deployment zone data and integration behavior unverified until separate authorized tests run; do not describe the whole scheduling system as proven.
Check your solution
- The fixed-clock result is scoped to its fixture.
- Unrun adapter and deployment checks are explicitly unverified.
Key takeaways
- Instants, local times, and durations are distinct.
- Test zone and transition policies explicitly.
- Offset representation equality and instant equality answer different questions.
- A fixed offset is not a named zone’s rule set.
- A fixed clock supports deterministic tests but does not prove deployment time behavior.