本文整理汇总了C++中DateFormat::setTimeZone方法的典型用法代码示例。如果您正苦于以下问题:C++ DateFormat::setTimeZone方法的具体用法?C++ DateFormat::setTimeZone怎么用?C++ DateFormat::setTimeZone使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DateFormat
的用法示例。
在下文中一共展示了DateFormat::setTimeZone方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: umsg_set_timezone
static void umsg_set_timezone(MessageFormatter_object *mfo,
intl_error& err)
{
MessageFormat *mf = (MessageFormat *)mfo->mf_data.umsgf;
TimeZone *used_tz = NULL;
const Format **formats;
int32_t count;
/* Unfortanely, this cannot change the time zone for arguments that
* appear inside complex formats because ::getFormats() returns NULL
* for all uncached formats, which is the case for complex formats
* unless they were set via one of the ::setFormat() methods */
if (mfo->mf_data.tz_set) {
return; /* already done */
}
formats = mf->getFormats(count);
if (formats == NULL) {
intl_errors_set(&err, U_MEMORY_ALLOCATION_ERROR,
"Out of memory retrieving subformats", 0);
}
for (int i = 0; U_SUCCESS(err.code) && i < count; i++) {
DateFormat* df = dynamic_cast<DateFormat*>(
const_cast<Format *>(formats[i]));
if (df == NULL) {
continue;
}
if (used_tz == NULL) {
zval nullzv, *zvptr = &nullzv;
ZVAL_NULL(zvptr);
used_tz = timezone_process_timezone_argument(zvptr, &err, "msgfmt_format");
if (used_tz == NULL) {
continue;
}
}
df->setTimeZone(*used_tz);
}
if (U_SUCCESS(err.code)) {
mfo->mf_data.tz_set = 1;
}
}
示例2: getDateFormat
UnicodeString&
CalendarTimeZoneTest::dateToString(UDate d, UnicodeString& str,
const TimeZone& tz)
{
str.remove();
DateFormat* format = getDateFormat();
if (format == 0)
{
str += "DATE_FORMAT_FAILURE";
return str;
}
TimeZone* save = format->getTimeZone().clone();
format->setTimeZone(tz);
format->format(d, str);
format->adoptTimeZone(save);
releaseDateFormat(format);
return str;
}
示例3: IslamicCivil
void CalendarCaseTest::IslamicCivil()
{
static const TestCase tests[] = {
//
// Most of these test cases were taken from the back of
// "Calendrical Calculations", with some extras added to help
// debug a few of the problems that cropped up in development.
//
// The months in this table are 1-based rather than 0-based,
// because it's easier to edit that way.
// Islamic
// Julian Day Era Year Month Day WkDay Hour Min Sec
{ 1507231.5, 0, -1245, 12, 9, SUN, 0, 0, 0},
{ 1660037.5, 0, -813, 2, 23, WED, 0, 0, 0},
{ 1746893.5, 0, -568, 4, 1, WED, 0, 0, 0},
{ 1770641.5, 0, -501, 4, 6, SUN, 0, 0, 0},
{ 1892731.5, 0, -157, 10, 17, WED, 0, 0, 0},
{ 1931579.5, 0, -47, 6, 3, MON, 0, 0, 0},
{ 1974851.5, 0, 75, 7, 13, SAT, 0, 0, 0},
{ 2091164.5, 0, 403, 10, 5, SUN, 0, 0, 0},
{ 2121509.5, 0, 489, 5, 22, SUN, 0, 0, 0},
{ 2155779.5, 0, 586, 2, 7, FRI, 0, 0, 0},
{ 2174029.5, 0, 637, 8, 7, SAT, 0, 0, 0},
{ 2191584.5, 0, 687, 2, 20, FRI, 0, 0, 0},
{ 2195261.5, 0, 697, 7, 7, SUN, 0, 0, 0},
{ 2229274.5, 0, 793, 7, 1, SUN, 0, 0, 0},
{ 2245580.5, 0, 839, 7, 6, WED, 0, 0, 0},
{ 2266100.5, 0, 897, 6, 1, SAT, 0, 0, 0},
{ 2288542.5, 0, 960, 9, 30, SAT, 0, 0, 0},
{ 2290901.5, 0, 967, 5, 27, SAT, 0, 0, 0},
{ 2323140.5, 0, 1058, 5, 18, WED, 0, 0, 0},
{ 2334848.5, 0, 1091, 6, 2, SUN, 0, 0, 0},
{ 2348020.5, 0, 1128, 8, 4, FRI, 0, 0, 0},
{ 2366978.5, 0, 1182, 2, 3, SUN, 0, 0, 0},
{ 2385648.5, 0, 1234, 10, 10, MON, 0, 0, 0},
{ 2392825.5, 0, 1255, 1, 11, WED, 0, 0, 0},
{ 2416223.5, 0, 1321, 1, 21, SUN, 0, 0, 0},
{ 2425848.5, 0, 1348, 3, 19, SUN, 0, 0, 0},
{ 2430266.5, 0, 1360, 9, 8, MON, 0, 0, 0},
{ 2430833.5, 0, 1362, 4, 13, MON, 0, 0, 0},
{ 2431004.5, 0, 1362, 10, 7, THU, 0, 0, 0},
{ 2448698.5, 0, 1412, 9, 13, TUE, 0, 0, 0},
{ 2450138.5, 0, 1416, 10, 5, SUN, 0, 0, 0},
{ 2465737.5, 0, 1460, 10, 12, WED, 0, 0, 0},
{ 2486076.5, 0, 1518, 3, 5, SUN, 0, 0, 0},
{ -1,-1,-1,-1,-1,-1,-1,-1,-1 }
};
UErrorCode status = U_ZERO_ERROR;
Calendar *c = Calendar::createInstance("[email protected]=islamic-civil", status);
if (failure(status, "Calendar::createInstance", TRUE)) return;
c->setLenient(TRUE);
doTestCases(tests, c);
static const UChar expectedUChars[] = {
0x0627, 0x0644, 0x062e, 0x0645, 0x064a, 0x0633, 0x060c, 0x0020, 0x0662, 0x0662, 0x0020,
0x0634, 0x0648, 0x0627, 0x0644, 0x060c, 0x0020, 0x0661, 0x0663, 0x0668, 0x0669, 0x0020, 0x0647, 0x0640, 0
};
UnicodeString result;
DateFormat *fmt = DateFormat::createDateInstance(DateFormat::kFull, Locale("[email protected]=islamic-civil"));
if (fmt == NULL) {
dataerrln("Error calling DateFormat::createDateInstance");
delete c;
return;
}
fmt->setTimeZone(*TimeZone::getGMT());
fmt->format((UDate)2486076.5, result);
if (result != expectedUChars) {
errln((UnicodeString)"FAIL: DateFormatting failed. Got " + result + " and expected " + UnicodeString(expectedUChars) + UnicodeString("\n"));
errln("Maybe the resource aliasing isn't working");
}
delete fmt;
delete c;
}
示例4: testAPI
//.........这里部分代码省略.........
}
logln( (UnicodeString) "" + d + " formatted to " + res1);
res2 = it->format(d, res2, pos2);
logln( (UnicodeString) "" + d + " formatted to " + res2);
res3 = de->format(d, res3);
logln( (UnicodeString) "" + d + " formatted to " + res3);
}
// ======= Test parse()
if (def != NULL)
{
logln("Testing parse()");
UnicodeString text("02/03/76 2:50 AM, CST");
Formattable result1;
UDate result2, result3;
ParsePosition pos(0), pos01(0);
def->parseObject(text, result1, pos);
if(result1.getType() != Formattable::kDate) {
errln("ERROR: parseObject() failed for " + text);
}
logln(text + " parsed into " + result1.getDate());
status = U_ZERO_ERROR;
result2 = def->parse(text, status);
if(U_FAILURE(status)) {
errln("ERROR: parse() failed, stopping testing");
return;
}
logln(text + " parsed into " + result2);
result3 = def->parse(text, pos01);
logln(text + " parsed into " + result3);
}
// ======= Test getters and setters
if (fr != NULL && it != NULL && de != NULL)
{
logln("Testing getters and setters");
int32_t count = 0;
const Locale *locales = DateFormat::getAvailableLocales(count);
logln((UnicodeString) "Got " + count + " locales" );
for(int32_t i = 0; i < count; i++) {
UnicodeString name;
name = locales[i].getName();
logln(name);
}
fr->setLenient(it->isLenient());
if(fr->isLenient() != it->isLenient()) {
errln("ERROR: setLenient() failed");
}
const Calendar *cal = def->getCalendar();
Calendar *newCal = cal->clone();
de->adoptCalendar(newCal);
it->setCalendar(*newCal);
if( *(de->getCalendar()) != *(it->getCalendar())) {
errln("ERROR: adopt or set Calendar() failed");
}
const NumberFormat *nf = def->getNumberFormat();
NumberFormat *newNf = (NumberFormat*) nf->clone();
de->adoptNumberFormat(newNf);
it->setNumberFormat(*newNf);
if( *(de->getNumberFormat()) != *(it->getNumberFormat())) {
errln("ERROR: adopt or set NumberFormat() failed");
}
const TimeZone& tz = def->getTimeZone();
TimeZone *newTz = tz.clone();
de->adoptTimeZone(newTz);
it->setTimeZone(*newTz);
if( de->getTimeZone() != it->getTimeZone()) {
errln("ERROR: adopt or set TimeZone() failed");
}
}
// ======= Test getStaticClassID()
logln("Testing getStaticClassID()");
status = U_ZERO_ERROR;
DateFormat *test = new SimpleDateFormat(status);
if(U_FAILURE(status)) {
errln("ERROR: Couldn't create a DateFormat");
}
if(test->getDynamicClassID() != SimpleDateFormat::getStaticClassID()) {
errln("ERROR: getDynamicClassID() didn't return the expected value");
}
delete test;
delete def;
delete fr;
delete it;
delete de;
}
示例5: umsg_set_timezone
static void umsg_set_timezone(MessageFormatter_object *mfo,
intl_error& err)
{
MessageFormat *mf = (MessageFormat *)mfo->mf_data.umsgf;
TimeZone *used_tz = NULL;
const Format **formats;
int32_t count;
/* Unfortanely, this cannot change the time zone for arguments that
* appear inside complex formats because ::getFormats() returns NULL
* for all uncached formats, which is the case for complex formats
* unless they were set via one of the ::setFormat() methods */
if (mfo->mf_data.tz_set) {
return; /* already done */
}
/* There is a bug in ICU which prevents MessageFormatter::getFormats()
to handle more than 10 formats correctly. The enumerator could be
used to walk through the present formatters using getFormat(), which
however seems to provide just a readonly access. This workaround
prevents crash when there are > 10 formats but doesn't set any error.
As a result, only DateFormatters with > 10 subformats are affected.
This workaround should be ifdef'd out, when the bug has been fixed
in ICU. */
icu::StringEnumeration* fnames = mf->getFormatNames(err.code);
if (!fnames || U_FAILURE(err.code)) {
return;
}
count = fnames->count(err.code);
delete fnames;
if (count > 10) {
return;
}
formats = mf->getFormats(count);
if (formats == NULL) {
intl_errors_set(&err, U_MEMORY_ALLOCATION_ERROR,
"Out of memory retrieving subformats", 0);
}
for (int i = 0; U_SUCCESS(err.code) && i < count; i++) {
DateFormat* df = dynamic_cast<DateFormat*>(
const_cast<Format *>(formats[i]));
if (df == NULL) {
continue;
}
if (used_tz == NULL) {
zval nullzv, *zvptr = &nullzv;
ZVAL_NULL(zvptr);
used_tz = timezone_process_timezone_argument(zvptr, &err, "msgfmt_format");
if (used_tz == NULL) {
continue;
}
}
df->setTimeZone(*used_tz);
}
if (U_SUCCESS(err.code)) {
mfo->mf_data.tz_set = 1;
}
}
示例6: testConvertDate
void DataDrivenFormatTest::testConvertDate(TestData *testData,
const DataMap * /* settings */, UBool fmt) {
UnicodeString kPATTERN("PATTERN="); // TODO: static
UnicodeString kMILLIS("MILLIS="); // TODO: static
UnicodeString kRELATIVE_MILLIS("RELATIVE_MILLIS="); // TODO: static
UnicodeString kRELATIVE_ADD("RELATIVE_ADD:"); // TODO: static
UErrorCode status = U_ZERO_ERROR;
SimpleDateFormat basicFmt(UnicodeString("EEE MMM dd yyyy / YYYY'-W'ww-ee"),
status);
if (U_FAILURE(status)) {
dataerrln("FAIL: Couldn't create basic SimpleDateFormat: %s",
u_errorName(status));
return;
}
const DataMap *currentCase= NULL;
// Start the processing
int n = 0;
while (testData->nextCase(currentCase, status)) {
char calLoc[256] = "";
DateTimeStyleSet styleSet;
UnicodeString pattern;
UBool usePattern = FALSE;
(void)usePattern; // Suppress unused warning.
CalendarFieldsSet fromSet;
UDate fromDate = 0;
UBool useDate = FALSE;
UDate now = Calendar::getNow();
++n;
char theCase[200];
sprintf(theCase, "case %d:", n);
UnicodeString caseString(theCase, "");
// load params
UnicodeString locale = currentCase->getString("locale", status);
if (U_FAILURE(status)) {
errln("case %d: No 'locale' line.", n);
continue;
}
UnicodeString zone = currentCase->getString("zone", status);
if (U_FAILURE(status)) {
errln("case %d: No 'zone' line.", n);
continue;
}
UnicodeString spec = currentCase->getString("spec", status);
if(U_FAILURE(status)) {
errln("case %d: No 'spec' line.", n);
continue;
}
UnicodeString date = currentCase->getString("date", status);
if(U_FAILURE(status)) {
errln("case %d: No 'date' line.", n);
continue;
}
UnicodeString expectStr= currentCase->getString("str", status);
if(U_FAILURE(status)) {
errln("case %d: No 'str' line.", n);
continue;
}
DateFormat *format = NULL;
// Process: 'locale'
locale.extract(0, locale.length(), calLoc, (const char*)0); // default codepage. Invariant codepage doesn't have '@'!
Locale loc(calLoc);
if(spec.startsWith(kPATTERN)) {
pattern = UnicodeString(spec,kPATTERN.length());
usePattern = TRUE;
format = new SimpleDateFormat(pattern, loc, status);
if(U_FAILURE(status)) {
errln("case %d: could not create SimpleDateFormat from pattern: %s", n, u_errorName(status));
continue;
}
} else {
if(styleSet.parseFrom(spec, status)<0 || U_FAILURE(status)) {
errln("case %d: could not parse spec as style fields: %s", n, u_errorName(status));
continue;
}
format = DateFormat::createDateTimeInstance((DateFormat::EStyle)styleSet.getDateStyle(), (DateFormat::EStyle)styleSet.getTimeStyle(), loc);
if(format == NULL ) {
errln("case %d: could not create SimpleDateFormat from styles.", n);
continue;
}
}
Calendar *cal = Calendar::createInstance(loc, status);
if(U_FAILURE(status)) {
errln("case %d: could not create calendar from %s", n, calLoc);
}
if (zone.length() > 0) {
TimeZone * tz = TimeZone::createTimeZone(zone);
cal->setTimeZone(*tz);
format->setTimeZone(*tz);
delete tz;
}
//.........这里部分代码省略.........