void AstroTest::TestCoverage(void) { UErrorCode status = U_ZERO_ERROR; initAstro(status); ASSERT_OK(status); GregorianCalendar *cal = new GregorianCalendar(1958, UCAL_AUGUST, 15,status); UDate then = cal->getTime(status); CalendarAstronomer *myastro = new CalendarAstronomer(then); ASSERT_OK(status); //Latitude: 34 degrees 05' North //Longitude: 118 degrees 22' West double laLat = 34 + 5./60, laLong = 360 - (118 + 22./60); CalendarAstronomer *myastro2 = new CalendarAstronomer(laLong, laLat); double eclLat = laLat * CalendarAstronomer::PI / 360; double eclLong = laLong * CalendarAstronomer::PI / 360; CalendarAstronomer::Ecliptic ecl(eclLat, eclLong); CalendarAstronomer::Equatorial eq; CalendarAstronomer::Horizon hor; logln("ecliptic: " + ecl.toString()); CalendarAstronomer *myastro3 = new CalendarAstronomer(); myastro3->setJulianDay((4713 + 2000) * 365.25); CalendarAstronomer *astronomers[] = { myastro, myastro2, myastro3, myastro2 // check cache }; for (uint32_t i = 0; i < UPRV_LENGTHOF(astronomers); ++i) { CalendarAstronomer *anAstro = astronomers[i]; //logln("astro: " + astro); logln((UnicodeString)" date: " + anAstro->getTime()); logln((UnicodeString)" cent: " + anAstro->getJulianCentury()); logln((UnicodeString)" gw sidereal: " + anAstro->getGreenwichSidereal()); logln((UnicodeString)" loc sidereal: " + anAstro->getLocalSidereal()); logln((UnicodeString)" equ ecl: " + (anAstro->eclipticToEquatorial(eq,ecl)).toString()); logln((UnicodeString)" equ long: " + (anAstro->eclipticToEquatorial(eq, eclLong)).toString()); logln((UnicodeString)" horiz: " + (anAstro->eclipticToHorizon(hor, eclLong)).toString()); logln((UnicodeString)" sunrise: " + (anAstro->getSunRiseSet(TRUE))); logln((UnicodeString)" sunset: " + (anAstro->getSunRiseSet(FALSE))); logln((UnicodeString)" moon phase: " + anAstro->getMoonPhase()); logln((UnicodeString)" moonrise: " + (anAstro->getMoonRiseSet(TRUE))); logln((UnicodeString)" moonset: " + (anAstro->getMoonRiseSet(FALSE))); logln((UnicodeString)" prev summer solstice: " + (anAstro->getSunTime(CalendarAstronomer::SUMMER_SOLSTICE(), FALSE))); logln((UnicodeString)" next summer solstice: " + (anAstro->getSunTime(CalendarAstronomer::SUMMER_SOLSTICE(), TRUE))); logln((UnicodeString)" prev full moon: " + (anAstro->getMoonTime(CalendarAstronomer::FULL_MOON(), FALSE))); logln((UnicodeString)" next full moon: " + (anAstro->getMoonTime(CalendarAstronomer::FULL_MOON(), TRUE))); } delete myastro2; delete myastro3; delete myastro; delete cal; closeAstro(status); ASSERT_OK(status); }
void TimeZoneBoundaryTest::verifyDST(UDate d, TimeZone* time_zone, UBool expUseDaylightTime, UBool expInDaylightTime, UDate expZoneOffset, UDate expDSTOffset) { UnicodeString str; UErrorCode status = U_ZERO_ERROR; logln("-- Verifying time " + dateToString(d) + " in zone " + time_zone->getID(str)); if (time_zone->inDaylightTime(d, status) == expInDaylightTime) logln(UnicodeString("PASS: inDaylightTime = ") + (time_zone->inDaylightTime(d, status)?"true":"false")); else dataerrln(UnicodeString("FAIL: inDaylightTime = ") + (time_zone->inDaylightTime(d, status)?"true":"false")); if (failure(status, "TimeZone::inDaylightTime", TRUE)) return; if (time_zone->useDaylightTime() == expUseDaylightTime) logln(UnicodeString("PASS: useDaylightTime = ") + (time_zone->useDaylightTime()?"true":"false")); else dataerrln(UnicodeString("FAIL: useDaylightTime = ") + (time_zone->useDaylightTime()?"true":"false")); if (time_zone->getRawOffset() == expZoneOffset) logln(UnicodeString("PASS: getRawOffset() = ") + (expZoneOffset / ONE_HOUR)); else dataerrln(UnicodeString("FAIL: getRawOffset() = ") + (time_zone->getRawOffset() / ONE_HOUR) + "; expected " + (expZoneOffset / ONE_HOUR)); GregorianCalendar *gc = new GregorianCalendar(time_zone->clone(), status); gc->setTime(d, status); if (failure(status, "GregorianCalendar::setTime")) return; int32_t offset = time_zone->getOffset((uint8_t)gc->get(UCAL_ERA, status), gc->get(UCAL_YEAR, status), gc->get(UCAL_MONTH, status), gc->get(UCAL_DATE, status), (uint8_t)gc->get(UCAL_DAY_OF_WEEK, status), ((gc->get(UCAL_HOUR_OF_DAY, status) * 60 + gc->get(UCAL_MINUTE, status)) * 60 + gc->get(UCAL_SECOND, status)) * 1000 + gc->get(UCAL_MILLISECOND, status), status); if (failure(status, "GregorianCalendar::get")) return; if (offset == expDSTOffset) logln(UnicodeString("PASS: getOffset() = ") + (offset / ONE_HOUR)); else dataerrln(UnicodeString("FAIL: getOffset() = ") + (offset / ONE_HOUR) + "; expected " + (expDSTOffset / ONE_HOUR)); delete gc; }
U_CAPI void U_EXPORT2 ucal_setGregorianChange(UCalendar *cal, UDate date, UErrorCode *pErrorCode) { if(U_FAILURE(*pErrorCode)) { return; } Calendar *cpp_cal = (Calendar *)cal; GregorianCalendar *gregocal = dynamic_cast<GregorianCalendar *>(cpp_cal); // Not if(gregocal == NULL) { // because we really want to work only with a GregorianCalendar, not with // its subclasses like BuddhistCalendar. if(typeid(*cpp_cal) != typeid(GregorianCalendar)) { *pErrorCode = U_UNSUPPORTED_ERROR; return; } gregocal->setGregorianChange(date, *pErrorCode); }
/** * Overrides TimeZone * Queries if the given date is in Daylight Savings Time. */ UBool SimpleTimeZone::inDaylightTime(UDate date, UErrorCode& status) const { // This method is wasteful since it creates a new GregorianCalendar and // deletes it each time it is called. However, this is a deprecated method // and provided only for Java compatibility as of 8/6/97 [LIU]. if (U_FAILURE(status)) return FALSE; GregorianCalendar *gc = new GregorianCalendar(*this, status); /* test for NULL */ if (gc == 0) { status = U_MEMORY_ALLOCATION_ERROR; return FALSE; } gc->setTime(date, status); UBool result = gc->inDaylightTime(status); delete gc; return result; }
void GregorianCalendar::setGregorianChange(UDate date, UErrorCode& status) { if (U_FAILURE(status)) return; fGregorianCutover = date; // Precompute two internal variables which we use to do the actual // cutover computations. These are the normalized cutover, which is the // midnight at or before the cutover, and the cutover year. The // normalized cutover is in pure date milliseconds; it contains no time // of day or timezone component, and it used to compare against other // pure date values. int32_t cutoverDay = (int32_t)ClockMath::floorDivide(fGregorianCutover, (double)kOneDay); fNormalizedGregorianCutover = cutoverDay * kOneDay; // Handle the rare case of numeric overflow. If the user specifies a // change of UDate(Long.MIN_VALUE), in order to get a pure Gregorian // calendar, then the epoch day is -106751991168, which when multiplied // by ONE_DAY gives 9223372036794351616 -- the negative value is too // large for 64 bits, and overflows into a positive value. We correct // this by using the next day, which for all intents is semantically // equivalent. if (cutoverDay < 0 && fNormalizedGregorianCutover > 0) { fNormalizedGregorianCutover = (cutoverDay + 1) * kOneDay; } // Normalize the year so BC values are represented as 0 and negative // values. GregorianCalendar *cal = new GregorianCalendar(getTimeZone(), status); /* test for NULL */ if (cal == 0) { status = U_MEMORY_ALLOCATION_ERROR; return; } if(U_FAILURE(status)) return; cal->setTime(date, status); fGregorianCutoverYear = cal->get(UCAL_YEAR, status); if (cal->get(UCAL_ERA, status) == BC) fGregorianCutoverYear = 1 - fGregorianCutoverYear; fCutoverJulianDay = cutoverDay; delete cal; }
U_CAPI void U_EXPORT2 ucal_setGregorianChange(UCalendar *cal, UDate date, UErrorCode *pErrorCode) { if(U_FAILURE(*pErrorCode)) { return; } Calendar *cpp_cal = (Calendar *)cal; GregorianCalendar *gregocal = dynamic_cast<GregorianCalendar *>(cpp_cal); // Not if(gregocal == NULL) { // because we really want to work only with a GregorianCalendar, not with // its subclasses like BuddhistCalendar. if (cpp_cal == NULL) { // We normally don't check "this" pointers for NULL, but this here avoids // compiler-generated exception-throwing code in case cal == NULL. *pErrorCode = U_ILLEGAL_ARGUMENT_ERROR; return; } if(typeid(*cpp_cal) != typeid(GregorianCalendar)) { *pErrorCode = U_UNSUPPORTED_ERROR; return; } gregocal->setGregorianChange(date, *pErrorCode); }
/** * @bug 4109314 */ void TimeZoneRegressionTest:: Test4109314() { UErrorCode status = U_ZERO_ERROR; GregorianCalendar *testCal = (GregorianCalendar*)Calendar::createInstance(status); if(U_FAILURE(status)) { dataerrln("Error creating calendar %s", u_errorName(status)); delete testCal; return; } failure(status, "Calendar::createInstance"); TimeZone *PST = TimeZone::createTimeZone("PST"); /*Object[] testData = { PST, new Date(98,Calendar.APRIL,4,22,0), new Date(98, Calendar.APRIL, 5,6,0), PST, new Date(98,Calendar.OCTOBER,24,22,0), new Date(98,Calendar.OCTOBER,25,6,0), };*/ UDate testData [] = { CalendarRegressionTest::makeDate(98,UCAL_APRIL,4,22,0), CalendarRegressionTest::makeDate(98, UCAL_APRIL,5,6,0), CalendarRegressionTest::makeDate(98,UCAL_OCTOBER,24,22,0), CalendarRegressionTest::makeDate(98,UCAL_OCTOBER,25,6,0) }; UBool pass = TRUE; for (int32_t i = 0; i < 4; i+=2) { //testCal->setTimeZone((TimeZone) testData[i]); testCal->setTimeZone(*PST); UDate t = testData[i]; UDate end = testData[i+1]; while(testCal->getTime(status) < end) { testCal->setTime(t, status); if ( ! checkCalendar314(testCal, PST)) pass = FALSE; t += 60*60*1000.0; } } if ( ! pass) errln("Fail: TZ API inconsistent"); delete testCal; delete PST; }
void getCutOverTimes(UDate& lo, UDate& hi) { UErrorCode status = U_ZERO_ERROR; GregorianCalendar* gcal = new GregorianCalendar(timezone, Locale::getEnglish(), status); gcal->clear(); gcal->set(loyear, 0, 1, 0, 0, 0); lo = gcal->getTime(status); gcal->set(hiyear, 0, 1, 0, 0, 0); hi = gcal->getTime(status); }
void cpp_main() { UErrorCode status = U_ZERO_ERROR; puts("C++ sample"); GregorianCalendar* gc = new GregorianCalendar(status); if (U_FAILURE(status)) { puts("Couldn't create GregorianCalendar"); return; } /* set up the date */ gc->set(2000, UCAL_FEBRUARY, 26); gc->set(UCAL_HOUR_OF_DAY, 23); gc->set(UCAL_MINUTE, 0); gc->set(UCAL_SECOND, 0); gc->set(UCAL_MILLISECOND, 0); /* Iterate through the days and print it out. */ for (int32_t i = 0; i < 30; i++) { /* print out the date. */ /* You should use the DateFormat to properly format it */ printf("year: %d, month: %d (%d in the implementation), day: %d\n", gc->get(UCAL_YEAR, status), gc->get(UCAL_MONTH, status) + 1, gc->get(UCAL_MONTH, status), gc->get(UCAL_DATE, status)); if (U_FAILURE(status)) { puts("Calendar::get failed"); return; } /* Add a day to the date */ gc->add(UCAL_DATE, 1, status); if (U_FAILURE(status)) { puts("Calendar::add failed"); return; } } delete gc; }
void AstroTest::TestSunriseTimes(void) { UErrorCode status = U_ZERO_ERROR; initAstro(status); ASSERT_OK(status); // logln("Sunrise/Sunset times for San Jose, California, USA"); // CalendarAstronomer *astro2 = new CalendarAstronomer(-121.55, 37.20); // TimeZone *tz = TimeZone::createTimeZone("America/Los_Angeles"); // We'll use a table generated by the UNSO website as our reference // From: http://aa.usno.navy.mil/ //-Location: W079 25, N43 40 //-Rise and Set for the Sun for 2001 //-Zone: 4h West of Greenwich int32_t USNO[] = { 6,59, 19,45, 6,57, 19,46, 6,56, 19,47, 6,54, 19,48, 6,52, 19,49, 6,50, 19,51, 6,48, 19,52, 6,47, 19,53, 6,45, 19,54, 6,43, 19,55, 6,42, 19,57, 6,40, 19,58, 6,38, 19,59, 6,36, 20, 0, 6,35, 20, 1, 6,33, 20, 3, 6,31, 20, 4, 6,30, 20, 5, 6,28, 20, 6, 6,27, 20, 7, 6,25, 20, 8, 6,23, 20,10, 6,22, 20,11, 6,20, 20,12, 6,19, 20,13, 6,17, 20,14, 6,16, 20,16, 6,14, 20,17, 6,13, 20,18, 6,11, 20,19, }; logln("Sunrise/Sunset times for Toronto, Canada"); // long = 79 25", lat = 43 40" CalendarAstronomer *astro3 = new CalendarAstronomer(-(79+25/60), 43+40/60); // As of ICU4J 2.8 the ICU4J time zones implement pass-through // to the underlying JDK. Because of variation in the // underlying JDKs, we have to use a fixed-offset // SimpleTimeZone to get consistent behavior between JDKs. // The offset we want is [-18000000, 3600000] (raw, dst). // [aliu 10/15/03] // TimeZone tz = TimeZone.getTimeZone("America/Montreal"); TimeZone *tz = new SimpleTimeZone(-18000000 + 3600000, "Montreal(FIXED)"); GregorianCalendar *cal = new GregorianCalendar(tz->clone(), Locale::getUS(), status); GregorianCalendar *cal2 = new GregorianCalendar(tz->clone(), Locale::getUS(), status); cal->clear(); cal->set(UCAL_YEAR, 2001); cal->set(UCAL_MONTH, UCAL_APRIL); cal->set(UCAL_DAY_OF_MONTH, 1); cal->set(UCAL_HOUR_OF_DAY, 12); // must be near local noon for getSunRiseSet to work DateFormat *df_t = DateFormat::createTimeInstance(DateFormat::MEDIUM,Locale::getUS()); DateFormat *df_d = DateFormat::createDateInstance(DateFormat::MEDIUM,Locale::getUS()); DateFormat *df_dt = DateFormat::createDateTimeInstance(DateFormat::MEDIUM, DateFormat::MEDIUM, Locale::getUS()); if(!df_t || !df_d || !df_dt) { dataerrln("couldn't create dateformats."); return; } df_t->adoptTimeZone(tz->clone()); df_d->adoptTimeZone(tz->clone()); df_dt->adoptTimeZone(tz->clone()); for (int32_t i=0; i < 30; i++) { logln("setDate\n"); astro3->setDate(cal->getTime(status)); logln("getRiseSet(TRUE)\n"); UDate sunrise = astro3->getSunRiseSet(TRUE); logln("getRiseSet(FALSE)\n"); UDate sunset = astro3->getSunRiseSet(FALSE); logln("end of getRiseSet\n"); cal2->setTime(cal->getTime(status), status); cal2->set(UCAL_SECOND, 0); cal2->set(UCAL_MILLISECOND, 0); cal2->set(UCAL_HOUR_OF_DAY, USNO[4*i+0]); cal2->set(UCAL_MINUTE, USNO[4*i+1]); UDate exprise = cal2->getTime(status); cal2->set(UCAL_HOUR_OF_DAY, USNO[4*i+2]); cal2->set(UCAL_MINUTE, USNO[4*i+3]); UDate expset = cal2->getTime(status); // Compute delta of what we got to the USNO data, in seconds int32_t deltarise = (int32_t)uprv_fabs((sunrise - exprise) / 1000); int32_t deltaset = (int32_t)uprv_fabs((sunset - expset) / 1000); // Allow a deviation of 0..MAX_DEV seconds // It would be nice to get down to 60 seconds, but at this // point that appears to be impossible without a redo of the // algorithm using something more advanced than Duffett-Smith. int32_t MAX_DEV = 180; UnicodeString s1, s2, s3, s4, s5; if (deltarise > MAX_DEV || deltaset > MAX_DEV) { if (deltarise > MAX_DEV) { errln("FAIL: (rise) " + df_d->format(cal->getTime(status),s1) + ", Sunrise: " + df_dt->format(sunrise, s2) + " (USNO " + df_t->format(exprise,s3) + " d=" + deltarise + "s)"); } else { logln(df_d->format(cal->getTime(status),s1) + ", Sunrise: " + df_dt->format(sunrise,s2) + " (USNO " + df_t->format(exprise,s3) + ")"); } s1.remove(); s2.remove(); s3.remove(); s4.remove(); s5.remove(); if (deltaset > MAX_DEV) { errln("FAIL: (set) " + df_d->format(cal->getTime(status),s1) + ", Sunset: " + df_dt->format(sunset,s2) + " (USNO " + df_t->format(expset,s3) + " d=" + deltaset + "s)"); } else { logln(df_d->format(cal->getTime(status),s1) + ", Sunset: " + df_dt->format(sunset,s2) + " (USNO " + df_t->format(expset,s3) + ")"); } } else { logln(df_d->format(cal->getTime(status),s1) + ", Sunrise: " + df_dt->format(sunrise,s2) + " (USNO " + df_t->format(exprise,s3) + ")" + ", Sunset: " + df_dt->format(sunset,s4) + " (USNO " + df_t->format(expset,s5) + ")"); } cal->add(UCAL_DATE, 1, status); } // CalendarAstronomer a = new CalendarAstronomer(-(71+5/60), 42+37/60); // cal.clear(); // cal.set(cal.YEAR, 1986); // cal.set(cal.MONTH, cal.MARCH); // cal.set(cal.DATE, 10); // cal.set(cal.YEAR, 1988); // cal.set(cal.MONTH, cal.JULY); // cal.set(cal.DATE, 27); // a.setDate(cal.getTime()); // long r = a.getSunRiseSet2(true); delete astro3; delete tz; delete cal; delete cal2; delete df_t; delete df_d; delete df_dt; closeAstro(status); ASSERT_OK(status); }
static void _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAMETERS) { zval *tz_object = NULL; zval args_a[6] = {0}, *args = &args_a[0]; char *locale = NULL; int locale_len; zend_long largs[6]; UErrorCode status = U_ZERO_ERROR; int variant; intl_error_reset(NULL TSRMLS_CC); // parameter number validation / variant determination if (ZEND_NUM_ARGS() > 6 || zend_get_parameters_array_ex(ZEND_NUM_ARGS(), args) == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlgregcal_create_instance: too many arguments", 0 TSRMLS_CC); Z_OBJ_P(return_value) = NULL; return; } for (variant = ZEND_NUM_ARGS(); variant > 0 && Z_TYPE(args[variant - 1]) == IS_NULL; variant--) {} if (variant == 4) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlgregcal_create_instance: no variant with 4 arguments " "(excluding trailing NULLs)", 0 TSRMLS_CC); Z_OBJ_P(return_value) = NULL; return; } // argument parsing if (variant <= 2) { if (zend_parse_parameters(MIN(ZEND_NUM_ARGS(), 2) TSRMLS_CC, "|z!s!", &tz_object, &locale, &locale_len) == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlgregcal_create_instance: bad arguments", 0 TSRMLS_CC); Z_OBJ_P(return_value) = NULL; return; } } if (variant > 2 && zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll|lll", &largs[0], &largs[1], &largs[2], &largs[3], &largs[4], &largs[5]) == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlgregcal_create_instance: bad arguments", 0 TSRMLS_CC); Z_OBJ_P(return_value) = NULL; return; } // instantion of ICU object GregorianCalendar *gcal = NULL; if (variant <= 2) { // From timezone and locale (0 to 2 arguments) TimeZone *tz = timezone_process_timezone_argument(tz_object, NULL, "intlgregcal_create_instance" TSRMLS_CC); if (tz == NULL) { Z_OBJ_P(return_value) = NULL; return; } if (!locale) { locale = const_cast<char*>(intl_locale_get_default(TSRMLS_C)); } gcal = new GregorianCalendar(tz, Locale::createFromName(locale), status); if (U_FAILURE(status)) { intl_error_set(NULL, status, "intlgregcal_create_instance: error " "creating ICU GregorianCalendar from time zone and locale", 0 TSRMLS_CC); if (gcal) { delete gcal; } delete tz; Z_OBJ_P(return_value) = NULL; return; } } else { // From date/time (3, 5 or 6 arguments) for (int i = 0; i < variant; i++) { if (largs[i] < INT32_MIN || largs[i] > INT32_MAX) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlgregcal_create_instance: at least one of the arguments" " has an absolute value that is too large", 0 TSRMLS_CC); Z_OBJ_P(return_value) = NULL; return; } } if (variant == 3) { gcal = new GregorianCalendar((int32_t)largs[0], (int32_t)largs[1], (int32_t)largs[2], status); } else if (variant == 5) { gcal = new GregorianCalendar((int32_t)largs[0], (int32_t)largs[1], (int32_t)largs[2], (int32_t)largs[3], (int32_t)largs[4], status); } else if (variant == 6) { gcal = new GregorianCalendar((int32_t)largs[0], (int32_t)largs[1], (int32_t)largs[2], (int32_t)largs[3], (int32_t)largs[4], (int32_t)largs[5], status); } if (U_FAILURE(status)) { intl_error_set(NULL, status, "intlgregcal_create_instance: error " "creating ICU GregorianCalendar from date", 0 TSRMLS_CC); if (gcal) { delete gcal; } Z_OBJ_P(return_value) = NULL; return; } timelib_tzinfo *tzinfo = get_timezone_info(TSRMLS_C); #if U_ICU_VERSION_MAJOR_NUM * 10 + U_ICU_VERSION_MINOR_NUM >= 42 UnicodeString tzstr = UnicodeString::fromUTF8(StringPiece(tzinfo->name)); #else UnicodeString tzstr = UnicodeString(tzinfo->name, strlen(tzinfo->name), US_INV); #endif if (tzstr.isBogus()) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlgregcal_create_instance: could not create UTF-8 string " "from PHP's default timezone name (see date_default_timezone_get())", 0 TSRMLS_CC); delete gcal; Z_OBJ_P(return_value) = NULL; return; } TimeZone *tz = TimeZone::createTimeZone(tzstr); gcal->adoptTimeZone(tz); } Calendar_object *co = Z_INTL_CALENDAR_P(return_value); co->ucal = gcal; }
/** * @bug 4106807 */ void DateFormatRegressionTest::Test4106807(void) { UDate dt; DateFormat *df = DateFormat::createDateTimeInstance(); UErrorCode status = U_ZERO_ERROR; SimpleDateFormat *sdfs [] = { new SimpleDateFormat(UnicodeString("yyyyMMddHHmmss"), status), new SimpleDateFormat(UnicodeString("yyyyMMddHHmmss'Z'"), status), new SimpleDateFormat(UnicodeString("yyyyMMddHHmmss''"), status), new SimpleDateFormat(UnicodeString("yyyyMMddHHmmss'a''a'"), status), new SimpleDateFormat(UnicodeString("yyyyMMddHHmmss %"), status) }; if(U_FAILURE(status)) { dataerrln("Couldn't create SimpleDateFormat, error %s", u_errorName(status)); delete sdfs[0]; delete sdfs[1]; delete sdfs[2]; delete sdfs[3]; delete sdfs[4]; return; } failure(status, "new SimpleDateFormat"); UnicodeString strings [] = { (UnicodeString) "19980211140000", (UnicodeString) "19980211140000", (UnicodeString) "19980211140000", (UnicodeString) "19980211140000a", (UnicodeString) "19980211140000 " }; /*Object[] data = { new SimpleDateFormat("yyyyMMddHHmmss"), "19980211140000", new SimpleDateFormat("yyyyMMddHHmmss'Z'"), "19980211140000", new SimpleDateFormat("yyyyMMddHHmmss''"), "19980211140000", new SimpleDateFormat("yyyyMMddHHmmss'a''a'"), "19980211140000a", new SimpleDateFormat("yyyyMMddHHmmss %"), "19980211140000 ", };*/ GregorianCalendar *gc = new GregorianCalendar(status); failure(status, "new GregorianCalendar"); TimeZone *timeZone = TimeZone::createDefault(); TimeZone *gmt = timeZone->clone(); gmt->setRawOffset(0); for(int32_t i = 0; i < 5; i++) { SimpleDateFormat *format = sdfs[i]; UnicodeString dateString = strings[i]; //try { format->setTimeZone(*gmt); dt = format->parse(dateString, status); // {sfb} some of these parses will fail purposely if(U_FAILURE(status)) break; status = U_ZERO_ERROR; UnicodeString fmtd; FieldPosition pos(FieldPosition::DONT_CARE); fmtd = df->format(dt, fmtd, pos); logln(fmtd); //logln(df->format(dt)); gc->setTime(dt, status); failure(status, "gc->getTime"); logln(UnicodeString("") + gc->get(UCAL_ZONE_OFFSET, status)); failure(status, "gc->get"); UnicodeString s; s = format->format(dt, s, pos); logln(s); /*} catch (ParseException e) { logln("No way Jose"); }*/ } delete timeZone; delete df; for(int32_t j = 0; j < 5; j++) delete sdfs [j]; delete gc; delete gmt; }