This project is archived and is in readonly mode.
time.end_of_day not entirely accurate
-
Pratik
- Assigned user set to Geoff Buesing
-
Geoff Buesing
- Tag changed from activesupport, time, timestamps to activesupport, time, usec
- State changed from new to open
I can see how this would result unexpected behavior when you're sorting or comparing based on a timestamp -- you'd assume, for example, that any record that was created after the #end_of_day was created on the next day, but this would not necessarily be the case.
If we're going to go ahead and change #end_of_day, we should also change the other end_of_ methods: #end_of_week, #end_of_month, #end_of_quarter, #end_of_year.
Existing tests for these methods would break when we added :usec => 999999 to their implementations, so we'd need a patch that changed implementations and tests for these methods.
-
CancelProfileIsBroken
- Tag changed from activesupport, time, usec to activesupport, bugmash, time, usec
-
Matt Duncan
Attached patch to fix all of the end_of methods: #end_of_day, #end_of_week, #end_of_month, #end_of_quarter, and #end_of_year. I've also updated the tests for these methods to check for the correct usec value.
-
Geoff Buesing
@Matt - thanks for this patch.
One issue: your updated docs for Date#end_of_ methods say that "DateTime objects will have time set to 23:59:59.999999", but this isn't true -- the existing tests confirm this (you're passing a :usec value into DateTime change, but that doesn't do anything.)
We could go forward without worrying about DateTime. DateTime has a weird sec_fraction value that's a Rational; I don't know how that would translate into usec, or something similar.
-
Matt Duncan
@Geoff - Here is the fixed patch, it includes only changes to the Time#end_of_ methods.
-
Josh Sharpe
The patch applies successfully and all tests pass.
The tests look good, and the new functionality makes sense to me.
+1
-
Hugo Peixoto
+1 for the idea, but the patch doesn't apply to 2-3-stable. I've attached a patch that works. It was probably due to all the recent commits or something.
-
Rizwan Reza
verified
+1 The patch by Hugo works on 2-3-stable.
-
Matt Duncan
Hugo, I see the following two stylistic items got changed in your patch (vs my original):
# Extra space before closing paren: last_day = ::Time.days_in_month( self.month, self.year ) # Missing space after first comma: # (and while it's being fixed, the spacing around the second comma could probably be fixed also) change(:month => 12,:day => 31,:hour => 23, :min => 59, :sec => 59) -
Kieran P
+1 for Hugo's patch for 2-3. Uploading one compatible with master branch.
-
Kieran P
- Title changed from time.end_of_day not entirely accurate to [PATCH] time.end_of_day not entirely accurate
-
Jeremy Kemper
- State changed from incomplete to open
One downside is that this complicates compatibility with Ruby 1.9.2. It has Time#nsec - nanosecond resolution.
-
Jeremy Kemper
- Title changed from [PATCH] time.end_of_day not entirely accurate to time.end_of_day not entirely accurate
-
Hugo Peixoto
I've attached a patch for master that supposedly on master, with both ruby1.8 and 1.9. Please test it, as my 1.9 setup is kind of broken.
-
railsbob
+1 Hugo's patch applied cleanly on master, with ruby 1.8
-
Nikolay Petrachkov
+1 Hugo's patch applied on master with ruby 1.9.2.
-
Hugo Peixoto
Here's the 2-3-stable patch. Please test it in ruby 1.9.
-
José Valim
Both patches (master and 2-3) pass on both 1.8.7 and 1.9.1.
-
José Valim
- Tag changed from activesupport, bugmash, time, usec to activesupport, time, usec
- State changed from open to resolved
-
Repository
(from [3545d6b0b227cc9ee4a645097bdbd43b33b42a87]) Setting usec (and nsec for Ruby 1.9) on Time#end_of_* methods [#1255 time.end_of_day not entirely accurate status:resolved]
Signed-off-by: José Valim jose.valim@gmail.com
http://github.com/rails/rails/commit/3545d6b0b227cc9ee4a645097bdbd4...
