lean4-htt/tests/lean/run/timeLimits.lean
Sofia Rodrigues d95a2ee35e
feat: add FormatConfig for GenericFormat with leap second validation (#7584)
This PR introduces a structure called `FormatConfig`, which provides
additional configuration options for `GenericFormat`, such as whether
leap seconds should be allowed during parsing. By default, this option
is set to `false`.

This PR also fixes certain flaws to make the implementation less
permissive by:

- Disallowing the final leap second, such as `2016-12-31T23:59:60Z`,
when `allowLeapSeconds = false`.
- Disallowing invalid leap seconds, such as `2017-06-30T23:59:60Z`, when
`allowLeapSeconds = false`.
- Disallowing leap-minute time zones, such as
`2016-12-31T00:00:00+2360`, and out-of-range time zones, such as
`2016-12-31T00:00:00+2490`.

These changes ensure that Lean aligns with TypeScript's behavior, as
outlined in this table:
https://github.com/cedar-policy/cedar-spec/pull/519#issuecomment-2613547897.
2025-03-27 13:25:23 +00:00

77 lines
2.1 KiB
Text

import Std.Time
open Std.Time
def ISO8601UTCAllow : GenericFormat .any := datespec("uuuu-MM-dd'T'HH:mm:ss.SSSSSSSSSZ", { allowLeapSeconds := true })
def ISO8601UTCNot : GenericFormat .any := datespec("uuuu-MM-dd'T'HH:mm:ss.SSSSSSSSSZ", { allowLeapSeconds := false })
def ISO8601UTCDef : GenericFormat .any := datespec("uuuu-MM-dd'T'HH:mm:ss.SSSSSSSSSZ")
/--
info: Except.ok (zoned("2002-07-14T23:14:00.324354679-23:59"))
-/
#guard_msgs in
#eval ISO8601UTCAllow.parse "2002-07-14T23:13:60.324354679-2359"
/--
info: Except.error "offset 19: need a natural number in the interval of 0 to 59"
-/
#guard_msgs in
#eval ISO8601UTCNot.parse "2002-07-14T23:13:60.324354679-2359"
/--
info: Except.error "offset 19: need a natural number in the interval of 0 to 59"
-/
#guard_msgs in
#eval ISO8601UTCDef.parse "2002-07-14T23:13:60.324354679-2359"
/-
Offset
-/
/--
info: Except.error "offset 32: invalid hour offset: 24. Must be between 0 and 23."
-/
#guard_msgs in
#eval ISO8601UTCAllow.parse "2002-07-14T23:14:00.324354679+2400"
/--
info: Except.error "offset 32: invalid hour offset: 99. Must be between 0 and 23."
-/
#guard_msgs in
#eval ISO8601UTCAllow.parse "2002-07-14T23:14:00.324354679+9900"
/--
info: Except.error "offset 34: invalid minute offset: 99. Must be between 0 and 59."
-/
#guard_msgs in
#eval ISO8601UTCAllow.parse "2002-07-14T23:14:00.324354679+0099"
/--
info: Except.ok (zoned("2002-07-14T23:14:00.324354679-23:59"))
-/
#guard_msgs in
#eval ISO8601UTCAllow.parse "2002-07-14T23:14:00.324354679-2359"
/--
info: Except.ok (zoned("2002-07-14T23:14:00.324354679+23:59"))
-/
#guard_msgs in
#eval ISO8601UTCAllow.parse "2002-07-14T23:14:00.324354679+2359"
/--
info: Except.error "offset 32: invalid hour offset: 24. Must be between 0 and 23."
-/
#guard_msgs in
#eval ISO8601UTCAllow.parse "2002-07-14T23:14:00.324354679-2400"
/--
info: Except.error "offset 32: invalid hour offset: 99. Must be between 0 and 23."
-/
#guard_msgs in
#eval ISO8601UTCAllow.parse "2002-07-14T23:14:00.324354679-9900"
/--
info: Except.error "offset 34: invalid minute offset: 99. Must be between 0 and 59."
-/
#guard_msgs in
#eval ISO8601UTCAllow.parse "2002-07-14T23:14:00.324354679-0099"