<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -138,7 +138,7 @@
       new Timeframe('calendars', {
         startField: 'start',
         endField: 'end',
-        earliest: new Date(),
+        latest: Date.parseToObject(&quot;April 30, 2008&quot;),
         resetButton: 'reset' });
     //]]&gt;
   &lt;/script&gt;</diff>
      <filename>example/example.html</filename>
    </modified>
    <modified>
      <diff>@@ -471,6 +471,10 @@
       var timeframe = new Timeframe('timeframe', {
         startField: 'start', endField: 'end', latest: Date.parseToObject('January 25, 2008')
       });
+      var date = new Date(timeframe.latest);
+      date.setMonth(date.getMonth() - (timeframe.months - 1));
+      assert(timeframe.date.getMonth() == date.getMonth() &amp;&amp;
+        timeframe.date.getYear() == date.getYear());
       assert(timeframe.element.select('td').last().hasClassName('unselectable'));
       assert(!timeframe.element.select('td').first().hasClassName('unselectable'));
       assert(timeframe.buttons.get('next').get('element').hasClassName('disabled'));
@@ -515,7 +519,7 @@
       assertInstanceOf(Date, neutralDate);
       assertEqual(neutralDate.toString(), new Date().neutral().toString());
     }},
-    
+
     // TODO: test Datejs support
 
   }, { testLog: 'testlog' });</diff>
      <filename>test/index.html</filename>
    </modified>
    <modified>
      <diff>@@ -1,4 +1,4 @@
-/* Timeframe, version 0.3
+/* Timeframe, version 0.3.1
  * (c) 2008 Stephen Celis
  *
  * Freely distributable under the terms of an MIT-style license. 
@@ -48,9 +48,12 @@ var Timeframe = Class.create({
     this.fields = $H({ start: $(this.options.get('startField')), end: $(this.options.get('endField')) });
 
     this.range = $H({});
-    this._buildButtons()._buildFields();
     this.earliest = Date.parseToObject(this.options.get('earliest'));
     this.latest   = Date.parseToObject(this.options.get('latest'));
+    if (this.earliest &amp;&amp; this.latest &amp;&amp; this.earliest &gt; this.latest)
+      throw new Error(&quot;Timeframe: 'earliest' cannot come later than 'latest'&quot;);
+
+    this._buildButtons()._buildFields();
 
     this.calendars = [];
     this.element.insert(new Element('div', { id: this.element.id + '_container' }));
@@ -143,10 +146,11 @@ var Timeframe = Class.create({
       month.setMonth(month.getMonth() + 1);
     }.bind(this));
 
-    this.latest === null || this.latest &gt; month.setDate(-1) ?
-      this.buttons.get('next').get('element').removeClassName('disabled') :
+    if (this.latest === null || this.latest &gt; month)
+      this.buttons.get('next').get('element').removeClassName('disabled');
+    else
       this.buttons.get('next').get('element').addClassName('disabled');
-    
+
     return this;
   },
 
@@ -218,9 +222,9 @@ var Timeframe = Class.create({
       this.element.onselectstart = function(event) {
         if (!/input|textarea/i.test(Event.element(event).tagName)) return false;
       };
-    } else if (Prototype.Browser.Opera) {
+    } else if (Prototype.Browser.Opera)
       document.observe('mousemove', this.handleMouseMove.bind(this));
-    } else {
+    else {
       this.element.onmousedown = function(event) {
         if (!/input|textarea/i.test(Event.element(event).tagName)) return false;
       };
@@ -241,6 +245,17 @@ var Timeframe = Class.create({
       field.addClassName('error');
     var date = Date.parseToObject(this.range.get(fieldName));
     this.date = date || new Date();
+    if (this.earliest &amp;&amp; this.earliest &gt; this.date) {
+      this.date = new Date(this.earliest);
+    } else if (this.latest) {
+      date = new Date(this.date);
+      date.setMonth(date.getMonth() + (this.months - 1));
+      if (date &gt; this.latest) {
+        this.date = new Date(this.latest);
+        this.date.setMonth(this.date.getMonth() - (this.months - 1));
+      }
+    }
+    this.date.setDate(1);
     if (populate &amp;&amp; date) this.populate()
     this.refreshRange();
     return this;</diff>
      <filename>timeframe.js</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>cf0c0767a5fac8886a9b1a53ec01ee8949084ef4</id>
    </parent>
  </parents>
  <author>
    <name>Stephen Celis</name>
    <email>stephen@stephencelis.com</email>
  </author>
  <url>http://github.com/stephencelis/timeframe/commit/ab059009e28e062d3cc38842427a5b6f9423faa3</url>
  <id>ab059009e28e062d3cc38842427a5b6f9423faa3</id>
  <committed-date>2009-05-18T07:30:25-07:00</committed-date>
  <authored-date>2009-05-18T07:30:25-07:00</authored-date>
  <message>Initial date should reflect earliest or latest dates [closes #1].</message>
  <tree>a38d3f05605133f7ddc2b7107a18e463b25ca491</tree>
  <committer>
    <name>Stephen Celis</name>
    <email>stephen@stephencelis.com</email>
  </committer>
</commit>
