bestField == UCAL_DAY_OF_WEEK_IN_MONTH);
int32_t year;
- if (bestField == UCAL_WEEK_OF_YEAR) {
- year = internalGet(UCAL_YEAR_WOY, handleGetExtendedYear());
- internalSet(UCAL_EXTENDED_YEAR, year);
+ if (bestField == UCAL_WEEK_OF_YEAR && newerField(UCAL_YEAR_WOY, UCAL_YEAR) == UCAL_YEAR_WOY) {
+ year = internalGet(UCAL_YEAR_WOY);
} else {
year = handleGetExtendedYear();
- internalSet(UCAL_EXTENDED_YEAR, year);
}
+ internalSet(UCAL_EXTENDED_YEAR, year);
+
#if defined (U_DEBUG_CAL)
fprintf(stderr, "%s:%d: bestField= %s - y=%d\n", __FILE__, __LINE__, fldName(bestField), year);
#endif
#include "unicode/simpletz.h"
#include "unicode/smpdtfmt.h"
#include "unicode/strenum.h"
+#include "unicode/localpointer.h"
#include "cmemory.h"
#include "caltest.h"
#include "unicode/localpointer.h"
CASE(51,TestT11632);
CASE(52,TestPersianCalOverflow);
CASE(53,TestIslamicCalOverflow);
+ CASE(54,TestWeekOfYear13548);
default: name = ""; break;
}
}
}
}
+void CalendarRegressionTest::TestWeekOfYear13548(void) {
+ int32_t year = 2000;
+ UErrorCode status = U_ZERO_ERROR;
+ LocalPointer<Calendar> cal(Calendar::createInstance(status));
+ failure(status, "Calendar::createInstance(status)");
+
+ cal->set(UCAL_YEAR, year);
+ cal->set(UCAL_WEEK_OF_YEAR, 4);
+
+ int32_t resultYear = cal->get(UCAL_YEAR, status);
+ failure(status, "get(UCAL_YEAR, status)");
+ if (year != resultYear) {
+ errln((UnicodeString)"Fail: Expected year=" + year + ", actual=" + resultYear);
+ }
+}
+
#endif /* #if !UCONFIG_NO_FORMATTING */
void TestT11632(void);
void TestPersianCalOverflow(void);
void TestIslamicCalOverflow(void);
+ void TestWeekOfYear13548(void);
void printdate(GregorianCalendar *cal, const char *string);
void dowTest(UBool lenient) ;
int year;
- if (bestField == WEEK_OF_YEAR) {
+ if (bestField == WEEK_OF_YEAR && newerField(YEAR_WOY, YEAR) == YEAR_WOY) {
// Nota Bene! It is critical that YEAR_WOY be used as the year here, if it is
// set. Otherwise, when WOY is the best field, the year may be wrong at the
// extreme limits of the year. If YEAR_WOY is not set then it will fall back.
// TODO: Should resolveField(YEAR_PRECEDENCE) be brought to bear?
- year = internalGet(YEAR_WOY, handleGetExtendedYear());
+ year = internalGet(YEAR_WOY);
} else {
year = handleGetExtendedYear();
}
}
}
}
+
+ @Test
+ public void TestWeekOfYear13548() {
+ int year = 2000;
+
+ Calendar cal = Calendar.getInstance();
+ cal.set(Calendar.YEAR, year);
+ cal.set(Calendar.WEEK_OF_YEAR, 4);
+
+ int resultYear = cal.get(Calendar.YEAR);
+ if (year != resultYear) {
+ errln("Fail: Expected year=" + year + ", actual=" + resultYear);
+ }
+ }
}
//eof