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
a1f36316
Commit
a1f36316
authored
Jan 20, 2018
by
ken-mu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mruby-time: Fix mruby specific timegm() cannot return minus
parent
e5fb21b6
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
2 deletions
+24
-2
mrbgems/mruby-time/src/time.c
mrbgems/mruby-time/src/time.c
+8
-2
mrbgems/mruby-time/test/time.rb
mrbgems/mruby-time/test/time.rb
+16
-0
No files found.
mrbgems/mruby-time/src/time.c
View file @
a1f36316
...
...
@@ -138,8 +138,14 @@ timegm(struct tm *tm)
int
i
;
unsigned
int
*
nday
=
(
unsigned
int
*
)
ndays
[
is_leapyear
(
tm
->
tm_year
+
1900
)];
for
(
i
=
70
;
i
<
tm
->
tm_year
;
++
i
)
static
const
int
epoch_year
=
70
;
if
(
tm
->
tm_year
>=
epoch_year
)
{
for
(
i
=
epoch_year
;
i
<
tm
->
tm_year
;
++
i
)
r
+=
is_leapyear
(
i
+
1900
)
?
366
*
24
*
60
*
60
:
365
*
24
*
60
*
60
;
}
else
{
for
(
i
=
tm
->
tm_year
;
i
<
epoch_year
;
++
i
)
r
-=
is_leapyear
(
i
+
1900
)
?
366
*
24
*
60
*
60
:
365
*
24
*
60
*
60
;
}
for
(
i
=
0
;
i
<
tm
->
tm_mon
;
++
i
)
r
+=
nday
[
i
]
*
24
*
60
*
60
;
r
+=
(
tm
->
tm_mday
-
1
)
*
24
*
60
*
60
;
...
...
mrbgems/mruby-time/test/time.rb
View file @
a1f36316
...
...
@@ -226,3 +226,19 @@ assert('2000 times 500us make a second') do
end
t
.
usec
==
0
end
assert
(
'Time.new with Dec 31 23:59:59 1969 raise ArgumentError'
)
do
assert_raise
(
ArgumentError
)
{
Time
.
new
(
1969
,
12
,
31
,
23
,
59
,
59
)}
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
assert
(
'Time.new can make less than Dec 31 23:59:58 1969'
)
do
Time
.
new
(
1969
,
12
,
31
,
23
,
59
,
58
).
year
==
1969
end
assert
(
'Time.gm can make less than Dec 31 23:59:58 1969'
)
do
Time
.
gm
(
1969
,
12
,
31
,
23
,
59
,
58
).
year
==
1969
end
\ No newline at end of file
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