From 24c23c23f4abcbfe556f2b76c081bcbb43c286a2 Mon Sep 17 00:00:00 2001 From: AJ Lewis Date: Fri, 7 Sep 2012 10:09:50 -0500 Subject: [PATCH] Remove weekStartsMonday and weekStartsSunday and replace with weekStartsOn This change allows the work week to start on any day - this is 0-based starting with Sunday. --- lib/taskjuggler/Limits.rb | 8 ++++---- lib/taskjuggler/Project.rb | 6 +++--- lib/taskjuggler/Tj3Config.rb | 4 ++-- lib/taskjuggler/TjTime.rb | 12 ++++++++---- lib/taskjuggler/TjpSyntaxRules.rb | 26 +++++++++++++------------- lib/taskjuggler/reports/GanttChart.rb | 10 +++++----- lib/taskjuggler/reports/GanttHeader.rb | 2 +- lib/taskjuggler/reports/TableReport.rb | 6 +++--- 8 files changed, 39 insertions(+), 35 deletions(-) diff --git a/lib/taskjuggler/Limits.rb b/lib/taskjuggler/Limits.rb index 8ef5eab6..8bbe2a30 100644 --- a/lib/taskjuggler/Limits.rb +++ b/lib/taskjuggler/Limits.rb @@ -197,14 +197,14 @@ def setLimit(name, value, interval = nil, resource = nil) upper = false when 'weeklymax' iv.start = iv.startDate.beginOfWeek( - @project['weekStartsMonday']) - iv.end = iv.endDate.beginOfWeek(@project['weekStartsMonday']) + @project['weekStartsOn']) + iv.end = iv.endDate.beginOfWeek(@project['weekStartsOn']) period = 60 * 60 * 24 * 7 upper = true when 'weeklymin' iv.start = iv.startDate.beginOfWeek( - @project['weekStartsMonday']) - iv.end = iv.endDate.beginOfWeek(@project['weekStartsMonday']) + @project['weekStartsOn']) + iv.end = iv.endDate.beginOfWeek(@project['weekStartsOn']) period = 60 * 60 * 24 * 7 upper = false when 'monthlymax' diff --git a/lib/taskjuggler/Project.rb b/lib/taskjuggler/Project.rb index 48b42cac..6f2704f7 100644 --- a/lib/taskjuggler/Project.rb +++ b/lib/taskjuggler/Project.rb @@ -98,7 +98,7 @@ def initialize(id, name, version) 'timezone' => TjTime.timeZone, 'trackingScenarioIdx' => nil, 'version' => version || "1.0", - 'weekStartsMonday' => true, + 'weekStartsOn' => 0, 'workinghours' => nil, 'yearlyworkingdays' => 260.714 } @@ -450,8 +450,8 @@ def initialize(id, name, version) true, false, false, nil ], [ 'tree', 'Tree Index', StringAttribute, false, false, false, "" ], - [ 'weekStartsMonday', 'Week Starts Monday', BooleanAttribute, - true, true, false, false ], + [ 'weekStartsOn', 'Week Starts On', FixnumAttribute, + true, true, false, 0 ], [ 'width', 'Width', FixnumAttribute, true, false, false, 640 ] ] diff --git a/lib/taskjuggler/Tj3Config.rb b/lib/taskjuggler/Tj3Config.rb index 438bae63..39e2d32f 100644 --- a/lib/taskjuggler/Tj3Config.rb +++ b/lib/taskjuggler/Tj3Config.rb @@ -16,10 +16,10 @@ AppConfig.version = '3.3.0' AppConfig.packageName = 'taskjuggler' -AppConfig.softwareName = 'TaskJuggler' +AppConfig.softwareName = 'TaskJuggler-AJL' AppConfig.packageInfo = 'A Project Management Software' AppConfig.copyright = [ (2006..2012).to_a ] -AppConfig.authors = [ 'Chris Schlaeger ' ] +AppConfig.authors = [ 'Chris Schlaeger ', 'AJ Lewis ' ] AppConfig.contact = 'http://www.taskjuggler.org' AppConfig.license = <<'EOT' This program is free software; you can redistribute it and/or modify it under diff --git a/lib/taskjuggler/TjTime.rb b/lib/taskjuggler/TjTime.rb index d516eb32..91789f8a 100644 --- a/lib/taskjuggler/TjTime.rb +++ b/lib/taskjuggler/TjTime.rb @@ -205,19 +205,23 @@ def midnight TjTime.new([ year, month, day, hour, min, sec, 0 ]) end - # Normalize time to the beginning of the current week. _startMonday_ - # determines whether the week should start on Monday or Sunday. - def beginOfWeek(startMonday) + # Normalize time to the beginning of the current week. _startOn_ + # determines what day the week should start on + def beginOfWeek(startOn) t = localtime.to_a # Set time to noon, 12:00:00 t[0, 3] = [ 0, 0, 12 ] weekday = t[6] t.slice!(6, 4) t.reverse! + newweekday = weekday - startOn + if (newweekday < 0) + newweekday += 7 + end # Substract the number of days determined by the weekday t[6] and set time # to midnight of that day. (TjTime.new(Time.local(*t)) - - (weekday - (startMonday ? 1 : 0)) * 60 * 60 * 24).midnight + (newweekday) * 60 * 60 * 24).midnight end # Normalize time to the beginning of the current month. diff --git a/lib/taskjuggler/TjpSyntaxRules.rb b/lib/taskjuggler/TjpSyntaxRules.rb index 51b5040f..6a2da6cf 100644 --- a/lib/taskjuggler/TjpSyntaxRules.rb +++ b/lib/taskjuggler/TjpSyntaxRules.rb @@ -3303,19 +3303,19 @@ def rule_projectBodyAttributes ) example('TimeSheet1', '2') - pattern(%w( _weekstartsmonday ), lambda { - @project['weekStartsMonday'] = true - }) - doc('weekstartsmonday', - 'Specify that you want to base all week calculation on weeks ' + - 'starting on Monday. This is common in many European countries.') - - pattern(%w( _weekstartssunday ), lambda { - @project['weekStartsMonday'] = false - }) - doc('weekstartssunday', - 'Specify that you want to base all week calculation on weeks ' + - 'starting on Sunday. This is common in the United States of America.') + pattern(%w( _weekstartson !number), lambda { + @project['weekStartsOn'] = @val[1] + }) + doc('weekstartson', + 'Specify the day of the week you want to base all week calculation on ' + + 'Sunday=0, Monday=1, etc.') + +# pattern(%w( _weekstartssunday ), lambda { +# @project['weekStartsMonday'] = false +# }) +# doc('weekstartssunday', +# 'Specify that you want to base all week calculation on weeks ' + +# 'starting on Sunday. This is common in the United States of America.') pattern(%w( !workinghoursProject )) pattern(%w( _yearlyworkingdays !number ), lambda { diff --git a/lib/taskjuggler/reports/GanttChart.rb b/lib/taskjuggler/reports/GanttChart.rb index 01decedf..5521d551 100644 --- a/lib/taskjuggler/reports/GanttChart.rb +++ b/lib/taskjuggler/reports/GanttChart.rb @@ -34,16 +34,16 @@ class GanttChart include HTMLGraphics - attr_reader :start, :end, :now, :weekStartsMonday, :header, :width, + attr_reader :start, :end, :now, :weekStartsOn, :header, :width, :scale, :scales, :table attr_writer :viewWidth # Create the GanttChart object, but don't do much right now. We still need # more information about the chart before we can actually generate it. _now_ - # is the date that should be used as current date. _weekStartsMonday_ is - # true if the weeks should start on Mondays instead of Sundays. _table_ is a + # is the date that should be used as current date. _weekStartsOn is + # a number representing the first day of the week. _table_ is a # reference to the TableReport that the chart is part of. - def initialize(now, weekStartsMonday, columnDef, table = nil) + def initialize(now, weekStartsOn, columnDef, table = nil) # The start and end dates of the reported interval. @start = nil @end = nil @@ -83,7 +83,7 @@ def initialize(now, weekStartsMonday, columnDef, table = nil) # view will be adapted to the width of the chart. @viewWidth = nil # True of the week starts on a Monday. - @weekStartsMonday = weekStartsMonday + @weekStartsOn = weekStartsOn # Reference to the GanttHeader object that models the chart header. @header = nil diff --git a/lib/taskjuggler/reports/GanttHeader.rb b/lib/taskjuggler/reports/GanttHeader.rb index ff576ddb..9bef8e21 100644 --- a/lib/taskjuggler/reports/GanttHeader.rb +++ b/lib/taskjuggler/reports/GanttHeader.rb @@ -110,7 +110,7 @@ def genHeaderScale(scale, y, h, beginOfFunc, sameTimeNextFunc, timeformat) # The beginOfWeek function needs a parameter, so we have to handle it as a # special case. if beginOfFunc == :beginOfWeek - t = @chart.start.send(beginOfFunc, @chart.weekStartsMonday) + t = @chart.start.send(beginOfFunc, @chart.weekStartsOn) else t = @chart.start.send(beginOfFunc) end diff --git a/lib/taskjuggler/reports/TableReport.rb b/lib/taskjuggler/reports/TableReport.rb index fdf1cbce..4238fb12 100644 --- a/lib/taskjuggler/reports/TableReport.rb +++ b/lib/taskjuggler/reports/TableReport.rb @@ -339,7 +339,7 @@ def generateHeaderCell(columnDef) # set so that the lines of the Gantt chart line up with the lines of the # table. gantt = GanttChart.new(a('now'), - a('weekStartsMonday'), columnDef, self) + a('weekStartsOn'), columnDef, self) gantt.generateByScale(rStart, rEnd, columnDef.scale) # The header consists of 2 lines separated by a 1 pixel boundary. @@ -361,7 +361,7 @@ def generateHeaderCell(columnDef) '%b %Y', '%d') when 'weekly' genCalChartHeader(columnDef, - rStart.beginOfWeek(a('weekStartsMonday')), rEnd, + rStart.beginOfWeek(a('weekStartsOn')), rEnd, :sameTimeNextWeek, '%b %Y', '%d') when 'monthly' genCalChartHeader(columnDef, rStart.beginOfMonth, rEnd, @@ -662,7 +662,7 @@ def generateTableCell(line, columnDef, query) start = query.start.midnight sameTimeNextFunc = :sameTimeNextDay when 'weekly' - start = query.start.beginOfWeek(a('weekStartsMonday')) + start = query.start.beginOfWeek(a('weekStartsOn')) sameTimeNextFunc = :sameTimeNextWeek when 'monthly' start = query.start.beginOfMonth