Commit 05721ed6 authored by Kurt Maute's avatar Kurt Maute

patch to correct week number by Maurice van der Pot

    libplanner/mrp-time.h
    libplanner/mrp-time.c
    src/planner-scale-utils.c
    data/stylesheets/html1_gantt.xsl

svn path=/trunk/; revision=850
parent d9757ae8
2007-07-28 Kurt Maute <kurt@maute.us>
Patch to correct week number by Maurice van der Pot <griffon26@kfk4ever.com>
*libplanner/mrp-time.c
*libplanner/mrp-time.h
*src/planner-scale-utils.c
*data/stylesheets/html1_gantt.xsl
2007-07-28 Kurt Maute <kurt@maute.us>
Two patches from Maurice van der Pot:
* src/planner-task-tree.c - disable selection updates before manipulating
......
......@@ -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">
......
......@@ -415,7 +415,7 @@ mrp_time_week_number (mrptime t)
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 @@ time_format_helper (const gchar *format,
/* 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 @@ stolen_g_date_get_iso8601_week_of_year (const GDate *d)
}
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
......
......@@ -146,7 +146,8 @@ time_t mrp_time2_get_epoch (MrpTime *t);
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,
......
......@@ -69,7 +69,7 @@ planner_scale_format_time (mrptime t,
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 @@ planner_scale_format_time (mrptime t,
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;
}
......
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