fact
stringlengths 10
4.79k
| type
stringclasses 9
values | library
stringclasses 44
values | imports
listlengths 0
13
| filename
stringclasses 718
values | symbolic_name
stringlengths 1
76
| docstring
stringlengths 10
64.6k
⌀ |
|---|---|---|---|---|---|---|
@[inline]
toMilliseconds (offset : Hour.Offset) : Millisecond.Offset :=
offset.mul 3600000 |>.cast (by decide +kernel)
|
def
|
Std.Time
|
[
"Std.Time.Time.Unit.Hour",
"Std.Time.Time.Unit.Millisecond"
] |
Std/Time/Time/Unit/Basic.lean
|
toMilliseconds
|
Converts an `Hour.Offset` to a `Millisecond.Offset`.
|
@[inline]
ofMilliseconds (offset : Millisecond.Offset) : Hour.Offset :=
offset.toHours
|
def
|
Std.Time
|
[
"Std.Time.Time.Unit.Hour",
"Std.Time.Time.Unit.Millisecond"
] |
Std/Time/Time/Unit/Basic.lean
|
ofMilliseconds
|
Converts a `Millisecond.Offset` to an `Hour.Offset`.
|
@[inline]
toSeconds (offset : Hour.Offset) : Second.Offset :=
offset.mul 3600 |>.cast (by decide +kernel)
|
def
|
Std.Time
|
[
"Std.Time.Time.Unit.Hour",
"Std.Time.Time.Unit.Millisecond"
] |
Std/Time/Time/Unit/Basic.lean
|
toSeconds
|
Converts an `Hour.Offset` to a `Second.Offset`.
|
@[inline]
ofSeconds (offset : Second.Offset) : Hour.Offset :=
offset.toHours
|
def
|
Std.Time
|
[
"Std.Time.Time.Unit.Hour",
"Std.Time.Time.Unit.Millisecond"
] |
Std/Time/Time/Unit/Basic.lean
|
ofSeconds
|
Converts a `Second.Offset` to an `Hour.Offset`.
|
@[inline]
toMinutes (offset : Hour.Offset) : Minute.Offset :=
offset.mul 60 |>.cast (by decide +kernel)
|
def
|
Std.Time
|
[
"Std.Time.Time.Unit.Hour",
"Std.Time.Time.Unit.Millisecond"
] |
Std/Time/Time/Unit/Basic.lean
|
toMinutes
|
Converts an `Hour.Offset` to a `Minute.Offset`.
|
@[inline]
ofMinutes (offset : Minute.Offset) : Hour.Offset :=
offset.toHours
|
def
|
Std.Time
|
[
"Std.Time.Time.Unit.Hour",
"Std.Time.Time.Unit.Millisecond"
] |
Std/Time/Time/Unit/Basic.lean
|
ofMinutes
|
Converts a `Minute.Offset` to an `Hour.Offset`.
|
@[expose] Ordinal := Bounded.LE 0 23
deriving Repr, DecidableEq, LE, LT
|
def
|
Std.Time
|
[
"Std.Time.Time.Unit.Minute"
] |
Std/Time/Time/Unit/Hour.lean
|
Ordinal
|
`Ordinal` represents a bounded value for hours, ranging from 0 to 23.
|
@[expose] Offset : Type := UnitVal 3600
deriving Repr, DecidableEq, Inhabited, Add, Sub, Neg, ToString, LT, LE
|
def
|
Std.Time
|
[
"Std.Time.Time.Unit.Minute"
] |
Std/Time/Time/Unit/Hour.lean
|
Offset
|
`Offset` represents an offset in hours, defined as an `Int`. This can be used to express durations
or differences in hours.
|
@[inline]
ofInt (data : Int) (h : 0 ≤ data ∧ data ≤ 23) : Ordinal :=
Bounded.LE.mk data h
|
def
|
Std.Time
|
[
"Std.Time.Time.Unit.Minute"
] |
Std/Time/Time/Unit/Hour.lean
|
ofInt
|
Creates an `Ordinal` from an integer, ensuring the value is within bounds.
|
toRelative (ordinal : Ordinal) : Bounded.LE 1 12 :=
(ordinal.add 11).emod 12 (by decide) |>.add 1
|
def
|
Std.Time
|
[
"Std.Time.Time.Unit.Minute"
] |
Std/Time/Time/Unit/Hour.lean
|
toRelative
|
Converts an `Ordinal` into a relative hour in the range of 1 to 12.
|
shiftTo1BasedHour (ordinal : Ordinal) : Bounded.LE 1 24 :=
if h : ordinal.val < 1
then Internal.Bounded.LE.ofNatWrapping 24 (by decide)
else ordinal.truncateBottom (Int.not_lt.mp h) |>.expandTop (by decide)
|
def
|
Std.Time
|
[
"Std.Time.Time.Unit.Minute"
] |
Std/Time/Time/Unit/Hour.lean
|
shiftTo1BasedHour
|
Converts an Ordinal into a 1-based hour representation within the range of 1 to 24.
|
@[inline]
ofNat (data : Nat) (h : data ≤ 23) : Ordinal :=
Bounded.LE.ofNat data h
|
def
|
Std.Time
|
[
"Std.Time.Time.Unit.Minute"
] |
Std/Time/Time/Unit/Hour.lean
|
ofNat
|
Creates an `Ordinal` from a natural number, ensuring the value is within the valid bounds for hours.
|
@[inline]
ofFin (data : Fin 24) : Ordinal :=
Bounded.LE.ofFin data
|
def
|
Std.Time
|
[
"Std.Time.Time.Unit.Minute"
] |
Std/Time/Time/Unit/Hour.lean
|
ofFin
|
Creates an `Ordinal` from a `Fin` value.
|
@[inline]
toOffset (ordinal : Ordinal) : Offset :=
UnitVal.ofInt ordinal.val
|
def
|
Std.Time
|
[
"Std.Time.Time.Unit.Minute"
] |
Std/Time/Time/Unit/Hour.lean
|
toOffset
|
Converts an `Ordinal` to an `Offset`, which represents the duration in hours as an integer value.
|
@[inline]
ofNat (data : Nat) : Offset :=
UnitVal.ofInt data
|
def
|
Std.Time
|
[
"Std.Time.Time.Unit.Minute"
] |
Std/Time/Time/Unit/Hour.lean
|
ofNat
|
Creates an `Offset` from a natural number.
|
@[inline]
ofInt (data : Int) : Offset :=
UnitVal.ofInt data
|
def
|
Std.Time
|
[
"Std.Time.Time.Unit.Minute"
] |
Std/Time/Time/Unit/Hour.lean
|
ofInt
|
Creates an `Offset` from an integer.
|
@[expose] Ordinal := Bounded.LE 0 999
deriving Repr, DecidableEq, LE, LT
|
def
|
Std.Time
|
[
"Std.Time.Time.Unit.Nanosecond"
] |
Std/Time/Time/Unit/Millisecond.lean
|
Ordinal
|
`Ordinal` represents a bounded value for milliseconds, ranging from 0 to 999 milliseconds.
|
@[expose] Offset : Type := UnitVal (1 / 1000)
deriving Repr, DecidableEq, Inhabited, Add, Sub, Neg, LE, LT, ToString
|
def
|
Std.Time
|
[
"Std.Time.Time.Unit.Nanosecond"
] |
Std/Time/Time/Unit/Millisecond.lean
|
Offset
|
`Offset` represents a duration offset in milliseconds.
|
@[inline]
ofNat (data : Nat) : Offset :=
UnitVal.ofInt data
|
def
|
Std.Time
|
[
"Std.Time.Time.Unit.Nanosecond"
] |
Std/Time/Time/Unit/Millisecond.lean
|
ofNat
|
Creates an `Offset` from a natural number.
|
@[inline]
ofInt (data : Int) : Offset :=
UnitVal.ofInt data
|
def
|
Std.Time
|
[
"Std.Time.Time.Unit.Nanosecond"
] |
Std/Time/Time/Unit/Millisecond.lean
|
ofInt
|
Creates an `Offset` from an integer.
|
@[inline]
ofInt (data : Int) (h : 0 ≤ data ∧ data ≤ 999) : Ordinal :=
Bounded.LE.mk data h
|
def
|
Std.Time
|
[
"Std.Time.Time.Unit.Nanosecond"
] |
Std/Time/Time/Unit/Millisecond.lean
|
ofInt
|
Creates an `Ordinal` from an integer, ensuring the value is within bounds.
|
@[inline]
ofNat (data : Nat) (h : data ≤ 999) : Ordinal :=
Bounded.LE.ofNat data h
|
def
|
Std.Time
|
[
"Std.Time.Time.Unit.Nanosecond"
] |
Std/Time/Time/Unit/Millisecond.lean
|
ofNat
|
Creates an `Ordinal` from a natural number, ensuring the value is within bounds.
|
@[inline]
ofFin (data : Fin 1000) : Ordinal :=
Bounded.LE.ofFin data
|
def
|
Std.Time
|
[
"Std.Time.Time.Unit.Nanosecond"
] |
Std/Time/Time/Unit/Millisecond.lean
|
ofFin
|
Creates an `Ordinal` from a `Fin`, ensuring the value is within bounds.
|
@[inline]
toOffset (ordinal : Ordinal) : Offset :=
UnitVal.ofInt ordinal.val
|
def
|
Std.Time
|
[
"Std.Time.Time.Unit.Nanosecond"
] |
Std/Time/Time/Unit/Millisecond.lean
|
toOffset
|
Converts an `Ordinal` to an `Offset`.
|
@[expose] Ordinal := Bounded.LE 0 59
deriving Repr, DecidableEq, LE, LT
|
def
|
Std.Time
|
[
"Std.Time.Time.Unit.Second"
] |
Std/Time/Time/Unit/Minute.lean
|
Ordinal
|
`Ordinal` represents a bounded value for minutes, ranging from 0 to 59. This is useful for representing the minute component of a time.
|
@[expose] Offset : Type := UnitVal 60
deriving Repr, DecidableEq, Inhabited, Add, Sub, Neg, ToString, LT, LE
|
def
|
Std.Time
|
[
"Std.Time.Time.Unit.Second"
] |
Std/Time/Time/Unit/Minute.lean
|
Offset
|
`Offset` represents a duration offset in minutes.
|
@[inline]
ofInt (data : Int) (h : 0 ≤ data ∧ data ≤ 59) : Ordinal :=
Bounded.LE.mk data h
|
def
|
Std.Time
|
[
"Std.Time.Time.Unit.Second"
] |
Std/Time/Time/Unit/Minute.lean
|
ofInt
|
Creates an `Ordinal` from an integer, ensuring the value is within bounds.
|
@[inline]
ofNat (data : Nat) (h : data ≤ 59) : Ordinal :=
Bounded.LE.ofNat data h
|
def
|
Std.Time
|
[
"Std.Time.Time.Unit.Second"
] |
Std/Time/Time/Unit/Minute.lean
|
ofNat
|
Creates an `Ordinal` from a natural number, ensuring the value is within bounds.
|
@[inline]
ofFin (data : Fin 60) : Ordinal :=
Bounded.LE.ofFin data
|
def
|
Std.Time
|
[
"Std.Time.Time.Unit.Second"
] |
Std/Time/Time/Unit/Minute.lean
|
ofFin
|
Creates an `Ordinal` from a `Fin`, ensuring the value is within bounds.
|
@[inline]
toOffset (ordinal : Ordinal) : Offset :=
UnitVal.ofInt ordinal.val
|
def
|
Std.Time
|
[
"Std.Time.Time.Unit.Second"
] |
Std/Time/Time/Unit/Minute.lean
|
toOffset
|
Converts an `Ordinal` to an `Offset`.
|
@[inline]
ofNat (data : Nat) : Offset :=
UnitVal.ofInt data
|
def
|
Std.Time
|
[
"Std.Time.Time.Unit.Second"
] |
Std/Time/Time/Unit/Minute.lean
|
ofNat
|
Creates an `Offset` from a natural number.
|
@[inline]
ofInt (data : Int) : Offset :=
UnitVal.ofInt data
|
def
|
Std.Time
|
[
"Std.Time.Time.Unit.Second"
] |
Std/Time/Time/Unit/Minute.lean
|
ofInt
|
Creates an `Offset` from an integer.
|
@[expose] Ordinal := Bounded.LE 0 999999999
deriving Repr, DecidableEq, LE, LT
|
def
|
Std.Time
|
[
"Std.Time.Internal"
] |
Std/Time/Time/Unit/Nanosecond.lean
|
Ordinal
|
`Ordinal` represents a nanosecond value that is bounded between 0 and 999,999,999 nanoseconds.
|
@[expose] Offset : Type := UnitVal (1 / 1000000000)
deriving Repr, DecidableEq, Inhabited, Add, Sub, Neg, LE, LT, ToString
|
def
|
Std.Time
|
[
"Std.Time.Internal"
] |
Std/Time/Time/Unit/Nanosecond.lean
|
Offset
|
`Offset` represents a time offset in nanoseconds.
|
@[inline]
ofNat (data : Nat) : Offset :=
UnitVal.ofInt data
|
def
|
Std.Time
|
[
"Std.Time.Internal"
] |
Std/Time/Time/Unit/Nanosecond.lean
|
ofNat
|
Creates an `Offset` from a natural number.
|
@[inline]
ofInt (data : Int) : Offset :=
UnitVal.ofInt data
|
def
|
Std.Time
|
[
"Std.Time.Internal"
] |
Std/Time/Time/Unit/Nanosecond.lean
|
ofInt
|
Creates an `Offset` from an integer.
|
@[expose] Span := Bounded.LE (-999999999) 999999999
deriving Repr, DecidableEq, LE, LT
|
def
|
Std.Time
|
[
"Std.Time.Internal"
] |
Std/Time/Time/Unit/Nanosecond.lean
|
Span
|
`Span` represents a bounded value for nanoseconds, ranging between -999999999 and 999999999.
This can be used for operations that involve differences or adjustments within this range.
|
toOffset (span : Span) : Offset :=
UnitVal.ofInt span.val
|
def
|
Std.Time
|
[
"Std.Time.Internal"
] |
Std/Time/Time/Unit/Nanosecond.lean
|
toOffset
|
Creates a new `Offset` out of a `Span`.
|
@[expose] OfDay := Bounded.LE 0 86400000000000
deriving Repr, DecidableEq, LE, LT
|
def
|
Std.Time
|
[
"Std.Time.Internal"
] |
Std/Time/Time/Unit/Nanosecond.lean
|
OfDay
|
`Ordinal` represents a bounded value for nanoseconds in a day, which ranges between 0 and 86400000000000.
|
@[inline]
ofInt (data : Int) (h : 0 ≤ data ∧ data ≤ 999999999) : Ordinal :=
Bounded.LE.mk data h
|
def
|
Std.Time
|
[
"Std.Time.Internal"
] |
Std/Time/Time/Unit/Nanosecond.lean
|
ofInt
|
Creates an `Ordinal` from an integer, ensuring the value is within bounds.
|
@[inline]
ofNat (data : Nat) (h : data ≤ 999999999) : Ordinal :=
Bounded.LE.ofNat data h
|
def
|
Std.Time
|
[
"Std.Time.Internal"
] |
Std/Time/Time/Unit/Nanosecond.lean
|
ofNat
|
Creates an `Ordinal` from a natural number, ensuring the value is within bounds.
|
@[inline]
ofFin (data : Fin 1000000000) : Ordinal :=
Bounded.LE.ofFin data
|
def
|
Std.Time
|
[
"Std.Time.Internal"
] |
Std/Time/Time/Unit/Nanosecond.lean
|
ofFin
|
Creates an `Ordinal` from a `Fin`, ensuring the value is within bounds.
|
@[inline]
toOffset (ordinal : Ordinal) : Offset :=
UnitVal.ofInt ordinal.val
|
def
|
Std.Time
|
[
"Std.Time.Internal"
] |
Std/Time/Time/Unit/Nanosecond.lean
|
toOffset
|
Converts an `Ordinal` to an `Offset`.
|
@[expose] Ordinal (leap : Bool) := Bounded.LE 0 (.ofNat (if leap then 60 else 59))
|
def
|
Std.Time
|
[
"Std.Time.Time.Unit.Nanosecond"
] |
Std/Time/Time/Unit/Second.lean
|
Ordinal
|
`Ordinal` represents a bounded value for second, which ranges between 0 and 59 or 60. This accounts
for potential leap second.
|
@[expose] Offset : Type := UnitVal 1
deriving Repr, DecidableEq, Inhabited, Add, Sub, Neg, LE, LT, ToString
|
def
|
Std.Time
|
[
"Std.Time.Time.Unit.Nanosecond"
] |
Std/Time/Time/Unit/Second.lean
|
Offset
|
`Offset` represents an offset in seconds. It is defined as an `Int`.
|
@[inline]
ofNat (data : Nat) : Second.Offset :=
UnitVal.ofInt data
|
def
|
Std.Time
|
[
"Std.Time.Time.Unit.Nanosecond"
] |
Std/Time/Time/Unit/Second.lean
|
ofNat
|
Creates an `Second.Offset` from a natural number.
|
@[inline]
ofInt (data : Int) : Second.Offset :=
UnitVal.ofInt data
|
def
|
Std.Time
|
[
"Std.Time.Time.Unit.Nanosecond"
] |
Std/Time/Time/Unit/Second.lean
|
ofInt
|
Creates an `Second.Offset` from an integer.
|
@[inline]
ofInt (data : Int) (h : 0 ≤ data ∧ data ≤ Int.ofNat (if leap then 60 else 59)) : Ordinal leap :=
Bounded.LE.mk data h
|
def
|
Std.Time
|
[
"Std.Time.Time.Unit.Nanosecond"
] |
Std/Time/Time/Unit/Second.lean
|
ofInt
|
Creates an `Ordinal` from an integer, ensuring the value is within bounds.
|
@[inline]
ofNat (data : Nat) (h : data ≤ (if leap then 60 else 59)) : Ordinal leap :=
Bounded.LE.ofNat data h
|
def
|
Std.Time
|
[
"Std.Time.Time.Unit.Nanosecond"
] |
Std/Time/Time/Unit/Second.lean
|
ofNat
|
Creates an `Ordinal` from a natural number, ensuring the value is within bounds.
|
@[inline]
ofFin (data : Fin (if leap then 61 else 60)) : Ordinal leap :=
match leap with
| true => Bounded.LE.ofFin data
| false => Bounded.LE.ofFin data
|
def
|
Std.Time
|
[
"Std.Time.Time.Unit.Nanosecond"
] |
Std/Time/Time/Unit/Second.lean
|
ofFin
|
Creates an `Ordinal` from a `Fin`, ensuring the value is within bounds.
|
@[inline]
toOffset (ordinal : Ordinal leap) : Second.Offset :=
UnitVal.ofInt ordinal.val
|
def
|
Std.Time
|
[
"Std.Time.Time.Unit.Nanosecond"
] |
Std/Time/Time/Unit/Second.lean
|
toOffset
|
Converts an `Ordinal` to an `Second.Offset`.
|
protected Database (α : Type) where
/--
Retrieves the zone rules information (`ZoneRules`) for a given area at a specific point in time.
-/
getZoneRules : α → String → IO TimeZone.ZoneRules
/--
Retrieves the local zone rules information (`ZoneRules`) at a given timestamp.
-/
getLocalZoneRules : α → IO TimeZone.ZoneRules
|
class
|
Std.Time
|
[
"Std.Time.Zoned.ZoneRules",
"Std.Time.Zoned.Database.TzIf"
] |
Std/Time/Zoned/Database/Basic.lean
|
Database
|
A timezone database from which we can read the `ZoneRules` of some area by it's id.
|
convertWall : Bool → StdWall
| true => .standard
| false => .wall
|
def
|
Std.Time
|
[
"Std.Time.Zoned.ZoneRules",
"Std.Time.Zoned.Database.TzIf"
] |
Std/Time/Zoned/Database/Basic.lean
|
convertWall
|
Converts a Boolean value to a corresponding `StdWall` type.
|
convertUt : Bool → UTLocal
| true => .ut
| false => .local
|
def
|
Std.Time
|
[
"Std.Time.Zoned.ZoneRules",
"Std.Time.Zoned.Database.TzIf"
] |
Std/Time/Zoned/Database/Basic.lean
|
convertUt
|
Converts a Boolean value to a corresponding `UTLocal` type.
|
convertLocalTimeType (index : Nat) (tz : TZif.TZifV1) (identifier : String) : Option LocalTimeType := do
let localType ← tz.localTimeTypes[index]?
let offset := Offset.ofSeconds <| .ofInt localType.gmtOffset
let abbreviation := tz.abbreviations.getD index (offset.toIsoString true)
let wallflag := convertWall (tz.stdWallIndicators.getD index true)
let utLocal := convertUt (tz.utLocalIndicators.getD index true)
return {
gmtOffset := offset
isDst := localType.isDst
abbreviation
wall := wallflag
utLocal
identifier
}
|
def
|
Std.Time
|
[
"Std.Time.Zoned.ZoneRules",
"Std.Time.Zoned.Database.TzIf"
] |
Std/Time/Zoned/Database/Basic.lean
|
convertLocalTimeType
|
Converts a given time index into a `LocalTimeType` by using a time zone (`tz`) and its identifier.
|
convertTransition (times: Array LocalTimeType) (index : Nat) (tz : TZif.TZifV1) : Option Transition := do
let time := tz.transitionTimes[index]!
let time := Second.Offset.ofInt time
let indice := tz.transitionIndices[index]!
return { time, localTimeType := times[indice.toNat]! }
|
def
|
Std.Time
|
[
"Std.Time.Zoned.ZoneRules",
"Std.Time.Zoned.Database.TzIf"
] |
Std/Time/Zoned/Database/Basic.lean
|
convertTransition
|
Converts a transition.
|
convertTZifV1 (tz : TZif.TZifV1) (id : String) : Except String ZoneRules := do
let mut times : Array LocalTimeType := #[]
for i in *...tz.header.typecnt.toNat do
if let some result := convertLocalTimeType i tz id
then times := times.push result
else .error s!"cannot convert local time {i} of the file"
let mut transitions := #[]
for i in *...tz.transitionTimes.size do
if let some result := convertTransition times i tz
then transitions := transitions.push result
else .error s!"cannot convert transition {i} of the file"
-- Local time for timestamps before the first transition is specified by the first time
-- type (time type 0).
let initialLocalTimeType ←
if let some res := convertLocalTimeType 0 tz id
then .ok res
else .error s!"empty transitions for {id}"
.ok { transitions, initialLocalTimeType }
|
def
|
Std.Time
|
[
"Std.Time.Zoned.ZoneRules",
"Std.Time.Zoned.Database.TzIf"
] |
Std/Time/Zoned/Database/Basic.lean
|
convertTZifV1
|
Converts a `TZif.TZifV1` structure to a `ZoneRules` structure.
|
convertTZifV2 (tz : TZif.TZifV2) (id : String) : Except String ZoneRules := do
convertTZifV1 tz.toTZifV1 id
|
def
|
Std.Time
|
[
"Std.Time.Zoned.ZoneRules",
"Std.Time.Zoned.Database.TzIf"
] |
Std/Time/Zoned/Database/Basic.lean
|
convertTZifV2
|
Converts a `TZif.TZifV2` structure to a `ZoneRules` structure.
|
convertTZif (tz : TZif.TZif) (id : String) : Except String ZoneRules := do
if let some v2 := tz.v2
then convertTZifV2 v2 id
else convertTZifV1 tz.v1 id
|
def
|
Std.Time
|
[
"Std.Time.Zoned.ZoneRules",
"Std.Time.Zoned.Database.TzIf"
] |
Std/Time/Zoned/Database/Basic.lean
|
convertTZif
|
Converts a `TZif.TZif` structure to a `ZoneRules` structure.
|
TZdb where
/--
The path to the local timezone file. This is typically a symlink to a file within the timezone
database that corresponds to the current local time zone.
-/
localPath : System.FilePath := "/etc/localtime"
/--
All the possible paths to the directories containing all available time zone files. These files define various
time zones and their rules.
-/
zonesPaths : Array System.FilePath := #["/usr/share/zoneinfo", "/share/zoneinfo", "/etc/zoneinfo", "/usr/share/lib/zoneinfo"]
|
structure
|
Std.Time
|
[
"Std.Time.Zoned.Database.Basic",
"Init.Data.String.TakeDrop"
] |
Std/Time/Zoned/Database/TZdb.lean
|
TZdb
|
Represents a Time Zone Database (TZdb) configuration with paths to local and general timezone data.
|
@[inline]
default : TZdb := {}
|
def
|
Std.Time
|
[
"Std.Time.Zoned.Database.Basic",
"Init.Data.String.TakeDrop"
] |
Std/Time/Zoned/Database/TZdb.lean
|
default
|
Returns a default `TZdb` instance with common timezone data paths for most Linux distributions and macOS.
|
parseTZif (bin : ByteArray) (id : String) : Except String ZoneRules := do
let database ← TZif.parse.run bin
convertTZif database id
|
def
|
Std.Time
|
[
"Std.Time.Zoned.Database.Basic",
"Init.Data.String.TakeDrop"
] |
Std/Time/Zoned/Database/TZdb.lean
|
parseTZif
|
Parses binary timezone data into zone rules based on a given timezone ID.
|
parseTZIfFromDisk (path : System.FilePath) (id : String) : IO ZoneRules := do
let binary ← try IO.FS.readBinFile path catch _ => throw <| IO.userError s!"unable to locate {id} in the local timezone database at '{path}'"
IO.ofExcept (parseTZif binary id)
|
def
|
Std.Time
|
[
"Std.Time.Zoned.Database.Basic",
"Init.Data.String.TakeDrop"
] |
Std/Time/Zoned/Database/TZdb.lean
|
parseTZIfFromDisk
|
Reads a TZif file from disk and retrieves the zone rules for the specified timezone ID.
|
idFromPath (path : System.FilePath) : Option String := do
let res := path.components.toArray
let last ← res[res.size - 1]?
let last₁ ← res[res.size - 2]?
if last₁ = "zoneinfo"
then some <| last.trimAscii.copy
else some <| last₁.trimAscii.copy ++ "/" ++ last.trimAscii
|
def
|
Std.Time
|
[
"Std.Time.Zoned.Database.Basic",
"Init.Data.String.TakeDrop"
] |
Std/Time/Zoned/Database/TZdb.lean
|
idFromPath
|
Extracts a timezone ID from a file path.
|
localRules (path : System.FilePath) : IO ZoneRules := do
let localTimePath ← IO.FS.realPath path
if let some id := idFromPath localTimePath
then parseTZIfFromDisk path id
else throw (IO.userError "cannot read the id of the path.")
|
def
|
Std.Time
|
[
"Std.Time.Zoned.Database.Basic",
"Init.Data.String.TakeDrop"
] |
Std/Time/Zoned/Database/TZdb.lean
|
localRules
|
Retrieves the timezone rules from the local timezone data file.
|
readRulesFromDisk (path : System.FilePath) (id : String) : IO ZoneRules := do
parseTZIfFromDisk (System.FilePath.join path id) id
|
def
|
Std.Time
|
[
"Std.Time.Zoned.Database.Basic",
"Init.Data.String.TakeDrop"
] |
Std/Time/Zoned/Database/TZdb.lean
|
readRulesFromDisk
|
Reads timezone rules from disk based on the provided file path and timezone ID.
|
Header where
/--
The version of the TZif file format.
-/
version : UInt8
/--
The count of UT local indicators in the file.
-/
isutcnt : UInt32
/--
The count of standard/wall indicators in the file.
-/
isstdcnt : UInt32
/--
The number of leap second records.
-/
leapcnt : UInt32
/--
The number of transition times in the file.
-/
timecnt : UInt32
/--
The number of local time types in the file.
-/
typecnt : UInt32
/--
The total number of characters used in abbreviations.
-/
charcnt : UInt32
deriving Repr, Inhabited
|
structure
|
Std.Time
|
[
"Init.Data.Range.Polymorphic.Iterators",
"Std.Internal.Parsec",
"Init.Data.ByteArray.Extra"
] |
Std/Time/Zoned/Database/TzIf.lean
|
Header
|
Represents the header of a TZif file, containing metadata about the file's structure.
|
LocalTimeType where
/--
The GMT offset in seconds for this local time type.
-/
gmtOffset : Int32
/--
Indicates if this local time type observes daylight saving time.
-/
isDst : Bool
/--
The index into the abbreviation string table for this time type.
-/
abbreviationIndex : UInt8
deriving Repr, Inhabited
|
structure
|
Std.Time
|
[
"Init.Data.Range.Polymorphic.Iterators",
"Std.Internal.Parsec",
"Init.Data.ByteArray.Extra"
] |
Std/Time/Zoned/Database/TzIf.lean
|
LocalTimeType
|
Represents the local time type information, including offset and daylight saving details.
|
LeapSecond where
/--
The transition time of the leap second event.
-/
transitionTime : Int64
/--
The correction applied during the leap second event in seconds.
-/
correction : Int64
deriving Repr, Inhabited
|
structure
|
Std.Time
|
[
"Init.Data.Range.Polymorphic.Iterators",
"Std.Internal.Parsec",
"Init.Data.ByteArray.Extra"
] |
Std/Time/Zoned/Database/TzIf.lean
|
LeapSecond
|
Represents a leap second record, including the transition time and the correction applied.
|
TZifV1 where
/--
The header information of the TZif file.
-/
header : Header
/--
The array of transition times in seconds since the epoch.
-/
transitionTimes : Array Int32
/--
The array of local time type indices corresponding to each transition time.
-/
transitionIndices : Array UInt8
/--
The array of local time type structures.
-/
localTimeTypes : Array LocalTimeType
/--
The array of abbreviation strings used by local time types.
-/
abbreviations : Array String
/--
The array of leap second records.
-/
leapSeconds : Array LeapSecond
/--
The array indicating whether each transition time uses wall clock time or standard time.
-/
stdWallIndicators : Array Bool
/--
The array indicating whether each transition time uses universal time or local time.
-/
utLocalIndicators : Array Bool
deriving Repr, Inhabited
|
structure
|
Std.Time
|
[
"Init.Data.Range.Polymorphic.Iterators",
"Std.Internal.Parsec",
"Init.Data.ByteArray.Extra"
] |
Std/Time/Zoned/Database/TzIf.lean
|
TZifV1
|
Represents version 1 of the TZif format.
|
TZifV2 extends TZifV1 where
/--
An optional footer for additional metadata in version 2.
-/
footer : Option String
deriving Repr, Inhabited
|
structure
|
Std.Time
|
[
"Init.Data.Range.Polymorphic.Iterators",
"Std.Internal.Parsec",
"Init.Data.ByteArray.Extra"
] |
Std/Time/Zoned/Database/TzIf.lean
|
TZifV2
|
Represents version 2 of the TZif format, extending TZifV1 with an optional footer.
|
TZif where
/--
The data for version 1 of the TZif file.
-/
v1 : TZifV1
/--
Optionally, the data for version 2 of the TZif file.
-/
v2 : Option TZifV2
deriving Repr, Inhabited
|
structure
|
Std.Time
|
[
"Init.Data.Range.Polymorphic.Iterators",
"Std.Internal.Parsec",
"Init.Data.ByteArray.Extra"
] |
Std/Time/Zoned/Database/TzIf.lean
|
TZif
|
Represents a TZif file, which can be either version 1 or version 2.
|
private toUInt32 (bs : ByteArray) : UInt32 :=
assert! bs.size == 4
(bs.get! 0).toUInt32 <<< 0x18 |||
(bs.get! 1).toUInt32 <<< 0x10 |||
(bs.get! 2).toUInt32 <<< 0x8 |||
(bs.get! 3).toUInt32
|
def
|
Std.Time
|
[
"Init.Data.Range.Polymorphic.Iterators",
"Std.Internal.Parsec",
"Init.Data.ByteArray.Extra"
] |
Std/Time/Zoned/Database/TzIf.lean
|
toUInt32
| null |
private toInt32 (bs : ByteArray) : Int32 :=
let n := toUInt32 bs |>.toNat
if n < (1 <<< 31)
then Int.ofNat n
else Int.negOfNat (UInt32.size - n)
|
def
|
Std.Time
|
[
"Init.Data.Range.Polymorphic.Iterators",
"Std.Internal.Parsec",
"Init.Data.ByteArray.Extra"
] |
Std/Time/Zoned/Database/TzIf.lean
|
toInt32
| null |
private toInt64 (bs : ByteArray) : Int64 :=
let n := ByteArray.toUInt64BE! bs |>.toNat
if n < (1 <<< 63)
then Int.ofNat n
else Int.negOfNat (UInt64.size - n)
|
def
|
Std.Time
|
[
"Init.Data.Range.Polymorphic.Iterators",
"Std.Internal.Parsec",
"Init.Data.ByteArray.Extra"
] |
Std/Time/Zoned/Database/TzIf.lean
|
toInt64
| null |
private manyN (n : Nat) (p : Parser α) : Parser (Array α) := do
let mut result := #[]
for _ in *...n do
let x ← p
result := result.push x
return result
|
def
|
Std.Time
|
[
"Init.Data.Range.Polymorphic.Iterators",
"Std.Internal.Parsec",
"Init.Data.ByteArray.Extra"
] |
Std/Time/Zoned/Database/TzIf.lean
|
manyN
| null |
private pu64 : Parser UInt64 := ByteArray.toUInt64LE! <$> ByteSlice.toByteArray <$> take 8
|
def
|
Std.Time
|
[
"Init.Data.Range.Polymorphic.Iterators",
"Std.Internal.Parsec",
"Init.Data.ByteArray.Extra"
] |
Std/Time/Zoned/Database/TzIf.lean
|
pu64
| null |
private pi64 : Parser Int64 := toInt64 <$> ByteSlice.toByteArray <$> take 8
|
def
|
Std.Time
|
[
"Init.Data.Range.Polymorphic.Iterators",
"Std.Internal.Parsec",
"Init.Data.ByteArray.Extra"
] |
Std/Time/Zoned/Database/TzIf.lean
|
pi64
| null |
private pu32 : Parser UInt32 := toUInt32 <$> ByteSlice.toByteArray <$> take 4
|
def
|
Std.Time
|
[
"Init.Data.Range.Polymorphic.Iterators",
"Std.Internal.Parsec",
"Init.Data.ByteArray.Extra"
] |
Std/Time/Zoned/Database/TzIf.lean
|
pu32
| null |
private pi32 : Parser Int32 := toInt32 <$> ByteSlice.toByteArray <$> take 4
|
def
|
Std.Time
|
[
"Init.Data.Range.Polymorphic.Iterators",
"Std.Internal.Parsec",
"Init.Data.ByteArray.Extra"
] |
Std/Time/Zoned/Database/TzIf.lean
|
pi32
| null |
private pu8 : Parser UInt8 := any
|
def
|
Std.Time
|
[
"Init.Data.Range.Polymorphic.Iterators",
"Std.Internal.Parsec",
"Init.Data.ByteArray.Extra"
] |
Std/Time/Zoned/Database/TzIf.lean
|
pu8
| null |
private pbool : Parser Bool := (· != 0) <$> pu8
|
def
|
Std.Time
|
[
"Init.Data.Range.Polymorphic.Iterators",
"Std.Internal.Parsec",
"Init.Data.ByteArray.Extra"
] |
Std/Time/Zoned/Database/TzIf.lean
|
pbool
| null |
private parseHeader : Parser Header :=
Header.mk
<$> (pstring "TZif" *> pu8)
<*> (take 15 *> pu32)
<*> pu32
<*> pu32
<*> pu32
<*> pu32
<*> pu32
|
def
|
Std.Time
|
[
"Init.Data.Range.Polymorphic.Iterators",
"Std.Internal.Parsec",
"Init.Data.ByteArray.Extra"
] |
Std/Time/Zoned/Database/TzIf.lean
|
parseHeader
| null |
private parseLocalTimeType : Parser LocalTimeType :=
LocalTimeType.mk
<$> pi32
<*> pbool
<*> pu8
|
def
|
Std.Time
|
[
"Init.Data.Range.Polymorphic.Iterators",
"Std.Internal.Parsec",
"Init.Data.ByteArray.Extra"
] |
Std/Time/Zoned/Database/TzIf.lean
|
parseLocalTimeType
| null |
private parseLeapSecond (p : Parser Int) : Parser LeapSecond :=
LeapSecond.mk
<$> p
<*> pi32
|
def
|
Std.Time
|
[
"Init.Data.Range.Polymorphic.Iterators",
"Std.Internal.Parsec",
"Init.Data.ByteArray.Extra"
] |
Std/Time/Zoned/Database/TzIf.lean
|
parseLeapSecond
| null |
private parseTransitionTimes (size : Parser Int32) (n : UInt32) : Parser (Array Int32) :=
manyN (n.toNat) size
|
def
|
Std.Time
|
[
"Init.Data.Range.Polymorphic.Iterators",
"Std.Internal.Parsec",
"Init.Data.ByteArray.Extra"
] |
Std/Time/Zoned/Database/TzIf.lean
|
parseTransitionTimes
| null |
private parseTransitionIndices (n : UInt32) : Parser (Array UInt8) :=
manyN (n.toNat) pu8
|
def
|
Std.Time
|
[
"Init.Data.Range.Polymorphic.Iterators",
"Std.Internal.Parsec",
"Init.Data.ByteArray.Extra"
] |
Std/Time/Zoned/Database/TzIf.lean
|
parseTransitionIndices
| null |
private parseLocalTimeTypes (n : UInt32) : Parser (Array LocalTimeType) :=
manyN (n.toNat) parseLocalTimeType
|
def
|
Std.Time
|
[
"Init.Data.Range.Polymorphic.Iterators",
"Std.Internal.Parsec",
"Init.Data.ByteArray.Extra"
] |
Std/Time/Zoned/Database/TzIf.lean
|
parseLocalTimeTypes
| null |
private parseAbbreviations (times : Array LocalTimeType) (n : UInt32) : Parser (Array String) := do
let mut strings := #[]
let mut current := ""
let mut chars ← manyN n.toNat pu8
for time in times do
for indx in time.abbreviationIndex.toNat...n.toNat do
let char := chars[indx]!
if char = 0 then
strings := strings.push current
current := ""
break
else
current := current.push (Char.ofUInt8 char)
return strings
|
def
|
Std.Time
|
[
"Init.Data.Range.Polymorphic.Iterators",
"Std.Internal.Parsec",
"Init.Data.ByteArray.Extra"
] |
Std/Time/Zoned/Database/TzIf.lean
|
parseAbbreviations
| null |
private parseLeapSeconds (size : Parser Int) (n : UInt32) : Parser (Array LeapSecond) :=
manyN (n.toNat) (parseLeapSecond size)
|
def
|
Std.Time
|
[
"Init.Data.Range.Polymorphic.Iterators",
"Std.Internal.Parsec",
"Init.Data.ByteArray.Extra"
] |
Std/Time/Zoned/Database/TzIf.lean
|
parseLeapSeconds
| null |
private parseIndicators (n : UInt32) : Parser (Array Bool) :=
manyN (n.toNat) pbool
|
def
|
Std.Time
|
[
"Init.Data.Range.Polymorphic.Iterators",
"Std.Internal.Parsec",
"Init.Data.ByteArray.Extra"
] |
Std/Time/Zoned/Database/TzIf.lean
|
parseIndicators
| null |
private parseTZifV1 : Parser TZifV1 := do
let header ← parseHeader
let transitionTimes ← parseTransitionTimes pi32 header.timecnt
let transitionIndices ← parseTransitionIndices header.timecnt
let localTimeTypes ← parseLocalTimeTypes header.typecnt
let abbreviations ← parseAbbreviations localTimeTypes header.charcnt
let leapSeconds ← parseLeapSeconds pi32 header.leapcnt
let stdWallIndicators ← parseIndicators header.isstdcnt
let utLocalIndicators ← parseIndicators header.isutcnt
return {
header
transitionTimes
transitionIndices
localTimeTypes
abbreviations
leapSeconds
stdWallIndicators
utLocalIndicators
}
|
def
|
Std.Time
|
[
"Init.Data.Range.Polymorphic.Iterators",
"Std.Internal.Parsec",
"Init.Data.ByteArray.Extra"
] |
Std/Time/Zoned/Database/TzIf.lean
|
parseTZifV1
| null |
private parseFooter : Parser (Option String) := do
let char ← pu8
if char = 0x0A then pure () else return none
let tzString ← many (satisfy (· ≠ 0x0A))
let mut str := ""
for byte in tzString do
str := str.push (Char.ofUInt8 byte)
return some str
|
def
|
Std.Time
|
[
"Init.Data.Range.Polymorphic.Iterators",
"Std.Internal.Parsec",
"Init.Data.ByteArray.Extra"
] |
Std/Time/Zoned/Database/TzIf.lean
|
parseFooter
| null |
private parseTZifV2 : Parser (Option TZifV2) := optional do
let header ← parseHeader
let transitionTimes ← parseTransitionTimes pi64 header.timecnt
let transitionIndices ← parseTransitionIndices header.timecnt
let localTimeTypes ← parseLocalTimeTypes header.typecnt
let abbreviations ← parseAbbreviations localTimeTypes header.charcnt
let leapSeconds ← parseLeapSeconds pi64 header.leapcnt
let stdWallIndicators ← parseIndicators header.isstdcnt
let utLocalIndicators ← parseIndicators header.isutcnt
return {
header
transitionTimes
transitionIndices
localTimeTypes
abbreviations
leapSeconds
stdWallIndicators
utLocalIndicators
footer := ← parseFooter
}
|
def
|
Std.Time
|
[
"Init.Data.Range.Polymorphic.Iterators",
"Std.Internal.Parsec",
"Init.Data.ByteArray.Extra"
] |
Std/Time/Zoned/Database/TzIf.lean
|
parseTZifV2
| null |
parse : Parser TZif := do
let v1 ← parseTZifV1
let v2 ← parseTZifV2
return { v1, v2 }
|
def
|
Std.Time
|
[
"Init.Data.Range.Polymorphic.Iterators",
"Std.Internal.Parsec",
"Init.Data.ByteArray.Extra"
] |
Std/Time/Zoned/Database/TzIf.lean
|
parse
|
Parses a TZif file, which may be in either version 1 or version 2 format.
|
@[extern "lean_windows_get_next_transition"]
getNextTransition : @&String → Int64 → Bool → IO (Option (Int64 × TimeZone))
|
opaque
|
Std.Time
|
[
"Init.Data.SInt.Basic",
"Std.Time.Zoned.Database.Basic"
] |
Std/Time/Zoned/Database/Windows.lean
|
getNextTransition
|
Fetches the next timezone transition for a given timezone identifier and timestamp.
|
@[extern "lean_get_windows_local_timezone_id_at"]
getLocalTimeZoneIdentifierAt : Int64 → IO String
|
opaque
|
Std.Time
|
[
"Init.Data.SInt.Basic",
"Std.Time.Zoned.Database.Basic"
] |
Std/Time/Zoned/Database/Windows.lean
|
getLocalTimeZoneIdentifierAt
|
Fetches the timezone at a timestamp.
|
getZoneRules (id : String) : IO TimeZone.ZoneRules := do
let mut start := -2147483648
let mut transitions : Array TimeZone.Transition := #[]
let mut initialLocalTimeType ←
if let some res := ← Windows.getNextTransition id start true
then pure (toLocalTime res.snd)
else throw (IO.userError "cannot find first transition in zone rules")
while true do
let result ← Windows.getNextTransition id start false
if let some res := result then
transitions := transitions.push { time := Second.Offset.ofInt start.toInt, localTimeType := toLocalTime res.snd }
-- Avoid zone rules for more than year 3000
if res.fst ≤ start ∨ res.fst >= 32503690800 then
break
start := res.fst
else
break
return { transitions, initialLocalTimeType }
where
toLocalTime (res : TimeZone) : TimeZone.LocalTimeType :=
{
gmtOffset := res.offset,
abbreviation := res.abbreviation,
identifier := res.name,
isDst := res.isDST,
wall := .wall,
utLocal := .local
}
|
def
|
Std.Time
|
[
"Init.Data.SInt.Basic",
"Std.Time.Zoned.Database.Basic"
] |
Std/Time/Zoned/Database/Windows.lean
|
getZoneRules
|
Retrieves the timezone rules, including all transitions, for a given timezone identifier.
|
WindowsDb where
|
structure
|
Std.Time
|
[
"Init.Data.SInt.Basic",
"Std.Time.Zoned.Database.Basic"
] |
Std/Time/Zoned/Database/Windows.lean
|
WindowsDb
|
Represents a Time Zone Database that we get from ICU available on Windows SDK.
|
@[inline]
default : WindowsDb := {}
|
def
|
Std.Time
|
[
"Init.Data.SInt.Basic",
"Std.Time.Zoned.Database.Basic"
] |
Std/Time/Zoned/Database/Windows.lean
|
default
|
Returns a default `WindowsDb` instance.
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.