public static int getWeekOfYear(Calendar c, boolean weekStartsSunday, boolean jan1midweek) {
        Calendar c2 = Calendar.getInstance(c.getTimeZone());
        c2.setTime(c.getTime());
        c2.set(Calendar.MONTH, Calendar.JANUARY);
        c2.set(Calendar.DAY_OF_MONTH, 1);
        int dayOfWeek = c2.get(Calendar.DAY_OF_WEEK);
        if (weekStartsSunday && dayOfWeek != Calendar.SUNDAY) {
            c2.set(Calendar.DAY_OF_MONTH,(7 - dayOfWeek) + 1);
        } else if (dayOfWeek != Calendar.MONDAY) {
            c2.set(Calendar.DAY_OF_MONTH,(7 - dayOfWeek + 1) + 1);
        }
        long diff = c.getTime().getTime() - c2.getTime().getTime();

        int w = (int)(diff / MILLIS_PER_WEEK);

        if (jan1midweek && 7-dayOfWeek >= 4)
            w++;

        return w;
    }
converts the relevant fields in the given luatable to a Date object.
@param time LuaTable with entries for year month and day, and optionally hour/min/sec
@return a date object representing the date frim the luatable.
main/src/main/java/cgeo/geocaching/wherigo/kahlua/stdlib/OsLib.java