Skip to content

Commit

Permalink
Add start and end time options for the report period.
Browse files Browse the repository at this point in the history
These options, --start-time and --end-time, take ISO 8601 date/times (e.g., '2011-03-02T14:00:00-05:00'), and can be used to set any arbitrary reporting period you want.  The "previous" period will be the same length, one week earlier.  (Note all the labels say "vs. last week" for the percentage change values, but that should be roughly accurate for most uses.)

I added this because I noticed that using the current rotation period only works if no irregular exceptions are set. If you have a weekly rotation and someone sets a two-day exception, the report will only cover the two-day period versus the same two days a week ago.  Not as useful.  So, this works around that problem for now.
  • Loading branch information
precipice committed Mar 9, 2011
1 parent 0121aac commit 7124aec
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions rotation-report.rb
Expand Up @@ -48,8 +48,20 @@
options[:rotations_ago] = rotations_ago
end

options[:start_time] = nil
opts.on('-s', '--start-time DATETIME',
"Start of report (ex: '2011-03-02T14:00:00-05:00', defaults to current)") do |time|
options[:start_time] = time
end

options[:end_time] = nil
opts.on('-e', '--end-time DATETIME',
"End of report (ex: '2011-03-09T14:00:00-05:00', defaults to current)") do |time|
options[:end_time] = time
end

options[:campfire_message] = false
opts.on('-m', '--campfire-message', "Paste the results as message in a Campfire room") do
opts.on('-m', '--campfire-message', "Paste the results as message in configured Campfire room") do
options[:campfire_message] = true
end

Expand Down Expand Up @@ -94,8 +106,17 @@
rotation = policy.css("td.rotation_properties div table tr").each do |row|
if row.css("td")[0].text =~ /On-call now/i
period_offset = ONE_WEEK * options[:rotations_ago]
current_start = Chronic.parse(row.css("td span")[0].text) - period_offset
current_end = Chronic.parse(row.css("td span")[1].text) - period_offset
if options[:start_time]
current_start = Time.xmlschema(options[:start_time]) - period_offset
else
current_start = Chronic.parse(row.css("td span")[0].text) - period_offset
end

if options[:end_time]
current_end = Time.xmlschema(options[:end_time]) - period_offset
else
current_end = Chronic.parse(row.css("td span")[1].text) - period_offset
end

# Shifts are either one day or one week (currently, at least).
# For a week-long shift, we want the previous full week. For a day
Expand Down

0 comments on commit 7124aec

Please sign in to comment.