本文整理汇总了C++中GregorianCalendar类的典型用法代码示例。如果您正苦于以下问题:C++ GregorianCalendar类的具体用法?C++ GregorianCalendar怎么用?C++ GregorianCalendar使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GregorianCalendar类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: initAstro
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);
}
示例2: logln
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;
}
示例3: ucal_setGregorianChange
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);
}
示例4: GregorianCalendar
/**
* 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;
}
示例5: GregorianCalendar
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;
}
示例6: ucal_setGregorianChange
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);
}
示例7: Test4109314
/**
* @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;
}
示例8: getCutOverTimes
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);
}
示例9: cpp_main
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;
}
示例10: _php_intlgregcal_constructor_body
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);
}
//.........这里部分代码省略.........
示例11: SimpleDateFormat
/**
* @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;
}