Skip to content
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
17 changes: 17 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions crates/ts_goport/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ tikv-jemalloc-ctl = { version = "=0.7.0", optional = true }
# through miow's safe `NamedPipe` API. execute/tsc/compile.rs: Go
# `os.SameFile` in the Windows `LookPath`. No `unsafe` here (D-W1).
[target.'cfg(windows)'.dependencies]
# Go `time.Local` on Windows (time/zoneinfo_windows.go) asks the system for
# its zone. jiff does the same with `tz-system`; Windows has no zoneinfo
# files, so the zone data comes with the binary. See
# execute/tsc/diagnostics.rs `init_local`.
jiff = { version = "=0.2.37", default-features = false, features = ["std", "tz-system", "tzdb-bundle-platform"] }
miow = "=0.6.1"
same-file = "=1.0.6"

Expand Down
29 changes: 24 additions & 5 deletions crates/ts_goport/src/execute/tsc/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,12 +307,13 @@ pub fn format_status_time(now: SystemTime) -> String {
}

// ---------------------------------------------------------------------------
// Go time.Local (go1.27.1 time/zoneinfo_unix.go), for the status clock
// Go time.Local (go1.27.1 time/zoneinfo_unix.go and zoneinfo_windows.go),
// for the status clock
// ---------------------------------------------------------------------------
// PORT: Go `time.Location` is a `jiff::tz::TimeZone`. Go parses zone files
// with `LoadLocationFromTZData`; jiff parses the same TZif data (the
// transitions and the POSIX TZ footer) with `TimeZone::tzif`. This is the
// Unix path (zoneinfo_unix.go); the port targets Linux.
// PORT: Go `time.Location` is a `jiff::tz::TimeZone`. On Unix, Go parses
// zone files with `LoadLocationFromTZData`; jiff parses the same TZif data
// (the transitions and the POSIX TZ footer) with `TimeZone::tzif`. Windows
// has its own `init_local` (below).

// Go: time/zoneinfo.go:88 localLoc, :89 localOnce, :91 (*Location).get
static LOCAL_LOC: OnceLock<jiff::tz::TimeZone> = OnceLock::new();
Expand All @@ -336,6 +337,7 @@ const PLATFORM_ZONE_SOURCES: &[&str] = &[
// Go: time/zoneinfo_unix.go:28 initLocal
// PORT: Go `syscall.Getenv` gives the raw bytes of the value; so does
// `as_encoded_bytes` on Unix.
#[cfg(not(windows))]
fn init_local() -> jiff::tz::TimeZone {
// consult $TZ to find the time zone to use.
// no $TZ means use the system default /etc/localtime.
Expand Down Expand Up @@ -370,6 +372,23 @@ fn init_local() -> jiff::tz::TimeZone {
jiff::tz::TimeZone::UTC
}

// Go: time/zoneinfo_windows.go:230 initLocal
// PORT: Go calls `GetTimeZoneInformation` and makes the zone from the
// Windows standard and daylight rules. jiff asks Windows for the zone key
// name (`GetDynamicTimeZoneInformation`), maps it to an IANA name (CLDR
// windowsZones) and takes that zone from the zone data in the binary. For a
// mapped zone, both give the same civil time now. On failure both fall back
// to UTC.
// DIVERGES: jiff reads `TZ` first; Go on Windows does not read it. The
// logger test `log_time_is_local_time` sets `TZ`, so on Windows it needs
// this. A Windows zone with no IANA name in jiff's table gives UTC, and jiff
// does not read the Windows setting that turns off daylight saving time.
// Go's exact path needs `unsafe` FFI, which the workspace forbids.
#[cfg(windows)]
fn init_local() -> jiff::tz::TimeZone {
jiff::tz::TimeZone::try_system().unwrap_or(jiff::tz::TimeZone::UTC)
}

// Go: time/zoneinfo_read.go:531 loadLocation
// PORT: `initLocal` reads only whether it failed, so the Go first-error
// bookkeeping is dropped. After the sources Go tries the embedded
Expand Down