プロジェクト

全般

プロフィール

Vote #68892

完了

Date range error on issue query

Admin Redmine さんがほぼ4年前に追加. ほぼ4年前に更新.

ステータス:
Closed
優先度:
通常
担当者:
-
カテゴリ:
Issues_2
対象バージョン:
開始日:
2011/01/03
期日:
進捗率:

0%

予定工数:
category_id:
2
version_id:
27
issue_org_id:
7218
author_id:
3866
assigned_to_id:
0
comments:
4
status_id:
5
tracker_id:
1
plus1:
0
affected_version:
closed_on:
affected_version_id:
ステータス-->[Closed]

説明

When filtering issues for "this week" on issues the ranges are broken on core as well as on custom fields. The following examples were all tested against r4471 on MySQL with german locale (week starts on monday), the tests were realized on a sqlite installation too yielding similar but sometimes even "more broken" results.

When filtering issues for "this week" on core issue field, for example "Due date", the query returns results for 8 days instead of 7. This query executed today returns results from 03.01.2011 to 10.01.2011 (both dates included), whereas the current week is from 03.01.2011 to 09.01.2011.

When filtering issues for "this week" on a custom issue field with the type date, the query doesn't return results for the first day of the expected range (in this case monday) but does return them for one extra day at the end of the range. This query executed today returns results from 04.01.2011 to 10.01.2011 (both dates included), whereas the current week is from 03.01.2011 to 09.01.2011.


journals

The culprit is source:/trunk/app/models/query.rb#L606, though I'm not sure where the problem is (I'd wager it has something to do with querying a date column with time values), but using the same "trick"/hack as in r2054, I was able to produce following diff:

<pre><code class="diff">diff --git a/app/models/query.rb b/app/models/query.rb
index 7a42de1..b1b919d 100644
--- a/app/models/query.rb
+++ b/app/models/query.rb
@@ -602,7 +602,7 @@ class Query < ActiveRecord::Base
((Date.today.cwday == 7) ? Time.now.at_beginning_of_day : Time.now.at_beginning_of_week - 1.day) :
# week starts on monday (Rails default)
Time.now.at_beginning_of_week
- sql = "#{db_table}.#{db_field} BETWEEN '%s' AND '%s'" % [connection.quoted_date(from), connection.quoted_date(from + 7.days)]
+ sql = "#{db_table}.#{db_field} BETWEEN '%s' AND '%s'" % [connection.quoted_date((from - 1.day).to_time.end_of_day), connection.quoted_date((from + 6.days).to_time.end_of_day)]
when "l"
from = l(:general_first_day_of_week) == '7' ?
# week starts on sunday</code></pre>

This seems to alleviate the problem for me on MySQL and as far as I tested it on SQLite too. I'd really like this operator tested though (currently the only test done is if it runs, not if the result is correct), but I haven't come up with a good way to do it yet.
--------------------------------------------------------------------------------
(I missed a part of the diff in the reply above, I have edited it to include the missing part, sorry)
--------------------------------------------------------------------------------
See that on this site, but isn't it due to localization ? I'm on GMT+1, what timezone is Redmine website running in ?
--------------------------------------------------------------------------------
Fixed in r5596 using @#date_range_clause@.
--------------------------------------------------------------------------------

Admin Redmine さんがほぼ4年前に更新

  • カテゴリIssues_2 にセット
  • 対象バージョン1.2.0_27 にセット

他の形式にエクスポート: Atom PDF

いいね!0
いいね!0