VirtualBox

Changeset 72285 in vbox for trunk/src


Ignore:
Timestamp:
May 22, 2018 12:35:20 PM (7 years ago)
Author:
vboxsync
Message:

IPRT: Adding RTTimeLocalDeltaNanoFor.

Location:
trunk/src/VBox/Runtime
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/posix/timelocal-posix.cpp

    r72163 r72285  
    148148
    149149/**
    150  * Gets the delta between UTC and local time.
     150 * Gets the current delta between UTC and local time.
    151151 *
    152152 * @code
     
    161161    RTTIMESPEC Time;
    162162    return rtTimeLocalUTCOffset(RTTimeNow(&Time), true /* current time, skip fallback */);
     163}
     164
     165
     166/**
     167 * Gets the delta between UTC and local time at the given time.
     168 *
     169 * @code
     170 *      RTTIMESPEC LocalTime;
     171 *      RTTimeNow(&LocalTime);
     172 *      RTTimeSpecAddNano(&LocalTime, RTTimeLocalDeltaNanoFor(&LocalTime));
     173 * @endcode
     174 *
     175 * @param   pTimeSpec   The time spec giving the time to get the delta for.
     176 * @returns Returns the nanosecond delta between UTC and local time.
     177 */
     178RTDECL(int64_t) RTTimeLocalDeltaNanoFor(PCRTTIMESPEC pTimeSpec)
     179{
     180    AssertPtr(pTimeSpec);
     181    return rtTimeLocalUTCOffset(pTimeSpec, false /* current time, skip fallback */);
    163182}
    164183
  • trunk/src/VBox/Runtime/r3/win/time2-win.cpp

    r72163 r72285  
    107107}
    108108
     109
     110/**
     111 * Gets the delta between UTC and local time at the given time.
     112 *
     113 * @code
     114 *      RTTIMESPEC LocalTime;
     115 *      RTTimeNow(&LocalTime);
     116 *      RTTimeSpecAddNano(&LocalTime, RTTimeLocalDeltaNanoFor(&LocalTime));
     117 * @endcode
     118 *
     119 * @param   pTimeSpec   The time spec giving the time to get the delta for.
     120 * @returns Returns the nanosecond delta between UTC and local time.
     121 */
     122RTDECL(int64_t) RTTimeLocalDeltaNanoFor(PCRTTIMESPEC pTimeSpec)
     123{
     124    RTTIMESPEC LocalTime;
     125    if (g_pfnSystemTimeToTzSpecificLocalTime)
     126    {
     127        /*
     128         * FileTimeToLocalFileTime does not do the right thing, so we'll have
     129         * to convert to system time and SystemTimeToTzSpecificLocalTime instead.
     130         *
     131         * Note! FileTimeToSystemTime drops resoultion down to milliseconds, thus
     132         *       we have to do the offUTC calculation using milliseconds and adjust
     133         *       u32Nanosecons by sub milliseconds digits.
     134         */
     135        SYSTEMTIME SystemTimeIn;
     136        FILETIME FileTime;
     137        if (FileTimeToSystemTime(RTTimeSpecGetNtFileTime(pTimeSpec, &FileTime), &SystemTimeIn))
     138        {
     139            SYSTEMTIME SystemTimeOut;
     140            if (g_pfnSystemTimeToTzSpecificLocalTime(NULL /* use current TZI */, &SystemTimeIn, &SystemTimeOut))
     141            {
     142                if (SystemTimeToFileTime(&SystemTimeOut, &FileTime))
     143                {
     144                    RTTimeSpecSetNtFileTime(&LocalTime, &FileTime);
     145
     146                    return (RTTimeSpecGetMilli(&LocalTime) - RTTimeSpecGetMilli(pTimeSpec)) * RT_NS_1MS;
     147                }
     148            }
     149        }
     150    }
     151
     152    return RTTimeLocalDeltaNano();
     153}
     154
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