<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,35 +1,49 @@
 class GraphsController &lt; ApplicationController
   
-  # GET /graphs/running_month
-  def running_month
-    @period = (Time.now.to_date - 30)..Time.now.to_date
+  # GET /graphs/running
+  def running
+    set_period
     respond_to do |format|
-      format.xml
+      format.xml do
+        if @period.to_a.length &gt; 31
+          render :action=&gt;'running_year.xml.builder'
+        else
+          render :action=&gt;'running_month.xml.builder'
+        end
+      end
     end
   end
   
-  # GET /graphs/running_year
-  def running_year
-    @period = (Time.now.to_date - 365)..Time.now.to_date
+  # GET /graphs/spending
+  def spending
+    set_period
     respond_to do |format|
-      format.xml
+      format.xml do
+        if @period.to_a.length &gt; 31
+          render :action=&gt;'spending_year.xml.builder'
+        else
+          render :action=&gt;'spending_month.xml.builder'
+        end
+      end
     end
   end
   
-  # GET /graphs/spending_month
-  def spending_month
-    @period = (Time.now.to_date - 30)..Time.now.to_date
-    respond_to do |format|
-      format.xml
+  protected
+  def set_period
+    begin
+      @start = Date.parse params[:start]
+    rescue
+      @start = Time.now.to_date - 30
     end
-  end
-  
-  # GET /graphs/spending_year
-  def spending_year
-    @period = (Time.now.to_date - 365)..Time.now.to_date
-    respond_to do |format|
-      format.xml
+    begin
+      @finish = Date.parse params[:finish]
+    rescue
+      @finish = Time.now.to_date
     end
+    @period = @start..@finish
+    logger.info &quot;start: #{@start}&quot;
+    logger.info &quot;finish: #{@finish}&quot;
+    logger.info &quot;period: #{@period.first}-#{@period.last}&quot;
   end
 
 end
\ No newline at end of file</diff>
      <filename>app/controllers/graphs_controller.rb</filename>
    </modified>
    <modified>
      <diff>@@ -3,6 +3,8 @@ class ThingsController &lt; ApplicationController
   # GET /
   def index
     @things = current_user.things_during((Time.now.to_date - 4)..Time.now.to_date)
+    @start  = Time.now.to_date - 30
+    @finish = Time.now.to_date
   end
   
   # GET /things/new</diff>
      <filename>app/controllers/things_controller.rb</filename>
    </modified>
    <modified>
      <diff>@@ -13,11 +13,11 @@
 #SpendingYear
 %script{:type=&gt;'text/javascript'}
   var spending = new FusionCharts(&quot;/flash/MSArea.swf&quot;, &quot;Spending&quot;, &quot;940&quot;, &quot;300&quot;, &quot;0&quot;, &quot;0&quot;);
-  = &quot;spending.setDataURL(\&quot;#{spending_year_url(:start=&gt;@start, :finish=&gt;@finish, :format=&gt;'xml')}\&quot;);&quot;
+  = &quot;spending.setDataURL(\&quot;#{spending_url(:start=&gt;@start, :finish=&gt;@finish, :format=&gt;'xml')}\&quot;);&quot;
   spending.render(&quot;SpendingYear&quot;);
 
 #RunningYear
 %script{:type=&gt;'text/javascript'}
   var running = new FusionCharts(&quot;/flash/MSCombiDY2D.swf&quot;, &quot;Running&quot;, &quot;940&quot;, &quot;300&quot;, &quot;0&quot;, &quot;0&quot;);
-  = &quot;running.setDataURL(\&quot;#{running_year_url(:format=&gt;'xml')}\&quot;);&quot;
+  = &quot;running.setDataURL(\&quot;#{running_url(:start=&gt;@start, :finish=&gt;@finish, :format=&gt;'xml')}\&quot;);&quot;
   running.render(&quot;RunningYear&quot;);
\ No newline at end of file</diff>
      <filename>app/views/reports/index.html.haml</filename>
    </modified>
    <modified>
      <diff>@@ -24,12 +24,12 @@
   #SpendingMonth
   %script{:type=&gt;'text/javascript'}
     var spending = new FusionCharts(&quot;/flash/MSArea.swf&quot;, &quot;Spending&quot;, &quot;430&quot;, &quot;250&quot;, &quot;0&quot;, &quot;0&quot;);
-    = &quot;spending.setDataURL(\&quot;#{spending_month_url(:format=&gt;'xml')}\&quot;);&quot;
+    = &quot;spending.setDataURL(\&quot;#{spending_url(:start=&gt;@start, :finish=&gt;@finish, :format=&gt;'xml')}\&quot;);&quot;
     spending.render(&quot;SpendingMonth&quot;);
   #RunningMonth
   %script{:type=&gt;'text/javascript'}
     var running = new FusionCharts(&quot;/flash/MSCombiDY2D.swf&quot;, &quot;Running&quot;, &quot;410&quot;, &quot;250&quot;, &quot;0&quot;, &quot;0&quot;);
-    = &quot;running.setDataURL(\&quot;#{running_month_url(:format=&gt;'xml')}\&quot;);&quot;
+    = &quot;running.setDataURL(\&quot;#{running_url(:start=&gt;@start, :finish=&gt;@finish, :format=&gt;'xml')}\&quot;);&quot;
     running.render(&quot;RunningMonth&quot;);
 .clear
 </diff>
      <filename>app/views/things/index.html.haml</filename>
    </modified>
    <modified>
      <diff>@@ -13,10 +13,8 @@ ActionController::Routing::Routes.draw do |map|
   map.date 'date/:year/:month/:day', :controller=&gt;'date', :action=&gt;'show', :requirements=&gt;{:year=&gt;/(19|20)\d\d/, :month=&gt;/[01]?\d/, :day=&gt;/[0-3]?\d/}
   
   map.with_options :controller=&gt;'graphs' do |g|
-    g.running_month  'graphs/running_month.:format',  :action=&gt;'running_month'
-    g.running_year   'graphs/running_year.:format',   :action=&gt;'running_year'
-    g.spending_month 'graphs/spending_month.:format', :action=&gt;'spending_month'
-    g.spending_year  'graphs/spending_year.:format',  :action=&gt;'spending_year'
+    g.running  'graphs/running/:start/:finish.:format',  :action=&gt;'running'
+    g.spending 'graphs/spending/:start/:finish.:format', :action=&gt;'spending'
   end
 
   map.root :controller=&gt;'things'</diff>
      <filename>config/routes.rb</filename>
    </modified>
    <modified>
      <diff>@@ -6,23 +6,31 @@ describe GraphsController do
     @request.env['HTTP_ACCEPT'] = 'application/xml'
   end
   
-  it 'handles /graphs/running_month with GET' do
-    get :running_month
+  it 'handles /graphs/running with valid date and GET' do
+    get :running, :start=&gt;'2009-01-01', :finish=&gt;'2009-02-02'
+    assigns(:start).should == Date.new(2009, 1, 1)
+    assigns(:finish).should == Date.new(2009, 2, 2)
     response.should be_success
   end
   
-  it 'handles /graphs/running/:year with GET' do
-    get :running_year
+  it 'handles /graphs/running with invalid date and GET' do
+    get :running, :start=&gt;'2009-01-41', :finish=&gt;'20090230'
+    assigns(:start).should == (Date.today - 30)
+    assigns(:finish).should == Date.today
     response.should be_success
   end
   
-  it 'handles /graphs/spending_month with GET' do
-    get :spending_month
+  it 'handles /graphs/spending with valid date and GET' do
+    get :spending, :start=&gt;'2009-01-01', :finish=&gt;'2009-02-02'
+    assigns(:start).should == Date.new(2009, 1, 1)
+    assigns(:finish).should == Date.new(2009, 2, 2)
     response.should be_success
   end
   
-  it 'handles /graphs/spending/:year with GET' do
-    get :spending_year
+  it 'handles /graphs/spending with invalid date and GET' do
+    get :spending, :start=&gt;'2009-01-41', :finish=&gt;'20090230'
+    assigns(:start).should == (Date.today - 30)
+    assigns(:finish).should == Date.today
     response.should be_success
   end
   </diff>
      <filename>spec/controllers/graphs_controller_spec.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>6302ecc8c07b8ef3933f41dd7cee07aa6c674520</id>
    </parent>
  </parents>
  <author>
    <name>Jordan McKible</name>
    <email>jordan@mckible.com</email>
  </author>
  <url>http://github.com/jmckible/stardate/commit/2208182d18de92a54849d5f9f68aec6b87960815</url>
  <id>2208182d18de92a54849d5f9f68aec6b87960815</id>
  <committed-date>2009-09-24T00:25:35-07:00</committed-date>
  <authored-date>2009-09-24T00:25:35-07:00</authored-date>
  <message>Variable periods on graphs.</message>
  <tree>f7b837c7d033a2ca4610d9a0b58688a3e2dc3de4</tree>
  <committer>
    <name>Jordan McKible</name>
    <email>jordan@mckible.com</email>
  </committer>
</commit>
