-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: use syscall to set time on Linux and macOS
- Loading branch information
Showing
8 changed files
with
70 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
//go:build darwin | ||
|
||
package htp | ||
|
||
import "golang.org/x/sys/unix" | ||
|
||
func SyncSystem(model *SyncModel) error { | ||
now := model.Now() | ||
tv := &unix.Timeval{ | ||
Sec: now.Unix(), | ||
Usec: int32(now.UnixMicro() % 1_000_000), | ||
} | ||
return unix.Settimeofday(tv) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
//go:build linux && 386 | ||
|
||
package htp | ||
|
||
import "golang.org/x/sys/unix" | ||
|
||
func SyncSystem(model *SyncModel) error { | ||
now := model.Now() | ||
tv := &unix.Timeval{ | ||
Sec: int32(now.Unix()), | ||
Usec: int32(now.UnixMicro() % 1_000_000), | ||
} | ||
return unix.Settimeofday(tv) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
//go:build linux && (amd64 || arm64) | ||
|
||
package htp | ||
|
||
import "golang.org/x/sys/unix" | ||
|
||
func SyncSystem(model *SyncModel) error { | ||
now := model.Now() | ||
tv := &unix.Timeval{ | ||
Sec: now.Unix(), | ||
Usec: now.UnixMicro() % 1_000_000, | ||
} | ||
return unix.Settimeofday(tv) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
//go:build !(darwin || (linux && (amd64 || arm64 || 386)) || windows) | ||
|
||
package htp | ||
|
||
import ( | ||
"fmt" | ||
"runtime" | ||
) | ||
|
||
func SyncSystem(model *SyncModel) error { | ||
return fmt.Errorf("system not supported: %s", runtime.GOOS) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
//go:build windows | ||
|
||
package htp | ||
|
||
import ( | ||
"fmt" | ||
"os/exec" | ||
) | ||
|
||
func SyncSystem(model *SyncModel) error { | ||
arg := fmt.Sprintf("Set-Date -Adjust $([TimeSpan]::FromSeconds(%+.3f))", -model.Offset().Sec()) | ||
return exec.Command("powershell", "-Command", arg).Run() | ||
} |