-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
std/time: reimplement the Time and AbsTime
- Loading branch information
1 parent
fabb30d
commit 4853b84
Showing
7 changed files
with
320 additions
and
262 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,34 @@ | ||
// Copyright 2024 The Jule Programming Language. | ||
// Use of this source code is governed by a BSD 3-Clause | ||
// license that can be found in the LICENSE file. | ||
|
||
cpp fn GetSystemTimeAsFileTime(mut ft: *cpp.FILETIME) | ||
|
||
#typedef | ||
cpp struct FILETIME { | ||
dwLowDateTime: _DWORD | ||
dwHighDateTime: _DWORD | ||
} | ||
|
||
#typedef | ||
cpp struct LARGE_INTEGER { | ||
QuadPart: u64 | ||
} | ||
|
||
// Returns system-wide realtime clock in seconds and nanoseconds. | ||
// The nanoseconds is not a second yet, always in range (0, 999999999). | ||
fn timeNow(): (sec: i64, nsec: i64) { | ||
mut ft := cpp.FILETIME{} | ||
cpp.GetSystemTimeAsFileTime(&ft) // Returns ticks in UTC | ||
// Get the number of seconds since January 1, 1970 12:00am UTC | ||
// FILETIME is in 100-nanosecond intervals since 1601-01-01 | ||
mut t := cpp.LARGE_INTEGER{} | ||
t.QuadPart = u64(ft.dwHighDateTime) | ||
t.QuadPart <<= 32 | ||
t.QuadPart |= u64(ft.dwLowDateTime) | ||
t.QuadPart -= 116444736000000000 // Convert from 1601 to 1970 | ||
t.QuadPart = t.QuadPart / 10 // Convert from 100-ns intervals to nanoseconds | ||
sec = i64(t.QuadPart / 1000000) | ||
nsec = i64(t.QuadPart % 1000000) | ||
ret | ||
} |
Oops, something went wrong.