wineventsif.cpp

来自「funambol window mobile客户端源代码」· C++ 代码 · 共 473 行 · 第 1/2 页

CPP
473
字号
        }
    }

    if (propertyValue != L"") {
        return propertyValue;
    } 
    return propValue;
}



wstring WinEventSIF::adaptFromSIFSpecs(const wstring& propName, const wstring& propValue) {

    wstring propertyValue = L"";

    // the End value must be incremented of a day in allDayEvent appointment
    if ( propName == L"End" && 
        (propValue.size() == 8 || propValue.size() == 10)) { // both format yyyyMMdd and yyyy-MM-dd
        DATE d;
        stringTimeToDouble(propValue, &d);
        d += 1;
        doubleToStringTime(propertyValue, d, true);                                
    }


    if (propertyValue != L"") {
        return propertyValue;
    } 
    return propValue;
}



void WinEventSIF::parseExceptions(const wstring& sifString) {

    wstring exString;

    if (getElementContent(sifString, L"Exceptions", exString)) {
        // Not found: nothing to do.
        return;
    }

    // <Exceptions> not empty -> parse all exceptions
    if (exString.size() > 0) {
        wstring exDate, rDate;
        wstring::size_type pos, start, end;

        // Parse all <ExcludeDate>
        pos = 0;
        while ( !getElementContent(exString, L"ExcludeDate", exDate, pos, start, end) ) {
            pos = end;
            if (exDate.size() > 0) {
                excludeDate.push_back(exDate);
            }
        }

        // Parse all <IncludeDate>
        pos = start = end = 0;
        while ( !getElementContent(exString, L"IncludeDate", rDate, pos, start, end) ) {
            pos = end;
            if (rDate.size() > 0) {
                includeDate.push_back(rDate);
            }
        }
    }
}


void WinEventSIF::addTimezone(wstring& sif) {

    sif += L"<Timezone>\n";

    //
    // <BasicOffset> = - (Bias + StandardBias)     [StandardBias is usually = 0]
    //
    sif += L"<BasicOffset>";
    sif += formatBias(tzInfo.Bias + tzInfo.StandardBias);
    sif += L"</BasicOffset>\n";

    //
    // <DayLight> = list of tag for every year that this appointment occurr.
    //
    int yearBegin = 0;
    int yearEnd   = 5000;
    getIntervalOfRecurrence(&yearBegin, &yearEnd);


    // DSTOffset = - (Bias + StandardBias + DaylightBias)
    // [StandardBias is usually = 0]
    bool hasDST = false;
    int diffBias = tzInfo.Bias + tzInfo.StandardBias + tzInfo.DaylightBias;
    wstring daylightBias;
    if (diffBias != 0) { 
        hasDST = true;
        daylightBias = formatBias(diffBias);
    }

    // Max 6 iterations (for infinite recurrences).
    if (yearEnd - yearBegin > MAX_DAYLIGHT_PROPS) {
        yearEnd = yearBegin + MAX_DAYLIGHT_PROPS;
    }

    if (hasDST && hasDayLightSaving(&tzInfo)) {
        // Add a DayLight tag for every year that this appointment occurr. (max = 6)
        for (int year = yearBegin; year <= yearEnd; year++) {

            wstring daylightDate = getDateFromTzRule(year, tzInfo.DaylightDate);
            wstring standardDate = getDateFromTzRule(year, tzInfo.StandardDate);

            sif += L"<DayLight>\n";
            sif += L"<DSTOffset>" ;    sif += daylightBias;     sif += L"</DSTOffset>";
            sif += L"<DSTStart>"  ;    sif += daylightDate;     sif += L"</DSTStart>" ;
            sif += L"<DSTEnd>"    ;    sif += standardDate;     sif += L"</DSTEnd>"   ;
            if (wcslen(tzInfo.StandardName) > 0) {
                sif += L"<StandardName>";  sif += tzInfo.StandardName;   sif += L"</StandardName>";
            }
            else { 
                sif += L"<StandardName/>";
            }
            if (wcslen(tzInfo.StandardName) > 0) {
                sif += L"<DSTName>";       sif += tzInfo.DaylightName;   sif += L"</DSTName>\n";
            }
            else {
                sif += L"<DSTName/>";
            }
            sif += L"</DayLight>\n";
        }
    }
    else {
        // No daylight for this timezone
        // It doesn't add anything.
        // sif += L"<DayLight/>\n";
    }

    sif += L"</Timezone>\n";
}


bool WinEventSIF::parseTimezone(const wstring& data) {

    wstring timezone;
    if (getElementContent(data, L"Timezone", timezone, 0)) {
        return false;
    }
    if (timezone.size() == 0) {
        return false;
    }
    
    /**
    * This check is for avoid scenarios in which the client receives the PatternStartDate and
    * Timezone together that is not permitted and it is not handled properly by the clients.
    * So, if the client gets the PatternStartDate with 'Z', the way to handle is the same as the 6.5 version.
    */
    wstring patDate;
    if (!getElementContent(data, L"PatternStartDate", patDate, 0) && patDate.size()) {
        if (patDate.find(TEXT("Z")) != wstring::npos) {
            LOG.debug("PatternStartDate is in UTC format: the Timezone is not consider");
            return false;
        }
    }

    bool found = false;
    wstring element;
    if ( !getElementContent(timezone, L"BasicOffset", element, 0) && element.size() ) {

        int bias = parseBias(element.c_str());

        wstring dstOffset, standardName, daylightName;
        list<wstring> daylightDates;
        list<wstring> standardDates;

        //
        // Search all <DayLight> inside <Timezone> (one for every year). It cannot exist
        // it there is not DayLight
        //
        wstring::size_type start = 0, end = 0;
        bool dstFlag = false;
        wstring daylight;
        while (!getElementContent(timezone, L"DayLight", daylight, end, start, end)) {
            if (daylight.size()) {
                // Found a DayLight tag. Many props are redundant, now are overwritten.
                dstFlag = true;
                getElementContent(daylight, L"DSTOffset",    dstOffset);
                getElementContent(daylight, L"DSTStart",     element);
                daylightDates.push_back(element);
                getElementContent(daylight, L"DSTEnd",       element);
                standardDates.push_back(element);
                getElementContent(daylight, L"StandardName", standardName);
                getElementContent(daylight, L"DSTName",      daylightName);
            }
            else {
                // Empty <DayLight/> = no daylight for this timezone
                dstFlag = false;
                break;
            }
        }


        //
        // If we have all required data, fill the tzInfo structure.
        //
        if (dstFlag == false) {
            // Easy timezone, no DST
            found = true;
            tzInfo.Bias         = bias;
            tzInfo.StandardBias = 0;        // Cannot retrieve it, assume = 0 (usually is 0)
            tzInfo.DaylightBias = -60;      // most of the tiemzone is -60. only 1 is not (baghdad)
            memset((void*)(&tzInfo.DaylightDate), 0, sizeof(SYSTEMTIME));
            memset((void*)(&tzInfo.StandardDate) , 0, sizeof(SYSTEMTIME));           
            wcsncpy(tzInfo.StandardName, standardName.c_str(), 32);
            wcsncpy(tzInfo.DaylightName, daylightName.c_str(), 32);
        }
        else if (dstOffset.size() && daylightDates.size() && standardDates.size() ) {
            // Standard timezone, the DST rules are extracted from list of dates
            // >> Bias = -TZ
            // >> StandardBias = 0  (Cannot retrieve it, assume = 0 as usually is 0)
            // >> DaylightBias = - (DSTOffset + Bias)
            bool rightValue = true;
            found = true;
            tzInfo.Bias         = bias;
            tzInfo.StandardBias = 0;
            tzInfo.DaylightBias = parseBias(dstOffset.c_str()) - bias;
            tzInfo.DaylightDate = getTzRuleFromDates(daylightDates, &rightValue);
            tzInfo.StandardDate = getTzRuleFromDates(standardDates, &rightValue);
            wcsncpy(tzInfo.StandardName, standardName.c_str(), 32);
            wcsncpy(tzInfo.DaylightName, daylightName.c_str(), 32);
        }
    }
    else {
        // <BasicOffset> missing (it's mandatory)
        found = false;
    }
    
    return found;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?