date bug ?

19 views
Skip to first unread message

Damian Suarez

unread,
May 31, 2011, 6:56:54 PM5/31/11
to nod...@googlegroups.com
reproduce under node console

var date = new Date()
date.setMonth(0) is Jun
date.setMonth(1) is Mar.

Bas Dirks

unread,
May 31, 2011, 7:05:38 PM5/31/11
to nod...@googlegroups.com
> var date = new Date
> date.setMonth(0); date
Sat, 01 Jan 2011 00:02:46 GMT
> date.setMonth(1); date
Tue, 01 Feb 2011 00:02:46 GMT

> process.version
'v0.4.7'

What version do you use?

-- 
Bas Dirks
Sent with Sparrow
--
You received this message because you are subscribed to the Google Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com.
To unsubscribe from this group, send email to nodejs+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nodejs?hl=en.

Damian Suarez

unread,
May 31, 2011, 7:07:30 PM5/31/11
to nod...@googlegroups.com
0.4.3

Bas Dirks

unread,
May 31, 2011, 7:15:09 PM5/31/11
to nod...@googlegroups.com
Is there a reason that you can't update to a more recent version?

-- 
Bas Dirks
Sent with Sparrow

Onteria

unread,
May 31, 2011, 8:28:32 PM5/31/11
to nodejs
On May 31, 4:15 pm, Bas Dirks <i...@basdirks.eu> wrote:
> Is there a reason that you can't update to a more recent version?

I think this has something to do with the fact that it's the 31st
here:

15.9.5.38 Date.prototype.setMonth (month [, date ] )
If date is not specified, this behaves as if date were specified with
the value getDate().
1. Let t be the result of LocalTime(this time value).
2. Let m be ToNumber(month).
3. If date is not specified, then let dt be DateFromTime(t);
otherwise, let dt be ToNumber(date).
4. Let newDate be MakeDate(MakeDay(YearFromTime(t), m, dt),
TimeWithinDay(t)).
5. Let u be TimeClip(UTC(newDate)).
6. Set the [[PrimitiveValue]] internal property of this Date object to
u.
7. Return u.

Note the getDate bit. So:

> var date = new Date()
> date.getDate()
31
> date.setMonth(1); date
Fri, 04 Mar 2011 01:25:13 GMT
> date.getDate()
3
> // overflow due to February being the 28th as the last day
> date.setMonth(1); date
Fri, 04 Feb 2011 01:25:13 GMT
> date.setMonth(0); date
Tue, 04 Jan 2011 01:25:13 GMT

---
Looks like there's some overflow happening on months.

Nathan Rajlich

unread,
May 31, 2011, 9:23:38 PM5/31/11
to nod...@googlegroups.com
Onteria nailed it :P

node has no time bug :)

Reply all
Reply to author
Forward
0 new messages