PDA

View Full Version : [CLOSED-35] [3.x/2.x] DatePicker Picks wrong date



Sina
9 Mar 2009, 6:37 AM
Hi,
When you pick 22 and 23 th march of 2009, the picker shows 21 of march, and for dates after that, there is always 1 day difference. for example if you pick 29th, Field value would be 03/28/2009. You can find a Simple runnable DateField here:

http://www.extjs.com/deploy/dev/examples/form/adv-vtypes.html

I traced the source and I got to here:

ext 2.2
ext-2.2\source\widgets\DatePicker.js
@class Ext.DatePicker
line 666 - 686

Sometimes d.setDate(d.getDate()+1); doesn't add a day!! I know it's weird, but it happens!! Actually this kind of problem occurs in many days. Above example is only one of them. I am using
Windows XP,
FF3, IE7

Hope to hear from you guys soon.
Thanks

evant
9 Mar 2009, 6:41 AM
Can't replicate it using the online examples. Anyone else?

mystix
9 Mar 2009, 8:45 AM
i've seen this reported before, but it's never been 100% reproducible.

@sina: what's your computer's locale setting?
do your friends / colleagues experience the same problem?
can you reproduce the problem on other browsers (e.g. chrome / safari / opera)?
is there some sort of daylight savings thing going on in your part of the world?

rajmohan
9 Mar 2009, 7:11 PM
I don't know about the 1-day-difference bug.
But I know that there is a bug in the validation code in the sample page.

http://extjs.com/forum/showthread.php?t=62176

Sina
10 Mar 2009, 3:50 AM
Great tips from mystix,
If you want to see the bug:
Go to Date and Time in control panel
In the timezone select (GMT +03:30) Tehran (I don't know about other time zones, but it work fine for "Canada&US")
Tick the check box: "Automatically adjust clock for daylight saving changes"
Restart windows
Go to online examples that contain DateFieldThanks a lot for quick responses

mystix
10 Mar 2009, 6:10 AM
Great tips from mystix,
If you want to see the bug:
Go to Date and Time in control panel
In the timezone select (GMT +03:30) Tehran (I don't know about other time zones, but it work fine for "Canada&US")
Tick the check box: "Automatically adjust clock for daylight saving changes"
Restart windows
Go to online examples that contain DateFieldThanks a lot for quick responses

followed the steps you outlined above on a virtual image of WinXP SP3 machine running FF3.0.5, using the following example:
http://www.extjs.com/deploy/dev/examples/form/xml-form.html

works correctly for me.

i also fired up the Firebug console and typed new Date(); into the console just to make sure, and it gave me this:


Tue Mar 10 2009 18:39:33 GMT+0430 (Iran Daylight Time)

is there anything else i'm missing?

p.s. what was the exact Tehran time when you tried the example?

Sina
11 Mar 2009, 1:16 AM
Hi and thanks again for your time mystix,
I had an idea, there is a slight chance, that you don't see the bug on virtual machines. So I installed Microsoft Virtual PC, set up Win XP on that, and there was no error. It is really appreciated if you test it on a real Win XP.

All my colleagues have the same problem when that check box is checked. The bug also happens in chrome and opera. And I also don't think it's a matter of time, because I am working from 8 am to 8 pm and there is no sign of a working DateField!

Thanks a lot

Sina
11 Mar 2009, 11:15 PM
I was getting used to quick responses, but it seems there is no more!
Is there someone working on this issue?

mystix
11 Mar 2009, 11:57 PM
calm down calm down... ~o)

apply this override in your local environment:


Ext.apply(Date.prototype, {
isDST: function() {
// adapted from http://extjs.com/forum/showthread.php?p=247172#post247172
// courtesy of @geoffrey.mcgill
return new Date(this.getFullYear(), 0, 1).getTimezoneOffset() != this.getTimezoneOffset();
}
});

and then run this in the firebug console:


(new Date()).isDST();

and tell me if that returns true or false. nevermind. i switched my date time settings like you've recommended and verified that this works.



next, pick march 23rd 2009 using this example: http://extjs.com/deploy/dev/examples/form/xml-form.html,
then open up firebug for that page and type this into the firebug console:


Ext.getCmp(Ext.get('form-ct').first().id).find('name', 'dob')[0].getValue()

and post the resulting date string.


and lastly, check if clicking the "Today" button in the datepicker ever returns the incorrect date.


[update]
i've changed my date-time settings on a real WinXP SP3 machine as you've suggested in post #5 but i'm still unable to reproduce the problem. the dates i pick are displayed correctly in the datefield's <input> field. still trying to find ways to reproduce your reported problem.

mystix
12 Mar 2009, 3:22 AM
@sina,

i've tried the following (after setting my date-time settings as detailed by @sina in post #5):

with my windows calendar set to today, picking 22 / 23 march and the dates beyond
setting my windows calendar to 28th Feb 2009 (because, according to Firefox 3.0.7, DST in tehran starts at 3am, march 1, 2009. DST in tehran ends at 12am, Sept 23, 2009. but the links i mentioned at the end of this post say otherwise), then picking march 22 and 23, and dates beyond

both of which return correct results.

could you post a complete drop in html test page? (what i'd really like to see are your script includes)

also, what is your WinXP machine's region / location (under Control Panel > Regional and Language Options) set to?
(and what were these settings in your virtual PC?)[/s]

[update 1]
found the following 2 links, which hint at what might be going wrong:
http://www.timeanddate.com/worldclock/timezone.html?n=246
http://www.timeanddate.com/worldclock/clockchange.html?n=246&year=2009
could you please verify the information?


[update 2]
i also found this: http://support.microsoft.com/kb/914387
attempting to update my settings now.

[update 3]
updated timezone settings. i'm now finally able to see the problem as described by @sina. the timezone update registry patch (http://support.microsoft.com/kb/914387) provided my microsoft did the trick.

Sina
12 Mar 2009, 5:19 AM
Thanks again,
The only thing that remains is, my regional and language settings. I have changed all my settings from Farsi and Iran to English, United States (in the first tab) and English in the third tab, and the bug still exists.
Although there was no bug on Virtual PC, but every settings were as same as each other! The only point is on Virtual PC I never changed the Regional Settings. They were default settings of Win XP.

P.S. Unfortunately I am not available, until next Monday. I hope not answering to this thread until then, does not apprehend to my rudeness.

Thanks

mystix
12 Mar 2009, 5:31 AM
Thanks again,
The only thing that remains is, my regional and language settings. I have changed all my settings from Farsi and Iran to English, United States (in the first tab) and English in the third tab, and the bug still exists.
Although there was no bug on Virtual PC, but every settings were as same as each other! The only point is on Virtual PC I never changed the Regional Settings. They were default settings of Win XP.


you don't have to change your settings anymore.
using the microsoft timezone update registry update, i'm able to reproduce the problem you're seeing, even on my winxp virtual machine.

check this thread again when you're back on monday. i should have a fix out by then. :)

mystix
12 Mar 2009, 11:56 AM
alritey, use this override (tested in FF3.0.7 / Safari):
(new / modified code is red)

Ext.DatePicker override (for 2.3.0):


Ext.override(Ext.DatePicker, {
// PUBLIC -- to be documented
// default value used to initialise each date in the DatePicker
// (note: 12 noon was chosen because it steers well clear of all DST timezone changes)
initHour: 12, // 24-hour format

// private
update : function(date, forceRefresh) {
var vd = this.activeDate;
this.activeDate = date;
if (!forceRefresh && vd && this.el) {
var t = date.getTime();
if (vd.getMonth() == date.getMonth() && vd.getFullYear() == date.getFullYear()) {
this.cells.removeClass("x-date-selected");
this.cells.each(function(c) {
if (c.dom.firstChild.dateValue == t) {
c.addClass("x-date-selected");
setTimeout(function() {
try {
c.dom.firstChild.focus();
} catch(e) {
}
}, 50);
return false;
}
});
return;
}
}
var days = date.getDaysInMonth(),
firstOfMonth = date.getFirstDateOfMonth(),
startingPos = firstOfMonth.getDay() - this.startDay;

if (startingPos <= this.startDay) {
startingPos += 7;
}
days += startingPos;

var pm = date.add("mo", -1),
prevStart = pm.getDaysInMonth() - startingPos,
cells = this.cells.elements,
textEls = this.textNodes,

// convert everything to numbers so it's fast
// var day = 86400000; // not in use throughout the update() method
d = (new Date(pm.getFullYear(), pm.getMonth(), prevStart, this.initHour)), // .clearTime();
today = new Date().clearTime().getTime(),
sel = date.clearTime(true).getTime(),
min = this.minDate ? this.minDate.clearTime(true) : Number.NEGATIVE_INFINITY,
max = this.maxDate ? this.maxDate.clearTime(true) : Number.POSITIVE_INFINITY,
ddMatch = this.disabledDatesRE,
ddText = this.disabledDatesText,
ddays = this.disabledDays ? this.disabledDays.join("") : false,
ddaysText = this.disabledDaysText,
format = this.format;

if (this.showToday) {
var td = new Date().clearTime();
var disable = (td < min || td > max ||
(ddMatch && format && ddMatch.test(td.dateFormat(format))) ||
(ddays && ddays.indexOf(td.getDay()) != -1));

this.todayBtn.setDisabled(disable);
this.todayKeyListener[disable ? 'disable' : 'enable']();
}

var setCellClass = function(cal, cell) {
cell.title = "";
var t = d.clearTime(true).getTime();
cell.firstChild.dateValue = t;
if (t == today) {
cell.className += " x-date-today";
cell.title = cal.todayText;
}
if (t == sel) {
cell.className += " x-date-selected";
setTimeout(function() {
try {
cell.firstChild.focus();
} catch(e) {
}
}, 50);
}
// disabling
if (t < min) {
cell.className = " x-date-disabled";
cell.title = cal.minText;
return;
}
if (t > max) {
cell.className = " x-date-disabled";
cell.title = cal.maxText;
return;
}
if (ddays) {
if (ddays.indexOf(d.getDay()) != -1) {
cell.title = ddaysText;
cell.className = " x-date-disabled";
}
}
if (ddMatch && format) {
var fvalue = d.dateFormat(format);
if (ddMatch.test(fvalue)) {
cell.title = ddText.replace("%0", fvalue);
cell.className = " x-date-disabled";
}
}
};

var i = 0;
for (; i < startingPos; i++) {
textEls[i].innerHTML = (++prevStart);
d.setDate(d.getDate() + 1);
cells[i].className = "x-date-prevday";
setCellClass(this, cells[i]);
}
for (; i < days; i++) {
var intDay = i - startingPos + 1;
textEls[i].innerHTML = (intDay);
d.setDate(d.getDate() + 1);
cells[i].className = "x-date-active";
setCellClass(this, cells[i]);
}
var extraDays = 0;
for (; i < 42; i++) {
textEls[i].innerHTML = (++extraDays);
d.setDate(d.getDate() + 1);
cells[i].className = "x-date-nextday";
setCellClass(this, cells[i]);
}

this.mbtn.setText(this.monthNames[date.getMonth()] + " " + date.getFullYear());

if (!this.internalRender) {
var main = this.el.dom.firstChild;
var w = main.offsetWidth;
this.el.setWidth(w + this.el.getBorderWidth("lr"));
Ext.fly(main).setWidth(w);
this.internalRender = true;
// opera does not respect the auto grow header center column
// then, after it gets a width opera refuses to recalculate
// without a second pass
if (Ext.isOpera && !this.secondPass) {
main.rows[0].cells[1].style.width = (w - (main.rows[0].cells[0].offsetWidth + main.rows[0].cells[2].offsetWidth)) + "px";
this.secondPass = true;
this.update.defer(10, this, [date]);
}
}
}
});



Ext.DatePicker override (for 3.1.1):


Ext.override(Ext.DatePicker, {
// PUBLIC -- to be documented
// default value used to initialise each date in the DatePicker
// (note: 12 noon was chosen because it steers well clear of all DST timezone changes)
initHour: 12, // 24-hour format

update : function(date, forceRefresh){
if(this.rendered){
var vd = this.activeDate, vis = this.isVisible();
this.activeDate = date;
if(!forceRefresh && vd && this.el){
var t = date.getTime();
if(vd.getMonth() == date.getMonth() && vd.getFullYear() == date.getFullYear()){
this.cells.removeClass('x-date-selected');
this.cells.each(function(c){
if(c.dom.firstChild.dateValue == t){
c.addClass('x-date-selected');
if(vis && !this.cancelFocus){
Ext.fly(c.dom.firstChild).focus(50);
}
return false;
}
}, this);
return;
}
}
var days = date.getDaysInMonth(),
firstOfMonth = date.getFirstDateOfMonth(),
startingPos = firstOfMonth.getDay()-this.startDay;

if(startingPos < 0){
startingPos += 7;
}
days += startingPos;

var pm = date.add('mo', -1),
prevStart = pm.getDaysInMonth()-startingPos,
cells = this.cells.elements,
textEls = this.textNodes,

// convert everything to numbers so it's fast
// day = 86400000, // not in use throughout the update() method
d = (new Date(pm.getFullYear(), pm.getMonth(), prevStart, this.initHour)), // .clearTime(),
today = new Date().clearTime().getTime(),
sel = date.clearTime(true).getTime(),
min = this.minDate ? this.minDate.clearTime(true) : Number.NEGATIVE_INFINITY,
max = this.maxDate ? this.maxDate.clearTime(true) : Number.POSITIVE_INFINITY,
ddMatch = this.disabledDatesRE,
ddText = this.disabledDatesText,
ddays = this.disabledDays ? this.disabledDays.join('') : false,
ddaysText = this.disabledDaysText,
format = this.format;

if(this.showToday){
var td = new Date().clearTime(),
disable = (td < min || td > max ||
(ddMatch && format && ddMatch.test(td.dateFormat(format))) ||
(ddays && ddays.indexOf(td.getDay()) != -1));

if(!this.disabled){
this.todayBtn.setDisabled(disable);
this.todayKeyListener[disable ? 'disable' : 'enable']();
}
}

var setCellClass = function(cal, cell){
cell.title = '';
var t = d.clearTime(true).getTime();
cell.firstChild.dateValue = t;
if(t == today){
cell.className += ' x-date-today';
cell.title = cal.todayText;
}
if(t == sel){
cell.className += ' x-date-selected';
if(vis){
Ext.fly(cell.firstChild).focus(50);
}
}
// disabling
if(t < min) {
cell.className = ' x-date-disabled';
cell.title = cal.minText;
return;
}
if(t > max) {
cell.className = ' x-date-disabled';
cell.title = cal.maxText;
return;
}
if(ddays){
if(ddays.indexOf(d.getDay()) != -1){
cell.title = ddaysText;
cell.className = ' x-date-disabled';
}
}
if(ddMatch && format){
var fvalue = d.dateFormat(format);
if(ddMatch.test(fvalue)){
cell.title = ddText.replace('%0', fvalue);
cell.className = ' x-date-disabled';
}
}
};

var i = 0;
for(; i < startingPos; i++) {
textEls[i].innerHTML = (++prevStart);
d.setDate(d.getDate()+1);
cells[i].className = 'x-date-prevday';
setCellClass(this, cells[i]);
}
for(; i < days; i++){
var intDay = i - startingPos + 1;
textEls[i].innerHTML = (intDay);
d.setDate(d.getDate()+1);
cells[i].className = 'x-date-active';
setCellClass(this, cells[i]);
}
var extraDays = 0;
for(; i < 42; i++) {
textEls[i].innerHTML = (++extraDays);
d.setDate(d.getDate()+1);
cells[i].className = 'x-date-nextday';
setCellClass(this, cells[i]);
}

this.mbtn.setText(this.monthNames[date.getMonth()] + ' ' + date.getFullYear());

if(!this.internalRender){
var main = this.el.dom.firstChild,
w = main.offsetWidth;
this.el.setWidth(w + this.el.getBorderWidth('lr'));
Ext.fly(main).setWidth(w);
this.internalRender = true;
// opera does not respect the auto grow header center column
// then, after it gets a width opera refuses to recalculate
// without a second pass
if(Ext.isOpera && !this.secondPass){
main.rows[0].cells[1].style.width = (w - (main.rows[0].cells[0].offsetWidth+main.rows[0].cells[2].offsetWidth)) + 'px';
this.secondPass = true;
this.update.defer(10, this, [date]);
}
}
}
}
});


Ext.form.DateField override (applicable for both 2.3.0 and 3.1.1):


Ext.override(Ext.form.DateField, {
// PUBLIC -- to be documented
// in the absence of a time value, a default value of 12 noon will be used
// (note: 12 noon was chosen because it steers well clear of all DST timezone changes)
initTime: '12', // 24 hour format

// PUBLIC -- to be documented
initTimeFormat: 'H',

// PUBLIC -- to be documented
// Should be explictly stated that this method should be overriden
// for use in timezones which experience DST
//
// note: this turned out to be reaaaaaalllly difficult to customize to
// fit every situation, so what i've put up here is a real naive implementation which
// works for the online examples (disclaimer: i've only tried it on one, but most of the configs are similar).
// i suggest customizing it so it fits your particular situation. ask if you don't understand what on earth
// i'm trying to achieve with this function.
safeParse : function(value, format) {
if (/[gGhH]/.test(format.replace(/(\\.)/g, ''))) {
// if parse format contains hour information, no DST adjustment is necessary
return Date.parseDate(value, format);
} else {
// set time to 12 noon, then clear the time
return Date.parseDate(value + ' ' + this.initTime, format + ' ' + this.initTimeFormat).clearTime();
}
},

parseDate : function(value) {
if(!value || Ext.isDate(value)){
return value;
}

var v = this.safeParse(value, this.format),
af = this.altFormats,
afa = this.altFormatsArray;

if (!v && af) {
afa = afa || af.split("|");

for (var i = 0, len = afa.length; i < len && !v; i++) {
v = this.safeParse(value, afa[i]);
}
}
return v;
}
});


remember to test this in IE / Opera.


[note]
consolidated multiple var declarations in 2.3.0's DatePicker code

Sina
16 Mar 2009, 2:45 AM
Thanks for you effort,
When I add the first part of your code to override clearTime and isDTS functions, I get this error in firebug:

ext-base.js (line 9)
p is undefined
Ext={version:"2.2"};window["undefined"]=...|new Date()).getTime()-this.getTime())};

should I add this part to special file, special place or something?

mystix
16 Mar 2009, 8:06 PM
create an overrides.js file, paste all the overrides in post #13 into this file, and include it immediately after ext-all.js / ext-all-debug.js.

i.e.


<script src="ext-base.js">
<script src="ext-all.js">
<script src="overrides.js">

Sina
17 Mar 2009, 4:33 AM
I am receiving the same error I described in #14, I traced a little and came up with this:
in ext-base.js we have a code:



if(overrides)
{
var p=origclass.prototype;
for(var method in overrides)
{
p[method]=overrides[method]
}
}
origclass.prototype is undefined, so I receive the error in #14. I made the file overrides.js and included it where you said, but there is no difference. Any idea?

Sina
17 Mar 2009, 4:49 AM
I removed the .prototype from first line of your code so it is now:


Ext.override(Date, {
...
and it seems like working. I am going to test it now and report the result.
Thanks

mystix
17 Mar 2009, 5:32 AM
my mistake, copy-paste error.

that should be


Ext.apply(Date.prototype, {
// ...
});

mystix
9 Jun 2009, 10:00 AM
[ friendly bump ]
this DST bug affects the 3.x branch as well.
see post #13 for the complete fix.

note 1: the Date.prototype changes are already in 2.x/3.x SVN.
note 2: the new DateField#safeParse() method might need some optimising.

mystix
24 Jun 2009, 7:55 PM
[ moved to 3.x Bugs from 2.x Bugs ]

and

[ a bump for posterity ]

in light of this 3.x bug report:
72326

AVerta
2 Oct 2009, 6:11 AM
Hi mystix,

I´m from Brazil, and here we use the GMT-03:00. I put your override in my code, and works. But in a specific date 11/10/2009 (october, 11, 2009), the error persist. I select this date, and the datefield value is changed for 10/10/2009 (october, 10, 2009).

In my tests, I saw that all dates less or same to 10/10/2009 (october, 10, 2009), the timezone is GMT-03:00. But, all dates above or same to 12/10/2009 (october, 12, 2009), the timezone is GMT-02:00.

What´s wrong? Can you help me to solve this?

Thanks a lot

mystix
2 Oct 2009, 10:06 AM
if i'm guessing right you're running a Windows machine, likely Windows XP, and your timezone database hasn't been updated.

see post #10 -- and the links contained therein.

p.s. i presume you're on Ext 3.x and using the override from post #13?

AVerta
6 Oct 2009, 2:09 AM
Hi Mystix,

I´m using Windows XP, and I had the timezone update, but didn´t works. I´m using de override in #13 too, but I´m using the Ext 2.2.

Do you have any other trick?

Thanks

mystix
6 Oct 2009, 7:36 AM
does the problem still occur if you switch to Ext 2.3 / 3.0?

also, what's the exact date + time when DST goes into effect in brazil for the year 2009?

Nom4d3
6 Oct 2009, 10:37 AM
It works fine here.
ExtJS 2.3 - Brazilian Timezone
our DST starts at october, 18

mystix
6 Oct 2009, 8:16 PM
It works fine here.
ExtJS 2.3 - Brazilian Timezone
our DST starts at october, 18

that's great. at least now my sanity's preserved ;)
just for completeness -- what time does DST take effect on october 18, 2009?

Nom4d3
7 Oct 2009, 3:22 AM
Starts october, 18 - 00:00 from GMT-3 to GMT-2

At 00:00 we change our clocks to 01:00

andregufc
7 Oct 2009, 4:43 AM
I'm using ext 2.2 and found this error in firebug:

Date.parseDate(value + " " + this.initTime, format + " " + this.initTimeFormat, strict) is undefined
http://xxxxxx/public/js/overrides_date.js
Line 173

the overrides works in ext 2.2?

thanks :)

Nom4d3
7 Oct 2009, 5:59 AM
I'm using ext 2.2 and found this error in firebug:

Date.parseDate(value + " " + this.initTime, format + " " + this.initTimeFormat, strict) is undefined
http://xxxxxx/public/js/overrides_date.js
Line 173

the overrides works in ext 2.2?

thanks :)

i had the same problem. I was setting a fixed value to the datefield in this format ("Y-m-d"), but all my system is in this format ("d/m/Y").
Before this override both formats was working fine, but now i needed to set only on the ("d/m/Y") format.

Nom4d3
7 Oct 2009, 11:43 AM
a little fix to solve this issue:


safeParse : function(value, format, strict) {
if (/[gGhH]/.test(format.replace(/(\\.)/g, ''))) {
return Date.parseDate(value, format, strict);
} else {
var nd = Date.parseDate(value + ' ' + this.initTime, format + ' ' + this.initTimeFormat, strict);
if (nd !== undefined)
return nd.clearTime();
}
},

mystix
7 Oct 2009, 7:48 PM
I'm using ext 2.2 and found this error in firebug:

Date.parseDate(value + " " + this.initTime, format + " " + this.initTimeFormat, strict) is undefined
http://xxxxxx/public/js/overrides_date.js
Line 173

the overrides works in ext 2.2?

thanks :)

Date.parseDate in 2.2 does not support the strict parsing option.

mystix
7 Oct 2009, 7:52 PM
a little fix to solve this issue:


safeParse : function(value, format, strict) {
if (/[gGhH]/.test(format.replace(/(\\.)/g, ''))) {
return Date.parseDate(value, format, strict);
} else {
var nd = Date.parseDate(value + ' ' + this.initTime, format + ' ' + this.initTimeFormat, strict);
if (nd !== undefined)
return nd.clearTime();
}
},

bingo. i'd completely forgotten about safeParse() -- i wrote it with the intention that it should be overridden to provide locale-specific DST handling (as per the comments i'd written for the method).

andregufc
8 Oct 2009, 3:39 AM
thanks a lot!

benyhapper
19 Oct 2009, 10:02 AM
Really solved in parts, but now if I put minValue: new Date ()
He does not accept the present day as a minimum, only days later.
He should accept today 19/10/2009 that is the least tested it with any other date and the problem occurs after this Override for a minimum is considered only the day after the current date.

Does anyone know how to solve?

Condor
19 Oct 2009, 10:20 AM
You should specify a date and not a timestamp:

minValue: new Date().clearTime()

benyhapper
19 Oct 2009, 10:28 AM
Thanks Condor, solved my problem

mofo
21 Oct 2009, 7:59 AM
Hi, I've had this problem, I saw the posts #9, #10 and #13. It works very fine.
But there is a day that doesn't work. I'm using GMT -3:00(Brazil), and here the daylight saving time was on october 18th, and if I choose this day, the DateField goes to october 17th.
I was looking the problem and I saw that It occurs when I call the clearTime function.
Can someone help me?
Thx.

AVerta
21 Oct 2009, 9:44 AM
Hi Mofo,

I get the same error here. When I select the october 18th, the Datefield change for 17th.

The amazing is that I found the problem with another application that I have with Java, only in october 18th. The error be in the Java object Calendar.

I think that this error occur because the Brazilian summer time started in october 18th.

Anyone can help us?

benyhapper
21 Oct 2009, 10:15 AM
In English
----------------
Have you used the override that is on page 2 of this topic, because it solves the problem.
I had the same problem and solved it, including my system where I called the function new Date () I moved to new Date (). clearTime (), and also solved the problem for the comparison of date Min and Max

Em português
----------------
Vocês já usaram o override que está na página 2 deste tópico, pois ele resolve o problema.
Eu tive o mesmo problema e ele resolveu, inclusive no meu sistema onde eu chamava a função new Date() eu mudei para new Date().clearTime(), assim resolvi também o problema para a comparação de Min e Max.

mofo
21 Oct 2009, 10:16 AM
Hi Mofo,

I get the same error here. When I select the october 18th, the Datefield change for 17th.

The amazing is that I found the problem with another application that I have with Java, only in october 18th. The error be in the Java object Calendar.

I think that this error occur because the Brazilian summer time started in october 18th.

Anyone can help us?
How I saw, the problem is on the clearTime I'm trying to resolve, But It's a little difficult becouse the method clearTime calls setHours(0), setMinutes(0), setSeconds(0), setMilliseconds(0), these methods are from JavaScript.

mofo
21 Oct 2009, 10:19 AM
In English
----------------
Have you used the override that is on page 2 of this topic, because it solves the problem.
I had the same problem and solved it, including my system where I called the function new Date () I moved to new Date (). clearTime (), and also solved the problem for the comparison of date Min and Max

Em português
----------------
Vocês já usaram o override que está na página 2 deste tópico, pois ele resolve o problema.
Eu tive o mesmo problema e ele resolveu, inclusive no meu sistema onde eu chamava a função new Date() eu mudei para new Date().clearTime(), assim resolvi também o problema para a comparação de Min e Max.

English:
Use where?
I was looking, the problem accurs when call the clearTime.
Yes, I'm using that codes but the problem still stay there, it's on october 18th, see if you have this problem too.
portugues:
Usar onde?
Eu estava olhando lá, o problema ocorre na chamado do clearTime
Sim eu já estou usando aqueles codigo mas o problema ainda esta lá, é no dia 18 the outrubro. da uma olhada se vc não esta com o mesmo problema.

AVerta
21 Oct 2009, 10:36 AM
In English
-------------
I´m using the override from page 2 and put the Nom4d3 correction on page 3. But, don´t works. And I´m using the DateField in FormPanel (see the code), and not call the function with new Date(). Any suggestion?

Em Português
-------------
Estou usando o override da página 2 e ainda apliquei a correção feita pelo Nom4d3 na página 3. E mesmo assim não funciona. Eu estou usando o DateField dentro do FormPanel (veja o código), e não chamando a função através de new Date(). Alguma sugestão?



items: [{
fieldLabel:'De',
xtype:'datefield',
id:'dt_ini_periodo',
name:'dt_ini_periodo',
maxLength:60,
width:200,
allowBlank:false
}

mofo
21 Oct 2009, 10:45 AM
In English
-------------
I´m using the override from page 2 and put the Nom4d3 correction on page 3. But, don´t works. And I´m using the DateField in FormPanel (see the code), and not call the function with new Date(). Any suggestion?

Em Português
-------------
Estou usando o override da página 2 e ainda apliquei a correção feita pelo Nom4d3 na página 3. E mesmo assim não funciona. Eu estou usando o DateField dentro do FormPanel (veja o código), e não chamando a função através de new Date(). Alguma sugestão?



items: [{
fieldLabel:'De',
xtype:'datefield',
id:'dt_ini_periodo',
name:'dt_ini_periodo',
maxLength:60,
width:200,
allowBlank:false
}

English:
So, I'm using these overrides too and I have the same problem.
I don't know what happen. ''/

Portuguese:
Então, Eu também estou usando, e to com o mesmo problema.
Eu não sei o que acontece não ''/

mystix
21 Oct 2009, 10:52 AM
How I saw, the problem is on the clearTime I'm trying to resolve, But It's a little difficult becouse the method clearTime calls setHours(0), setMinutes(0), setSeconds(0), setMilliseconds(0), these methods are from JavaScript.

but Date.prototype.clearTime() (in both Ext 2.3.0 and 3.x) does make provision for DST:


clearTime : function(clone) {
if (clone) {
return this.clone().clearTime();
}

// get current date before clearing time
var d = this.getDate();

// clear time
this.setHours(0);
this.setMinutes(0);
this.setSeconds(0);
this.setMilliseconds(0);

if (this.getDate() != d) { // account for DST (i.e. day of month changed when setting hour = 0)
// note: DST adjustments are assumed to occur in multiples of 1 hour (this is almost always the ca
// refer to http://www.timeanddate.com/time/aboutdst.html for the (rare) exceptions to this rule

// increment hour until cloned date == current date
for (var hr = 1, c = this.add(Date.HOUR, hr); c.getDate() != d; hr++, c = this.add(Date.HOUR, hr));

this.setDate(d);
this.setHours(c.getHours());
}

return this;
}

mofo
21 Oct 2009, 11:04 AM
mystix when I use this code, still don't work.
If I type 18/10/2009, the function returns 'Sat Oct 17 23:00:00 UTC-0300 2009'
If I select on the DatePicker,october 18th, still goes to october 17th.

mofo
22 Oct 2009, 7:20 AM
but Date.prototype.clearTime() (in both Ext 2.3.0 and 3.x) does make provision for DST:


clearTime : function(clone) {
if (clone) {
return this.clone().clearTime();
}

// get current date before clearing time
var d = this.getDate();

// clear time
this.setHours(0);
this.setMinutes(0);
this.setSeconds(0);
this.setMilliseconds(0);

if (this.getDate() != d) { // account for DST (i.e. day of month changed when setting hour = 0)
// note: DST adjustments are assumed to occur in multiples of 1 hour (this is almost always the ca
// refer to http://www.timeanddate.com/time/aboutdst.html for the (rare) exceptions to this rule

// increment hour until cloned date == current date
for (var hr = 1, c = this.add(Date.HOUR, hr); c.getDate() != d; hr++, c = this.add(Date.HOUR, hr))

this.setDate(d);
this.setHours(c.getHours());
}

return this;
}

did you have any evolution?
Thx

mystix
22 Oct 2009, 8:04 AM
sorry i don't understand. what "evolution" are you referring to? :-/

mofo
22 Oct 2009, 8:07 AM
sorry i don't understand. what "evolution" are you referring to? :-/
please look post #45.
Thx

mystix
22 Oct 2009, 8:23 AM
according to @nom4d3, he's also in the Brazillian timezone, using Ext 2.3, but he's not experiencing any problems (please see his posts earlier in this thread).

have you updated your Windows XP timezone database as mentioned in post #10?
http://support.microsoft.com/kb/914387
(i'm assuming you're running Windows XP, please correct me if i'm wrong)

pabloidz
22 Oct 2009, 8:28 AM
Hi there,

I was getting the same error (another victim of Brazilian Oct 18), with Ext 2.2. I discovered that the clearTime function in this version doesn't account for DST, but the override per se didn't solve the problem.

I had to change a single line in the function: in the for-loop marked below, I included brackets, and now it does work for any date. I didn't tried it with 2.3+, but let me know if it will solve in subsequent versions:


Date.prototype.clearTime = function(clone) {
if (clone) {
return this.clone().clearTime();
}

// get current date before clearing time
var d = this.getDate();

// clear time
this.setHours(0);
this.setMinutes(0);
this.setSeconds(0);
this.setMilliseconds(0);

if (this.getDate() != d) { // account for DST (i.e. day of month changed when setting hour = 0)
// note: DST adjustments are assumed to occur in multiples of 1 hour (this is almost always the ca
// refer to http://www.timeanddate.com/time/aboutdst.html for the (rare) exceptions to this rule
// increment hour until cloned date == current date
for (var hr = 1, c = this.add(Date.HOUR, hr); c.getDate() != d; hr++, c = this.add(Date.HOUR, hr)) {}
this.setDate(d);
this.setHours(c.getHours());
}

return this;
}

You must add the code above in the same file as the @mystix's patch at second page.

mystix
22 Oct 2009, 9:01 AM
@pabloidz:

i see the problem with the override now -- there's a missing semicolon at the end of the for loop. when the code gets minified the next line gets merged into a single line, which will cause problems.

you can safely remove the empty parentheses and add a single semicolon, like so:


for (var hr = 1, c = this.add(Date.HOUR, hr); c.getDate() != d; hr++, c = this.add(Date.HOUR, hr));

that should do the trick.

i'll update the override to include that missing semicolon.

mofo
22 Oct 2009, 9:04 AM
Hi there,

I was getting the same error (another victim of Brazilian Oct 18), with Ext 2.2. I discovered that the clearTime function in this version doesn't account for DST, but the override per se didn't solve the problem.

I had to change a single line in the function: in the for-loop marked below, I included brackets, and now it does work for any date. I didn't tried it with 2.3+, but let me know if it will solve in subsequent versions:


Date.prototype.clearTime = function(clone) {
if (clone) {
return this.clone().clearTime();
}

// get current date before clearing time
var d = this.getDate();

// clear time
this.setHours(0);
this.setMinutes(0);
this.setSeconds(0);
this.setMilliseconds(0);

if (this.getDate() != d) { // account for DST (i.e. day of month changed when setting hour = 0)
// note: DST adjustments are assumed to occur in multiples of 1 hour (this is almost always the ca
// refer to http://www.timeanddate.com/time/aboutdst.html for the (rare) exceptions to this rule
// increment hour until cloned date == current date
for (var hr = 1, c = this.add(Date.HOUR, hr); c.getDate() != d; hr++, c = this.add(Date.HOUR, hr)) {}
this.setDate(d);
this.setHours(c.getHours());
}

return this;
}You must add the code above in the same file as the @mystix's patch at second page.

It works. Thx very mach.

mystix
22 Oct 2009, 9:25 AM
@mofo, for completeness, could you state the version of Ext you're currently using?
i searched through all your posts in this thread but didn't see you / @averta mention any version number.

pabloidz
22 Oct 2009, 9:51 AM
@pabloidz:

i see the problem with the override now -- there's a missing semicolon at the end of the for loop. when the code gets minified the next line gets merged into a single line, which will cause problems.

you can safely remove the empty parentheses and add a single semicolon, like so:


for (var hr = 1, c = this.add(Date.HOUR, hr); c.getDate() != d; hr++, c = this.add(Date.HOUR, hr));

that should do the trick.

i'll update the override to include that missing semicolon.

Thanks mystix, just with the single semicolon it already works. I might get confused while testing and debugging ~o) ;)

mofo
22 Oct 2009, 10:08 AM
@mofo, for completeness, could you state the version of Ext you're currently using?
i searched through all your posts in this thread but didn't see you / @averta mention any version number.
I work with 1.1.1 and 2.x. . 1.1.1 it worked well, too, only need to put the modification on the code from 1.1.1.

wagner-morais
19 Oct 2010, 5:00 AM
I'm on 2.3.0, my timezone is -3 (Brazil).
I did the overrides but I still cannot use the date 17/10/2010.

Any help?
Thanks!

mystix
19 Oct 2010, 5:25 AM
I'm on 2.3.0, my timezone is -3 (Brazil).
I did the overrides but I still cannot use the date 17/10/2010.

Any help?
Thanks!

see post post #49.

wagner-morais
19 Oct 2010, 5:35 AM
I'm using Windows 7 Professional, not XP.

AVerta
19 Oct 2010, 8:11 AM
Wagner,

The code posted here works. The full code for use:



Ext.override(Ext.DatePicker, {
// private
update : function(date, forceRefresh) {
var vd = this.activeDate;
this.activeDate = date;
if (!forceRefresh && vd && this.el) {
var t = date.getTime();
if (vd.getMonth() == date.getMonth() && vd.getFullYear() == date.getFullYear()) {
this.cells.removeClass("x-date-selected");
this.cells.each(function(c) {
if (c.dom.firstChild.dateValue == t) {
c.addClass("x-date-selected");
setTimeout(function() {
try {
c.dom.firstChild.focus();
} catch(e) {
}
}, 50);
return false;
}
});
return;
}
}
var days = date.getDaysInMonth();
var firstOfMonth = date.getFirstDateOfMonth();
var startingPos = firstOfMonth.getDay() - this.startDay;

if (startingPos <= this.startDay) {
startingPos += 7;
}

var pm = date.add("mo", -1);
var prevStart = pm.getDaysInMonth() - startingPos;

var cells = this.cells.elements;
var textEls = this.textNodes;
days += startingPos;

// convert everything to numbers so it's fast
// var day = 86400000; // not in use
var d = (new Date(pm.getFullYear(), pm.getMonth(), prevStart, 12)); // )).clearTime();
var today = new Date().clearTime().getTime();
var sel = date.clearTime().getTime(true);
var min = this.minDate ? this.minDate.clearTime(true) : Number.NEGATIVE_INFINITY;
var max = this.maxDate ? this.maxDate.clearTime(true) : Number.POSITIVE_INFINITY;
var ddMatch = this.disabledDatesRE;
var ddText = this.disabledDatesText;
var ddays = this.disabledDays ? this.disabledDays.join("") : false;
var ddaysText = this.disabledDaysText;
var format = this.format;

if (this.showToday) {
var td = new Date().clearTime();
var disable = (td < min || td > max ||
(ddMatch && format && ddMatch.test(td.dateFormat(format))) ||
(ddays && ddays.indexOf(td.getDay()) != -1));

this.todayBtn.setDisabled(disable);
this.todayKeyListener[disable ? 'disable' : 'enable']();
}

var setCellClass = function(cal, cell) {
cell.title = "";
var t = d.clearTime(true).getTime();
cell.firstChild.dateValue = t;
if (t == today) {
cell.className += " x-date-today";
cell.title = cal.todayText;
}
if (t == sel) {
cell.className += " x-date-selected";
setTimeout(function() {
try {
cell.firstChild.focus();
} catch(e) {
}
}, 50);
}
// disabling
if (t < min) {
cell.className = " x-date-disabled";
cell.title = cal.minText;
return;
}
if (t > max) {
cell.className = " x-date-disabled";
cell.title = cal.maxText;
return;
}
if (ddays) {
if (ddays.indexOf(d.getDay()) != -1) {
cell.title = ddaysText;
cell.className = " x-date-disabled";
}
}
if (ddMatch && format) {
var fvalue = d.dateFormat(format);
if (ddMatch.test(fvalue)) {
cell.title = ddText.replace("%0", fvalue);
cell.className = " x-date-disabled";
}
}
};

var i = 0;
for (; i < startingPos; i++) {
textEls[i].innerHTML = (++prevStart);
d.setDate(d.getDate() + 1);
cells[i].className = "x-date-prevday";
setCellClass(this, cells[i]);
}
for (; i < days; i++) {
var intDay = i - startingPos + 1;
textEls[i].innerHTML = (intDay);
d.setDate(d.getDate() + 1);
cells[i].className = "x-date-active";
setCellClass(this, cells[i]);
}
var extraDays = 0;
for (; i < 42; i++) {
textEls[i].innerHTML = (++extraDays);
d.setDate(d.getDate() + 1);
cells[i].className = "x-date-nextday";
setCellClass(this, cells[i]);
}

this.mbtn.setText(this.monthNames[date.getMonth()] + " " + date.getFullYear());

if (!this.internalRender) {
var main = this.el.dom.firstChild;
var w = main.offsetWidth;
this.el.setWidth(w + this.el.getBorderWidth("lr"));
Ext.fly(main).setWidth(w);
this.internalRender = true;
// opera does not respect the auto grow header center column
// then, after it gets a width opera refuses to recalculate
// without a second pass
if (Ext.isOpera && !this.secondPass) {
main.rows[0].cells[1].style.width = (w - (main.rows[0].cells[0].offsetWidth + main.rows[0].cells[2].offsetWidth)) + "px";
this.secondPass = true;
this.update.defer(10, this, [date]);
}
}
}
});

Ext.override(Ext.form.DateField, {
/**
* @cfg {Boolean} strict
* false to allow Date "rollover" for invalid dates (defaults to true)
*/
strict: true,

// private -- in the absence of a time value, a default value of 12 noon will be used
// (note: 12 noon was chosen because it steers well clear of all DST timezone changes)
initTime: '12', // 24 hour format

// private
initTimeFormat: 'H',

// note: this turned out to be reaaaaaalllly difficult to customize to
// fit every situation, so what i've put up here is a real naive implementation which
// works for the online examples (disclaimer: i've only tried it on one, but most of the configs are similar).
// i suggest customizing it so it fits your particular situation. ask if you don't understand what on earth
// i'm trying to achieve with this function
safeParse : function(value, format, strict) {
if (/[gGhH]/.test(format.replace(/(\\.)/g, ''))) {
// if parse format contains hour information, no DST adjustment is necessary
return Date.parseDate(value, format, strict);
} else {
// set time to 12 noon, then clear the time
//return Date.parseDate(value + ' ' + this.initTime, format + ' ' + this.initTimeFormat, strict).clearTime();
var nd = Date.parseDate(value + ' ' + this.initTime, format + ' ' + this.initTimeFormat, strict);
if (nd != undefined)
return nd.clearTime();
}
},

parseDate : function(value) {
if(!value || Ext.isDate(value)){
return value;
}

var v = this.safeParse(value, this.format, this.strict),
af = this.altFormats;

if (!v && af) {
if (!this.altFormatsArray) {
this.altFormatsArray = af.split("|");
}

for (var i = 0, afa = this.altFormatsArray, len = afa.length; i < len && !v; i++) {
v = this.safeParse(value, afa[i], this.strict);
}
}
return v;
}
});

Date.prototype.clearTime = function(clone) {
if (clone) {
return this.clone().clearTime();
}

// get current date before clearing time
var d = this.getDate();

// clear time
this.setHours(0);
this.setMinutes(0);
this.setSeconds(0);
this.setMilliseconds(0);

if (this.getDate() != d) { // account for DST (i.e. day of month changed when setting hour = 0)
// note: DST adjustments are assumed to occur in multiples of 1 hour (this is almost always the ca
// refer to http://www.timeanddate.com/time/aboutdst.html for the (rare) exceptions to this rule
// increment hour until cloned date == current date
for (var hr = 1, c = this.add(Date.HOUR, hr); c.getDate() != d; hr++, c = this.add(Date.HOUR, hr)) {}
this.setDate(d);
this.setHours(c.getHours());
}

return this;
}

wagner-morais
19 Oct 2010, 8:48 AM
AVerta, Thank you VERY much!
It works!