In Developer 5.2 on Mac, Java 1.6 I’m seeing inconsistent results with utils.dateFormat(df, ‘MM-dd-yyyy’) for dates prior to 1/1/1970
For the months November through to March, it can return the day before the actual date.
April to October returns the correct day.
function date_test() {
// TODO Auto-generated method stub
var dd = 1
var df = null
var ds = ""
for ( var yy = 1968; yy <= 1972 ; yy++ )
{
for ( var mm = 0 ; mm <= 11 ; mm++ )
{
df = new Date(yy, mm, dd)
ds = utils.dateFormat(df, 'MM-dd-yyyy')
application.output(ds + " " + df)
}
}
}
returns this - the first date string ds on each line should be the first of the month, based on the datetime value df. It’s not a leap year thing, it’s not a summer time thing. It must have something to do with java dates using 1/1/1970 as the reference point.
12-31-1967 Mon Jan 01 1968 00:00:00 GMT+1100 (EST)
01-31-1968 Thu Feb 01 1968 00:00:00 GMT+1100 (EST)
02-29-1968 Fri Mar 01 1968 00:00:00 GMT+1100 (EST)
04-01-1968 Mon Apr 01 1968 00:00:00 GMT+1000 (EST)
05-01-1968 Wed May 01 1968 00:00:00 GMT+1000 (EST)
06-01-1968 Sat Jun 01 1968 00:00:00 GMT+1000 (EST)
07-01-1968 Mon Jul 01 1968 00:00:00 GMT+1000 (EST)
08-01-1968 Thu Aug 01 1968 00:00:00 GMT+1000 (EST)
09-01-1968 Sun Sep 01 1968 00:00:00 GMT+1000 (EST)
10-01-1968 Tue Oct 01 1968 00:00:00 GMT+1000 (EST)
10-31-1968 Fri Nov 01 1968 00:00:00 GMT+1100 (EST)
11-30-1968 Sun Dec 01 1968 00:00:00 GMT+1100 (EST)
12-31-1968 Wed Jan 01 1969 00:00:00 GMT+1100 (EST)
01-31-1969 Sat Feb 01 1969 00:00:00 GMT+1100 (EST)
02-28-1969 Sat Mar 01 1969 00:00:00 GMT+1100 (EST)
04-01-1969 Tue Apr 01 1969 00:00:00 GMT+1000 (EST)
05-01-1969 Thu May 01 1969 00:00:00 GMT+1000 (EST)
06-01-1969 Sun Jun 01 1969 00:00:00 GMT+1000 (EST)
07-01-1969 Tue Jul 01 1969 00:00:00 GMT+1000 (EST)
08-01-1969 Fri Aug 01 1969 00:00:00 GMT+1000 (EST)
09-01-1969 Mon Sep 01 1969 00:00:00 GMT+1000 (EST)
10-01-1969 Wed Oct 01 1969 00:00:00 GMT+1000 (EST)
10-31-1969 Sat Nov 01 1969 00:00:00 GMT+1100 (EST)
11-30-1969 Mon Dec 01 1969 00:00:00 GMT+1100 (EST)
12-31-1969 Thu Jan 01 1970 00:00:00 GMT+1100 (EST)
02-01-1970 Sun Feb 01 1970 00:00:00 GMT+1000 (EST)
03-01-1970 Sun Mar 01 1970 00:00:00 GMT+1000 (EST)
04-01-1970 Wed Apr 01 1970 00:00:00 GMT+1000 (EST)
05-01-1970 Fri May 01 1970 00:00:00 GMT+1000 (EST)
06-01-1970 Mon Jun 01 1970 00:00:00 GMT+1000 (EST)
07-01-1970 Wed Jul 01 1970 00:00:00 GMT+1000 (EST)
08-01-1970 Sat Aug 01 1970 00:00:00 GMT+1000 (EST)
09-01-1970 Tue Sep 01 1970 00:00:00 GMT+1000 (EST)
10-01-1970 Thu Oct 01 1970 00:00:00 GMT+1000 (EST)
11-01-1970 Sun Nov 01 1970 00:00:00 GMT+1000 (EST)
12-01-1970 Tue Dec 01 1970 00:00:00 GMT+1000 (EST)
01-01-1971 Fri Jan 01 1971 00:00:00 GMT+1000 (EST)
02-01-1971 Mon Feb 01 1971 00:00:00 GMT+1000 (EST)
03-01-1971 Mon Mar 01 1971 00:00:00 GMT+1000 (EST)
04-01-1971 Thu Apr 01 1971 00:00:00 GMT+1000 (EST)
05-01-1971 Sat May 01 1971 00:00:00 GMT+1000 (EST)
06-01-1971 Tue Jun 01 1971 00:00:00 GMT+1000 (EST)
07-01-1971 Thu Jul 01 1971 00:00:00 GMT+1000 (EST)
08-01-1971 Sun Aug 01 1971 00:00:00 GMT+1000 (EST)
09-01-1971 Wed Sep 01 1971 00:00:00 GMT+1000 (EST)
10-01-1971 Fri Oct 01 1971 00:00:00 GMT+1000 (EST)
11-01-1971 Mon Nov 01 1971 00:00:00 GMT+1100 (EST)
12-01-1971 Wed Dec 01 1971 00:00:00 GMT+1100 (EST)
01-01-1972 Sat Jan 01 1972 00:00:00 GMT+1100 (EST)
02-01-1972 Tue Feb 01 1972 00:00:00 GMT+1100 (EST)
03-01-1972 Wed Mar 01 1972 00:00:00 GMT+1000 (EST)
04-01-1972 Sat Apr 01 1972 00:00:00 GMT+1000 (EST)
05-01-1972 Mon May 01 1972 00:00:00 GMT+1000 (EST)
06-01-1972 Thu Jun 01 1972 00:00:00 GMT+1000 (EST)
07-01-1972 Sat Jul 01 1972 00:00:00 GMT+1000 (EST)
08-01-1972 Tue Aug 01 1972 00:00:00 GMT+1000 (EST)
09-01-1972 Fri Sep 01 1972 00:00:00 GMT+1000 (EST)
10-01-1972 Sun Oct 01 1972 00:00:00 GMT+1000 (EST)
11-01-1972 Wed Nov 01 1972 00:00:00 GMT+1100 (EST)
12-01-1972 Fri Dec 01 1972 00:00:00 GMT+1100 (EST)
for the once that go wrong you suddenly see: “GMT+1100”
and that extra hour is i guess DST
But why that suddenly has an effect on the actual toString() of the date, i dont know
what does a browser do if you run that script?
jcompagner:
for the once that go wrong you suddenly see: “GMT+1100”
and that extra hour is i guess DST
Yes, the +1100 would fit with our Australian DST months. However the results >= 1/1/1970 give the correct date with and without DST.
what does a browser do if you run that script?
The same results in WC (Safari). I’ve tried running it late at night and early morning to see if the difference between local and UTC date makes a difference - it doesn’t. BTW, I tried in Servoy 3, the function works fine there, same machine, same Java.
12-31-1967 Mon Jan 01 1968 00:00:00 GMT+1100 (EST)
01-31-1968 Thu Feb 01 1968 00:00:00 GMT+1100 (EST)
02-29-1968 Fri Mar 01 1968 00:00:00 GMT+1100 (EST)
04-01-1968 Mon Apr 01 1968 00:00:00 GMT+1000 (EST)
05-01-1968 Wed May 01 1968 00:00:00 GMT+1000 (EST)
06-01-1968 Sat Jun 01 1968 00:00:00 GMT+1000 (EST)
07-01-1968 Mon Jul 01 1968 00:00:00 GMT+1000 (EST)
08-01-1968 Thu Aug 01 1968 00:00:00 GMT+1000 (EST)
09-01-1968 Sun Sep 01 1968 00:00:00 GMT+1000 (EST)
10-01-1968 Tue Oct 01 1968 00:00:00 GMT+1000 (EST)
10-31-1968 Fri Nov 01 1968 00:00:00 GMT+1100 (EST)
11-30-1968 Sun Dec 01 1968 00:00:00 GMT+1100 (EST)
12-31-1968 Wed Jan 01 1969 00:00:00 GMT+1100 (EST)
01-31-1969 Sat Feb 01 1969 00:00:00 GMT+1100 (EST)
02-28-1969 Sat Mar 01 1969 00:00:00 GMT+1100 (EST)
04-01-1969 Tue Apr 01 1969 00:00:00 GMT+1000 (EST)
05-01-1969 Thu May 01 1969 00:00:00 GMT+1000 (EST)
06-01-1969 Sun Jun 01 1969 00:00:00 GMT+1000 (EST)
07-01-1969 Tue Jul 01 1969 00:00:00 GMT+1000 (EST)
08-01-1969 Fri Aug 01 1969 00:00:00 GMT+1000 (EST)
09-01-1969 Mon Sep 01 1969 00:00:00 GMT+1000 (EST)
10-01-1969 Wed Oct 01 1969 00:00:00 GMT+1000 (EST)
10-31-1969 Sat Nov 01 1969 00:00:00 GMT+1100 (EST)
11-30-1969 Mon Dec 01 1969 00:00:00 GMT+1100 (EST)
12-31-1969 Thu Jan 01 1970 00:00:00 GMT+1100 (EST)
02-01-1970 Sun Feb 01 1970 00:00:00 GMT+1000 (EST)
03-01-1970 Sun Mar 01 1970 00:00:00 GMT+1000 (EST)
04-01-1970 Wed Apr 01 1970 00:00:00 GMT+1000 (EST)
05-01-1970 Fri May 01 1970 00:00:00 GMT+1000 (EST)
06-01-1970 Mon Jun 01 1970 00:00:00 GMT+1000 (EST)
07-01-1970 Wed Jul 01 1970 00:00:00 GMT+1000 (EST)
08-01-1970 Sat Aug 01 1970 00:00:00 GMT+1000 (EST)
09-01-1970 Tue Sep 01 1970 00:00:00 GMT+1000 (EST)
10-01-1970 Thu Oct 01 1970 00:00:00 GMT+1000 (EST)
11-01-1970 Sun Nov 01 1970 00:00:00 GMT+1000 (EST)
12-01-1970 Tue Dec 01 1970 00:00:00 GMT+1000 (EST)
01-01-1971 Fri Jan 01 1971 00:00:00 GMT+1000 (EST)
02-01-1971 Mon Feb 01 1971 00:00:00 GMT+1000 (EST)
03-01-1971 Mon Mar 01 1971 00:00:00 GMT+1000 (EST)
04-01-1971 Thu Apr 01 1971 00:00:00 GMT+1000 (EST)
05-01-1971 Sat May 01 1971 00:00:00 GMT+1000 (EST)
06-01-1971 Tue Jun 01 1971 00:00:00 GMT+1000 (EST)
07-01-1971 Thu Jul 01 1971 00:00:00 GMT+1000 (EST)
08-01-1971 Sun Aug 01 1971 00:00:00 GMT+1000 (EST)
09-01-1971 Wed Sep 01 1971 00:00:00 GMT+1000 (EST)
10-01-1971 Fri Oct 01 1971 00:00:00 GMT+1000 (EST)
11-01-1971 Mon Nov 01 1971 00:00:00 GMT+1100 (EST)
12-01-1971 Wed Dec 01 1971 00:00:00 GMT+1100 (EST)
01-01-1972 Sat Jan 01 1972 00:00:00 GMT+1100 (EST)
02-01-1972 Tue Feb 01 1972 00:00:00 GMT+1100 (EST)
03-01-1972 Wed Mar 01 1972 00:00:00 GMT+1000 (EST)
04-01-1972 Sat Apr 01 1972 00:00:00 GMT+1000 (EST)
05-01-1972 Mon May 01 1972 00:00:00 GMT+1000 (EST)
06-01-1972 Thu Jun 01 1972 00:00:00 GMT+1000 (EST)
07-01-1972 Sat Jul 01 1972 00:00:00 GMT+1000 (EST)
08-01-1972 Tue Aug 01 1972 00:00:00 GMT+1000 (EST)
09-01-1972 Fri Sep 01 1972 00:00:00 GMT+1000 (EST)
10-01-1972 Sun Oct 01 1972 00:00:00 GMT+1000 (EST)
11-01-1972 Wed Nov 01 1972 00:00:00 GMT+1100 (EST)
12-01-1972 Fri Dec 01 1972 00:00:00 GMT+1100 (EST)
how did you run in safari? just in the webclient? i meant really as script in a temp.html file
But then you dont have utils.dateFormat ofcouse, what does the toString() of the date print out then?
Because i have no idee what we could do different in dateformat call itself, thats just 1/2 lines of code:
SimpleDateFormat sdf = new SimpleDateFormat(format.toString(), application.getLocale());
return sdf.format((Date)date);
so somehow it should already be wrong in the date itself coming from rhino/js
<html>
<body>
<script>
for (year = 1969; year < 1972; year++){
document.write("<H1>"+ year + "</H1>");
document.write("<table border=1>");
for (month = 0; month < 12; month++) {
d = new Date(year,month,1,1,0,0)
document.write("<tr>");
document.write("<td>");
document.write(d.toUTCString());
document.write("</td>");
document.write("<td>");
document.write(d.toString());
document.write("</td>");
document.write("</tr>");
}
document.write("</table>");
}
</script>
</body>
</html>
I had to add 1 hour in new Date because I am in GMT + 1 so the behaviour can only be seen if your os’s timezone is set to GTM+1. I guess Antonio’s timezone adds that one hour for him automatically.
UTC is compensating for DST setting you back one hour crossing the date border setting you back one day.
So maybe it is in the way Rhino implements dates for you would expect the same behviour in Servoy. I have no other working Rhino implementations, would be interesting to see what it does there.
Strangely enough, you will get the same behaviour for year before 1895 when DST didn’t exist.
On the DST theme, why are only dates < 1/1/1970 affected? That seems like a pointer to the source of the problem.
I use utils.dateFormat() to display dates of birth, so everyone here more than 40 years old and born in summer is now a day older.
Being over 40 is already bad enough.
Has anything changed between Servoy 3 and 5 with date handling?
Could it be the new Date() function rather than the utils.dateFormat() function, that is processing dates differently in 5.x compared to 3.x
This problem is now fixed (for 5.2.3). It was indeed related to DST and it was indeed different in Servoy 3, because Servoy 3 uses an older version of Rhino.
A change in the newer versions of Rhino made it handle DST differently then the way Java does. Anyway, although the dates were displayed differently, if you would convert them to GMT they would be the same.