VirtualBox

Changeset 72094 in vbox


Ignore:
Timestamp:
May 3, 2018 2:11:50 PM (7 years ago)
Author:
vboxsync
Message:

IPRT: Fixed incorrect local timestamp/string conversion in RTTimeToString and RTTimeFromString.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/time/time.cpp

    r71268 r72094  
    712712        &&  pTime->offUTC)
    713713    {
    714         int32_t offUTCHour   = pTime->offUTC / 60;
    715         int32_t offUTCMinute = pTime->offUTC % 60;
    716         char    chSign;
    717         Assert(pTime->offUTC <= 840 && pTime->offUTC >= -840);
    718         if (pTime->offUTC >= 0)
     714        int32_t  offUTC = pTime->offUTC;
     715        Assert(offUTC <= 840 && offUTC >= -840);
     716        char     chSign;
     717        if (offUTC >= 0)
    719718            chSign = '+';
    720719        else
    721720        {
    722721            chSign = '-';
    723             offUTCMinute = -offUTCMinute;
    724             offUTCHour = -offUTCHour;
     722            offUTC = -offUTC;
    725723        }
     724        uint32_t offUTCHour   = (uint32_t)offUTC / 60;
     725        uint32_t offUTCMinute = (uint32_t)offUTC % 60;
    726726        cch = RTStrPrintf(psz, cb,
    727                           "%RI32-%02u-%02uT%02u:%02u:%02u.%09RU32%c%02d%02d",
     727                          "%RI32-%02u-%02uT%02u:%02u:%02u.%09RU32%c%02d%:02d",
    728728                          pTime->i32Year, pTime->u8Month, pTime->u8MonthDay,
    729729                          pTime->u8Hour, pTime->u8Minute, pTime->u8Second, pTime->u32Nanosecond,
    730730                          chSign, offUTCHour, offUTCMinute);
    731731        if (    cch <= 15
    732             ||  psz[cch - 5] != chSign)
     732            ||  psz[cch - 6] != chSign)
    733733            return NULL;
    734734    }
     
    885885             || *pszString == '-')
    886886    {
    887         rc = RTStrToInt32Ex(pszString, (char **)&pszString, 10, &pTime->offUTC);
     887        int8_t cUtcHours = 0;
     888        rc = RTStrToInt8Ex(pszString, (char **)&pszString, 10, &cUtcHours);
    888889        if (rc != VINF_SUCCESS && rc != VWRN_TRAILING_CHARS && rc != VWRN_TRAILING_SPACES)
     890            return NULL;
     891        uint8_t cUtcMin = 0;
     892        if (*pszString == ':')
     893        {
     894            rc = RTStrToUInt8Ex(pszString + 1, (char **)&pszString, 10, &cUtcMin);
     895            if (rc != VINF_SUCCESS && rc != VWRN_TRAILING_SPACES)
     896                return NULL;
     897        }
     898        else if (*pszString && !RT_C_IS_BLANK(*pszString))
     899            return NULL;
     900        if (cUtcHours >= 0)
     901            pTime->offUTC = cUtcHours * 60 + cUtcMin;
     902        else
     903            pTime->offUTC = cUtcHours * 60 - cUtcMin;
     904        if (RT_ABS(pTime->offUTC) > 840)
    889905            return NULL;
    890906    }
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette