Skip to content

Commit 7921d55

Browse files
committed
time: add time_ns function
1 parent 4dc023d commit 7921d55

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

‎time/time.go‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ func time_time(self py.Object) (py.Object, error){
2121
returnpy.Float(time.Now().UnixNano()) /1e9, nil
2222
}
2323

24+
consttime_ns_doc=`time_ns() -> int
25+
26+
Return the current time in nanoseconds since the Epoch.
27+
`
28+
29+
functime_time_ns(self py.Object) (py.Object, error){
30+
returnpy.Int(time.Now().UnixNano()), nil
31+
}
32+
2433
// func floatclock(_Py_clock_info_t *info) (py.Object, error){
2534
// value := clock()
2635
// if value == (clock_t)-1{
@@ -979,6 +988,7 @@ func PyInit_timezone(m py.Object){
979988
funcinit(){
980989
methods:= []*py.Method{
981990
py.MustNewMethod("time", time_time, 0, time_doc),
991+
py.MustNewMethod("time_ns", time_time_ns, 0, time_ns_doc),
982992
py.MustNewMethod("clock", time_clock, 0, clock_doc),
983993
py.MustNewMethod("clock_gettime", time_clock_gettime, 0, clock_gettime_doc),
984994
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)
10371047
Functions:
10381048
10391049
time() -- return current time in seconds since the Epoch as a float
1050+
time_ns() -- return current time in nanoseconds since the Epoch
10401051
clock() -- return CPU time since process start as a float
10411052
sleep() -- delay for a number of seconds given as a float
10421053
gmtime() -- convert seconds since Epoch to UTC tuple

0 commit comments

Comments
(0)