/* Format the date */ static void date(const UChar *tz, UDateFormatStyle style, char *format, UErrorCode *status) { UChar *s = 0; int32_t len = 0; UDateFormat *fmt; UChar uFormat[100]; fmt = udat_open(style, style, 0, tz, -1,NULL,0, status); if ( format != NULL ) { u_charsToUChars(format,uFormat,strlen(format)), udat_applyPattern(fmt,FALSE,uFormat,strlen(format)); } len = udat_format(fmt, ucal_getNow(), 0, len, 0, status); if(*status == U_BUFFER_OVERFLOW_ERROR) { *status = U_ZERO_ERROR; s = (UChar*) malloc(sizeof(UChar) * (len+1)); if(s == 0) goto finish; udat_format(fmt, ucal_getNow(), s, len + 1, 0, status); if(U_FAILURE(*status)) goto finish; } /* print the date string */ uprint(s, stdout, status); /* print a trailing newline */ printf("\n"); finish: udat_close(fmt); free(s); }
void TestRunTogetherPattern985() { int32_t pos; UChar *pattern=NULL, *now=NULL, *then=NULL; UDateFormat *format; UDate date1, date2; UErrorCode status = U_ZERO_ERROR; pattern=(UChar*)malloc(sizeof(UChar) * (strlen("yyyyMMddHHmmssSSS")+1) ); u_uastrcpy(pattern, "yyyyMMddHHmmssSSS"); format = udat_open(UDAT_IGNORE, UDAT_IGNORE, NULL, NULL, 0,pattern, u_strlen(pattern), &status); if(U_FAILURE(status)){ log_err_status(status, "FAIL: Error in date format construction with pattern: %s\n", myErrorName(status)); return; } date1 = ucal_getNow(); now=myDateFormat(format, date1); log_verbose("%s\n", austrdup(now) ); pos = 0; date2 = udat_parse(format, now, u_strlen(now), &pos, &status); if (date2 == 0) log_verbose("Parse stopped at : %d\n", pos); else then=myDateFormat(format, date2); log_verbose("%s\n", austrdup(then) ); if (!(date2 == date1)) log_err("FAIL\n"); udat_close(format); free(pattern); }
ERL_NIF_TERM date_now(ErlNifEnv* env, int argc, const ERL_NIF_TERM /*argv*/[]) { if (argc != 0) return enif_make_badarg(env); return enif_make_double(env, (double) ucal_getNow()); }
void EraRules::initCurrentEra() { UDate now = ucal_getNow(); int year, month0, dom, dow, doy, mid; Grego::timeToFields(now, year, month0, dom, dow, doy, mid); int currentEncodedDate = encodeDate(year, month0 + 1 /* changes to 1-base */, dom); int eraIdx = numEras - 1; while (eraIdx > 0) { if (currentEncodedDate >= startDates[eraIdx]) { break; } eraIdx--; } // Note: current era could be before the first era. // In this case, this implementation returns the first era index (0). currentEra = eraIdx;}
U_CAPI int32_t U_EXPORT2 getCurrentYear() { #if !UCONFIG_NO_FORMATTING UErrorCode status=U_ZERO_ERROR; UCalendar *cal = NULL; if(currentYear == -1) { cal = ucal_open(NULL, -1, NULL, UCAL_TRADITIONAL, &status); ucal_setMillis(cal, ucal_getNow(), &status); currentYear = ucal_get(cal, UCAL_YEAR, &status); ucal_close(cal); } #else /* No formatting- no way to set the current year. */ #endif return currentYear; }
static void TestRelativeDateFormat() { UDate today = 0.0; const UDateFormatStyle * stylePtr; const UChar ** monthPtnPtr; UErrorCode status = U_ZERO_ERROR; UCalendar * ucal = ucal_open(trdfZone, -1, trdfLocale, UCAL_GREGORIAN, &status); if ( U_SUCCESS(status) ) { int32_t year, month, day; ucal_setMillis(ucal, ucal_getNow(), &status); year = ucal_get(ucal, UCAL_YEAR, &status); month = ucal_get(ucal, UCAL_MONTH, &status); day = ucal_get(ucal, UCAL_DATE, &status); ucal_setDateTime(ucal, year, month, day, 18, 49, 0, &status); /* set to today at 18:49:00 */ today = ucal_getMillis(ucal, &status); ucal_close(ucal); } if ( U_FAILURE(status) || today == 0.0 ) { log_data_err("Generate UDate for a specified time today fails, error %s - (Are you missing data?)\n", myErrorName(status) ); return; } for (stylePtr = dateStylesList, monthPtnPtr = monthPatnsList; *stylePtr != UDAT_NONE; ++stylePtr, ++monthPtnPtr) { UDateFormat* fmtRelDateTime; UDateFormat* fmtRelDate; UDateFormat* fmtTime; int32_t dayOffset, limit; UFieldPosition fp; UChar strDateTime[kDateAndTimeOutMax]; UChar strDate[kDateOrTimeOutMax]; UChar strTime[kDateOrTimeOutMax]; UChar * strPtr; int32_t dtpatLen; fmtRelDateTime = udat_open(UDAT_SHORT, *stylePtr | UDAT_RELATIVE, trdfLocale, trdfZone, -1, NULL, 0, &status); if ( U_FAILURE(status) ) { log_data_err("udat_open timeStyle SHORT dateStyle (%d | UDAT_RELATIVE) fails, error %s (Are you missing data?)\n", *stylePtr, myErrorName(status) ); continue; } fmtRelDate = udat_open(UDAT_NONE, *stylePtr | UDAT_RELATIVE, trdfLocale, trdfZone, -1, NULL, 0, &status); if ( U_FAILURE(status) ) { log_err("udat_open timeStyle NONE dateStyle (%d | UDAT_RELATIVE) fails, error %s\n", *stylePtr, myErrorName(status) ); udat_close(fmtRelDateTime); continue; } fmtTime = udat_open(UDAT_SHORT, UDAT_NONE, trdfLocale, trdfZone, -1, NULL, 0, &status); if ( U_FAILURE(status) ) { log_err("udat_open timeStyle SHORT dateStyle NONE fails, error %s\n", myErrorName(status) ); udat_close(fmtRelDateTime); udat_close(fmtRelDate); continue; } dtpatLen = udat_toPatternRelativeDate(fmtRelDateTime, strDate, kDateAndTimeOutMax, &status); if ( U_FAILURE(status) ) { log_err("udat_toPatternRelativeDate timeStyle SHORT dateStyle (%d | UDAT_RELATIVE) fails, error %s\n", *stylePtr, myErrorName(status) ); status = U_ZERO_ERROR; } else if ( u_strstr(strDate, *monthPtnPtr) == NULL || dtpatLen != u_strlen(strDate) ) { log_err("udat_toPatternRelativeDate timeStyle SHORT dateStyle (%d | UDAT_RELATIVE) date pattern incorrect\n", *stylePtr ); } dtpatLen = udat_toPatternRelativeTime(fmtRelDateTime, strTime, kDateAndTimeOutMax, &status); if ( U_FAILURE(status) ) { log_err("udat_toPatternRelativeTime timeStyle SHORT dateStyle (%d | UDAT_RELATIVE) fails, error %s\n", *stylePtr, myErrorName(status) ); status = U_ZERO_ERROR; } else if ( u_strstr(strTime, minutesPatn) == NULL || dtpatLen != u_strlen(strTime) ) { log_err("udat_toPatternRelativeTime timeStyle SHORT dateStyle (%d | UDAT_RELATIVE) time pattern incorrect\n", *stylePtr ); } dtpatLen = udat_toPattern(fmtRelDateTime, FALSE, strDateTime, kDateAndTimeOutMax, &status); if ( U_FAILURE(status) ) { log_err("udat_toPattern timeStyle SHORT dateStyle (%d | UDAT_RELATIVE) fails, error %s\n", *stylePtr, myErrorName(status) ); status = U_ZERO_ERROR; } else if ( u_strstr(strDateTime, strDate) == NULL || u_strstr(strDateTime, strTime) == NULL || dtpatLen != u_strlen(strDateTime) ) { log_err("udat_toPattern timeStyle SHORT dateStyle (%d | UDAT_RELATIVE) dateTime pattern incorrect\n", *stylePtr ); } udat_applyPatternRelative(fmtRelDateTime, strDate, u_strlen(strDate), newTimePatn, u_strlen(newTimePatn), &status); if ( U_FAILURE(status) ) { log_err("udat_applyPatternRelative timeStyle SHORT dateStyle (%d | UDAT_RELATIVE) fails, error %s\n", *stylePtr, myErrorName(status) ); status = U_ZERO_ERROR; } else { udat_toPattern(fmtRelDateTime, FALSE, strDateTime, kDateAndTimeOutMax, &status); if ( U_FAILURE(status) ) { log_err("udat_toPattern timeStyle SHORT dateStyle (%d | UDAT_RELATIVE) fails, error %s\n", *stylePtr, myErrorName(status) ); status = U_ZERO_ERROR; } else if ( u_strstr(strDateTime, newTimePatn) == NULL ) { log_err("udat_applyPatternRelative timeStyle SHORT dateStyle (%d | UDAT_RELATIVE) didn't update time pattern\n", *stylePtr ); } } udat_applyPatternRelative(fmtRelDateTime, strDate, u_strlen(strDate), strTime, u_strlen(strTime), &status); /* restore original */ fp.field = UDAT_MINUTE_FIELD; for (dayOffset = -2, limit = 2; dayOffset <= limit; ++dayOffset) { UDate dateToUse = today + (float)dayOffset*dayInterval; udat_format(fmtRelDateTime, dateToUse, strDateTime, kDateAndTimeOutMax, &fp, &status); if ( U_FAILURE(status) ) { log_err("udat_format timeStyle SHORT dateStyle (%d | UDAT_RELATIVE) fails, error %s\n", *stylePtr, myErrorName(status) ); status = U_ZERO_ERROR; } else { udat_format(fmtRelDate, dateToUse, strDate, kDateOrTimeOutMax, NULL, &status); if ( U_FAILURE(status) ) { log_err("udat_format timeStyle NONE dateStyle (%d | UDAT_RELATIVE) fails, error %s\n", *stylePtr, myErrorName(status) ); status = U_ZERO_ERROR; } else if ( u_strstr(strDateTime, strDate) == NULL ) { log_err("relative date string not found in udat_format timeStyle SHORT dateStyle (%d | UDAT_RELATIVE)\n", *stylePtr ); } udat_format(fmtTime, dateToUse, strTime, kDateOrTimeOutMax, NULL, &status); if ( U_FAILURE(status) ) { log_err("udat_format timeStyle SHORT dateStyle NONE fails, error %s\n", myErrorName(status) ); status = U_ZERO_ERROR; } else if ( u_strstr(strDateTime, strTime) == NULL ) { log_err("time string not found in udat_format timeStyle SHORT dateStyle (%d | UDAT_RELATIVE)\n", *stylePtr ); } strPtr = u_strstr(strDateTime, minutesStr); if ( strPtr != NULL ) { int32_t beginIndex = strPtr - strDateTime; if ( fp.beginIndex != beginIndex ) { log_err("UFieldPosition beginIndex %d, expected %d, in udat_format timeStyle SHORT dateStyle (%d | UDAT_RELATIVE)\n", fp.beginIndex, beginIndex, *stylePtr ); } } else { log_err("minutes string not found in udat_format timeStyle SHORT dateStyle (%d | UDAT_RELATIVE)\n", *stylePtr ); } } } udat_close(fmtRelDateTime); udat_close(fmtRelDate); udat_close(fmtTime); } }
static void TestBuilder() { UErrorCode errorCode=U_ZERO_ERROR; UDateTimePatternGenerator *dtpg; UDateTimePatternConflict conflict; UEnumeration *en; UChar result[20]; int32_t length, pLength; const UChar *s, *p; const UChar* ptrResult[2]; int32_t count=0; UDateTimePatternGenerator *generator; int32_t formattedCapacity, resultLen,patternCapacity ; UChar pattern[40], formatted[40]; UDateFormat *formatter; UDate sampleDate = 837039928046.0; static const char locale[]= "fr"; UErrorCode status=U_ZERO_ERROR; /* test create an empty DateTimePatternGenerator */ dtpg=udatpg_openEmpty(&errorCode); if(U_FAILURE(errorCode)) { log_err("udatpg_openEmpty() failed - %s\n", u_errorName(errorCode)); return; } /* Add a pattern */ conflict = udatpg_addPattern(dtpg, redundantPattern, 5, FALSE, result, 20, &length, &errorCode); if(U_FAILURE(errorCode)) { log_err("udatpg_addPattern() failed - %s\n", u_errorName(errorCode)); return; } /* Add a redundant pattern */ conflict = udatpg_addPattern(dtpg, redundantPattern, 5, FALSE, result, 20, &length, &errorCode); if(conflict == UDATPG_NO_CONFLICT) { log_err("udatpg_addPattern() failed to find the duplicate pattern.\n"); return; } /* Test pattern == NULL */ s=NULL; length = udatpg_addPattern(dtpg, s, 0, FALSE, result, 20, &length, &errorCode); if(!U_FAILURE(errorCode)&&(length!=0) ) { log_err("udatpg_addPattern failed in illegal argument - pattern is NULL.\n"); return; } /* replace field type */ errorCode=U_ZERO_ERROR; conflict = udatpg_addPattern(dtpg, testPattern2, 7, FALSE, result, 20, &length, &errorCode); if((conflict != UDATPG_NO_CONFLICT)||U_FAILURE(errorCode)) { log_err("udatpg_addPattern() failed to add HH:mm v. - %s\n", u_errorName(errorCode)); return; } length = udatpg_replaceFieldTypes(dtpg, testPattern2, 7, replacedStr, 4, result, 20, &errorCode); if (U_FAILURE(errorCode) || (length==0) ) { log_err("udatpg_replaceFieldTypes failed!\n"); return; } /* Get all skeletons and the crroespong pattern for each skeleton. */ ptrResult[0] = testPattern2; ptrResult[1] = redundantPattern; count=0; en = udatpg_openSkeletons(dtpg, &errorCode); if (U_FAILURE(errorCode) || (length==0) ) { log_err("udatpg_openSkeletons failed!\n"); return; } while ( (s=uenum_unext(en, &length, &errorCode))!= NULL) { p = udatpg_getPatternForSkeleton(dtpg, s, length, &pLength); if (U_FAILURE(errorCode) || p==NULL || u_memcmp(p, ptrResult[count], pLength)!=0 ) { log_err("udatpg_getPatternForSkeleton failed!\n"); return; } count++; } uenum_close(en); /* Get all baseSkeletons */ en = udatpg_openBaseSkeletons(dtpg, &errorCode); count=0; while ( (s=uenum_unext(en, &length, &errorCode))!= NULL) { p = udatpg_getPatternForSkeleton(dtpg, s, length, &pLength); if (U_FAILURE(errorCode) || p==NULL || u_memcmp(p, resultBaseSkeletons[count], pLength)!=0 ) { log_err("udatpg_getPatternForSkeleton failed!\n"); return; } count++; } if (U_FAILURE(errorCode) || (length==0) ) { log_err("udatpg_openSkeletons failed!\n"); return; } uenum_close(en); udatpg_close(dtpg); /* sample code in Userguide */ patternCapacity = (int32_t)(sizeof(pattern)/sizeof((pattern)[0])); status=U_ZERO_ERROR; generator=udatpg_open(locale, &status); if(U_FAILURE(status)) { return; } /* get a pattern for an abbreviated month and day */ length = udatpg_getBestPattern(generator, skeleton, 4, pattern, patternCapacity, &status); formatter = udat_open(UDAT_IGNORE, UDAT_DEFAULT, locale, timeZoneGMT, -1, pattern, length, &status); if (formatter==NULL) { log_err("Failed to initialize the UDateFormat of the sample code in Userguide.\n"); udatpg_close(generator); return; } /* use it to format (or parse) */ formattedCapacity = (int32_t)(sizeof(formatted)/sizeof((formatted)[0])); resultLen=udat_format(formatter, ucal_getNow(), formatted, formattedCapacity, NULL, &status); /* for French, the result is "13 sept." */ /* cannot use the result from ucal_getNow() because the value change evreyday. */ resultLen=udat_format(formatter, sampleDate, formatted, formattedCapacity, NULL, &status); if ( u_memcmp(sampleFormatted, formatted, resultLen) != 0 ) { log_err("Failed udat_format() of sample code in Userguide.\n"); } udatpg_close(generator); udat_close(formatter); }
void CalendarLimitTest::doLimitsTest(Calendar& cal, const int32_t* fieldsToTest, UDate startDate, int32_t testDuration) { static const int32_t FIELDS[] = { UCAL_ERA, UCAL_YEAR, UCAL_MONTH, UCAL_WEEK_OF_YEAR, UCAL_WEEK_OF_MONTH, UCAL_DAY_OF_MONTH, UCAL_DAY_OF_YEAR, UCAL_DAY_OF_WEEK_IN_MONTH, UCAL_YEAR_WOY, UCAL_EXTENDED_YEAR, -1, }; static const char* FIELD_NAME[] = { "ERA", "YEAR", "MONTH", "WEEK_OF_YEAR", "WEEK_OF_MONTH", "DAY_OF_MONTH", "DAY_OF_YEAR", "DAY_OF_WEEK", "DAY_OF_WEEK_IN_MONTH", "AM_PM", "HOUR", "HOUR_OF_DAY", "MINUTE", "SECOND", "MILLISECOND", "ZONE_OFFSET", "DST_OFFSET", "YEAR_WOY", "DOW_LOCAL", "EXTENDED_YEAR", "JULIAN_DAY", "MILLISECONDS_IN_DAY", "IS_LEAP_MONTH" }; UErrorCode status = U_ZERO_ERROR; int32_t i, j; UnicodeString ymd; GregorianCalendar greg(status); if (failure(status, "new GregorianCalendar")) { return; } greg.setTime(startDate, status); if (failure(status, "GregorianCalendar::setTime")) { return; } logln((UnicodeString)"Start: " + startDate); if (fieldsToTest == NULL) { fieldsToTest = FIELDS; } // Keep a record of minima and maxima that we actually see. // These are kept in an array of arrays of hashes. int32_t limits[UCAL_FIELD_COUNT][4]; for (j = 0; j < UCAL_FIELD_COUNT; j++) { limits[j][0] = INT32_MAX; limits[j][1] = INT32_MIN; limits[j][2] = INT32_MAX; limits[j][3] = INT32_MIN; } // This test can run for a long time; show progress. UDate millis = ucal_getNow(); UDate mark = millis + 5000; // 5 sec millis -= testDuration * 1000; // stop time if testDuration<0 for (i = 0; testDuration > 0 ? i < testDuration : ucal_getNow() < millis; ++i) { if (ucal_getNow() >= mark) { logln((UnicodeString)"(" + i + " days)"); mark += 5000; // 5 sec } UDate testMillis = greg.getTime(status); cal.setTime(testMillis, status); cal.setMinimalDaysInFirstWeek(1); if (failure(status, "Calendar set/getTime")) { return; } for (j = 0; fieldsToTest[j] >= 0; ++j) { UCalendarDateFields f = (UCalendarDateFields)fieldsToTest[j]; int32_t v = cal.get(f, status); int32_t minActual = cal.getActualMinimum(f, status); int32_t maxActual = cal.getActualMaximum(f, status); int32_t minLow = cal.getMinimum(f); int32_t minHigh = cal.getGreatestMinimum(f); int32_t maxLow = cal.getLeastMaximum(f); int32_t maxHigh = cal.getMaximum(f); if (limits[j][0] > minActual) { // the minimum limits[j][0] = minActual; } if (limits[j][1] < minActual) { // the greatest minimum limits[j][1] = minActual; } if (limits[j][2] > maxActual) { // the least maximum limits[j][2] = maxActual; } if (limits[j][3] < maxActual) { // the maximum limits[j][3] = maxActual; } if (minActual < minLow || minActual > minHigh) { errln((UnicodeString)"Fail: [" + cal.getType() + "] " + ymdToString(cal, ymd) + " Range for min of " + FIELD_NAME[f] + "(" + f + ")=" + minLow + ".." + minHigh + ", actual_min=" + minActual); } if (maxActual < maxLow || maxActual > maxHigh) { if ( uprv_strcmp(cal.getType(), "chinese") == 0 && testMillis >= 2842992000000.0 && testMillis <= 2906668800000.0 && logKnownIssue("12620", "chinese calendar failures for some actualMax tests")) { logln((UnicodeString)"KnownFail: [" + cal.getType() + "] " + ymdToString(cal, ymd) + " Range for max of " + FIELD_NAME[f] + "(" + f + ")=" + maxLow + ".." + maxHigh + ", actual_max=" + maxActual); } else { errln((UnicodeString)"Fail: [" + cal.getType() + "] " + ymdToString(cal, ymd) + " Range for max of " + FIELD_NAME[f] + "(" + f + ")=" + maxLow + ".." + maxHigh + ", actual_max=" + maxActual); } } if (v < minActual || v > maxActual) { // timebomb per #9967, fix with #9972 if ( uprv_strcmp(cal.getType(), "dangi") == 0 && testMillis >= 1865635198000.0 && logKnownIssue("9972", "as per #9967")) { // Feb 2029 gregorian, end of dangi 4361 logln((UnicodeString)"KnownFail: [" + cal.getType() + "] " + ymdToString(cal, ymd) + " " + FIELD_NAME[f] + "(" + f + ")=" + v + ", actual=" + minActual + ".." + maxActual + ", allowed=(" + minLow + ".." + minHigh + ")..(" + maxLow + ".." + maxHigh + ")"); } else if ( uprv_strcmp(cal.getType(), "chinese") == 0 && testMillis >= 2842992000000.0 && testMillis <= 2906668800000.0 && logKnownIssue("12620", "chinese calendar failures for some actualMax tests")) { logln((UnicodeString)"KnownFail: [" + cal.getType() + "] " + ymdToString(cal, ymd) + " " + FIELD_NAME[f] + "(" + f + ")=" + v + ", actual=" + minActual + ".." + maxActual + ", allowed=(" + minLow + ".." + minHigh + ")..(" + maxLow + ".." + maxHigh + ")"); } else { errln((UnicodeString)"Fail: [" + cal.getType() + "] " + ymdToString(cal, ymd) + " " + FIELD_NAME[f] + "(" + f + ")=" + v + ", actual=" + minActual + ".." + maxActual + ", allowed=(" + minLow + ".." + minHigh + ")..(" + maxLow + ".." + maxHigh + ")"); } } } greg.add(UCAL_DAY_OF_YEAR, 1, status); if (failure(status, "Calendar::add")) { return; } } // Check actual maxima and minima seen against ranges returned // by API. UnicodeString buf; for (j = 0; fieldsToTest[j] >= 0; ++j) { int32_t rangeLow, rangeHigh; UBool fullRangeSeen = TRUE; UCalendarDateFields f = (UCalendarDateFields)fieldsToTest[j]; buf.remove(); buf.append((UnicodeString)"[" + cal.getType() + "] " + FIELD_NAME[f]); // Minumum rangeLow = cal.getMinimum(f); rangeHigh = cal.getGreatestMinimum(f); if (limits[j][0] != rangeLow || limits[j][1] != rangeHigh) { fullRangeSeen = FALSE; } buf.append((UnicodeString)" minima range=" + rangeLow + ".." + rangeHigh); buf.append((UnicodeString)" minima actual=" + limits[j][0] + ".." + limits[j][1]); // Maximum rangeLow = cal.getLeastMaximum(f); rangeHigh = cal.getMaximum(f); if (limits[j][2] != rangeLow || limits[j][3] != rangeHigh) { fullRangeSeen = FALSE; } buf.append((UnicodeString)" maxima range=" + rangeLow + ".." + rangeHigh); buf.append((UnicodeString)" maxima actual=" + limits[j][2] + ".." + limits[j][3]); if (fullRangeSeen) { logln((UnicodeString)"OK: " + buf); } else { // This may or may not be an error -- if the range of dates // we scan over doesn't happen to contain a minimum or // maximum, it doesn't mean some other range won't. logln((UnicodeString)"Warning: " + buf); } } logln((UnicodeString)"End: " + greg.getTime(status)); }
/** * @bug 4029195 */ void Test4029195() { int32_t resultlength, resultlengthneeded; UChar *fmdt, *todayS, *rt; UChar *pat=NULL; UChar *temp; UDate today, d1; UDateFormat *df; int32_t parsepos; UErrorCode status = U_ZERO_ERROR; log_verbose("Testing date format and parse function in regression test\n"); today = ucal_getNow(); df = udat_open(UDAT_DEFAULT,UDAT_DEFAULT ,"en_US", NULL, 0, NULL, 0, &status); if(U_FAILURE(status)) { log_data_err("FAIL: error in creating the dateformat using default date and time style : %s (Are you missing data?)\n", myErrorName(status)); return; } resultlength=0; resultlengthneeded=udat_toPattern(df, TRUE, NULL, resultlength, &status); if(status==U_BUFFER_OVERFLOW_ERROR) { status=U_ZERO_ERROR; resultlength=resultlengthneeded + 1; pat=(UChar*)malloc(sizeof(UChar) * resultlength); udat_toPattern(df, TRUE, pat, resultlength, &status); } log_verbose("pattern: %s\n", austrdup(pat)); fmdt = myFormatit(df, today); if(fmdt) { log_verbose("today: %s\n", austrdup(fmdt)); } else { log_data_err("ERROR: couldn't format, exitting test"); return; } temp=(UChar*)malloc(sizeof(UChar) * 10); u_uastrcpy(temp, "M yyyy dd"); udat_applyPattern(df, TRUE, temp, u_strlen(temp)); todayS =myFormatit(df, today); log_verbose("After teh pattern is applied\n today: %s\n", austrdup(todayS) ); parsepos=0; d1=udat_parse(df, todayS, u_strlen(todayS), &parsepos, &status); if(U_FAILURE(status)) { log_err("FAIL: Error in parsing using udat_parse(.....): %s\n", myErrorName(status)); } rt =myFormatit(df, d1); log_verbose("today: %s\n", austrdup(rt) ); log_verbose("round trip: %s\n", austrdup(rt) ); if(u_strcmp(rt, todayS)!=0) { log_err("Fail: Want %s Got %s\n", austrdup(todayS), austrdup(rt) ); } else log_verbose("Pass: parse and format working fine\n"); udat_close(df); free(temp); if(pat != NULL) { free(pat); } }
/** * call-seq: * UCalendar.now * * Get the current date and time. in millis * * UCalendar.now # => 1137934561000.0 * */ VALUE icu4r_cal_now(VALUE obj){ return rb_float_new(ucal_getNow()); }