473,831 Members | 2,308 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

JS Date - JS Engine bug, or I'm losing my mind?!

5 New Member
Greetings all. My 1st post here - hoping someone can help out.

First I've tested this on FF 1.5.0.9, 2.x and Safari on OSX.

here's the code that exhibits the behaviour:

#case 1 - fails
var date1 = new Date();
date1.setYear(2 007);
date1.setMonth( 3);
date1.setDate(1 0);
alert('(2007-3-10) ::' + date1.getFullYe ar() + '-' + (date1.getMonth ()) + '-' + date1.getDate() ); // 2007-4-10
alert('(April 10, 2007) ::' + date1.toDateStr ing()); #Thu May 10 2007

#case 2 - succeeds - expected behaviour
var date2 = new Date();
date2.setYear(2 007);
date2.setMonth( 4);
date2.setDate(1 2);
alert('(2007-4-12) ::' + date2.getFullYe ar() + '-' + (date2.getMonth ()) + '-' + date2.getDate() ); // 2007-4-12
alert('(May 12, 2007) :: ' + date2.toDateStr ing()); // #Sat May 12 2007

So I'm seeing a nasty behaviour:
date1.setMonth + 1 == date1.getMonth

I've only seen this happen for month 3 (April).

Am I losing my mind (perhaps the wrong group)? Or can someone help me identify what's missing in my logic - because it would be unusual if a bug was identical across browsers (unless the JS engine is the same in both FF and Safari in osx).

I'll try IE Windows next.

TIA!
Jodi
Jan 31 '07
12 2693
Motoma
3,237 Recognized Expert Specialist
Here is a better explanation of why the error is occurring.

When you call new Date(), your date is initialized to today. You then go and change the year, month, then day:

January 31 2007
Doesn't change when updating the year:
January 31 2007
then it becomes:
April 31 2007
Which doesn't exist, therefor it rolls over to:
May 31 2007
and then you update the day:
May 10 2007

Hope this makes sense...it took me a moment to figure out.
Jan 31 '07 #11
acoder
16,027 Recognized Expert Moderator MVP
If you look at my code, you can specify the month and date with setFullYear().
Beat me to it!
Jan 31 '07 #12
jodishowers
5 New Member
Motoma - yes. Now I understand.

When I read "works for me" I thought you were referring to my code sample where I:

Expand|Select|Wrap|Line Numbers
  1.  date1.setFullYear(2007);
  2.  
Upon re-reading I see you coded as
Expand|Select|Wrap|Line Numbers
  1.  date1.setFullYear(2007,3,10);
  2.  
yes. that's a workable approach. Not a very good name for a method call IMO (setFullYear).

How about JS testing frameworks? I'm looking at scriptaculous Test.Unit (http://wiki.script.acu lo.us/scriptaculous/show/Test.Unit.Runne r).

Thanx for you help.
Jodi
Jan 31 '07 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

7
7796
by: vivek | last post by:
Do any of you guys have any idea what might be the reason for losing session variables, i was working on a page where i had to stroe a array in a session(trust me that was the only 'way' i could imagine doing it), and i am losing the session variable, its just returning empty values...does any one has any ideas?
1
1338
by: Larry Jaques | last post by:
I scanned the last 500 messages and didn't see anything like I'm trying to do so I ask you guys for your help, please. I want to change a lady's logo block/page layout by date and she doesn't want to change from a .html page suffix for fear of losing customers and search engine status. The current look is logo at top left, animation in the middle, and a picture of one of her baskets on the right, which is hotlinked to that page. I...
9
1910
by: Neil | last post by:
I have been coding with ASP for some time now. I am using an ACCESS database. I am in the UK and wish to use DD/MM/YYYY format for dates. I have had no end of problems and possible solutions to dates such as 1/8/05 being interpreted in the wrong way. I have been given many suggestions (setting LCID, submitting dates in long format etc. etc.) Is there any definitive sloution or tutorial available? This is driving me
2
5161
by: Jim H | last post by:
I'm trying to get a bunch of records based on client id and a date range. I keep getting an error when I enclose my date string in quotes in the where cleause. The error is: Microsoft JET Database Engine: Data type mismatch in criteria expression. If I remove the quotes and use MyDateVar.ToShortDateString the select executes but ignores the date in the resulting dataset. I get all dates.
0
1214
by: Al Fatykhov | last post by:
Using MABLE logic engine with existing .NET applications. MABLE web services provide an interface to MABLE business objects and logic. Let us review some technical details of the MABLE web services. · MABLE utilizes SOAP 1.2 protocol. · MABLE uses AXIS 1.4 as a web service transport. · MABLE support state-full conversations by implementing a conversation session.
28
2646
by: richardlang | last post by:
Anyone out there ever come across a preprocessor macro that compares an argument value against the predefined __DATE__ macro in order to control conditional compilation based on date. Something along the lines of... # define DateLaterThan(x) ... that could be used for things like
1
1196
by: steven scaife | last post by:
Ok I know its probably not relevant here but i didn't know of a good place to post. I have been asked to develop a site in asp.net. The current site is written in PHP, if i change the server side technology to dot net will it affect the sites search engine rank. The site gets 70000 unique visits per month so losing the ranking is not an option. I have read a few articles on SEO and it mentions the url as a factor, so i have a feeling...
10
3282
by: Daniel | last post by:
In Microsoft Access I can write a query that includes the criteria: Between Date()-7 And Date() to retrieve the records from a table that fall within the last week. I'm trying to write a procedure to do this in VB.NET (2005 Express Edition). But I always get the message that the Jet database engine does not recognize the syntax (of the Date function I assume). I've also tried Now() and it works but only by itself. I seem to add or
110
10652
by: alf | last post by:
Hi, is it possible that due to OS crash or mysql itself crash or some e.g. SCSI failure to lose all the data stored in the table (let's say million of 1KB rows). In other words what is the worst case scenario for MyISAM backend? Also is it possible to not to lose data but get them corrupted?
0
9794
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9642
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10778
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10496
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10538
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7750
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5622
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5788
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3967
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.