QTimeZonePrivate::Data QWinTimeZonePrivate::nextTransition(qint64 afterMSecsSinceEpoch) const
{
    // Convert MSecs to year to get transitions for, assumes no transitions around 31 Dec/1 Jan
    int year = msecsToDate(afterMSecsSinceEpoch).year();

    QWinTransitionRule rule;
    // If the required year falls after the last rule start year and the last rule has no
    // valid future transition calculations then there is no next transition
    if (year > m_tranRules.last().startYear) {
        rule = ruleForYear(year);
        // If the rules have either a fixed year, or no month, then no future trans
        if (rule.standardTimeRule.wYear != 0 || rule.daylightTimeRule.wYear != 0
            || rule.standardTimeRule.wMonth == 0 || rule.daylightTimeRule.wMonth == 0) {
            return invalidData();
        }
    }

    // Otherwise we have a valid rule for the required year that can be used
    // to calculate this year or next
    qint64 first;
    qint64 second;
    qint64 next = minMSecs();
    qint64 stdMSecs;
    qint64 dstMSecs;
    do {
        // Convert the transition rules into msecs for the year we want to try
        rule = ruleForYear(year);
        // If no transition rules to calculate then no next transition
        if (rule.standardTimeRule.wMonth == 0 && rule.daylightTimeRule.wMonth == 0)
            return invalidData();
        calculateTransitionsForYear(rule, year, &stdMSecs, &dstMSecs);
        // Find the first and second transition for the year
        if (stdMSecs < dstMSecs) {
            first = stdMSecs;
            second = dstMSecs;
        } else {
            first = dstMSecs;
            second = stdMSecs;
        }
        if (afterMSecsSinceEpoch < first)
            next = first;
        else if (afterMSecsSinceEpoch < second)
            next = second;
        // If didn't fall in this year, try the next
        ++year;
    } while (next == minMSecs() && year <= MAX_YEAR);

    if (next == minMSecs() || next == invalidMSecs())
        return invalidData();

    return ruleToData(rule, next, (next == dstMSecs) ? QTimeZone::DaylightTime : QTimeZone::StandardTime);
}
QTimeZonePrivate::Data QWinTimeZonePrivate::previousTransition(qint64 beforeMSecsSinceEpoch) const
{
    // Convert MSecs to year to get transitions for, assumes no transitions around 31 Dec/1 Jan
    int year = msecsToDate(beforeMSecsSinceEpoch).year();

    QWinTransitionRule rule;
    // If the required year falls before the first rule start year and the first rule has no
    // valid transition calculations then there is no previous transition
    if (year < m_tranRules.first().startYear) {
        rule = ruleForYear(year);
        // If the rules have either a fixed year, or no month, then no previous trans
        if (rule.standardTimeRule.wYear != 0 || rule.daylightTimeRule.wYear != 0
            || rule.standardTimeRule.wMonth == 0 || rule.daylightTimeRule.wMonth == 0) {
            return invalidData();
        }
    }

    qint64 first;
    qint64 second;
    qint64 next = maxMSecs();
    qint64 stdMSecs;
    qint64 dstMSecs;
    do {
        // Convert the transition rules into msecs for the year we want to try
        rule = ruleForYear(year);
        // If no transition rules to calculate then no previous transition
        if (rule.standardTimeRule.wMonth == 0 && rule.daylightTimeRule.wMonth == 0)
            return invalidData();
        calculateTransitionsForYear(rule, year, &stdMSecs, &dstMSecs);
        if (stdMSecs < dstMSecs) {
            first = stdMSecs;
            second = dstMSecs;
        } else {
            first = dstMSecs;
            second = stdMSecs;
        }
        if (beforeMSecsSinceEpoch > second && second != invalidMSecs())
            next = second;
        else if (beforeMSecsSinceEpoch > first && first != invalidMSecs())
            next = first;
        // If didn't fall in this year, try the previous
        --year;
    } while (next == maxMSecs() && year >= MIN_YEAR);

    if (next == maxMSecs())
        return invalidData();

    return ruleToData(rule, next, (next == dstMSecs) ? QTimeZone::DaylightTime : QTimeZone::StandardTime);
}
QTimeZonePrivate::Data QIcuTimeZonePrivate::previousTransition(qint64 beforeMSecsSinceEpoch) const
{
    // Available in ICU C++ api, and draft C api in v50
    // TODO When v51 released see if api is stable
#if U_ICU_VERSION_MAJOR_NUM == 50
    return ucalTimeZoneTransition(m_ucal, UCAL_TZ_TRANSITION_PREVIOUS, beforeMSecsSinceEpoch);
#else
    Q_UNUSED(beforeMSecsSinceEpoch)
    return invalidData();
#endif // U_ICU_VERSION_MAJOR_NUM == 50
}
QTimeZonePrivate::Data QAndroidTimeZonePrivate::data(qint64 forMSecsSinceEpoch) const
{
    if (androidTimeZone.isValid()) {
        Data data;
        data.atMSecsSinceEpoch = forMSecsSinceEpoch;
        data.standardTimeOffset = standardTimeOffset(forMSecsSinceEpoch);
        data.offsetFromUtc = offsetFromUtc(forMSecsSinceEpoch);
        data.daylightTimeOffset = data.offsetFromUtc - data.standardTimeOffset;
        data.abbreviation = abbreviation(forMSecsSinceEpoch);
        return data;
    } else {
        return invalidData();
    }
}
// Since Android does not provide an API to access transitions,
// dataForLocalTime needs to be reimplemented without direct use of transitions
QTimeZonePrivate::Data QAndroidTimeZonePrivate::dataForLocalTime(qint64 forLocalMSecs) const
{
    if (!androidTimeZone.isValid()) {
        return invalidData();
    } else {
        qint64 UTCepochMSecs;

        // compare the UTC time with standard offset against normal daylight offset of one hour
        qint64 standardUTCMSecs(forLocalMSecs - (standardTimeOffset(forLocalMSecs) * 1000));
        qint64 daylightUTCMsecs;

        // Check if daylight time does apply,
        // checking also for daylight time boundaries
        if (isDaylightTime(standardUTCMSecs)) {
            // If daylight does apply, then standardUTCMSecs will be an hour or so ahead of the real epoch time
            // so check that time
            daylightUTCMsecs = standardUTCMSecs - daylightTimeOffset(standardUTCMSecs)*1000;
            if (isDaylightTime(daylightUTCMsecs)) {
                // daylight time confirmed
                UTCepochMSecs = daylightUTCMsecs;
            } else {
                // daylight time has just finished
                UTCepochMSecs = standardUTCMSecs;
            }
        } else {
            // Standard time indicated, but check for a false negative.
            // Would a standard one-hour daylight offset indicate daylight time?
            daylightUTCMsecs = standardUTCMSecs - 3600000; // 3600000 MSECS_PER_HOUR
            if (isDaylightTime(daylightUTCMsecs)) {
                // daylight time may have just started,
                // but double check against timezone's own daylight offset
                // (don't necessarily assume a one-hour offset)
                daylightUTCMsecs = standardUTCMSecs - daylightTimeOffset(daylightUTCMsecs)*1000;
                if (isDaylightTime(daylightUTCMsecs)) {
                    // daylight time confirmed
                    UTCepochMSecs = daylightUTCMsecs;
                } else {
                    // false positive, apply standard time after all
                    UTCepochMSecs = standardUTCMSecs;
                }
            } else {
                // confirmed standard time
                UTCepochMSecs = standardUTCMSecs;
            }
        }

        return data(UTCepochMSecs);
    }
}
QTimeZonePrivate::Data QIcuTimeZonePrivate::data(qint64 forMSecsSinceEpoch) const
{
    // Available in ICU C++ api, and draft C api in v50
    // TODO When v51 released see if api is stable
    QTimeZonePrivate::Data data = invalidData();
#if U_ICU_VERSION_MAJOR_NUM == 50
    data = ucalTimeZoneTransition(m_ucal, UCAL_TZ_TRANSITION_PREVIOUS_INCLUSIVE,
                                  forMSecsSinceEpoch);
#else
    ucalOffsetsAtTime(m_ucal, forMSecsSinceEpoch, &data.standardTimeOffset,
                      &data.daylightTimeOffset);
    data.offsetFromUtc = data.standardTimeOffset + data.daylightTimeOffset;
    data.abbreviation = abbreviation(forMSecsSinceEpoch);
#endif // U_ICU_VERSION_MAJOR_NUM == 50
    data.atMSecsSinceEpoch = forMSecsSinceEpoch;
    return data;
}
Beispiel #7
0
	void TcpConnection::handle_read(const boost::system::error_code& e, std::size_t bytes_transferred) {
		if (!e)  {
			if (bytes_transferred) {
				try{
					uint8_t c = (uint8_t)incomming_packet[0];
					
					if(c >= P_ID_COUNT || c < 0){
						std::cout << c << std::endl;
						throw std::exception("Out of range");
					}
					func_ptr[c](&socket_);
					read();
				}catch(std::exception&){
					invalidData();
					read();
				}
			}
		}
	}
QTimeZonePrivate::Data QAndroidTimeZonePrivate::previousTransition(qint64 beforeMSecsSinceEpoch) const
{
    // transitions not available on Android, so return an invalid data object
    Q_UNUSED( beforeMSecsSinceEpoch );
    return invalidData();
}
QTimeZonePrivate::Data QAndroidTimeZonePrivate::nextTransition(qint64 afterMSecsSinceEpoch) const
{
    // transitions not available on Android, so return an invalid data object
    Q_UNUSED( afterMSecsSinceEpoch );
    return invalidData();
}