Permalink
Browse files

weeks start at sunday, fix mysql weeks range counting

  • Loading branch information...
1 parent ed7681e commit 69b8eb379adee461116a5b646dce2b26457d6a73 @mszczytowski mszczytowski committed Jan 26, 2009
Showing with 5 additions and 6 deletions.
  1. +3 −3 lib/redmine_charts/date_format.rb
  2. +2 −3 lib/redmine_charts/range_utils.rb
@@ -6,7 +6,7 @@ module DateFormat
def format_date(format, column)
case format
when :weeks
- "(case when date_format(#{column}, '%d') < date_format(#{column}, '%w') then date_format(date_add(#{column}, interval - 7 day), '%Y%m%d') - date_format(#{column}, '%w') + 8 else date_format(#{column}, '%Y%m%d') - date_format(#{column}, '%w') + 1 end)"
+ "(case when cast(date_format(#{column}, '%d') as unsigned) <= cast(date_format(#{column}, '%w') as unsigned) then date_format(date_add(#{column}, interval - 7 day), '%Y%m%d') - date_format(#{column}, '%w') + 7 else date_format(#{column}, '%Y%m%d') - date_format(#{column}, '%w') end)"
when :months
"date_format(#{column}, '%Y%m01')"
else
@@ -17,7 +17,7 @@ def format_date(format, column)
def format_date(format, column)
case format
when :weeks
- "(case when date_part('days', #{column}) < date_part('dow', #{column}) then cast(to_char(#{column} - interval '7 days','YYYYMMDD') as integer) - date_part('dow', #{column}) + 8 else cast(to_char(#{column},'YYYYMMDD') as integer) - date_part('dow', #{column}) + 1 end)"
+ "(case when date_part('days', #{column}) <= date_part('dow', #{column}) then cast(to_char(#{column} - interval '7 days','YYYYMMDD') as integer) - date_part('dow', #{column}) + 7 else cast(to_char(#{column},'YYYYMMDD') as integer) - date_part('dow', #{column}) end)"
when :months
"to_char(#{column},'YYYYMM01')"
else
@@ -28,7 +28,7 @@ def format_date(format, column)
def format_date(format, column)
case format
when :weeks
- "(case when cast(strftime('%d', #{column}) as 'integer') < strftime('%w', #{column}) then strftime('%Y%m%d', date(#{column}, '-7 day')) - strftime('%w', #{column}) + 8 else strftime('%Y%m%d', #{column}) - strftime('%w', #{column}) + 1 end)"
+ "(case when cast(strftime('%d', #{column}) as 'integer') <= strftime('%w', #{column}) then strftime('%Y%m%d', date(#{column}, '-7 day')) - strftime('%w', #{column}) + 7 else strftime('%Y%m%d', #{column}) - strftime('%w', #{column}) end)"
when :months
"strftime('%Y%m01', #{column})"
else
@@ -65,7 +65,7 @@ def self.get_label(from, to, type)
year_to = to.strftime("%y")
month_to = to.strftime("%b")
- day_to = to.strftime("%d").to_i # - 1
+ day_to = to.strftime("%d").to_i
if year_from != year_to
return "#{day_from} #{month_from} #{year_from} - #{day_to} #{month_to} #{year_to}"
@@ -92,8 +92,7 @@ def self.get_times(steps, offset, i, type)
]
else
time = ((steps*offset)-i-1).send(type).ago
- day_of_week = time.strftime('%w').to_i - 1
- day_of_week = 7 if day_of_week < 0
+ day_of_week = time.strftime('%w').to_i
time -= day_of_week.days
time2 = time + 6.days
[

0 comments on commit 69b8eb3

Please sign in to comment.