X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/73c04bcfe1096173b00431f0cdc742894b15eef0..a0b4f637ba1a6c3c5651b61a69303b029bacf7d3:/icuSources/i18n/gregoimp.h diff --git a/icuSources/i18n/gregoimp.h b/icuSources/i18n/gregoimp.h index 8b1d12c7..f65d1410 100644 --- a/icuSources/i18n/gregoimp.h +++ b/icuSources/i18n/gregoimp.h @@ -1,13 +1,14 @@ /* -********************************************************************** -* Copyright (c) 2003-2005, International Business Machines -* Corporation and others. All Rights Reserved. -********************************************************************** -* Author: Alan Liu -* Created: September 2 2003 -* Since: ICU 2.8 -********************************************************************** -*/ + ********************************************************************** + * Copyright (c) 2003-2008, International Business Machines + * Corporation and others. All Rights Reserved. + ********************************************************************** + * Author: Alan Liu + * Created: September 2 2003 + * Since: ICU 2.8 + ********************************************************************** + */ + #ifndef GREGOIMP_H #define GREGOIMP_H #include "unicode/utypes.h" @@ -21,9 +22,10 @@ U_NAMESPACE_BEGIN /** * A utility class providing mathematical functions used by time zone - * and calendar code. Do not instantiate. + * and calendar code. Do not instantiate. Formerly just named 'Math'. + * @internal */ -class Math { +class ClockMath { public: /** * Divide two integers, returning the floor of the quotient. @@ -190,6 +192,37 @@ class Grego { static inline void dayToFields(double day, int32_t& year, int32_t& month, int32_t& dom, int32_t& dow); + /** + * Convert a 1970-epoch milliseconds to proleptic Gregorian year, + * month, day-of-month, and day-of-week, day of year and millis-in-day. + * @param time 1970-epoch milliseconds + * @param year output parameter to receive year + * @param month output parameter to receive month (0-based, 0==Jan) + * @param dom output parameter to receive day-of-month (1-based) + * @param dow output parameter to receive day-of-week (1-based, 1==Sun) + * @param doy output parameter to receive day-of-year (1-based) + * @param mid output parameter to recieve millis-in-day + */ + static void timeToFields(UDate time, int32_t& year, int32_t& month, + int32_t& dom, int32_t& dow, int32_t& doy, int32_t& mid); + + /** + * Return the day of week on the 1970-epoch day + * @param day the 1970-epoch day (integral value) + * @return the day of week + */ + static int32_t dayOfWeek(double day); + + /** + * Returns the ordinal number for the specified day of week within the month. + * The valid return value is 1, 2, 3, 4 or -1. + * @param year Gregorian year, with 0 == 1 BCE, -1 == 2 BCE, etc. + * @param month 0-based month, with 0==Jan + * @param dom 1-based day of month + * @return The ordinal number for the specified day of week within the month + */ + static int32_t dayOfWeekInMonth(int32_t year, int32_t month, int32_t dom); + /** * Converts Julian day to time as milliseconds. * @param julian the given Julian day number. @@ -218,7 +251,7 @@ class Grego { static const int8_t MONTH_LENGTH[24]; }; -inline double Math::floorDivide(double numerator, double denominator) { +inline double ClockMath::floorDivide(double numerator, double denominator) { return uprv_floor(numerator / denominator); } @@ -229,7 +262,7 @@ inline UBool Grego::isLeapYear(int32_t year) { inline int8_t Grego::monthLength(int32_t year, int32_t month) { - return MONTH_LENGTH[month + isLeapYear(year)?12:0]; + return MONTH_LENGTH[month + (isLeapYear(year) ? 12 : 0)]; } inline int8_t @@ -249,12 +282,12 @@ inline double Grego::julianDayToMillis(int32_t julian) } inline int32_t Grego::millisToJulianDay(double millis) { - return (int32_t) (kEpochStartAsJulianDay + Math::floorDivide(millis, (double)kOneDay)); + return (int32_t) (kEpochStartAsJulianDay + ClockMath::floorDivide(millis, (double)kOneDay)); } inline int32_t Grego::gregorianShift(int32_t eyear) { int32_t y = eyear-1; - int32_t gregShift = Math::floorDivide(y, 400) - Math::floorDivide(y, 100) + 2; + int32_t gregShift = ClockMath::floorDivide(y, 400) - ClockMath::floorDivide(y, 100) + 2; return gregShift; }