FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
openapi/java/src/types/datetime.rs at main · noneback/openapi · GitHub
noneback
/
openapi
Public
forked from
longbridge/openapi
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
openapi
/
java
/
src
/
types
/
datetime.rs
Copy path
More file actions
More file actions
Latest commit
History
History
History
176 lines (153 loc) · 5.12 KB
Breadcrumbs
openapi
/
java
/
src
/
types
/
datetime.rs
Copy path
File metadata and controls
176 lines (153 loc) · 5.12 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
use
std
::
borrow
::
Cow
;
use
jni
::
{
JNIEnv
,
errors
::
Result
,
objects
::
{
JValue
,
JValueOwned
}
,
}
;
use
time
::
{
Date
,
Month
,
OffsetDateTime
,
PrimitiveDateTime
,
Time
}
;
use
crate
::
{
init
::
{
TIME_INSTANT_CLASS
,
TIME_LOCALDATE_CLASS
,
TIME_LOCALDATETIME_CLASS
,
TIME_LOCALTIME_CLASS
,
TIME_OFFSETDATETIME_CLASS
,
TIME_ZONE_ID
,
}
,
types
::
{
ClassLoader
,
FromJValue
,
IntoJValue
,
JSignature
,
get_field
}
,
}
;
impl
ClassLoader
for
OffsetDateTime
{
fn
init
(
_env
:
&
mut
JNIEnv
)
{
}
fn
class_ref
(
)
-> jni
::
objects
::
GlobalRef
{
TIME_OFFSETDATETIME_CLASS
.
get
(
)
.
cloned
(
)
.
unwrap
(
)
}
}
impl
JSignature
for
OffsetDateTime
{
fn
signature
(
)
->
Cow
<
'
static
,
str
>
{
"Ljava/time/OffsetDateTime;"
.
into
(
)
}
}
impl
FromJValue
for
OffsetDateTime
{
fn
from_jvalue
(
env
:
&
mut
JNIEnv
,
value
:
JValueOwned
)
->
Result
<
Self
>
{
let
obj = value
.
l
(
)
?
;
let
value = env
.
call_method
(
obj
,
"toEpochSecond"
,
"()J"
,
&
[
]
)
?
.
j
(
)
?
;
Ok
(
OffsetDateTime
::
from_unix_timestamp
(
value
)
.
unwrap
(
)
)
}
}
impl
IntoJValue
for
OffsetDateTime
{
fn
into_jvalue
<
'
a
>
(
self
,
env
:
&
mut
JNIEnv
<
'
a
>
)
->
Result
<
JValueOwned
<
'
a
>
>
{
let
instant = env
.
call_static_method
(
TIME_INSTANT_CLASS
.
get
(
)
.
unwrap
(
)
,
"ofEpochSecond"
,
"(J)Ljava/time/Instant;"
,
&
[
JValue
::
from
(
self
.
unix_timestamp
(
)
)
]
,
)
?
;
env
.
call_static_method
(
TIME_OFFSETDATETIME_CLASS
.
get
(
)
.
unwrap
(
)
,
"ofInstant"
,
"(Ljava/time/Instant;Ljava/time/ZoneId;)Ljava/time/OffsetDateTime;"
,
&
[
instant
.
borrow
(
)
,
JValue
::
from
(
TIME_ZONE_ID
.
get
(
)
.
unwrap
(
)
.
as_obj
(
)
)
,
]
,
)
}
}
impl
ClassLoader
for
Date
{
fn
init
(
_env
:
&
mut
JNIEnv
)
{
}
fn
class_ref
(
)
-> jni
::
objects
::
GlobalRef
{
TIME_LOCALDATE_CLASS
.
get
(
)
.
cloned
(
)
.
unwrap
(
)
}
}
impl
JSignature
for
Date
{
fn
signature
(
)
->
Cow
<
'
static
,
str
>
{
"Ljava/time/LocalDate;"
.
into
(
)
}
}
impl
FromJValue
for
Date
{
fn
from_jvalue
(
env
:
&
mut
JNIEnv
,
value
:
JValueOwned
)
->
Result
<
Self
>
{
let
obj = value
.
l
(
)
?
;
let
year = env
.
call_method
(
&
obj
,
"getYear"
,
"()I"
,
&
[
]
)
?
.
i
(
)
?
;
let
month = env
.
call_method
(
&
obj
,
"getMonthValue"
,
"()I"
,
&
[
]
)
?
.
i
(
)
?
;
let
day = env
.
call_method
(
&
obj
,
"getDayOfMonth"
,
"()I"
,
&
[
]
)
?
.
i
(
)
?
;
Ok
(
Date
::
from_calendar_date
(
year
,
Month
::
try_from
(
month
as
u8
)
.
unwrap
(
)
,
day
as
u8
)
.
unwrap
(
)
,
)
}
}
impl
IntoJValue
for
Date
{
fn
into_jvalue
<
'
a
>
(
self
,
env
:
&
mut
JNIEnv
<
'
a
>
)
->
Result
<
JValueOwned
<
'
a
>
>
{
env
.
call_static_method
(
TIME_LOCALDATE_CLASS
.
get
(
)
.
unwrap
(
)
,
"of"
,
"(III)Ljava/time/LocalDate;"
,
&
[
JValue
::
from
(
self
.
year
(
)
)
,
JValue
::
from
(
self
.
month
(
)
as
i32
)
,
JValue
::
from
(
self
.
day
(
)
as
i32
)
,
]
,
)
}
}
impl
ClassLoader
for
Time
{
fn
init
(
_env
:
&
mut
JNIEnv
)
{
}
fn
class_ref
(
)
-> jni
::
objects
::
GlobalRef
{
TIME_LOCALTIME_CLASS
.
get
(
)
.
cloned
(
)
.
unwrap
(
)
}
}
impl
JSignature
for
Time
{
fn
signature
(
)
->
Cow
<
'
static
,
str
>
{
"Ljava/time/LocalTime;"
.
into
(
)
}
}
impl
FromJValue
for
Time
{
fn
from_jvalue
(
env
:
&
mut
JNIEnv
,
value
:
JValueOwned
)
->
Result
<
Self
>
{
let
obj = value
.
l
(
)
?
;
let
hour = env
.
call_method
(
&
obj
,
"getHour"
,
"()I"
,
&
[
]
)
?
.
i
(
)
?
;
let
minute = env
.
call_method
(
&
obj
,
"getMinute"
,
"()I"
,
&
[
]
)
?
.
i
(
)
?
;
let
second = env
.
call_method
(
&
obj
,
"getSecond"
,
"()I"
,
&
[
]
)
?
.
i
(
)
?
;
Ok
(
Time
::
from_hms
(
hour
as
u8
,
minute
as
u8
,
second
as
u8
)
.
unwrap
(
)
)
}
}
impl
IntoJValue
for
Time
{
fn
into_jvalue
<
'
a
>
(
self
,
env
:
&
mut
JNIEnv
<
'
a
>
)
->
Result
<
JValueOwned
<
'
a
>
>
{
env
.
call_static_method
(
TIME_LOCALTIME_CLASS
.
get
(
)
.
unwrap
(
)
,
"of"
,
"(III)Ljava/time/LocalTime;"
,
&
[
JValue
::
from
(
self
.
hour
(
)
as
i32
)
,
JValue
::
from
(
self
.
minute
(
)
as
i32
)
,
JValue
::
from
(
self
.
second
(
)
as
i32
)
,
]
,
)
}
}
impl
ClassLoader
for
PrimitiveDateTime
{
fn
init
(
_env
:
&
mut
JNIEnv
)
{
}
fn
class_ref
(
)
-> jni
::
objects
::
GlobalRef
{
TIME_LOCALTIME_CLASS
.
get
(
)
.
cloned
(
)
.
unwrap
(
)
}
}
impl
JSignature
for
PrimitiveDateTime
{
fn
signature
(
)
->
Cow
<
'
static
,
str
>
{
"Ljava/time/LocalDateTime;"
.
into
(
)
}
}
impl
FromJValue
for
PrimitiveDateTime
{
fn
from_jvalue
(
env
:
&
mut
JNIEnv
,
value
:
JValueOwned
)
->
Result
<
Self
>
{
let
obj = value
.
l
(
)
?
;
let
date
:
Date
=
get_field
(
env
,
&
obj
,
"date"
)
?
;
let
time
:
Time
=
get_field
(
env
,
&
obj
,
"time"
)
?
;
Ok
(
PrimitiveDateTime
::
new
(
date
,
time
)
)
}
}
impl
IntoJValue
for
PrimitiveDateTime
{
fn
into_jvalue
<
'
a
>
(
self
,
env
:
&
mut
JNIEnv
<
'
a
>
)
->
Result
<
JValueOwned
<
'
a
>
>
{
let
date =
self
.
date
(
)
.
into_jvalue
(
env
)
?
;
let
time =
self
.
time
(
)
.
into_jvalue
(
env
)
?
;
let
obj = env
.
new_object
(
TIME_LOCALDATETIME_CLASS
.
get
(
)
.
unwrap
(
)
,
"(Ljava/time/LocalDate;Ljava/time/LocalTime;)V"
,
&
[
date
.
borrow
(
)
,
time
.
borrow
(
)
]
,
)
?
;
Ok
(
JValueOwned
::
from
(
obj
)
)
}
}
Back
|
FazBrowse Home
|
New Git URL