[#66126] Creation/Conversion methods/functions table for Ruby types — SASADA Koichi <ko1@...>
Hi,
5 messages
2014/11/07
[#66248] [ruby-trunk - Feature #10423] [PATCH] opt_str_lit*: avoid literal string allocations — normalperson@...
Issue #10423 has been updated by Eric Wong.
3 messages
2014/11/13
[#66595] [ruby-trunk - Bug #10557] [Open] Block not given when the argument is a string — bartosz@...
Issue #10557 has been reported by Bartosz Kopinski.
3 messages
2014/11/30
[ruby-core:66494] [ruby-trunk - Feature #10544] Time#to_i(:millisecond)
From:
davidm@...
Date:
2014-11-26 19:14:50 UTC
List:
ruby-core #66494
Issue #10544 has been updated by David MacMahon. How about a more general `Time#to_i(scale=1)`? Examples: * Passing `1` for `scale` (or passing nothing) would return seconds. * Passing `1000` for `scale` would return milliseconds. * Passing `1/60r` for scale would return minutes. Masaki Matsushita wrote: > > ~~~ruby > milliseconds = (time.to_i * 1000) + (time.usec / 1000.0).round > ~~~ IMHO, it is generally preferable to avoid time travel by truncating to the beginning of the "present" millisecond rather than possibly rounding to the beginning of the "future" millisecond. ---------------------------------------- Feature #10544: Time#to_i(:millisecond) https://bugs.ruby-lang.org/issues/10544#change-50110 * Author: Masaki Matsushita * Status: Open * Priority: Normal * Assignee: * Category: core * Target version: next minor ---------------------------------------- Currently, we have to take an indirect way to get unix_time in milliseconds. ~~~ruby time = Time.now milliseconds = (time.to_i * 1000) + (time.usec / 1000.0).round ~~~ I think it would be convenient if `Time#to_i` accepts unit parameter like following. ~~~ruby time = Time.now milliseconds = time.to_i(:millisecond) ~~~ ---Files-------------------------------- patch.diff (2.71 KB) -- https://bugs.ruby-lang.org/