Commit c1508f6d authored by lpsolit%gmail.com's avatar lpsolit%gmail.com

Bug 315551: time summary split by month counts days twice - Patch by Miluse…

Bug 315551: time summary split by month counts days twice - Patch by Miluse Nemcova <miluse.nemcova@volny.cz> r=wicked a=justdave
parent ede2d35c
...@@ -38,17 +38,23 @@ GetVersionTable(); ...@@ -38,17 +38,23 @@ GetVersionTable();
# Date handling # Date handling
# #
sub date_adjust { sub date_adjust_down {
my ($year, $month, $day) = @_; my ($year, $month, $day) = @_;
if ($month == 13) { if ($day == 0) {
$month = 1; $month -= 1;
$year += 1; $day = 31;
# Proper day adjustment is done later.
if ($month == 0) {
$year -= 1;
$month = 12;
}
} }
if ($month == 2 && ($day == 31 || $day == 30 || $day == 29)) { if (($month == 2) && ($day > 28)) {
if ($year % 4 == 0) { if ($year % 4 == 0 && $year % 100 != 0) {
$day = 29; $day = 29;
} else { } else {
$day = 28; $day = 28;
...@@ -63,6 +69,36 @@ sub date_adjust { ...@@ -63,6 +69,36 @@ sub date_adjust {
return ($year, $month, $day); return ($year, $month, $day);
} }
sub date_adjust_up {
my ($year, $month, $day) = @_;
if ($day > 31) {
$month += 1;
$day = 1;
if ($month == 13) {
$month = 1;
$year += 1;
}
}
if ($month == 2 && $day > 28) {
if ($year % 4 != 0 || $year % 100 == 0 || $day > 29) {
$month = 3;
$day = 1;
}
}
if (($month == 4 || $month == 6 || $month == 9 || $month == 11) &&
($day == 31) )
{
$month += 1;
$day = 1;
}
return ($year, $month, $day);
}
sub check_dates { sub check_dates {
my ($start_date, $end_date) = @_; my ($start_date, $end_date) = @_;
if ($start_date) { if ($start_date) {
...@@ -96,46 +132,47 @@ sub split_by_month { ...@@ -96,46 +132,47 @@ sub split_by_month {
my (undef, undef, undef, $sd, $sm, $sy, undef) = strptime($start_date); my (undef, undef, undef, $sd, $sm, $sy, undef) = strptime($start_date);
my (undef, undef, undef, $ed, $em, $ey, undef) = strptime($end_date); my (undef, undef, undef, $ed, $em, $ey, undef) = strptime($end_date);
# Find out how many months fit between the two dates so we know many # Find out how many months fit between the two dates so we know
# many times we loop. # how many times we loop.
my $yd = $ey - $sy; my $yd = $ey - $sy;
my $md = 12 * $yd + $em - $sm; my $md = 12 * $yd + $em - $sm;
# If the end day is smaller than the start day, last interval is not a whole month.
if ($sd > $ed) {
$md -= 1;
}
my (@months, $sub_start, $sub_end); my (@months, $sub_start, $sub_end);
# This +1 and +1900 are a result of strptime's bizarre semantics # This +1 and +1900 are a result of strptime's bizarre semantics
my $year = $sy + 1900; my $year = $sy + 1900;
my $month = $sm + 1; my $month = $sm + 1;
# If both years and months were equals. # Keep the original date, when the date will be changed in the adjust_date.
if ($md == 0) {
push @months, [sprintf("%04d-%02d-%02d", $year, $month, $sd),
sprintf("%04d-%02d-%02d", $year, $month, $ed)];
return @months;
}
# Keep the original $sd, when the day will be changed in the adjust_date.
# Case day > 28 and month = 2, for instance.
my $sd_tmp = $sd; my $sd_tmp = $sd;
my $month_tmp = $month;
my $year_tmp = $year;
# This section handles only the whole months.
for (my $i=0; $i < $md; $i++) { for (my $i=0; $i < $md; $i++) {
($year, $month, $sd_tmp) = date_adjust($year, $month, $sd); # Start of interval is adjusted up: 31.2. -> 1.3.
$sub_start = sprintf("%04d-%02d-%02d", $year, $month, $sd_tmp); ($year_tmp, $month_tmp, $sd_tmp) = date_adjust_up($year, $month, $sd);
($year, $month, $sd_tmp) = date_adjust($year, $month + 1, $sd); $sub_start = sprintf("%04d-%02d-%02d", $year_tmp, $month_tmp, $sd_tmp);
$sub_end = sprintf("%04d-%02d-%02d", $year, $month, $sd_tmp); $month += 1;
if ($month == 13) {
$month = 1;
$year += 1;
}
# End of interval is adjusted down: 31.2 -> 28.2.
($year_tmp, $month_tmp, $sd_tmp) = date_adjust_down($year, $month, $sd - 1);
$sub_end = sprintf("%04d-%02d-%02d", $year_tmp, $month_tmp, $sd_tmp);
push @months, [$sub_start, $sub_end]; push @months, [$sub_start, $sub_end];
} }
# This section handles the last month for cases where the starting # This section handles the last (unfinished) month.
# day and ending day aren't identical; in this case we need to fudge $sub_end = sprintf("%04d-%02d-%02d", $ey + 1900, $em + 1, $ed);
# the last entry -- either add an extra one (for the extra days) or ($year_tmp, $month_tmp, $sd_tmp) = date_adjust_up($year, $month, $sd);
# swap the last one for a shorter one (for the fewer days). $sub_start = sprintf("%04d-%02d-%02d", $year_tmp, $month_tmp, $sd_tmp);
my $fixup = sprintf("%04d-%02d-%02d", $ey + 1900, $em + 1, $ed); push @months, [$sub_start, $sub_end];
if ($sd < $ed) {
push @months, [$sub_end, $fixup];
} elsif ($sd > $ed) {
pop @months;
push @months, [$sub_start, $fixup];
}
return @months; return @months;
} }
...@@ -179,8 +216,10 @@ sub sqlize_dates { ...@@ -179,8 +216,10 @@ sub sqlize_dates {
} }
if ($end_date) { if ($end_date) {
# we need to add one day to end_date to catch stuff done today # we need to add one day to end_date to catch stuff done today
# do not forget to adjust date if it was the last day of month
my (undef, undef, undef, $ed, $em, $ey, undef) = strptime($end_date); my (undef, undef, undef, $ed, $em, $ey, undef) = strptime($end_date);
$end_date = sprintf("%04d-%02d-%02d", $ey+1900, $em+1, $ed+1); ($ey, $em, $ed) = date_adjust_up($ey+1900, $em+1, $ed+1);
$end_date = sprintf("%04d-%02d-%02d", $ey, $em, $ed);
$date_bits .= " AND longdescs.bug_when < ?"; $date_bits .= " AND longdescs.bug_when < ?";
push @date_values, $end_date; push @date_values, $end_date;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment