/** * Get day of week for this BigDate. Is it one-based starting with Sunday. * * @return day of week 1=Sunday 2=Monday 3=Tuesday 4=Wednesday 5=Thursday * 6=Friday 7=Saturday Compatible with Sun's 1=Calendar.SUNDAY Not * compatible with BigDate.getDayOfWee * * @see #getISODayOfWeek * @see #getDayOfWeek * @see #calendarDayOfWeek */ public final int getCalendarDayOfWeek() { return calendarDayOfWeek(ordinal); }
/** * Find the first monday in a given month, the 3rd monday or the last * Thursday... * * @param which * 1=first 2=second 3=third 4=fourth 5=last (might be 4th or 5th) * @param dayOfWeek * 0=Sunday 1=Monday 2=Tuesday 3=Wednesday 4=Thursday 5=Friday * 6=Saturday WARNING: not compatible with 1=Calendar.SUNDAY. * @param yyyy * year of interest. * @param mm * month 1 to 12 (not 0 to 11 as in Sun's Date) * * @return day of month 1..31 */ public static int nthXXXDay(int which, int dayOfWeek, int yyyy, int mm) { int dayOfWeekOf1st = BigDate.dayOfWeek(BigDate.toOrdinal(yyyy, mm, 1)); int dayOfMonthOfFirstDesiredDay = (dayOfWeek - dayOfWeekOf1st + 7) % 7 + 1; int dayOfMonthOfNthDesiredDay = dayOfMonthOfFirstDesiredDay + (which - 1) * 7; if (which >= 5 && dayOfMonthOfNthDesiredDay > daysInMonth(mm, yyyy)) { dayOfMonthOfNthDesiredDay -= 7; } return dayOfMonthOfNthDesiredDay; } // end nthXXXDay
/** * Convert date in form YYYY MM DD into days since the 1970 Jan 01. This * method lets you convert directly from Gregorian to ordinal without * creating a BigDate object. yyyy mm dd must be a valid date. * * @param yyyy * -999,999 (BC) to +999,999 (AD) * @param mm * month 1 to 12 (not 0 to 11 as in Sun's Date) * @param dd * day 1 to 31 * * @return ordinal, days since 1970 Jan 01. */ static public int toOrdinal(int yyyy, int mm, int dd) { // treat null date as a special case if ((yyyy == 0) && (mm == 0) && (dd == 0)) { return NULL_ORDINAL; } // jan01OfYear handles missing day adjustment for years > 1582 // We only need to handle year = 1582 here. int missingDayAdjust = (yyyy == OJC_lastYYYY && ((mm == OJC_lastMM && dd > OJC_lastDD) || mm > OJC_lastMM)) ? missingDays : 0; return jan01OfYear(yyyy) + daysInYearPriorToMonth(mm, isLeap(yyyy)) - missingDayAdjust + dd - 1; } // end toOrdinal
/** * Get week number 1 to 53 of the year this date falls in. This does NOT * follow the rules of ISO standard IS-8601 section 5.5. Week 1 is the first * week with any days in the current year. Weeks start on Sunday. Jan 1 and * Dec 31 are always considered part of the current year. Only defined for * dates on or after 1600 Jan 01. * * @return week number 1..53, 0 for null or invalid date. * * @see #getISOWeekNumber */ public final int getWeekNumber() { if (ordinal < Jan_01_Leap100RuleYear) { return 0; } int jan01 = jan01OfYear(yyyy); int jan01DayOfWeek = dayOfWeek(jan01); // 0=Sunday 1=Monday // 2=Tuesday 3=Wednesday // 4=Thursday 5=Friday // 6=Saturday int sundayOnOrBeforeJan01Ordinal = jan01 - jan01DayOfWeek; return ((ordinal - sundayOnOrBeforeJan01Ordinal) / 7) + 1; } // end getWeekNumber
setOrdinal((int) (utcTimestamp / 86400000L)); int offsetInMillis = timeZone.getOffset(getOrdinal() >= Jan_01_0001 ? 1 : 0, getYYYY(), getMM() - 1, getDD(), getCalendarDayOfWeek(), (int) (utcTimestamp % 86400000L) setOrdinal((int) ((utcTimestamp + offsetInMillis) / 86400000L));
if (birthDate.getOrdinal() >= asof.getOrdinal()) { return new int[] { 0, 0, 0 }; int birthYYYY = birthDate.getYYYY(); int birthMM = birthDate.getMM(); int birthDD = birthDate.getDD(); int asofYYYY = asof.getYYYY(); int asofMM = asof.getMM(); int asofDD = asof.getDD(); ageInDays += BigDate.daysInMonth(birthMM, birthYYYY); ageInMonths--;
} else if (ordinal >= GC_firstOrdinal) { yyyy = Leap400RuleYYYY + flooredMulDiv(ordinal - Jan_01_Leap400RuleYear, 10000, 3652425); /* 365 + 0.25 - 0.01 - 0.0025 */ yyyy = 4 + flooredMulDiv(ordinal - Jan_01_0004, 100, 36525); yyyy = -1 + flooredMulDiv(ordinal - Jan_01_0001BC, 100, 36525); int ddd = aim - jan01OfYear(yyyy); while (ddd <= 0) { ddd = aim - jan01OfYear(yyyy); boolean leap = isLeap(yyyy); while (ddd > (leap ? 366 : 365)) { ddd = aim - jan01OfYear(yyyy); leap = isLeap(yyyy); mm = dddToMM(ddd, leap); dd = ddd - daysInYearPriorToMonth(mm, leap);
/** * Returns a BigDate object initialised to the date right now in the given * timezone. It depends on your system clock accurately set to UTC time. * Experiment setting your system date/time to various values and making * sure you are getting the expected results. Note the date in the created * object does not keep updating every time you reference it with methods * like getOrdinal or getDD. You always get the date the object was created. * It is quite a production to get the this date. Best to ask once and save * the today object. * * @param timeZone * in which we want to know the today's date. * * @return BigDate object initialised to today at given timezone. * * @see #localToday * @see #UTCToday */ public static BigDate today(TimeZone timeZone) { BigDate d = new BigDate(); d.setDateAtTime(System.currentTimeMillis(), timeZone); return d; } // end today
/** * Get day of week for this BigDate. It is zero-based starting with Sunday. * * @return day of week 0=Sunday 1=Monday 2=Tuesday 3=Wednesday 4=Thursday * 5=Friday 6=Saturday WARNING: not compatible with * 1=Calendar.SUNDAY * * @see #getCalendarDayOfWeek * @see #getISODayOfWeek * @see #dayOfWeek */ public final int getDayOfWeek() { return dayOfWeek(ordinal); }
return false; return dd <= daysInMonth(mm, yyyy);
/** * Returns a BigDate object initialised to today's UTC (Greenwich GMT) date, * in other words that date the people in Greenwich England think it is * right now. It works even if Java's default Timezone is not configured * correctly, but it requires your system clock accurately set to UTC time. * Experiment setting your system date/time to various values and making * sure you are getting the expected results. Note the date in the created * object does not keep updating every time you reference it with methods * like getOrdinal or getDD. You always get the date the object was created. * * @return BigDate object initialised to today, in Greenwich. * * @see #localToday * @see #today */ public static BigDate UTCToday() { // 86,400,000 = 1000 * 60 * 60 * 24 = milliseconds per day return new BigDate((int) (System.currentTimeMillis() / 86400000L)); } // end UTCToday
yyyy, mm - 1, dd, getCalendarDayOfWeek(), 0);
/** * Convert date to a human-readable String wed mm/dd/yy * * @return this BigDate as a String in form fri 12/31/03 */ public String toDowMMDDYY() { if (ordinal == NULL_ORDINAL) { return ""; } return shortDayName[getDayOfWeek()] + " " + MString.toLZ(mm, 2) + "/" + MString.toLZ(dd, 2) + "/" + MString.toLZ(yyyy % 100, 2); } // end toDowMMDDYY
/** * Get day of week for given ordinal. It is one-based starting with Sunday. * * @param ordinal * days since Jan 1, 1970 to test. * * @return day of week 1=Sunday 2=Monday 3=Tuesday 4=Wednesday 5=Thursday * 6=Friday 7=Saturday Compatible with Sun's 1=Calendar.SUNDAY Not * compatiblse with BigDate.getDayOfWeek. * * @see #isoDayOfWeek * @see #dayOfWeek * @see #getCalendarDayOfWeek */ public static int calendarDayOfWeek(int ordinal) { return dayOfWeek(ordinal) + 1; }