-
Notifications
You must be signed in to change notification settings - Fork 717
feat: expand logic to determine local time #10509
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -86,19 +86,30 @@ Reads timezone rules from disk based on the provided file path and timezone ID. | |
| def readRulesFromDisk (path : System.FilePath) (id : String) : IO ZoneRules := do | ||
| parseTZIfFromDisk (System.FilePath.join path id) id | ||
|
|
||
| instance : Std.Time.Database TZdb where | ||
| getLocalZoneRules db := localRules db.localPath | ||
| /-- | ||
| Reads timezone rules from disk based on the provided timezone ID. | ||
| -/ | ||
| def getZoneRules (id : String) : IO ZoneRules := do | ||
| let env ← IO.getEnv "TZDIR" | ||
|
|
||
| getZoneRules db id := do | ||
| let env ← IO.getEnv "TZDIR" | ||
| if let some path := env then | ||
| let result ← readRulesFromDisk path id | ||
| return result | ||
|
|
||
| if let some path := env then | ||
| for path in default.zonesPaths do | ||
| if ← System.FilePath.pathExists path then | ||
| let result ← readRulesFromDisk path id | ||
| return result | ||
|
|
||
| for path in db.zonesPaths do | ||
| if ← System.FilePath.pathExists path then | ||
| let result ← readRulesFromDisk path id | ||
| return result | ||
| throw <| IO.userError s!"cannot find {id} in the local timezone database" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are some subtleties around the paths here that I think we should clear up. The docstring of the
To me this reads like This is not what currently happens (neither before nor after the PR). The @algebraic-dev, what did you intend the behavior to be here? I see two options:
|
||
|
|
||
| throw <| IO.userError s!"cannot find {id} in the local timezone database" | ||
| instance : Std.Time.Database TZdb where | ||
| getLocalZoneRules db := do | ||
| if let some id ← IO.getEnv "TZ" then | ||
| getZoneRules id | ||
| else if ← System.FilePath.pathExists db.localPath then | ||
| localRules db.localPath | ||
| else | ||
| getZoneRules "UTC" | ||
|
|
||
| getZoneRules _ id := TZdb.getZoneRules id | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import Std.Time | ||
| open Std.Time | ||
|
|
||
| def main : IO Unit := do | ||
| let res ← Database.defaultGetLocalZoneRules | ||
| println! repr res.initialLocalTimeType.gmtOffset |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| name = "debug" | ||
|
|
||
| [[lean_exe]] | ||
| name = "release" | ||
| root = "Main" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| if [ "$OS" = "Windows_NT" ]; then | ||
| exit 0 | ||
| fi | ||
|
|
||
| rm -rf .lake/build | ||
| [ "$(TZ=UTC lake exe release)" = "{ second := 0 }" ] || exit 1 | ||
| [ "$(TZ=America/Sao_Paulo lake exe release)" = "{ second := -11188 }" ] || exit 1 | ||
| exit 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here you're changing the logic by using the default paths instead of the paths given by the database that the user is supplying. This is not correct, we want users to configure their own timezone database location from application code if they are so inclined.