Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
6a2c0c6e
Commit
6a2c0c6e
authored
Jan 23, 2018
by
ken-mu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mruby-time: support time_t is uint
parent
f8ab3c1e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
2 deletions
+17
-2
mrbgems/mruby-time/src/time.c
mrbgems/mruby-time/src/time.c
+16
-1
mrbgems/mruby-time/test/time.rb
mrbgems/mruby-time/test/time.rb
+1
-1
No files found.
mrbgems/mruby-time/src/time.c
View file @
6a2c0c6e
...
...
@@ -67,6 +67,11 @@ double round(double x) {
/* define following macro to use probably faster timegm() on the platform */
/* #define USE_SYSTEM_TIMEGM */
/* time_t */
/* If your platform supports time_t as uint (e.g. uint32_t, uint64_t), */
/* uncomment following macro. */
/* #define MRB_TIME_T_UINT */
/** end of Time class configuration */
#ifndef NO_GETTIMEOFDAY
...
...
@@ -240,13 +245,21 @@ time_alloc(mrb_state *mrb, double sec, double usec, enum mrb_timezone timezone)
mrb_check_num_exact
(
mrb
,
(
mrb_float
)
sec
);
mrb_check_num_exact
(
mrb
,
(
mrb_float
)
usec
);
#ifndef MRB_TIME_T_UINT
if
(
sizeof
(
time_t
)
==
4
&&
(
sec
>
(
double
)
INT32_MAX
||
(
double
)
INT32_MIN
>
sec
))
{
goto
out_of_range
;
}
if
(
sizeof
(
time_t
)
==
8
&&
(
sec
>
(
double
)
INT64_MAX
||
(
double
)
INT64_MIN
>
sec
))
{
goto
out_of_range
;
}
#else
if
(
sizeof
(
time_t
)
==
4
&&
(
sec
>
(
double
)
UINT32_MAX
||
(
double
)
0
>
sec
))
{
goto
out_of_range
;
}
if
(
sizeof
(
time_t
)
==
8
&&
(
sec
>
(
double
)
UINT64_MAX
||
(
double
)
0
>
sec
))
{
goto
out_of_range
;
}
#endif
tsec
=
(
time_t
)
sec
;
if
((
sec
>
0
&&
tsec
<
0
)
||
(
sec
<
0
&&
(
double
)
tsec
>
sec
))
{
out_of_range:
...
...
@@ -371,9 +384,11 @@ time_mktime(mrb_state *mrb, mrb_int ayear, mrb_int amonth, mrb_int aday,
else
{
nowsecs
=
mktime
(
&
nowtime
);
}
#ifndef MRB_TIME_T_UINT
if
(
nowsecs
==
(
time_t
)
-
1
)
{
mrb_raise
(
mrb
,
E_ARGUMENT_ERROR
,
"Not a valid time."
);
}
#endif
return
time_alloc
(
mrb
,
(
double
)
nowsecs
,
(
double
)
ausec
,
timezone
);
}
...
...
mrbgems/mruby-time/test/time.rb
View file @
6a2c0c6e
...
...
@@ -233,4 +233,4 @@ end
assert
(
'Time.gm with Dec 31 23:59:59 1969 raise ArgumentError'
)
do
assert_raise
(
ArgumentError
)
{
Time
.
gm
(
1969
,
12
,
31
,
23
,
59
,
59
)}
end
\ No newline at end of file
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment