コード例 #1
0
ファイル: ucal.cpp プロジェクト: venkatarajasekhar/Qt
U_CAPI int32_t U_EXPORT2
ucal_getDSTSavings(const UChar* zoneID, UErrorCode* ec) {
    int32_t result = 0;
    TimeZone* zone = _createTimeZone(zoneID, -1, ec);
    if (U_SUCCESS(*ec)) {
        SimpleTimeZone* stz = dynamic_cast<SimpleTimeZone*>(zone);
        if (stz != NULL) {
            result = stz->getDSTSavings();
        } else {
            // Since there is no getDSTSavings on TimeZone, we use a
            // heuristic: Starting with the current time, march
            // forwards for one year, looking for DST savings.
            // Stepping by weeks is sufficient.
            UDate d = Calendar::getNow();
            for (int32_t i=0; i<53; ++i, d+=U_MILLIS_PER_DAY*7.0) {
                int32_t raw, dst;
                zone->getOffset(d, FALSE, raw, dst, *ec);
                if (U_FAILURE(*ec)) {
                    break;
                } else if (dst != 0) {
                    result = dst;
                    break;
                }
            }
        }
    }
    delete zone;
    return result;
}
コード例 #2
0
    TZEnumeration(int32_t rawOffset) : map(NULL), len(0), pos(0) {
        if (!getOlsonMeta()) {
            return;
        }

        // Allocate more space than we'll need.  The end of the array will
        // be blank.
        map = (int32_t*)uprv_malloc(OLSON_ZONE_COUNT * sizeof(int32_t));
        if (map == 0) {
            return;
        }

        uprv_memset(map, 0, sizeof(int32_t) * OLSON_ZONE_COUNT);

        UnicodeString s;
        for (int32_t i=0; i<OLSON_ZONE_COUNT; ++i) {
            if (getID(i)) {
                // This is VERY inefficient.
                TimeZone* z = TimeZone::createTimeZone(unistr);
                // Make sure we get back the ID we wanted (if the ID is
                // invalid we get back GMT).
                if (z != 0 && z->getID(s) == unistr &&
                    z->getRawOffset() == rawOffset) {
                    map[len++] = i;
                }
                delete z;
            }
        }
    }
コード例 #3
0
TimeZone*
TimeZone::createSystemTimeZone(const UnicodeString& id) {
    TimeZone* z = 0;
    UErrorCode ec = U_ZERO_ERROR;
    UResourceBundle res;
    ures_initStackObject(&res);
    U_DEBUG_TZ_MSG(("pre-err=%s\n", u_errorName(ec)));
    UResourceBundle *top = openOlsonResource(id, res, ec);
    U_DEBUG_TZ_MSG(("post-err=%s\n", u_errorName(ec)));
    if (U_SUCCESS(ec)) {
        z = new OlsonTimeZone(top, &res, ec);
        if (z) {
          z->setID(id);
        } else {
          U_DEBUG_TZ_MSG(("cstz: olson time zone failed to initialize - err %s\n", u_errorName(ec)));
        }
    }
    ures_close(&res);
    ures_close(top);
    if (U_FAILURE(ec)) {
        U_DEBUG_TZ_MSG(("cstz: failed to create, err %s\n", u_errorName(ec)));
        delete z;
        z = 0;
    }
    return z;
}
コード例 #4
0
void DateFormatRoundTripTest::TestDateFormatRoundTrip() 
{
    UErrorCode status = U_ZERO_ERROR;

    getFieldCal = Calendar::createInstance(status);
    failure(status, "Calendar::createInstance");
    if(!assertSuccess("trying to construct", status))return;


    int32_t locCount = 0;
    const Locale *avail = DateFormat::getAvailableLocales(locCount);
    logln("DateFormat available locales: %d", locCount);
    if(quick) {
        SPARSENESS = 18;
        logln("Quick mode: only testing SPARSENESS = 18");
    }
    TimeZone *tz = TimeZone::createDefault();
    UnicodeString temp;
    logln("Default TimeZone:             " + tz->getID(temp));
    delete tz;

#ifdef TEST_ONE_LOC // define this to just test ONE locale.
    Locale loc(TEST_ONE_LOC);
    test(loc);
#if INFINITE
    for(;;) {
      test(loc);
    }
#endif

#else
# if INFINITE
    // Special infinite loop test mode for finding hard to reproduce errors
    Locale loc = Locale::getDefault();
    logln("ENTERING INFINITE TEST LOOP FOR Locale: " + loc.getDisplayName(temp));
    for(;;) 
        test(loc);
# else
    test(Locale::getDefault());

#if 1
    // installed locales
    for (int i=0; i < locCount; ++i) {
            test(avail[i]);
    }
#endif

#if 1
    // special locales
    int32_t jCount = CalendarTest::testLocaleCount();
    for (int32_t j=0; j < jCount; ++j) {
        test(Locale(CalendarTest::testLocaleID(j)));
    }
#endif

# endif
#endif

    delete getFieldCal;
}
コード例 #5
0
static jstring getDisplayTimeZoneNative(JNIEnv* env, jclass clazz,
        jstring zoneID, jboolean isDST, jint style, jstring localeID) {

    // Build TimeZone object
    const jchar* idChars = env->GetStringChars(zoneID, NULL);
    jint idLength = env->GetStringLength(zoneID);
    UnicodeString idString((UChar*)idChars, idLength);
    TimeZone* zone = TimeZone::createTimeZone(idString);
    env->ReleaseStringChars(zoneID, idChars);

    // Build Locale object (can we rely on zero termination of JNI result?)
    const char* localeChars = env->GetStringUTFChars(localeID, NULL);
    jint localeLength = env->GetStringLength(localeID);
    Locale locale = Locale::createFromName(localeChars);

    // Try to get the display name of the TimeZone according to the Locale
    UnicodeString buffer;
    zone->getDisplayName((UBool)isDST, (style == 0 ? TimeZone::SHORT : TimeZone::LONG), locale, buffer);
    const UChar* tempChars = buffer.getBuffer();
    int tempLength = buffer.length();
    jstring result = env->NewString((jchar*)tempChars, tempLength);
    env->ReleaseStringUTFChars(localeID, localeChars);

    // Clean up everything
    delete(zone);
    
    return result;
}
コード例 #6
0
void TIMEZONE_Get_display_name(sLONG_PTR *pResult, PackagePtr pParams)
{
	C_TEXT Param1;
	C_TEXT Param2;
	C_LONGINT returnValue;
	
	Param1.fromParamAtIndex(pParams, 1);
	
	UErrorCode status = U_ZERO_ERROR;
	
	Param1.fromParamAtIndex(pParams, 1);
	UnicodeString zoneId = UnicodeString((const UChar *)Param1.getUTF16StringPtr());
	TimeZone *zone = TimeZone::createTimeZone(zoneId);
	
	if(zone){
		
		UnicodeString displayName;
		zone->getDisplayName (displayName);
		
		DT::setUnicodeString(Param2, displayName);
		
		delete zone;
		
	}else{
		status = U_ILLEGAL_ARGUMENT_ERROR;
	}
	
	returnValue.setIntValue(status);
	
	Param2.toParamAtIndex(pParams, 2);
	returnValue.setReturn(pResult);
}
コード例 #7
0
//
//  Constructor.
//
LocalTime::LocalTime(int32_t ot) :
    DateTime(),
    rule(&dstnever),
    dst(false)
{
    TimeZone zone;
    this->offset = zone.normalize(ot);
}
コード例 #8
0
//
//  Constructor.
//
LocalTime::LocalTime(int32_t ot, DaylightSavingTime& re) :
    DateTime(),
    rule(&re)
{
    TimeZone zone;
    this->offset = zone.normalize(ot);
    this->dst = (*(this->rule))(*this);
}
コード例 #9
0
ファイル: EditEventForm.cpp プロジェクト: minicho/TIZEN5-
String
EditEventForm::GetTimezoneString(void) const
{
	LocaleManager localeManager;
	localeManager.Construct();
	TimeZone timeZone = localeManager.GetSystemTimeZone();

	return timeZone.GetId();
}
コード例 #10
0
TimeZone VCardFormatImpl::readUTCValue( ContentLine *cl )
{
  UTCValue *utcValue = (UTCValue *)cl->value();
  if ( utcValue ) {
    TimeZone tz;
    tz.setOffset(((utcValue->hour()*60)+utcValue->minute())*(utcValue->positive() ? 1 : -1));
    return tz;
  } else
    return TimeZone();
}
コード例 #11
0
const char* TimeStamp::milspec(const LocalTime& lt) {
    TimeZone zone;
    ::snprintf(this->buffer, sizeof(this->buffer),
        "%04llu-%3.3s-%02u %02u:%02u:%02u%1.1s",
        lt.getYear(), lt.getDate().monthToString(), lt.getDay(),
        lt.getHour(), lt.getMinute(), lt.getSecond(),
        zone.milspec(lt.getOffset()));
    this->buffer[sizeof(this->buffer) - 1] = '\0';
    assert(std::strlen(this->buffer) < sizeof(this->buffer));
    return this->buffer;
}
コード例 #12
0
// Log line space is at a premium. It pays to have as high a precision timestamp
// as the underlying platform supports, but no more. Generally about a
// microsecond is the best we can hope for on Linux platforms. But I've used
// vxWorks platforms that had time bases accurate to tens of nanoseconds. So
// consider altering the print format from ".%06u" to ".%09u" and removing the
// "/ 1000" nanosecond divisor.
const char* TimeStamp::log(const LocalTime& lt) {
    TimeZone zone;
    ::snprintf(this->buffer, sizeof(this->buffer),
        "%04llu-%02u-%02u %02u:%02u:%02u.%06u%1.1s",
        lt.getYear(), lt.getMonth(), lt.getDay(),
        lt.getHour(), lt.getMinute(), lt.getSecond(),
        lt.getNanosecond() / 1000,
        zone.milspec(lt.getOffset()));
    this->buffer[sizeof(this->buffer) - 1] = '\0';
    assert(std::strlen(this->buffer) < sizeof(this->buffer));
    return this->buffer;
}
コード例 #13
0
int TimezoneUtils::offsetFromUtcToTz(QDateTime date, QString timezoneId, bool ignoreDstOffset, bool* error)
{
    int offset = 0;
    UErrorCode errorCode = U_ZERO_ERROR;

    // get timezone object
    TimeZone* tz = TimeZone::createTimeZone(reinterpret_cast<UChar*>(timezoneId.data()));
    if (!tz) {
        *error = true;
        return 0;
    }

    UnicodeString name;
    tz->getDisplayName(name);

    // get offset
    // cal takes ownership of tz - tried to delete it and got an error
    Calendar* cal = Calendar::createInstance(tz, errorCode);
    if (!cal || errorCode > 0) {
        *error = true;
        return 0;
    }
    cal->set(date.date().year(), date.date().month(), date.date().day(), date.time().hour(), date.time().minute());
    UDate udate = cal->getTime(errorCode);
    if (errorCode > 0) {
        *error = true;
        delete cal;
        return 0;
    }

    UBool isGmt = false;
    int32_t rawOffset = 0;
    int32_t dstOffset = 0;
    tz->getOffset(udate, isGmt, rawOffset, dstOffset, errorCode);
    if (errorCode > 0) {
        *error = true;
        delete cal;
        return 0;
    }

    if (!ignoreDstOffset) {
        offset = rawOffset + dstOffset;
    } else {
        offset = rawOffset;
    }
    delete cal;

    offset /= 1000;
    *error = false;

    return offset;
}
コード例 #14
0
static jstring getDisplayTimeZoneNative(JNIEnv* env, jclass clazz,
        jstring zoneId, jboolean isDST, jint style, jstring localeId) {

    TimeZone* zone = timeZoneFromId(env, zoneId);
    Locale locale = getLocale(env, localeId);

    // Try to get the display name of the TimeZone according to the Locale
    UnicodeString displayName;
    zone->getDisplayName((UBool)isDST, (style == 0 ? TimeZone::SHORT : TimeZone::LONG), locale, displayName);
    jstring result = env->NewString(displayName.getBuffer(), displayName.length());
    delete zone;
    return result;
}
コード例 #15
0
void
TimeAndPlace::SetSiderialTime(float longitude, float latitude, DateTime* currTime) {
	AppLog("Trying to access TimeAndPlace");
	TimeAndPlace::SetLongitude(longitude);
	AppLog("Trying to access TimeAndPlace 1");
	TimeAndPlace::SetLatitude(latitude);
	AppLog("Trying to access TimeAndPlace 2");
	//TimeZone timeZone(60, L"Europe/London");

	LocaleManager localeManager;
	localeManager.Construct();
	Locale locale = localeManager.GetSystemLocale();
	TimeZone timeZone = localeManager.GetSystemTimeZone();

	AppLog("Locale code %S", (locale.GetLanguageCodeString().GetPointer()));
	AppLog("TimeZone ID is %S", (timeZone.GetId()).GetPointer());

//	TimeZone timeZone(TimeZone::GetGmtTimeZone());
	AppLog("TP1");
	SystemTime::GetCurrentTime(*currTime);
	AppLog("TP2");
	dateTime = currTime;
	AppLog("TP2a");
	localDateTime = &(timeZone.UtcTimeToStandardTime(*currTime));
	Calendar* calendar;
	AppLog("TP3");
	calendar = Calendar::CreateInstanceN(timeZone, CALENDAR_GREGORIAN);
	AppLog("TP4");
	calendar->SetTime(*currTime);
	AppLog("TP5");
	float hrs = (calendar->GetTimeField(TIME_FIELD_HOUR_OF_DAY))-1;
	AppLog("TP6");
	float minHrs = calendar->GetTimeField(TIME_FIELD_MINUTE)/60.0;
	AppLog("TP7");
	float dayFract = (hrs + minHrs)/24.0;
	AppLog("TP8");
	float dayNum = calendar->GetTimeField(TIME_FIELD_DAY_OF_YEAR);
	AppLog("TP9");
	float year = calendar->GetTimeField(TIME_FIELD_YEAR);
	AppLog("TP10");
	double daysSinceJ2000 = -1.5 + dayNum + (year-2000)*365 + (int)((year-2000)/4) + dayFract;
	AppLog("TP11");
	double slt = 100.46 + 0.985647 * daysSinceJ2000 + longitude + 15*(hrs + minHrs);
	AppLog("TP12");
	int sltInt = (int)(slt/360);
	AppLog("TP13");
	float sltHrs = (slt-(360*sltInt))/15;
	AppLog("TP14");
	SetSiderialTime (sltHrs);
	AppLog("TP15");
}
コード例 #16
0
String
TimeAndPlace::GetReadableTime(void) {

	LocaleManager localeManager;
	localeManager.Construct();
	Locale locale = localeManager.GetSystemLocale();
	TimeZone timeZone = localeManager.GetSystemTimeZone();

	AppLog("GMT Time Zone id is %S", timeZone.GetGmtTimeZone().GetId().GetPointer());
	AppLog("Time Zone is %S", timeZone.GetId().GetPointer());
	AppLog("Time Zone offset is %d", timeZone.GetRawOffset());
	AppLog("Time Zone DST is %d", timeZone.GetDstSavings());

	String customizedPattern = L"HH:mm:ss";
	String readableDateTime;
	DateTimeFormatter* formatter = DateTimeFormatter::CreateDateFormatterN();
	formatter -> ApplyPattern(customizedPattern);

	DateTime standardOffsetDateTime = timeZone.UtcTimeToStandardTime(*dateTime, timeZone.GetRawOffset());
	formatter -> Format(standardOffsetDateTime, readableDateTime);
	AppLog("Standard Local Time is %S", readableDateTime.GetPointer());

	readableDateTime.Append("\n");
	readableDateTime.Append(timeZone.GetId());

	return readableDateTime;
}
コード例 #17
0
ファイル: main_1.cpp プロジェクト: winlibs/icu4c
/**
 * If the ID supplied to TimeZone is not a valid system ID,
 * TimeZone::createTimeZone() will return a GMT zone object.  In order
 * to detect this error, we check the ID of the returned zone against
 * the ID we requested.  If they don't match, we fail with an error.
 */
TimeZone* createZone(const UnicodeString& id) {
    UnicodeString str;
    TimeZone* zone = TimeZone::createTimeZone(id);
    if (zone->getID(str) != id) {
        delete zone;
        printf("Error: TimeZone::createTimeZone(");
        uprintf(id);
        printf(") returned zone with ID ");
        uprintf(str);
        printf("\n");
        exit(1);
    }
    return zone;
}
コード例 #18
0
CString DateTime::FormatISO8601(T_enISO8601Format enFormat, bool bBasic, const TimeZone& tz) const throw()
{
   CString cszDate;
   switch(enFormat)
   {
   case formatY:  return Format(_T("%Y"), tz);
   case formatYM: return Format(bBasic ? _T("%Y%m") : _T("%Y-%m"), tz);
   case formatYMD: return Format(bBasic ? _T("%Y%m%d") : _T("%Y-%m-%d"), tz);
   case formatYMD_HM_Z:
      cszDate = Format(bBasic ? _T("%Y%m%dT%H%M") : _T("%Y-%m-%dT%H:%M"), tz);
      break;

   case formatYMD_HMS_Z:
      cszDate = Format(bBasic ? _T("%Y%m%dT%H%M%S") : _T("%Y-%m-%dT%H:%M:%S"), tz);
      break;

   case formatYMD_HMSF_Z:
      {
         cszDate = Format(bBasic ? _T("%Y%m%dT%H%M%S") : _T("%Y-%m-%dT%H:%M:%S"), tz);

         CString cszFraction;
         cszFraction.Format(_T(".%03u"), Millisecond());
         cszDate += cszFraction;
      }
      break;
   }

   // add timezone
   if (tz.StandardName() == _T("UTC"))
      cszDate += _T("Z");
   else
   {
      TimeSpan spTimezone = tz.GetUtcOffset(*this);
      bool bNegative = spTimezone < TimeSpan(0, 0, 0, 0);

      TimeSpan spTimezoneAbs = bNegative ? -spTimezone : spTimezone;

      CString cszTimezone;
      cszTimezone.Format(bBasic ? _T("%c%02u%02u") : _T("%c%02u:%02u"),
         !bNegative ? _T('+') : _T('-'),
         spTimezoneAbs.Hours(),
         spTimezoneAbs.Minutes());

      cszDate += cszTimezone;
   }

   return cszDate;
}
コード例 #19
0
ファイル: ucal.cpp プロジェクト: venkatarajasekhar/Qt
U_CAPI int32_t U_EXPORT2
ucal_getDefaultTimeZone(UChar* result, int32_t resultCapacity, UErrorCode* ec) {
    int32_t len = 0;
    if (ec!=NULL && U_SUCCESS(*ec)) {
        TimeZone* zone = TimeZone::createDefault();
        if (zone == NULL) {
            *ec = U_MEMORY_ALLOCATION_ERROR;
        } else {
            UnicodeString id;
            zone->getID(id);
            delete zone;
            len = id.extract(result, resultCapacity, *ec);
        }
    }
    return len;
}
コード例 #20
0
const char* TimeStamp::civilian(const LocalTime& lt) {
    TimeZone zone;
    const char* timezone = zone.civilian(lt.getOffset());
    char effective[4];
    std::strncpy(effective, timezone, sizeof(effective));
    if (lt.getDst() && (3 <= std::strlen(effective))) {
        effective[1] = 'D';
    }
    ::snprintf(this->buffer, sizeof(this->buffer),
        "%04llu-%02u-%02u %02u:%02u:%02u %s",
        lt.getYear(), lt.getMonth(), lt.getDay(),
        lt.getHour(), lt.getMinute(), lt.getSecond(),
        effective);
    this->buffer[sizeof(this->buffer) - 1] = '\0';
    assert(std::strlen(this->buffer) < sizeof(this->buffer));
    return this->buffer;
}
コード例 #21
0
/**
 * Test to see if DateFormat understands zone equivalency groups.  It
 * might seem that this should be a DateFormat test, but it's really a
 * TimeZone test -- the changes to DateFormat are minor.
 *
 * We use two known, stable zones that shouldn't change much over time
 * -- America/Vancouver and America/Los_Angeles.  However, they MAY
 * change at some point -- if that happens, replace them with any two
 * zones in an equivalency group where one zone has localized name
 * data, and the other doesn't, in some locale.
 */
void TimeZoneRegressionTest::TestJ449() {
    UErrorCode status = U_ZERO_ERROR;
    UnicodeString str;

    // Modify the following three as necessary.  The two IDs must
    // specify two zones in the same equivalency group.  One must have
    // locale data in 'loc'; the other must not.
    const char* idWithLocaleData = "America/Los_Angeles";
    const char* idWithoutLocaleData = "US/Pacific";
    const Locale loc("en", "", "");

    TimeZone *zoneWith = TimeZone::createTimeZone(idWithLocaleData);
    TimeZone *zoneWithout = TimeZone::createTimeZone(idWithoutLocaleData);
    // Make sure we got valid zones
    if (zoneWith->getID(str) != UnicodeString(idWithLocaleData) ||
        zoneWithout->getID(str) != UnicodeString(idWithoutLocaleData)) {
      dataerrln(UnicodeString("Fail: Unable to create zones - wanted ") + idWithLocaleData + ", got " + zoneWith->getID(str) + ", and wanted " + idWithoutLocaleData + " but got " + zoneWithout->getID(str));
    } else {
        GregorianCalendar calWith(*zoneWith, status);
        GregorianCalendar calWithout(*zoneWithout, status);
        SimpleDateFormat fmt("MMM d yyyy hh:mm a zzz", loc, status);
        if (U_FAILURE(status)) {
            errln("Fail: Unable to create GregorianCalendar/SimpleDateFormat");
        } else {
            UDate date = 0;
            UnicodeString strWith, strWithout;
            fmt.setCalendar(calWith);
            fmt.format(date, strWith);
            fmt.setCalendar(calWithout);
            fmt.format(date, strWithout);
            if (strWith == strWithout) {
                logln((UnicodeString)"Ok: " + idWithLocaleData + " -> " +
                      strWith + "; " + idWithoutLocaleData + " -> " +
                      strWithout);
            } else {
                errln((UnicodeString)"FAIL: " + idWithLocaleData + " -> " +
                      strWith + "; " + idWithoutLocaleData + " -> " +
                      strWithout);
            }
        }
    }

    delete zoneWith;
    delete zoneWithout;
}
コード例 #22
0
void TIMEZONE_Get_default(sLONG_PTR *pResult, PackagePtr pParams)
{
	C_TEXT returnValue;
	
	TimeZone *defaultZone = TimeZone::createDefault();
	
	if(defaultZone){
		
		UnicodeString zoneId;
		defaultZone->getID(zoneId);
		DT::setUnicodeString(returnValue, zoneId);
		
		delete defaultZone;
		
	}
	
	returnValue.setReturn(pResult);
}
コード例 #23
0
DateTime*
TimeAndPlace::GetStandardDateTime(void) {

	LocaleManager localeManager;
	localeManager.Construct();
	Locale locale = localeManager.GetSystemLocale();
	TimeZone timeZone = localeManager.GetSystemTimeZone();

	AppLog("GMT Time Zone id is %S", timeZone.GetGmtTimeZone().GetId().GetPointer());
	AppLog("Time Zone is %S", timeZone.GetId().GetPointer());
	AppLog("Time Zone offset is %d", timeZone.GetRawOffset());
	AppLog("Time Zone DST is %d", timeZone.GetDstSavings());

	result r;

	String customizedPattern = L"HH:mm:ss zzz";
	String readableDateTime;
	DateTimeFormatter* formatter = DateTimeFormatter::CreateDateFormatterN();
	r = formatter -> ApplyPattern(customizedPattern);
	AppLog("formatter -> ApplyPattern(customizedPattern) result is %s", GetErrorMessage(r));

	DateTime standardOffsetDateTime = timeZone.UtcTimeToStandardTime(*dateTime, timeZone.GetRawOffset());
	r = formatter -> Format(standardOffsetDateTime, readableDateTime);
	AppLog("Standard Local Time is %S", readableDateTime.GetPointer());
	readableDateTime.Clear();

	DateTime standardDateTime = timeZone.UtcTimeToStandardTime(*dateTime);
	r = formatter -> Format(standardDateTime, readableDateTime);
	AppLog("Standard Time is %S", readableDateTime.GetPointer());
	readableDateTime.Clear();

	DateTime wallDateTime = timeZone.UtcTimeToWallTime(*dateTime);
	r = formatter -> Format(wallDateTime, readableDateTime);
	AppLog("Wall Time is %S", readableDateTime.GetPointer());
	readableDateTime.Clear();

	r = formatter -> Format(*dateTime, readableDateTime);
	AppLog("UTC Time is %S", readableDateTime.GetPointer());
	readableDateTime.Clear();

//	Calendar* calendar = Calendar::CreateInstanceN(timeZone, CALENDAR_GREGORIAN);
//	DateTime localTime1 = calendar -> GetTime();
//	r = formatter -> Format(localTime1, readableDateTime);
//	AppLog("Local Time is %S", readableDateTime.GetPointer());

	return localDateTime;
}
コード例 #24
0
ファイル: zonemeta.cpp プロジェクト: basti1302/node
const UChar* U_EXPORT2
ZoneMeta::getCanonicalCLDRID(const TimeZone& tz) {
    if (dynamic_cast<const OlsonTimeZone *>(&tz) != NULL) {
        // short cut for OlsonTimeZone
        const OlsonTimeZone *otz = (const OlsonTimeZone*)&tz;
        return otz->getCanonicalID();
    }
    UErrorCode status = U_ZERO_ERROR;
    UnicodeString tzID;
    return getCanonicalCLDRID(tz.getID(tzID), status);
}
コード例 #25
0
const char* TimeStamp::formal(const LocalTime& lt) {
    const Date& date = lt.getDate();
    const Time& time = lt.getTime();
    TimeZone zone;
    const char* timezone = zone.civilian(lt.getOffset());
    char effective[4];
    std::strncpy(effective, timezone, sizeof(effective));
    if (lt.getDst() && (3 <= std::strlen(effective))) {
        effective[1] = 'D';
    }
    uint8_t twelve;
    const char* meridiem = time.meridiemToString(time.oclock(twelve));
    ::snprintf(this->buffer, sizeof(this->buffer),
        "%s, %s %u, %04llu, %u:%02u %s %s",
        date.weekdayToString(), date.monthToString(), lt.getDay(), lt.getYear(),
        twelve, lt.getMinute(), meridiem,
        effective);
    this->buffer[sizeof(this->buffer) - 1] = '\0';
    assert(std::strlen(this->buffer) < sizeof(this->buffer));
    return this->buffer;
}
コード例 #26
0
/**
 * @bug 4126678
 * CANNOT REPRODUDE
 *
 * Yet another _alleged_ bug in TimeZone::getOffset(), a method that never
 * should have been made public.  It's simply too hard to use correctly.
 *
 * The original test code failed to do the following:
 * (1) Call Calendar::setTime() before getting the fields!
 * (2) Use the right millis (as usual) for getOffset(); they were passing
 *     in the MILLIS field, instead of the STANDARD MILLIS IN DAY.
 * When you fix these two problems, the test passes, as expected.
 */
void TimeZoneRegressionTest:: Test4126678() 
{
    UErrorCode status = U_ZERO_ERROR;
    Calendar *cal = Calendar::createInstance(status);
    if(U_FAILURE(status)) {
      dataerrln("Error creating calendar %s", u_errorName(status));
      delete cal;
      return;
    }
    failure(status, "Calendar::createInstance");
    TimeZone *tz = TimeZone::createTimeZone("PST");
    cal->adoptTimeZone(tz);

    cal->set(1998, UCAL_APRIL, 5, 10, 0);
    
    if (! tz->useDaylightTime() || U_FAILURE(status))
        dataerrln("We're not in Daylight Savings Time and we should be. - %s", u_errorName(status));

    //cal.setTime(dt);
    int32_t era = cal->get(UCAL_ERA, status);
    int32_t year = cal->get(UCAL_YEAR, status);
    int32_t month = cal->get(UCAL_MONTH, status);
    int32_t day = cal->get(UCAL_DATE, status);
    int32_t dayOfWeek = cal->get(UCAL_DAY_OF_WEEK, status);
    int32_t millis = cal->get(UCAL_MILLISECOND, status) +
        (cal->get(UCAL_SECOND, status) +
         (cal->get(UCAL_MINUTE, status) +
          (cal->get(UCAL_HOUR, status) * 60) * 60) * 1000) -
        cal->get(UCAL_DST_OFFSET, status);

    failure(status, "cal->get");
    int32_t offset = tz->getOffset((uint8_t)era, year, month, day, (uint8_t)dayOfWeek, millis, status);
    int32_t raw_offset = tz->getRawOffset();

    if (offset == raw_offset)
        dataerrln("Offsets should match");

    delete cal;
}
コード例 #27
0
void TIME_Get_offset(sLONG_PTR *pResult, PackagePtr pParams)
{
	C_REAL AbsoluteIn;
	C_TEXT ZoneIn;
	C_LONGINT OffsetOut;
	C_LONGINT DstOut;
	C_LONGINT returnValue;
	
	AbsoluteIn.fromParamAtIndex(pParams, 1);
	ZoneIn.fromParamAtIndex(pParams, 2);
	
	UErrorCode status = U_ZERO_ERROR;
	
	UnicodeString zoneId = UnicodeString((const UChar *)ZoneIn.getUTF16StringPtr());
	TimeZone *zone = TimeZone::createTimeZone(zoneId);
	
	if(zone){
		
		int32_t rawOffset, dstOffset;
		UDate date = AbsoluteIn.getDoubleValue();
		
		zone->getOffset(date, true, rawOffset, dstOffset, status);
		
		OffsetOut.setIntValue(rawOffset);
		DstOut.setIntValue(dstOffset);
		
		delete zone;
		
	}else{
		status = U_ILLEGAL_ARGUMENT_ERROR;
	}
	
	returnValue.setIntValue(status);
	
	OffsetOut.toParamAtIndex(pParams, 3);
	DstOut.toParamAtIndex(pParams, 4);
	returnValue.setReturn(pResult);
}
コード例 #28
0
ファイル: calendar.cpp プロジェクト: gitpan/ponie
Calendar::Calendar(const TimeZone& zone, const Locale& aLocale, UErrorCode& success)
:   UObject(),
    fIsTimeSet(FALSE),
    fAreFieldsSet(FALSE),
    fAreAllFieldsSet(FALSE),
    fNextStamp(kMinimumUserStamp),
    fTime(0),
    fLenient(TRUE),
    fZone(0)
{
    clear();
    fZone = zone.clone();
    setWeekCountData(aLocale, success);
}
コード例 #29
0
CString DateTime::Format(const CString& cszFormat, const TimeZone& tz) const throw()
{
   ATLASSERT(m_spImpl != NULL);

   if (m_spImpl->m_dt.is_not_a_date_time())
      return _T("");

   // calculate offset to UTC
   TimeSpan tsTimezone = tz.GetUtcOffset(*this);

   struct tm tmTemp = boost::posix_time::to_tm(m_spImpl->m_dt + tsTimezone.m_spImpl->m_span);

   CString cszDateTime;
   LPTSTR pszBuffer = cszDateTime.GetBufferSetLength(256);
   _tcsftime(pszBuffer, cszDateTime.GetLength(), cszFormat, &tmTemp);
   cszDateTime.ReleaseBuffer();

   return cszDateTime;
}
コード例 #30
0
void VCardFormatImpl::addUTCValue( VCARD::VCard *vcard, const TimeZone &tz )
{
  if ( !tz.isValid() ) return;

  ContentLine cl;
  cl.setName( EntityTypeToParamName( EntityTimeZone ) );

  UTCValue *v = new UTCValue;

  v->setPositive( tz.offset() >= 0 );
  v->setHour( (tz.offset() / 60) * ( tz.offset() >= 0 ? 1 : -1 ) );
  v->setMinute( (tz.offset() % 60) * ( tz.offset() >= 0 ? 1 : -1 ) );

  cl.setValue( v );
  vcard->add(cl);
}