View Full Version : Date.UTC difference
dotnetCarpenter
12 Oct 2007, 6:42 AM
While testing my brand new Ext app, I noticed something odd.
In Firefox Date.UTC is zero based but 1-based in IE. It throws my hole application but I can easy remedy that by using
if(Ext.IE){
// use 1-based UTC
} else {
// use 0-based UTC
}
I googled IE and Date.UTC but apparently this difference is not documented (anywhere I looked)! I'm thinking that maybe UTC is not as error resilient that I thought. What does the DateField use?
mystix
12 Oct 2007, 7:08 AM
:-/ what test case did you use?
dotnetCarpenter
12 Oct 2007, 7:17 AM
document.write(new Date(Date.UTC(2007, 0, 0));
Will display Mon Jan 1 00:00:00 UTC+0100 2007 in FF
and Sun Dec 31 01:00:00 UTC+0100 2006 in IE (in my timezone).I find that using Ext.parseDate will normalize the date creation between browsers.
mystix
12 Oct 2007, 8:27 AM
hmmm... i think you've misunderstood...
it's incorrect to say IE's js Date object is 0-based.
the javascript Date object's Date.UTC() method accepts 1-based day arguments -- this happens regardless of browser flavour (see http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Objects:Date:UTC)
IE's js Date object, in this case, makes a good attempt at being smart when an integer day argument less than 1 is passed to the Date.UTC() method -- it starts at the 1st day of the given month and counts backwards.
try the following code
// returns the same millisecond value in FF / IE
Date.UTC(2007, 0, 1);
// in FF, returns the same millisecond value as above; in IE, returns the millisecond value for Dec 31, 2006
Date.UTC(2007, 0, 0);
// in FF, returns the same millisecond value as above; in IE, returns the millisecond value for Dec 30, 2006
Date.UTC(2007, 0, -1);
dotnetCarpenter
15 Oct 2007, 9:05 AM
it's incorrect to say IE's js Date object is 0-based.
Yes, I said that IE Date.UTC method is 1-based.
If I read the docs correctly the first day of 2007 would be Date.UTC(2007, 0, 1).
Parameters
year
A year after 1900.
month
An integer between 0 and 11 representing the month.
date
An integer between 1 and 31 representing the day of the month.
dotnetCarpenter
15 Oct 2007, 9:06 AM
Thanks for the link
mystix
15 Oct 2007, 9:26 AM
Yes, I said that IE Date.UTC method is 1-based.
my bad. :">
meant to say "FF", but ended up typing "IE".
anyway, here's one more link i was reading:
http://www.merlyn.demon.co.uk/js-date5.htm#SLGD
knock yourself out ;)
dotnetCarpenter
20 Oct 2007, 5:23 PM
puh that's too much! :))
Powered by vBulletin® Version 4.1.5 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.