473,803 Members | 3,625 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 #1
12 2689
Motoma
3,237 Recognized Expert Specialist
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
I just fooled around with this...
I'm crying on the inside.

You can use setFullDate and it works correctly.
Jan 31 '07 #2
jodishowers
5 New Member
Thanx your response.

I'll try out setFullDate - but funny, I can't find a single google reference to this method!

Can you please tell me what browser you tested on?

Thanx.
Jodi
Jan 31 '07 #3
Motoma
3,237 Recognized Expert Specialist
Thanx your response.

I'll try out setFullDate - but funny, I can't find a single google reference to this method!

Can you please tell me what browser you tested on?

Thanx.
Jodi
Entirely sorry!
What I meant to say was the setFullYear function!
Jan 31 '07 #4
Motoma
3,237 Recognized Expert Specialist
P.S. Welcome to The Scripts!
Jan 31 '07 #5
jodishowers
5 New Member
P.S. Welcome to The Scripts!
Thanx.

Unfortunately (for me) setFullYear doens't make a difference.

Expand|Select|Wrap|Line Numbers
  1. ie; 
  2.     var date1 = new Date();
  3.     date1.setFullYear(2007);
  4.     date1.setMonth(3);
  5.     date1.setDate(10);
  6.     alert('(2007-3-10) ::' + date1.getFullYear() + '-' + (date1.getMonth()) + '-' + date1.getDate());
  7.     alert('(April 10, 2007) ::' + date1.toDateString());
  8.  
still results in the wrong Month (May not June). Actually setMonth(3) results in getMonth(4). This problem has recently reared it's head - so I'm suspecting it relates to a recent JS Engine update - still to be researched.

The good news (so far) looks like the problem doesn't exist using the Date constructor(new Date(yyyy,mm,dd ) - refactoring is in order.

RE: refactoring, are there any good testing frameworks for Javascript? I think it's time for some TDD.

thanx for your thoughts.
Jodi
Jan 31 '07 #6
Motoma
3,237 Recognized Expert Specialist
Expand|Select|Wrap|Line Numbers
  1.     var date1 = new Date();
  2.     date1.setFullYear(2007,3,10);
  3.    alert('(2007-3-10) ::' + date1.getFullYear() + '-' + (date1.getMonth()) + '-' + date1.getDate());
  4.     alert('(April 10, 2007) ::' + date1.toDateString());
  5.  
Works for me.
Jan 31 '07 #7
jodishowers
5 New Member
Works for me.
Not sure why. grin.

The bug has been identified here by Mozilla, and characterized as a 'feature' -rtfm

https://bugzilla.mozill a.org/show_bug.cgi?id =288495

The basis of the problem was that today is the 31st, and April doesn't have 31 days - so setMonth was advancing the month to May(rolling it forward) since it thought today was the 31st. Make sense?

BTW, you get into the same trouble if you try to set the day first - and you try to set it to 31, but the current month is April - it will then roll the day forward to 1(thinking you meant May)

The lesson I take away is to use the date Constructor.

Hope this trail of thought helps those following us.

Thanx for your help.
Jodi
Jan 31 '07 #8
Motoma
3,237 Recognized Expert Specialist
Not sure why. grin.
If you look at my code, you can specify the month and date with setFullYear().
Jan 31 '07 #9
acoder
16,027 Recognized Expert Moderator MVP
Glad your problem was solved.

Yes, it is a useful feature. It prevents errors in setting the date (the date is never in an error state).

Of course, with the example used by Motoma, no errors showed up because he set the date altogether.
Jan 31 '07 #10

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

Similar topics

7
7795
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
1908
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
5160
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
1194
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
10635
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
9700
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
9564
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
10546
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
10068
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9121
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5498
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
5627
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4275
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2970
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.