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
138845a5
Unverified
Commit
138845a5
authored
May 15, 2019
by
Yukihiro "Matz" Matsumoto
Committed by
GitHub
May 15, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4434 from shuujii/refine-Time-to_s-inspect
Refine `Time#(to_s|inspect)`
parents
fd37bc53
edf4b33c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
5 deletions
+14
-5
mrbgems/mruby-time/src/time.c
mrbgems/mruby-time/src/time.c
+12
-3
mrbgems/mruby-time/test/time.rb
mrbgems/mruby-time/test/time.rb
+2
-2
No files found.
mrbgems/mruby-time/src/time.c
View file @
138845a5
...
...
@@ -18,6 +18,7 @@
#endif
#define NDIV(x,y) (-(-((x)+1)/(y))-1)
#define TO_S_FMT "%Y-%m-%d %H:%M:%S "
#if defined(_MSC_VER) && _MSC_VER < 1800
double
round
(
double
x
)
{
...
...
@@ -760,7 +761,6 @@ mrb_time_sec(mrb_state *mrb, mrb_value self)
return
mrb_fixnum_value
(
tm
->
datetime
.
tm_sec
);
}
/* 15.2.19.7.24 */
/* Returns a Float with the time since the epoch in seconds. */
static
mrb_value
...
...
@@ -824,6 +824,15 @@ mrb_time_utc_p(mrb_state *mrb, mrb_value self)
return
mrb_bool_value
(
tm
->
timezone
==
MRB_TIMEZONE_UTC
);
}
static
mrb_value
mrb_time_to_s
(
mrb_state
*
mrb
,
mrb_value
self
)
{
char
buf
[
64
];
struct
mrb_time
*
tm
=
time_get_ptr
(
mrb
,
self
);
const
char
*
fmt
=
tm
->
timezone
==
MRB_TIMEZONE_UTC
?
TO_S_FMT
"UTC"
:
TO_S_FMT
"%z"
;
size_t
len
=
strftime
(
buf
,
sizeof
(
buf
),
fmt
,
&
tm
->
datetime
);
return
mrb_str_new
(
mrb
,
buf
,
len
);
}
void
mrb_mruby_time_gem_init
(
mrb_state
*
mrb
)
...
...
@@ -844,8 +853,8 @@ mrb_mruby_time_gem_init(mrb_state* mrb)
mrb_define_method
(
mrb
,
tc
,
"<=>"
,
mrb_time_cmp
,
MRB_ARGS_REQ
(
1
));
/* 15.2.19.7.1 */
mrb_define_method
(
mrb
,
tc
,
"+"
,
mrb_time_plus
,
MRB_ARGS_REQ
(
1
));
/* 15.2.19.7.2 */
mrb_define_method
(
mrb
,
tc
,
"-"
,
mrb_time_minus
,
MRB_ARGS_REQ
(
1
));
/* 15.2.19.7.3 */
mrb_define_method
(
mrb
,
tc
,
"to_s"
,
mrb_time_
asctime
,
MRB_ARGS_NONE
());
mrb_define_method
(
mrb
,
tc
,
"inspect"
,
mrb_time_
asctime
,
MRB_ARGS_NONE
());
mrb_define_method
(
mrb
,
tc
,
"to_s"
,
mrb_time_
to_s
,
MRB_ARGS_NONE
());
mrb_define_method
(
mrb
,
tc
,
"inspect"
,
mrb_time_
to_s
,
MRB_ARGS_NONE
());
mrb_define_method
(
mrb
,
tc
,
"asctime"
,
mrb_time_asctime
,
MRB_ARGS_NONE
());
/* 15.2.19.7.4 */
mrb_define_method
(
mrb
,
tc
,
"ctime"
,
mrb_time_asctime
,
MRB_ARGS_NONE
());
/* 15.2.19.7.5 */
mrb_define_method
(
mrb
,
tc
,
"day"
,
mrb_time_day
,
MRB_ARGS_NONE
());
/* 15.2.19.7.6 */
...
...
mrbgems/mruby-time/test/time.rb
View file @
138845a5
...
...
@@ -235,11 +235,11 @@ end
# Not ISO specified
assert
(
'Time#to_s'
)
do
assert_equal
(
"
Sun Mar 13 07:06:40 2011"
,
Time
.
at
(
1300000000.0
).
utc
.
to_s
)
assert_equal
(
"
2003-04-05 06:07:08 UTC"
,
Time
.
gm
(
2003
,
4
,
5
,
6
,
7
,
8
,
9
)
.
to_s
)
end
assert
(
'Time#inspect'
)
do
assert_
equal
(
"Sun Mar 13 07:06:40 2011"
,
Time
.
at
(
1300000000.0
).
utc
.
inspect
)
assert_
match
(
"2013-10-28 16:27:48 [^U]*"
,
Time
.
local
(
2013
,
10
,
28
,
16
,
27
,
48
)
.
inspect
)
end
assert
(
'day of week methods'
)
do
...
...
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