* [ruby-core:117132] [Ruby master Bug#20334] Time.to_i truncates a fractional timestamp instead of rounding up @ 2024-03-14 0:26 werelnon (Malcolm Patterson) via ruby-core 2024-03-14 1:37 ` [ruby-core:117133] " nobu (Nobuyoshi Nakada) via ruby-core 2024-03-14 13:08 ` [ruby-core:117167] " werelnon (Malcolm Patterson) via ruby-core 0 siblings, 2 replies; 3+ messages in thread From: werelnon (Malcolm Patterson) via ruby-core @ 2024-03-14 0:26 UTC (permalink / raw To: ruby-core; +Cc: werelnon (Malcolm Patterson) Issue #20334 has been reported by werelnon (Malcolm Patterson). ---------------------------------------- Bug #20334: Time.to_i truncates a fractional timestamp instead of rounding up https://bugs.ruby-lang.org/issues/20334 * Author: werelnon (Malcolm Patterson) * Status: Open * ruby -v: 3.2.2 * Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- Simple steps that can be executed in a ruby interactive shell ``` irb(main):007> t = Time.now => 2024-03-14 00:23:55.983885525 +0000 irb(main):008> t.to_f => 1710375835.9838855 irb(main):009> t.to_i => 1710375835 ``` Based on the example the result of `t.to_f.round` is the better result? -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/ ^ permalink raw reply [flat|nested] 3+ messages in thread
* [ruby-core:117133] [Ruby master Bug#20334] Time.to_i truncates a fractional timestamp instead of rounding up 2024-03-14 0:26 [ruby-core:117132] [Ruby master Bug#20334] Time.to_i truncates a fractional timestamp instead of rounding up werelnon (Malcolm Patterson) via ruby-core @ 2024-03-14 1:37 ` nobu (Nobuyoshi Nakada) via ruby-core 2024-03-14 13:08 ` [ruby-core:117167] " werelnon (Malcolm Patterson) via ruby-core 1 sibling, 0 replies; 3+ messages in thread From: nobu (Nobuyoshi Nakada) via ruby-core @ 2024-03-14 1:37 UTC (permalink / raw To: ruby-core; +Cc: nobu (Nobuyoshi Nakada) Issue #20334 has been updated by nobu (Nobuyoshi Nakada). Status changed from Open to Feedback It is the intended behavior. http://ruby-doc.com/3.2.2/Time.html#class-Time-label-Epoch+Seconds > Other retrieval methods such as `Time#to_i` and `Time#to_f` > may return a value that rounds or truncates subseconds. ---------------------------------------- Bug #20334: Time.to_i truncates a fractional timestamp instead of rounding up https://bugs.ruby-lang.org/issues/20334#change-107209 * Author: werelnon (Malcolm Patterson) * Status: Feedback * ruby -v: 3.2.2 * Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- Simple steps that can be executed in a ruby interactive shell ``` irb(main):007> t = Time.now => 2024-03-14 00:23:55.983885525 +0000 irb(main):008> t.to_f => 1710375835.9838855 irb(main):009> t.to_i => 1710375835 ``` Based on the example the result of `t.to_f.round` is the better result? -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/ ^ permalink raw reply [flat|nested] 3+ messages in thread
* [ruby-core:117167] [Ruby master Bug#20334] Time.to_i truncates a fractional timestamp instead of rounding up 2024-03-14 0:26 [ruby-core:117132] [Ruby master Bug#20334] Time.to_i truncates a fractional timestamp instead of rounding up werelnon (Malcolm Patterson) via ruby-core 2024-03-14 1:37 ` [ruby-core:117133] " nobu (Nobuyoshi Nakada) via ruby-core @ 2024-03-14 13:08 ` werelnon (Malcolm Patterson) via ruby-core 1 sibling, 0 replies; 3+ messages in thread From: werelnon (Malcolm Patterson) via ruby-core @ 2024-03-14 13:08 UTC (permalink / raw To: ruby-core; +Cc: werelnon (Malcolm Patterson) Issue #20334 has been updated by werelnon (Malcolm Patterson). Bit vague to say in the docs that `to_i` and `to_f` "may return a value that rounds or truncates". Why not just say it truncates? Regardless, I can live with it :) ---------------------------------------- Bug #20334: Time.to_i truncates a fractional timestamp instead of rounding up https://bugs.ruby-lang.org/issues/20334#change-107258 * Author: werelnon (Malcolm Patterson) * Status: Feedback * ruby -v: 3.2.2 * Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- Simple steps that can be executed in a ruby interactive shell ``` irb(main):007> t = Time.now => 2024-03-14 00:23:55.983885525 +0000 irb(main):008> t.to_f => 1710375835.9838855 irb(main):009> t.to_i => 1710375835 ``` Based on the example the result of `t.to_f.round` is the better result? -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/ ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-03-14 13:08 UTC | newest] Thread overview: 3+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2024-03-14 0:26 [ruby-core:117132] [Ruby master Bug#20334] Time.to_i truncates a fractional timestamp instead of rounding up werelnon (Malcolm Patterson) via ruby-core 2024-03-14 1:37 ` [ruby-core:117133] " nobu (Nobuyoshi Nakada) via ruby-core 2024-03-14 13:08 ` [ruby-core:117167] " werelnon (Malcolm Patterson) via ruby-core
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).