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
8dc69cf2
Commit
8dc69cf2
authored
Jul 23, 2012
by
Yukihiro Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
time.c: separate sec and usec to keep precisions
parent
6cd32ee4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
13 deletions
+15
-13
src/time.c
src/time.c
+15
-13
No files found.
src/time.c
View file @
8dc69cf2
...
...
@@ -160,13 +160,17 @@ mrb_time_wrap(mrb_state *mrb, struct RClass *tc, struct mrb_time *tm)
/* Allocates a mrb_time object and initializes it. */
static
struct
mrb_time
*
mrb_time_alloc
(
mrb_state
*
mrb
,
mrb_float
sec
onds
,
enum
mrb_timezone
timezone
)
mrb_time_alloc
(
mrb_state
*
mrb
,
mrb_float
sec
,
mrb_float
usec
,
enum
mrb_timezone
timezone
)
{
struct
mrb_time
*
tm
;
tm
=
mrb_malloc
(
mrb
,
sizeof
(
struct
mrb_time
));
tm
->
sec
=
(
time_t
)
seconds
;
tm
->
usec
=
(
seconds
-
tm
->
sec
)
*
1.0e6
;
tm
->
sec
=
(
time_t
)
sec
;
tm
->
usec
=
(
sec
-
tm
->
sec
)
*
1.0e6
+
usec
;
if
(
tm
->
usec
<
0
)
{
tm
->
sec
--
;
tm
->
usec
+=
1.0e6
;
}
tm
->
timezone
=
timezone
;
mrb_time_update_datetime
(
tm
);
...
...
@@ -174,9 +178,9 @@ mrb_time_alloc(mrb_state *mrb, mrb_float seconds, enum mrb_timezone timezone)
}
static
mrb_value
mrb_time_make
(
mrb_state
*
mrb
,
struct
RClass
*
c
,
mrb_float
sec
onds
,
enum
mrb_timezone
timezone
)
mrb_time_make
(
mrb_state
*
mrb
,
struct
RClass
*
c
,
mrb_float
sec
,
mrb_float
usec
,
enum
mrb_timezone
timezone
)
{
return
mrb_time_wrap
(
mrb
,
c
,
mrb_time_alloc
(
mrb
,
sec
onds
,
timezone
));
return
mrb_time_wrap
(
mrb
,
c
,
mrb_time_alloc
(
mrb
,
sec
,
usec
,
timezone
));
}
static
struct
mrb_time
*
...
...
@@ -230,8 +234,7 @@ mrb_time_at(mrb_state *mrb, mrb_value self)
mrb_float
f
,
f2
=
0
;
mrb_get_args
(
mrb
,
"f|f"
,
&
f
,
&
f2
);
f
+=
f2
*
1e-6
;
return
mrb_time_make
(
mrb
,
mrb_class_ptr
(
self
),
f
,
MRB_TIMEZONE_LOCAL
);
return
mrb_time_make
(
mrb
,
mrb_class_ptr
(
self
),
f
,
f2
,
MRB_TIMEZONE_LOCAL
);
}
static
struct
mrb_time
*
...
...
@@ -259,7 +262,7 @@ time_mktime(mrb_state *mrb, mrb_int ayear, mrb_int amonth, mrb_int aday,
mrb_raise
(
mrb
,
E_ARGUMENT_ERROR
,
"Not a valid time."
);
}
return
mrb_time_alloc
(
mrb
,
nowsecs
+
ausec
/
10e6
,
timezone
);
return
mrb_time_alloc
(
mrb
,
nowsecs
,
ausec
,
timezone
);
}
/* 15.2.19.6.2 */
...
...
@@ -343,7 +346,7 @@ mrb_time_plus(mrb_state *mrb, mrb_value self)
if
(
!
tm
)
return
mrb_nil_value
();
f
+=
tm
->
sec
;
f
+=
(
mrb_float
)
tm
->
usec
/
1.0e6
;
return
mrb_time_make
(
mrb
,
mrb_obj_class
(
mrb
,
self
),
f
,
tm
->
timezone
);
return
mrb_time_make
(
mrb
,
mrb_obj_class
(
mrb
,
self
),
f
,
0
,
tm
->
timezone
);
}
static
mrb_value
...
...
@@ -364,11 +367,10 @@ mrb_time_minus(mrb_state *mrb, mrb_value self)
return
mrb_float_value
(
f
);
}
else
{
mrb_float
f
,
f2
;
mrb_get_args
(
mrb
,
"f"
,
&
f2
);
mrb_float
f
;
f
=
((
mrb_float
)
tm
->
sec
+
(
mrb_float
)
tm
->
usec
/
1.0e6
);
return
mrb_time_make
(
mrb
,
mrb_obj_class
(
mrb
,
self
),
f
-
f2
,
tm
->
timezone
);
mrb_get_args
(
mrb
,
"f"
,
&
f
);
return
mrb_time_make
(
mrb
,
mrb_obj_class
(
mrb
,
self
),
tm
->
sec
-
f
,
tm
->
usec
,
tm
->
timezone
);
}
}
...
...
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