com.caucho.quercus.QuercusException: com.caucho.quercus.lib.date.DateTime.setISODate: `DateTime::setISODate()' has not been implemented. A more recent version of Quercus may be available at http://www.caucho.com/download Requests for unimplemented features can be entered in the bugtracking system at http://bugs.caucho.com
// See http://stackoverflow.com/questions/147178/what-is-a-good-simple-way-to-compute-iso-8601-week-number
private static Date setISODate(int weekYear, int weekOfYear, int dayOfWeek) {
Calendar calendar = Calendar.getInstance();
calendar.setMinimalDaysInFirstWeek(4);
calendar.setFirstDayOfWeek(Calendar.MONDAY);
if (dayOfWeek > 7) {
weekOfYear += dayOfWeek / 7;
dayOfWeek = ((dayOfWeek - 1) % 7) + 1;
}
int calDayOfWeek = 0;
switch (dayOfWeek) {
case 1:
calDayOfWeek = Calendar.MONDAY;
break;
case 2:
calDayOfWeek = Calendar.TUESDAY;
break;
case 3:
calDayOfWeek = Calendar.WEDNESDAY;
break;
case 4:
calDayOfWeek = Calendar.THURSDAY;
break;
case 5:
calDayOfWeek = Calendar.FRIDAY;
break;
case 6:
calDayOfWeek = Calendar.SATURDAY;
break;
case 7:
calDayOfWeek = Calendar.SUNDAY;
break;
default:
throw new IllegalArgumentException("Invalid dayOfWeek: " + dayOfWeek);
}
calendar.setWeekDate(weekYear, weekOfYear, calDayOfWeek);
calendar.set(Calendar.HOUR, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
return calendar.getTime();
}
// This is an overloaded version of the above function that does not require the dayOfWeek
// I am not sure how the @Optional annotation works in Quercus,
// so you may need to combine the two functions into one.
private static Date setISODate(int weekYear, int weekOfYear) {
return setISODate(weekYear, weekOfYear, 1);
}
// This is a simple test per the original PHP function
// http://php.net/manual/en/datetime.setisodate.php
private static void testSetISODate() {
System.out.println(setISODate(2008, 2));
System.out.println(setISODate(2008, 2, 7));
System.out.println(setISODate(2008, 2, 8));
System.out.println(setISODate(2008, 53, 7));
}
A few potential enhancements:
1. Check that weekYear >= 1583 or >= 1875 (see https://en.wikipedia.org/wiki/ISO_8601)
2. Handling of non-positive dayOfWeek (I know very little about PHP, but the description of the original function suggests that such values are supported and treated as negative offsets vs. Monday = 1).
3. Use one instance of Calendar and make it multi-threaded with synchronized() if required [creation of Calendar is apparently expensive].
Anyway, feel free to use/change this code as you see fit and check it into Quercus (the lack of setISODate() is a blocking issue for me and others).
--
You received this message because you are subscribed to the Google Groups "Quercus" group.
To unsubscribe from this group and stop receiving emails from it, send an email to caucho-quercu...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Add me to the list of those who would like setISODate support. Kudos on the current version of Pretty Permalink Filter - it is absolutely plug-and-play in our Tomcat / Quercos environment. Just dropped the jar in, restarted Tomcat, changed my permalinks to "postname" and was done. Very nice. I was skeptical about the maturity of the software, but it absolutely works as advertised. Alas, all of our existing posts have Month+Name permalinks... Feature request!
We can redirect all the Month+Name permalinks to point at the new Postname permalinks.
But we cannot redirect our archives (Year+Month). Any blog that makes their archives available will need setISODate support.
Pretty Permalink Filter is wonderful, nonetheless. Thank you!
// index = 0..6
private static final int[] calDaysOfWeek = {
Calendar.MONDAY,
Calendar.TUESDAY,
Calendar.WEDNESDAY,
Calendar.THURSDAY,
Calendar.FRIDAY,
Calendar.SATURDAY,
Calendar.SUNDAY
};
// http://stackoverflow.com/questions/147178/what-is-a-good-simple-way-to-compute-iso-8601-week-number
private static Date setISODate(int weekYear, int weekOfYear, int dayOfWeek) {
Calendar calendar = Calendar.getInstance();
calendar.setMinimalDaysInFirstWeek(4);
calendar.setFirstDayOfWeek(Calendar.MONDAY);
if (dayOfWeek < 1) {
// e.g. dayOfWeek == 0 is offset -1 (or 1 week) from dayOfWeek == 1 == Monday
// e.g. dayOfWeek == -6 is offset -7 (or still 1 week) from dayOfWeek == 1 == Monday
weekOfYear -= (7 - dayOfWeek) / 7;
// e.g. dayOfWeek == 0 is offset -1 from dayOfWeek == 1 == Monday, which means dayOfWeek == 6 ==Sunday
// e.g. dayOfWeek == -6 is offset -7 from dayOfWeek == 1 == Monday, which means dayOfWeek == 1 == Monday
dayOfWeek = 7 - ((-dayOfWeek) % 7);
}
else if (dayOfWeek > 7) {
// e.g. if dayOfWeek == 8, then advance by 1 week
weekOfYear += dayOfWeek / 7;
dayOfWeek = ((dayOfWeek - 1) % 7) + 1;
}
assert 1 <= dayOfWeek && dayOfWeek <= 7;
int calDayOfWeek = calDaysOfWeek[dayOfWeek - 1];
calendar.setWeekDate(weekYear, weekOfYear, calDayOfWeek);
calendar.set(Calendar.HOUR, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
return calendar.getTime();
}
private static Date setISODate(int weekYear, int weekOfYear) {
return setISODate(weekYear, weekOfYear, 1);
}
Kaz: Given that I have done most of the implementation work, when will you check in this code and make Quercus 4.0.40 available? Without setISODate(), WordPress on Quercus is not production-ready.
We also have to implement the simplexml_import_dom(). Without it, the key plugin wordpress-importer does not work, which means all posts (potentially, hundreds or thousands) from a WordPress export file would have to be manually imported. This, again, makes WordPress on Quercus not production-ready. Unfortunately, I do not have sufficient knowledge to implement this function. Perhaps someone else could step in and provide sample code?