Skip to content

Commit 33264fb

Browse files
committedOct 24, 2013
Fix Time#+ and Time#-
1 parent c723073 commit 33264fb

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed
 

‎corelib/time.rb

+15-2
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,24 @@ def self.parse(str)
9090
end
9191

9292
def +(other)
93-
Time.allocate(self.to_f + other.to_f)
93+
%x{
94+
if (other._isNumber) {
95+
return new Date(self.getTime() + (other * 1000));
96+
}
97+
}
98+
99+
raise TypeError, "Time#+"
94100
end
95101

96102
def -(other)
97-
Time.allocate(self.to_f - other.to_f)
103+
%x{
104+
if (other._isNumber) {
105+
return new Date(self.getTime() - (other * 1000));
106+
}
107+
else {
108+
return (self.getTime() - other.getTime()) / 1000;
109+
}
110+
}
98111
end
99112

100113
def <=>(other)

0 commit comments

Comments
 (0)
Please sign in to comment.