Skip to content

time: add time_ns function #146

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

Merged
merged 1 commit into from
Jan 10, 2022
Merged
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
11 changes: 11 additions & 0 deletions time/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ func time_time(self py.Object) (py.Object, error) {
return py.Float(time.Now().UnixNano()) / 1e9, nil
}

const time_ns_doc = `time_ns() -> int

Return the current time in nanoseconds since the Epoch.
`

func time_time_ns(self py.Object) (py.Object, error) {
return py.Int(time.Now().UnixNano()), nil
}

// func floatclock(_Py_clock_info_t *info) (py.Object, error) {
// value := clock()
// if value == (clock_t)-1 {
Expand Down Expand Up @@ -979,6 +988,7 @@ func PyInit_timezone(m py.Object) {
func init() {
methods := []*py.Method{
py.MustNewMethod("time", time_time, 0, time_doc),
py.MustNewMethod("time_ns", time_time_ns, 0, time_ns_doc),
py.MustNewMethod("clock", time_clock, 0, clock_doc),
py.MustNewMethod("clock_gettime", time_clock_gettime, 0, clock_gettime_doc),
py.MustNewMethod("clock_settime", time_clock_settime, 0, clock_settime_doc),
Expand Down Expand Up @@ -1037,6 +1047,7 @@ tzname -- tuple of (standard time zone name, DST time zone name)
Functions:

time() -- return current time in seconds since the Epoch as a float
time_ns() -- return current time in nanoseconds since the Epoch
clock() -- return CPU time since process start as a float
sleep() -- delay for a number of seconds given as a float
gmtime() -- convert seconds since Epoch to UTC tuple
Expand Down