summaryrefslogtreecommitdiff
path: root/time.c
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2022-12-16 11:55:54 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2022-12-16 22:52:59 +0900
commit0a2f300a8a21e013e5debb639adba77fb18b5f40 (patch)
tree5e8ad9b27e1f25f7cf521106e9b9ea8fdd8da849 /time.c
parent8c272f44816f098c1e057c72a47451efc8cd1739 (diff)
downloadruby-0a2f300a8a21e013e5debb639adba77fb18b5f40.tar.gz
[Feature #18033] Name a magic number
Diffstat (limited to 'time.c')
-rw-r--r--time.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/time.c b/time.c
index 560414e1f7..593941c29e 100644
--- a/time.c
+++ b/time.c
@@ -2532,12 +2532,16 @@ time_init_parse(rb_execution_context_t *ec, VALUE time, VALUE str, VALUE zone)
}
if (!NIL_P(subsec)) {
/* subseconds is the last using ndigits */
- if (ndigits < 9) {
- VALUE mul = rb_int_positive_pow(10, 9 - ndigits);
+ static const size_t TIME_SCALE_NUMDIGITS =
+ /* TIME_SCALE should be 10000... */
+ rb_strlen_lit(STRINGIZE(TIME_SCALE)) - 1;
+
+ if (ndigits < TIME_SCALE_NUMDIGITS) {
+ VALUE mul = rb_int_positive_pow(10, TIME_SCALE_NUMDIGITS - ndigits);
subsec = rb_int_mul(subsec, mul);
}
- else if (ndigits > 9) {
- VALUE num = rb_int_positive_pow(10, ndigits - 9);
+ else if (ndigits > TIME_SCALE_NUMDIGITS) {
+ VALUE num = rb_int_positive_pow(10, ndigits - TIME_SCALE_NUMDIGITS);
subsec = rb_rational_new(subsec, num);
}
}