Determine the latest expiry date from two optional certificates.

← Operators and Expressions · Ref: Q1215

The >? coalescing maximum operator returns the later of two Date values, handling unset gracefully.

  latestExpiry() as pure
    -> left as Date, right as Date
    <- rtn as Date: left >? right

If both dates are set, >? returns the later one. If one is unset (certificate missing), it returns the available date. If both are unset, the result is unset.

This is a COMPARISON operator — it picks the larger value. Do not confuse it with :=? (guarded assignment), which assigns only if the target is unset. See Q1226 for a side-by-side contrast.

See Q1092 for min/max coalescing overview. See Q1208 for <? minimum on Date.

Example

defines module qa.operators.coalescemax.date

  defines function

    latestExpiry() as pure
      ->
        left as Date
        right as Date
      <- rtn as Date: left >? right

  defines program

    CoalesceMaxDateDemo()
      stdout <- Stdout()

      // === BOTH CERTIFICATES PRESENT — returns the later expiry ===

      certA <- 2025-06-15
      certB <- 2026-01-20
      latestDate <- latestExpiry(certA, certB)
      stdout.println(`Latest expiry: ${latestDate}`)

      // === ONE CERTIFICATE MISSING — returns the available one ===

      activeCert <- 2025-09-30
      missingCert <- Date()
      onlyExpiry <- latestExpiry(activeCert, missingCert)
      stdout.println(`Available cert expires: ${onlyExpiry}`)

      // === BOTH MISSING — result is unset ===

      noCertA <- Date()
      noCertB <- Date()
      noExpiry <- latestExpiry(noCertA, noCertB)
      if noExpiry?
        stdout.println(`Expiry: ${noExpiry}`)
      else
        stdout.println("No certificates found")

Common mistakes

E50060 — Date has no isAfter() method, so left.isAfter(right) is unresolved — use the >? coalescing maximum operator instead. See ek9 -h E50060 for details.

Incorrect:

left.isAfter(right)

Correct:

left >? right
Other ways to ask this
  • How do I find the maximum of two Date values when one certificate might not exist?
  • A system has two TLS certificates but one might be missing — find the latest expiry.
  • In Java I'd need null checks and isAfter to find the latest date. What does EK9 use?
  • Migrating from Go where I check nil before comparing dates — what is the EK9 pattern?

Coming from another language?

Java: a == null ? b : b == null ? a : a.isAfter(b) ? a : b. Python: max(d for d in [a, b] if d is not None). Kotlin: listOfNotNull(a, b).maxOrNull(). EK9: left >? right — one operator handles all cases.

Keywords: certificate, coalescing, expiry, >?, maximum, date, TLS, latest