Open GoogleCodeExporter opened 8 years ago
Hi George,
I tested your sample on a couple different computers with different culture
settings
and different timezones and each one returned week "53".
Can you confirm that you are using the latest code from svn
(http://www.datejs.com/svn/)?
Thanks for the code samples.
Original comment by geoff%co...@gtempaccount.com
on 2 Oct 2008 at 8:32
Yes. I've tried the following variations of the 2008 code but I still get the
same:
1. date.js
2. date-en-US.js
3. Including the 6 component files separately and in order.
(The download has 2007 code and has getWeekOfYear but not getWeek or
getISOWeek.)
BTW: The ISO 8601 standard for week does not involve converting to UTC.
FYI: Here's what I use for getting the week. It covers 5 different kinds of
weeks and
is much cleaner than Claus's code. To fit your methodology, you might do
something
like eliminate the parameter and break it up in 5 distinct methods.
Date.prototype.getWeekOfYear = function(flag) {
var j1 = new Date(this.getFullYear(), 0, 1);
var d_dow, j1_dow, d1w1;
switch (flag) {
case 'mon_iso':
d_dow = this.getDay() || 7;
j1_dow = j1.getDay() || 7;
d1w1 = new Date(j1.getTime() + (j1_dow>4 ? 8-j1_dow :
-(j1_dow-1))*1000*60*60*24);
break;
case 'mon_jan':
d_dow = this.getDay() || 7;
j1_dow = j1.getDay() || 7;
d1w1 = new Date(j1.getTime() - j1_dow*1000*60*60*24);
break;
case 'mon_mon':
d_dow = this.getDay() || 7;
j1_dow = j1.getDay() || 7;
d1w1 = new Date(j1.getTime() + (j1_dow==1 ? 0 : 8-j1_dow)*1000*60*60*24);
break;
case 'sun_sun':
d_dow = this.getDay();
j1_dow = j1.getDay();
d1w1 = new Date(j1.getTime() + (j1_dow ? 7-j1_dow : 0)*1000*60*60*24);
break;
case 'sun_jan':
default:
d_dow = this.getDay();
j1_dow = j1.getDay();
d1w1 = new Date(j1.getTime() - j1_dow*1000*60*60*24);
}
var daysDiff = Math.floor((this.getTime() - d1w1) /1000/60/60/24);
if (flag=='mon_iso' && j1_dow>4) {
var endOfLastYear = new Date(this.getFullYear()-1, 11, 31);
var wk = endOfLastYear.getWeekOfYear(1, 'iso');
} else var wk = Math.floor((daysDiff/7)+1);
return wk;
}
-George Hernandez
Original comment by georgelhernandez
on 3 Oct 2008 at 5:27
Oops! I had pasted in an old copy. Here's the current:
Date.prototype.getWeek = function(flag) {
var j1 = new Date(this.getFullYear(), 0, 1);
var d_dow, j1_dow, d1w1;
switch (flag) {
case 'mon_iso':
d_dow = this.getDay() || 7;
j1_dow = j1.getDay() || 7;
d1w1 = new Date(j1.getTime() + (j1_dow>4 ? 8-j1_dow :
-(j1_dow-1))*1000*60*60*24);
break;
case 'mon_jan':
d_dow = this.getDay() || 7;
j1_dow = j1.getDay() || 7;
d1w1 = new Date(j1.getTime() - (j1_dow-1)*1000*60*60*24);
break;
case 'mon_mon':
d_dow = this.getDay() || 7;
j1_dow = j1.getDay() || 7;
d1w1 = new Date(j1.getTime() + (j1_dow==1 ? 0 : 8-j1_dow)*1000*60*60*24);
break;
case 'sun_sun':
d_dow = this.getDay();
j1_dow = j1.getDay();
d1w1 = new Date(j1.getTime() + (j1_dow==0 ? 0 : 7-j1_dow)*1000*60*60*24);
break;
case 'sun_jan':
default:
d_dow = this.getDay();
j1_dow = j1.getDay();
d1w1 = new Date(j1.getTime() - (j1_dow)*1000*60*60*24);
}
var daysDiff = Math.floor((this.getTime() - d1w1.getTime()) /1000/60/60/24);
var wk = Math.floor((daysDiff/7)+1);
if (flag=='mon_iso' && wk==0) {
var endOfLastYear = new Date(this.getFullYear()-1, 11, 31);
wk = endOfLastYear.getWeek('mon_iso');
}
return wk.pad(2); //Assumes Number.prototype.pad in place
}
-George Hernandez
Original comment by georgelhernandez
on 3 Oct 2008 at 9:20
OK: In the 2008-05-13 version of Datejs, getISOWeek() correctly returns "53" for
2005-01-01. Consider this issue closed.
BTW: Nice work!
-George Hernandez
Original comment by georgelhernandez
on 10 Oct 2008 at 4:35
Why hasn't this issue been closed?
Original comment by harris...@gmail.com
on 21 Jul 2010 at 1:52
because Geoff has abandoned the project.
I've made a lot of fixes and progress on the issues here (as well as other
changes and features) on my fork here: https://github.com/abritinthebay/datejs/
Original comment by gwildsm...@bleacherreport.com
on 14 Sep 2013 at 12:50
Original issue reported on code.google.com by
georgelhernandez
on 2 Oct 2008 at 8:26