Closed Bug 288495 Opened 20 years ago Closed 20 years ago

On the 31st of the month, the DateTime object may return wrong information about the month.

Categories

(Core :: JavaScript Engine, defect)

1.7 Branch
x86
All
defect
Not set
normal

Tracking

()

RESOLVED INVALID

People

(Reporter: clintonb, Unassigned)

References

()

Details

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0

When the system clock is set to the 31st of any month with 31 days, calls to the
.getMonth() method of any DateTime object may return incorrect values.  In the
URL specified, the .getMonth() method call (incorrectly) returns October on 31
March 2005 and (correctly) September on 30 March 2005.

Reproducible: Always

Steps to Reproduce:
1.  Set system clock to 31 March 2005.
2.  In Firefox, browse to javascript:var d=new
Date();d.setYear(2005);d.setMonth(8);d.setDate(1);alert(d.toString());
3.  An alert box appears containing incorrect information: "Sat Oct 01 2005 ..."
4.  Set system clock to 30 March 2005.
5.  Refresh the browser.
6.  An alert box appears containing correct information: "Thu Sep 01 2005 ..."

Actual Results:  
Execution on 31 March 2005 (DateTime.getMonth() returned 9) yield different
results from execution on 30 March 2005 (returned 8). 

Expected Results:  
DateTime.getMonth() should return identical results regardless of date of execution.

Although I am reporting this to you as a bug, I strongly suspect that the source
of the problem is not in the Firefox codebase but rather in the Microsoft
Windows operating system, as this issue reproduces on both IE 6.0/SP2 and
Firefox.  It also reproduces on both Windows XP Pro (English) and Windows Server
2003 (English).  It does not reproduce on Macintosh (either IE or Safari).  I
have not attempted to repro it on any other OS/browser platform combination.
Assignee: firefox → general
Component: General → JavaScript Engine
Product: Firefox → Core
QA Contact: general → general
Version: unspecified → 1.7 Branch
INVALID.  BTW, this worksforme on Linux, so it's not a Windows bug, and I don't
see why it wouldn't reproduce in Firefox or Camino or the Mozilla Suite on the
Mac too.  ECMA-262 specifies exactly what happens here.  Consider the commented
code broken up into one statement per line:

  var d=new Date();        // d is a date on March 31, 2005.
  d.setYear(2005);         // no-op: year doesn't change, and date is still 31.
  d.setMonth(8);           // 8 is September, but "30 days hath September,
                           // April, June, and November", so the date 31 does
                           // in fact overflow, and it must be wrapped to 1,
                           // with the carry out advancing the month to 9,
                           // for September 1, 2005.
  d.setDate(1);            // no-op: date is already 1.
  alert(d.toString());

See http://www.mozilla.org/js/language/ECMA-262-3.pdf 15.9 for the full spec.

/be
Status: UNCONFIRMED → RESOLVED
Closed: 20 years ago
Resolution: --- → INVALID
*** Bug 339869 has been marked as a duplicate of this bug. ***
You need to log in before you can comment on or make changes to this bug.