akr e$B$5$se(B
e$B1sF#$G$9!#e(B
Evan P. e$B$He(B Time e$B$N5sF0$K$D$$$FAjCL$7$?>e$Ge(B Time
e$B$K$D$$$F0l1~$Ne(B
e$B3NG’$G$9!#e(B
-
1.8 e$B$Ne(B Time#+ e$B$Oe(B usec e$B$G;M<N8^F~$7$F$$$^$9$,!“e(B1.9
e$B$G$O$7$^$;$s!#e(B
e$BFbItI=8=$,e(B Rational
e$B$K$J$C$?$N$@$+$iEvA3$@$H;W$$$^$9$,!”;EMMJQ99e(B
e$B$G$9$h$M!#e(B
-
1.8 e$B$Ne(B Time#usec e$B$de(B nsec
e$B$,;M<N8^F~$7$J$$$N$O;EMM$G$9$h$M!#e(B
usec e$B$,e(B 1000000 e$B$H$+$K$J$C$?$i7y$G$9$b$N$M!#e(B
e$B$=$&$@$h$s$H8@$C$F$/$@$5$l$P!"0J2<$N%3%%C%H$re(B rubyspec
e$B$K%3%%C%He(B
e$B$7$h$&$H;W$$$^$9!#e(B
diff --git a/core/time/plus_spec.rb b/core/time/plus_spec.rb
index 1f5c85f…e333430 100644
— a/core/time/plus_spec.rb
+++ b/core/time/plus_spec.rb
@@ -10,21 +10,33 @@ describe “Time#+” do
(Time.at(1.1) + 0.9).should == Time.at(0.9) + 1.1
end
- it “rounds micro seconds rather than truncates” do
-
The use of 8.9999999 is intentional. This is because
-
Time treats the fractional part as the number of micro seconds.
-
Thusly it multiplies the result by 1_000_000 to go from
-
seconds to microseconds. That conversion should be rounded
-
properly. In this case, it’s rounded up to 1,000,000, and thus
-
contributes a full extra second to the Time object.
- t = Time.at(0) + 8.9999999
- t.should == Time.at(9)
- t.usec.should == 0
- ruby_version_is “” … “1.9” do
- it “rounds micro seconds rather than truncates” do
-
# The use of 8.9999999 is intentional. This is because
-
# Time treats the fractional part as the number of micro seconds.
-
# Thusly it multiplies the result by 1_000_000 to go from
-
# seconds to microseconds. That conversion should be rounded
-
# properly. In this case, it's rounded up to 1,000,000, and thus
-
# contributes a full extra second to the Time object.
-
t = Time.at(0) + 8.9999999
-
t.should == Time.at(9)
-
t.usec.should == 0
-
-
# Check the non-edge case works properly, that the fractional
part
-
# contributes to #usecs
-
t2 = Time.at(0) + 8.9
-
t2.usec.should == 900000
- end
- end
-
Check the non-edge case works properly, that the fractional part
-
contributes to #usecs
- t2 = Time.at(0) + 8.9
- t2.usec.should == 900000
1_000_000_000_000_000)
-
t.should_not == Time.at(9)
-
t.usec.should == 999_999
-
t.nsec.should == 999_999_999
-
t.subsec.should == Rational(999_999_999_999_999,
1_000_000_000_000_000)
ruby_version_is “” … “1.9” do
2010e$BG/e(B2e$B7ne(B11e$BF|e(B2:58 Yusuke ENDOH [email protected]:
- 1.8 e$B$Ne(B Time#+ e$B$Oe(B usec e$B$G;M<N8^F~$7$F$$$^$9$,!“e(B1.9 e$B$G$O$7$^$;$s!#e(B
e$BFbItI=8=$,e(B Rational e$B$K$J$C$?$N$@$+$iEvA3$@$H;W$$$^$9$,!”;EMMJQ99e(B
e$B$G$9$h$M!#e(B
1.9.2 e$B$G$O$=$&$G$9!#e(B
1.9.1 e$B$NFbItI=8=$Oe(B nsec e$BC10L$J$N$G!"e(Bnsec
e$B$G;M<N8^F~$J$s$G$O$J$$$+$H;W$$$^$9!#e(B
- 1.8 e$B$Ne(B Time#usec e$B$de(B nsec e$B$,;M<N8^F~$7$J$$$N$O;EMM$G$9$h$M!#e(B
usec e$B$,e(B 1000000 e$B$H$+$K$J$C$?$i7y$G$9$b$N$M!#e(B
1.8 e$B$Ke(B nsec
e$B$O$“$j$^$;$s$,!”$^$!$=$&$J$i$6$k$rF@$J$$$G$9$+$M!#e(B
e$B7+$j>e$,$k@h$,$"$k>l9g$O$I$&$+$J$!!#e(B
e$B1sF#$G$9!#e(B
2010e$BG/e(B2e$B7ne(B11e$BF|e(B21:36 Tanaka A. [email protected]:
usec e$B$,e(B 1000000 e$B$H$+$K$J$C$?$i7y$G$9$b$N$M!#e(B
1.8 e$B$Ke(B nsec e$B$O$“$j$^$;$s$,!”$^$!$=$&$J$i$6$k$rF@$J$$$G$9$+$M!#e(B
e$B$"$j$,$H$&$4$6$$$^$9!#%3%_%C%H$5$;$FD:$-$^$7$?!#e(B
e$B$A$J$$Ke(B rubyspec e$B$Oe(B 1.9.1
e$B$N;EMM$rL5;k$9$kJ}?K$i$7$$$G$9e(B (1.9.1 e$B$He(B
1.9.2 e$B$N4V$G;EMMJQ99$,$"$j$9$.$@$+$ie(B) e$B!#$J$N$G!“e(B1.9
e$B$H=q$$$F$”$l$Pe(B
1.9.2 e$B0J9$r;X$9$H$$$&$3$H$G$9!#e(B
e$B7+$j>e$,$k@h$,$"$k>l9g$O$I$&$+$J$!!#e(B
e$B8D?ME*$K$O@Z$j<N$F$,$o$+$j$d$9$$$N$G$=$l$G$$$$$H;W$$$^$9$,!"JQ$($ke(B
e$B$J$iJQ$($F$b$i$C$F$b9=$o$J$$$G$9!#e(Brubyspec e$BB&$r=$@5$7$^$9!#e(B
個人的ã«ã¯åˆ‡ã‚Šæ¨ã¦ãŒã‚ã‹ã‚Šã‚„ã™ã„ã®ã§ãれã§ã„ã„ã¨æ€ã„ã¾ã™ãŒã€å¤‰ãˆã‚‹
ãªã‚‰å¤‰ãˆã¦ã‚‚らã£ã¦ã‚‚æ§‹ã‚ãªã„ã§ã™ã€‚rubyspec å´ã‚’ä¿®æ£ã—ã¾ã™ã€‚
仕掛ã‘ãŒã‚ã‹ã‚Šã‚„ã™ã„ã‹ã‚‰ã¨ã„ã£ã¦çµæžœãŒã‚ã‹ã‚Šã‚„ã™ã„ã‹ã¨ã„ã†ã¨
微妙ãªã®ã§ã¯ãªã„ã‹ã¨ã€‚
切りæ¨ã¦ã§å‡¦ç†ã™ã‚‹ã®ã¯å´–ã£ã·ã¡ã‚’æ©ãよã†ãªã‚‚ã®ã§ã€
ã²ã¨ã¤é–“é•ãˆã‚‹ã¨æ„図ã›ã–ã‚‹çµæžœã«ãªã‚ŠãŒã¡ã§ã™ã€‚
ã¨ã‚Šã‚ãˆãš Time#round(ndigits) ã¨ã‹ã©ã†ã‹ãªã。
Timeã®å…ƒãƒ‡ãƒ¼ã‚¿ã¯ä½•ãŒã‚ã‚‹ã‚“ã§ã—ょã†ï¼Ÿä¸€ç•ªè‹¦æƒ…ãŒãã‚‹ã®ã¯ oldtime > newtime ã¾ãŸã¯ oldtime > now
ã«ãªã£ã¦ã—ã¾ã†ã‚±ãƒ¼ã‚¹ã§ã€oldtimeãŒç²¾åº¦è½ã¨ã™ã¨ãã«åˆ‡ã‚Šä¸Šã’ã•れã¦ã„ã¦nowãŒé«˜ç²¾åº¦ã ã£ãŸã‚Šã™ã‚‹ã¨
èµ·ã“ã›ãã†ãªæ°—ãŒã—ã¾ã™ã€‚
個人的ã«ã¯åˆ‡ã‚Šæ¨ã¦ã«ä¸€ç¥¨ã§ã€ç†ç”±ã¯ã€Œãˆã€æ€ã£ã¦ãŸã‚ˆã‚Šã¡ã‚‡ã£ã¨å¤ã„時刻ã ã£ãŸï¼Ÿãりゃ測定ã—ã¦ã‚‹ã†ã¡ã«ã‚‚時間ã¯
経éŽã™ã‚‹ã‹ã‚‰ãHAHAHAã€ã§ã»ã¨ã‚“ã©ã®ã‚±ãƒ¼ã‚¹ã¯æ¸ˆã‚“ã§ã—ã¾ã†ã‚³ãƒ¼ãƒŠãƒ¼ã‚±ãƒ¼ã‚¹ã®å°‘ãªã•ã«åˆ©ç‚¹ãŒã‚ã‚‹ã‹ã¨ã€‚
2010e$BG/e(B2e$B7ne(B11e$BF|e(B21:58 Yusuke ENDOH [email protected]:
e$B8D?ME*$K$O@Z$j<N$F$,$o$+$j$d$9$$$N$G$=$l$G$$$$$H;W$$$^$9$,!"JQ$($ke(B
e$B$J$iJQ$($F$b$i$C$F$b9=$o$J$$$G$9!#e(Brubyspec e$BB&$r=$@5$7$^$9!#e(B
e$B;E3]$1$,$o$+$j$d$9$$$+$i$H$$$C$F7k2L$,$o$+$j$d$9$$$+$H$$$&$He(B
e$BHyL/$J$N$G$O$J$$$+$H!#e(B
e$B@Z$j<N$F$G=hM}$9$k$N$O33$C$W$A$rJb$/$h$&$J$b$N$G!"e(B
e$B$R$H$D4V0c$($k$H0U?^$;$6$k7k2L$K$J$j$,$A$G$9!#e(B
e$B$H$j$"$($:e(B Time#round(ndigits) e$B$H$+$I$&$+$J$!!#e(B
2010e$BG/e(B2e$B7ne(B11e$BF|e(B23:01 KOSAKI Motohiro
[email protected]:
Timee$B$N85%G!<%?$O2?$,$"$k$s$G$7$g$&!)0lHV6l>p$,$/$k$N$Oe(B oldtime > newtime e$B$^$?$Oe(B oldtime > now
e$B$K$J$C$F$7$^$&%1!<%9$G!"e(Boldtimee$B$,@:EYMn$H$9$H$-$K@Z$j>e$2$5$l$F$$$Fe(Bnowe$B$,9b@:EY$@$C$?$j$9$k$He(B
e$B5/$3$;$=$&$J5$$,$7$^$9!#e(B
e$B$9$0$K;W$$=P$;$k$N$Oe(B
- e$B8=:_;~9oe(B
gettimeofday e$B$N%^%$%/%mICe(B
clock_gettime e$B$N%J%NICe(B
- e$B%U%!%$%k$N%?%$%`%9%?%s%We(B
st_mtime e$B$J$I$NICe(B
st_mtim e$B$J$I$N%J%NICe(B
- e$B%Q%1%C%H$N%?%$%`%9%?%s%We(B
SCM_TIMESTAMP e$B$N%^%$%/%mICe(B
SCM_TIMESTAMPNS e$B$N%J%NICe(B
SCM_BINTIME e$B$Ne(B 2**(-64)e$BICe(B
- Ruby e$BFbe(B
DateTime e$B$NM-M}?te(B
- e$B3F<o%U%)!<%^%C%He(B
ISO 8601 e$B$Oe(B10e$B?J?t$G>.?tE@0J2<G$0U7eICe(B
e$B$/$i$$$+$J$!!#e(B
e$B$I$l$b@53N$Ke(B Time e$B$KJQ49$G$-$^$9!#e(B
e$B$^$!!"e(BTime e$B$NCf?H$Oe(B (e$B35G0E*$K$Oe(B) e$BM-M}?t$J$s$G!#e(B
e$B8D?ME*$K$O@Z$j<N$F$K0lI<$G!“M}M3$O!V$(!”;W$C$F$?$h$j$A$g$C$H8E$$;~9o$@$C$?!)$=$j$cB,Dj$7$F$k$&$A$K$b;~4V$Oe(B
e$B7P2a$9$k$+$i$Me(BHAHAHAe$B!W$G$[$H$s$I$N%1!<%9$O:Q$s$G$7$^$&%3!<%J!<%1!<%9$N>/$J$5$KMxE@$,$"$k$+$H!#e(B
e$B$J$k$[$I!#e(B
e$B$^$!!"$=$N$&$Ae(B
% ./ruby -ve ’
t = Time.new(1989,3,3)
p t, t + 0.3 + 0.7’
ruby 1.9.2dev (2010-02-11 trunk 26640) [i686-linux]
1989-03-03 00:00:00 +0900
1989-03-03 00:00:00 +0900
e$B$,JQ$@$H8@$$=P$9$R$H$,=P$F$/$k$s$8$c$J$$$+$J$!!"$H$$$&$/$i$$$NOC$J$N$G!“e(B
e$B8=<BE*$K@Z$j<N$F$KMxE@$,B?$$$J$i%G%U%)%k%H$=$C$A$H$$$&$N$O$”$j$&$ke(B
e$BA*Br;h$+$J$!!#e(B
e$B$=$l$O4]$a$?$$$H$-$K;H$($k%a%=%C%I$,$"$k$3$H$H$OL7=b$7$^$;$s$,!#e(B
e$B%A%1%C%He(B #2733 e$B$,99?7$5$l$^$7$?!#e(B (by Yusuke E.)
e$B%9%F!<%?%9e(B Assignede$B$+$ie(BRejectede$B$KJQ99e(B
e$B1sF#$G$9!#e(B
e$B2r7h:Q$_$J$N$Ge(B close e$B$7$^$9!#e(B
http://redmine.ruby-lang.org/issues/show/2733