Re: [PATCH] Correct week number in UI and HTML output



On Sat, Jul 28, 2007 at 01:52:36PM -0400, Kurt Maute wrote:
> I get a hunk failure on this patch.
> Could you correct and resend?

Here you go.

Maurice.

-- 
Maurice van der Pot

Gentoo Linux Developer   griffon26 gentoo org     http://www.gentoo.org
Creator of BiteMe!       griffon26 kfk4ever com   http://www.kfk4ever.com

Index: libplanner/mrp-time.h
===================================================================
--- libplanner/mrp-time.h	(revision 849)
+++ libplanner/mrp-time.h	(working copy)
@@ -146,7 +146,8 @@
 const gchar *mrp_time2_get_day_name      (MrpTime     *t);
 const gchar *mrp_time2_get_month_name    (MrpTime     *t);
 const gchar *mrp_time2_get_month_initial (MrpTime     *t);
-gint         mrp_time2_get_week_number   (MrpTime     *t);
+gint         mrp_time2_get_week_number   (MrpTime     *t, 
+					  gint        *year);
 void         mrp_time2_align_prev        (MrpTime     *t,
 					  MrpTimeUnit  unit);
 void         mrp_time2_align_next        (MrpTime     *t,
Index: libplanner/mrp-time.c
===================================================================
--- libplanner/mrp-time.c	(revision 849)
+++ libplanner/mrp-time.c	(working copy)
@@ -415,7 +415,7 @@
 	
 	mrp_time2_set_epoch (&t2, t);
 	
-	return mrp_time2_get_week_number (&t2);
+	return mrp_time2_get_week_number (&t2, NULL);
 }
 
 /**
@@ -839,7 +839,7 @@
 			/* The week number, (1 - 53), starting with the first
 			 *  Monday as the first day of week 1.
 			 */
-			snprintf (str, sizeof (str), "%d", mrp_time2_get_week_number (t));
+			snprintf (str, sizeof (str), "%d", mrp_time2_get_week_number (t, NULL));
 			if (buffer) {
 				strcpy (buffer + len, str);
 			}
@@ -1348,11 +1348,39 @@
 }
 
 gint
-mrp_time2_get_week_number (MrpTime *t)
+mrp_time2_get_week_number (MrpTime *t, gint *y)
 {
+	gint week;
+	gint year;
+
 	g_return_val_if_fail (t != NULL, 0);
 
-	return stolen_g_date_get_iso8601_week_of_year (&t->date);
+	week = stolen_g_date_get_iso8601_week_of_year (&t->date);
+
+	/* Calculate the year this week belongs to as it can be different than 
+	 * the year of the date (e.g. December 31 2002 is in week 1 of 2003).
+	 */
+	if(y != NULL) {
+		year = g_date_get_year (&t->date);
+  
+		switch(g_date_get_month (&t->date)) {
+		case G_DATE_JANUARY:
+			if(week > 50) {
+				year--;
+			}
+			break;
+		case G_DATE_DECEMBER:
+			if(week == 1) {
+				year++;
+			}
+			break;
+		default:
+			break;
+		}
+
+		*y = year;
+	}
+	return week;
 }
 
 void
Index: src/planner-scale-utils.c
===================================================================
--- src/planner-scale-utils.c	(revision 849)
+++ src/planner-scale-utils.c	(working copy)
@@ -69,7 +69,7 @@
 	MrpTime *t2;
 	gchar   *str = NULL;
 	gint     num;
-	gint     year, month, day;
+	gint     year, month, week, day;
 	gint     hour, min, sec;
 
 	t2 = mrp_time2_new ();
@@ -127,16 +127,17 @@
 		case PLANNER_SCALE_FORMAT_SHORT:
 			/* i18n: Short "Week", preferably 2 letters. */
 			str = g_strdup_printf (_("Wk %d"),
-					       mrp_time2_get_week_number (t2));
+					       mrp_time2_get_week_number (t2, NULL));
 			break;
 		case PLANNER_SCALE_FORMAT_MEDIUM:
 			str = g_strdup_printf (_("Week %d"),
-					       mrp_time2_get_week_number (t2));
+					       mrp_time2_get_week_number (t2, NULL));
 			break; 
 		case PLANNER_SCALE_FORMAT_LONG:
 			/* i18n: Week, year. */
+			week = mrp_time2_get_week_number (t2, &year),
 			str = g_strdup_printf (_("Week %d, %d"),
-					       mrp_time2_get_week_number (t2),
+					       week,
 					       year);
 			break;
 		}
Index: data/stylesheets/html1_gantt.xsl
===================================================================
--- data/stylesheets/html1_gantt.xsl	(revision 849)
+++ data/stylesheets/html1_gantt.xsl	(working copy)
@@ -19,7 +19,10 @@
   <xsl:choose>
     <xsl:when test="date:day-in-week($date) = 2 and $days >= 7">
       <th class="gantt-week-header" align="center" colspan="7">
-        <xsl:value-of select="I18N:gettext('Week')"/>&nbsp;<xsl:value-of select="date:week-in-year($date) + 1"/>, <xsl:value-of select="date:year($date)"/>
+        <!-- A week that crosses a year boundary is associated with the year that its thursday is in.
+             This means that the year of any thursday date is always equal to the year of the week number.
+             Because the date at this point is always a monday, we can add 3 days to get to the year for this week. -->
+        <xsl:value-of select="I18N:gettext('Week')"/>&nbsp;<xsl:value-of select="date:week-in-year($date)"/>, <xsl:value-of select="date:year(date:add($date, date:duration(86400 * 3)))"/>
       </th>
       <xsl:if test="not($days = 7)">
         <xsl:call-template name="create-week-row">

Attachment: pgprxh2rs8DC6.pgp
Description: PGP signature



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]