JosephMajaseSithole / datejs

Automatically exported from code.google.com/p/datejs
0 stars 0 forks source link

[FIXED] TimePeriod for two dates is broken #39

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Create a new TimePeriod object for two dates
2. var foo = TimePeriod(Date.today(), Date.today());

What is the expected output? What do you see instead?
expected: foo should be an object
actual: the error d1.getDaysInMonth() is not a function

What version of the product are you using? On what operating system?
Latest SVN nightly (as of May 7th, 2008)

Please provide any additional information below.
The problem is that lines 245 and 251 of time.js are using:
d1.getDaysInMonth()

However, getDaysInMonth is a static function, not an instance method. 

Changing the line:
 d1.getDaysInMonth() to
 Date.getDaysInMonth(d1.getYear(), d1.getMonth())

fixes the problem

Original issue reported on code.google.com by jeff.pen...@gmail.com on 7 May 2008 at 5:04

GoogleCodeExporter commented 8 years ago
Thanks for pointing out the bug. 

I've fixed the problem in TimePeriod and updated SVN (Build #189).

Example

var start = new Date();
var end = Date.today().add(15).days();
var ts = new TimePeriod(start, end);

ts.getDays(); // 14

Original comment by geoff%co...@gtempaccount.com on 8 May 2008 at 4:09

GoogleCodeExporter commented 8 years ago
Hey,
I have used the #189 code and if the line #245 has been fixed, the #251 still 
uses:
while (d1 > d2 && d1.clone().addDays(-d1.getDaysInMonth()) > d2)

Since I have not digged the code, I wonder whether this is right... 
The #189 was generating the same error as described by Jeff and his fix also 
worked
for the line #251. Now obviously, fixing the code like this is not optimal :P

Original comment by nicolas....@gmail.com on 30 Apr 2010 at 11:08