-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdatetime.go
51 lines (42 loc) · 1.14 KB
/
datetime.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package py
/*
#include "Python.h"
#include "datetime.h"
void init_PyDateTime() {
PyDateTime_IMPORT;
}
int IsPyTypeDateTime(PyObject* o) {
return PyDateTime_CheckExact(o);
}
int IsPyTypeTimeDelta(PyObject* o) {
return PyDelta_CheckExact(o);
}
PyObject* GetPyDateTime(int year, int month, int day, int hour, int minute,
int second, int us) {
return PyDateTime_FromDateAndTime(year, month, day, hour, minute, second, us);
}
*/
import "C"
import (
"gopkg.in/sensorbee/py.v0/mainthread"
"time"
)
func init() {
// Lock Native thread for initializing python
mainthread.ExecSync(func() {
C.init_PyDateTime()
})
}
// isPyTypeDateTime checks the object is `PyDateTime` type or not.
func isPyTypeDateTime(o *C.PyObject) bool {
return C.IsPyTypeDateTime(o) > 0
}
// isPyTypeTimeDelta checks the object is `PyDelta` type or not.
func isPyTypeTimeDelta(o *C.PyObject) bool {
return C.IsPyTypeTimeDelta(o) > 0
}
func getPyDateTime(t time.Time) *C.PyObject {
us := int(t.Nanosecond() / 1e3)
return C.GetPyDateTime(C.int(t.Year()), C.int(t.Month()), C.int(t.Day()),
C.int(t.Hour()), C.int(t.Minute()), C.int(t.Second()), C.int(us))
}