Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add decidable instances for comparison operations of time offset types #6587

Merged
merged 4 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Std/Time/Date/Unit/Month.lean
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ instance {x y : Ordinal} : Decidable (x < y) :=
def Offset : Type := Int
deriving Repr, BEq, Inhabited, Add, Sub, Mul, Div, Neg, ToString, LT, LE, DecidableEq

instance {x y : Offset} : Decidable (x ≤ y) :=
Int.decLe x y

instance {x y : Offset} : Decidable (x < y) :=
Int.decLt x y

instance : OfNat Offset n :=
⟨Int.ofNat n⟩

Expand Down
6 changes: 6 additions & 0 deletions src/Std/Time/Date/Unit/Week.lean
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ instance : Inhabited Ordinal where
def Offset : Type := UnitVal (86400 * 7)
deriving Repr, BEq, Inhabited, Add, Sub, Neg, LE, LT, ToString

instance {x y : Offset} : Decidable (x ≤ y) :=
inferInstanceAs (Decidable (x.val ≤ y.val))

instance {x y : Offset} : Decidable (x < y) :=
inferInstanceAs (Decidable (x.val < y.val))

instance : OfNat Offset n := ⟨UnitVal.ofNat n⟩

namespace Ordinal
Expand Down
8 changes: 7 additions & 1 deletion src/Std/Time/Time/Unit/Hour.lean
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@ instance {x y : Ordinal} : Decidable (x < y) :=
or differences in hours.
-/
def Offset : Type := UnitVal 3600
deriving Repr, BEq, Inhabited, Add, Sub, Neg, ToString
deriving Repr, BEq, Inhabited, Add, Sub, Neg, ToString, LT, LE

instance { x y : Offset } : Decidable (x ≤ y) :=
inferInstanceAs (Decidable (x.val ≤ y.val))

instance { x y : Offset } : Decidable (x < y) :=
inferInstanceAs (Decidable (x.val < y.val))

instance : OfNat Offset n :=
⟨UnitVal.ofNat n⟩
Expand Down
6 changes: 6 additions & 0 deletions src/Std/Time/Time/Unit/Millisecond.lean
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ instance {x y : Ordinal} : Decidable (x < y) :=
def Offset : Type := UnitVal (1 / 1000)
deriving Repr, BEq, Inhabited, Add, Sub, Neg, LE, LT, ToString

instance { x y : Offset } : Decidable (x ≤ y) :=
inferInstanceAs (Decidable (x.val ≤ y.val))

instance { x y : Offset } : Decidable (x < y) :=
inferInstanceAs (Decidable (x.val < y.val))

instance : OfNat Offset n :=
⟨UnitVal.ofNat n⟩

Expand Down
8 changes: 7 additions & 1 deletion src/Std/Time/Time/Unit/Minute.lean
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@ instance {x y : Ordinal} : Decidable (x < y) :=
`Offset` represents a duration offset in minutes.
-/
def Offset : Type := UnitVal 60
deriving Repr, BEq, Inhabited, Add, Sub, Neg, ToString
deriving Repr, BEq, Inhabited, Add, Sub, Neg, ToString, LT, LE

instance { x y : Offset } : Decidable (x ≤ y) :=
inferInstanceAs (Decidable (x.val ≤ y.val))

instance { x y : Offset } : Decidable (x < y) :=
inferInstanceAs (Decidable (x.val < y.val))

instance : OfNat Offset n :=
⟨UnitVal.ofInt <| Int.ofNat n⟩
Expand Down
3 changes: 3 additions & 0 deletions src/Std/Time/Time/Unit/Nanosecond.lean
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ def Offset : Type := UnitVal (1 / 1000000000)
instance { x y : Offset } : Decidable (x ≤ y) :=
inferInstanceAs (Decidable (x.val ≤ y.val))

instance { x y : Offset } : Decidable (x < y) :=
inferInstanceAs (Decidable (x.val < y.val))

instance : OfNat Offset n :=
⟨UnitVal.ofNat n⟩

Expand Down
6 changes: 6 additions & 0 deletions src/Std/Time/Time/Unit/Second.lean
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ instance {x y : Ordinal l} : Decidable (x < y) :=
def Offset : Type := UnitVal 1
deriving Repr, BEq, Inhabited, Add, Sub, Neg, LE, LT, ToString

instance { x y : Offset } : Decidable (x ≤ y) :=
inferInstanceAs (Decidable (x.val ≤ y.val))

instance { x y : Offset } : Decidable (x < y) :=
inferInstanceAs (Decidable (x.val < y.val))

instance : OfNat Offset n :=
⟨UnitVal.ofNat n⟩

Expand Down
Loading