diff --git a/time/time.go b/time/time.go index 88deb94a..c028966a 100644 --- a/time/time.go +++ b/time/time.go @@ -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 { @@ -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), @@ -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