From fded009425e4df5c5cfc1a0c3e8fef189bc736b6 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Tue, 10 May 2011 11:38:43 +0200 Subject: [PATCH 1/7] make date comparision correspond with labels --- lib/report/operator.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/report/operator.rb b/lib/report/operator.rb index 7bce779ee6..320b1be46f 100644 --- a/lib/report/operator.rb +++ b/lib/report/operator.rb @@ -148,14 +148,14 @@ class Report::Operator new " :label_less_or_equal, :validate => :dates do def modify(query, field, value) return query if value.to_s.empty? - "<".to_operator.modify query, field, quoted_date(value) + "<=".to_operator.modify query, field, quoted_date(value) end end new ">d", :label => :label_greater_or_equal, :validate => :dates do def modify(query, field, value) return query if value.to_s.empty? - ">".to_operator.modify query, field, quoted_date(value) + ">=".to_operator.modify query, field, quoted_date(value) end end From 34f6a60229c71874bfa85323c4f998f5381436ca Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Tue, 10 May 2011 12:05:47 +0200 Subject: [PATCH 2/7] use UTC week --- lib/report/operator.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/report/operator.rb b/lib/report/operator.rb index 320b1be46f..42f175fa65 100644 --- a/lib/report/operator.rb +++ b/lib/report/operator.rb @@ -37,7 +37,7 @@ class Report::Operator new "w", :arity => 0, :label => :label_this_week do def modify(query, field, offset = nil) offset ||= 0 - from = Time.now.at_beginning_of_week - ((I18n.t(:general_first_day_of_week).to_i % 7) + 1).days + from = Time.now.utc.at_beginning_of_week - ((I18n.t(:general_first_day_of_week).to_i % 7) + 1).days from -= offset.days '<>d'.to_operator.modify query, field, from, from + 7.days end From caf476b00351df23441ab0dc4a1d9832cc2bf9f3 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Tue, 10 May 2011 12:13:50 +0200 Subject: [PATCH 3/7] fix week start offset --- lib/report/operator.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/report/operator.rb b/lib/report/operator.rb index 42f175fa65..2785d7ad1a 100644 --- a/lib/report/operator.rb +++ b/lib/report/operator.rb @@ -37,7 +37,7 @@ class Report::Operator new "w", :arity => 0, :label => :label_this_week do def modify(query, field, offset = nil) offset ||= 0 - from = Time.now.utc.at_beginning_of_week - ((I18n.t(:general_first_day_of_week).to_i % 7) + 1).days + from = Time.now.utc.at_beginning_of_week + ((I18n.t(:general_first_day_of_week).to_i % 7) - 1).days from -= offset.days '<>d'.to_operator.modify query, field, from, from + 7.days end From 6aceb24c6969f7c38660436104a159b4868adaf9 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Tue, 10 May 2011 12:17:04 +0200 Subject: [PATCH 4/7] fail loud and clear if general_first_day_of_week is missing --- lib/report/operator.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/report/operator.rb b/lib/report/operator.rb index 2785d7ad1a..f3c832f644 100644 --- a/lib/report/operator.rb +++ b/lib/report/operator.rb @@ -37,7 +37,7 @@ class Report::Operator new "w", :arity => 0, :label => :label_this_week do def modify(query, field, offset = nil) offset ||= 0 - from = Time.now.utc.at_beginning_of_week + ((I18n.t(:general_first_day_of_week).to_i % 7) - 1).days + from = Time.now.utc.at_beginning_of_week + (Integer(I18n.t(:general_first_day_of_week)) % 7) - 1).days from -= offset.days '<>d'.to_operator.modify query, field, from, from + 7.days end From 984099f083b4266769843ec31864a2947fdc0825 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Tue, 10 May 2011 12:27:28 +0200 Subject: [PATCH 5/7] fall back to monday if first day of week is not set --- lib/report/operator.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/report/operator.rb b/lib/report/operator.rb index f3c832f644..0d21f4a136 100644 --- a/lib/report/operator.rb +++ b/lib/report/operator.rb @@ -36,8 +36,14 @@ class Report::Operator new "w", :arity => 0, :label => :label_this_week do def modify(query, field, offset = nil) - offset ||= 0 - from = Time.now.utc.at_beginning_of_week + (Integer(I18n.t(:general_first_day_of_week)) % 7) - 1).days + offset ||= 0 + first_day = begin + Integer I18n.t(:general_first_day_of_week) + rescue ArgumentError + 1 # assume mondays + end + + from = Time.now.utc.at_beginning_of_week + (first_day % 7) - 1).days from -= offset.days '<>d'.to_operator.modify query, field, from, from + 7.days end From 927feda8da9eca30d129417a97550794a0cd1115 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Tue, 10 May 2011 13:40:19 +0200 Subject: [PATCH 6/7] fix syntax --- lib/report/operator.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/report/operator.rb b/lib/report/operator.rb index 0d21f4a136..9001ae28ed 100644 --- a/lib/report/operator.rb +++ b/lib/report/operator.rb @@ -43,7 +43,7 @@ class Report::Operator 1 # assume mondays end - from = Time.now.utc.at_beginning_of_week + (first_day % 7) - 1).days + from = Time.now.utc.at_beginning_of_week + ((first_day % 7) - 1).days from -= offset.days '<>d'.to_operator.modify query, field, from, from + 7.days end From 2bb2fa5160411b2a1c6842cd383521046eecd9e7 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 11 May 2011 11:53:41 +0200 Subject: [PATCH 7/7] use UTC for DateRange, fixes #19263 --- lib/report/operator.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/report/operator.rb b/lib/report/operator.rb index 9001ae28ed..8365ea029d 100644 --- a/lib/report/operator.rb +++ b/lib/report/operator.rb @@ -277,8 +277,8 @@ class Report::Operator module DateRange def modify(query, field, from, to) - query.where ["#{field} > '%s'", quoted_date((Date.yesterday + from).to_time.end_of_day)] if from - query.where ["#{field} <= '%s'", quoted_date((Date.today + to).to_time.end_of_day)] if to + query.where ["#{field} > '%s'", quoted_date((Date.yesterday + from).to_time.utc.end_of_day)] if from + query.where ["#{field} <= '%s'", quoted_date((Date.today + to).to_time.utc.end_of_day)] if to query end end