VirtualBox

Changeset 2612 in vbox for trunk/src/VBox


Ignore:
Timestamp:
May 14, 2007 7:19:07 AM (18 years ago)
Author:
vboxsync
Message:

Implemented local time functions. (not properly tested yet)

Location:
trunk/src/VBox/Runtime
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/Makefile.kmk

    r2604 r2612  
    173173        md5.cpp \
    174174        path.cpp \
    175         req.cpp \
     175        req.cpp \
    176176        r3/alloc-ef.cpp \
    177177        r3/alloc.cpp \
     
    263263        generic/RTFileMove-generic.cpp \
    264264        generic/RTLogWriteDebugger-generic.cpp \
     265        generic/RTTimeLocalNow-generic.cpp \
    265266        generic/RTTimerCreate-generic.cpp \
    266267        r3/posix/RTTimeNow-posix.cpp \
     
    280281        r3/posix/thread-posix.cpp \
    281282        r3/linux/time-linux.cpp \
     283        r3/posix/timelocal-posix.cpp \
    282284        r3/posix/timer-posix.cpp \
    283285        generic/utf16locale-generic.cpp \
     
    296298        generic/RTFileMove-generic.cpp \
    297299        generic/RTLogWriteDebugger-generic.cpp \
     300        generic/RTTimeLocalNow-generic.cpp \
    298301        generic/RTTimerCreate-generic.cpp \
    299302        os2/RTErrConvertFromOS2.cpp \
     
    316319        generic/sched-generic.cpp \
    317320        r3/os2/time-os2.cpp \
     321        r3/posix/timelocal-posix.cpp \
    318322        generic/timer-generic.cpp \
    319323        r3/posix/RTTimeNow-posix.cpp \
     
    331335        generic/RTFileMove-generic.cpp \
    332336        generic/RTLogWriteDebugger-generic.cpp \
     337        generic/RTTimeLocalNow-generic.cpp \
    333338        generic/RTTimerCreate-generic.cpp \
    334339        generic/pathhost-generic.cpp \
     
    350355        r3/posix/system-posix.cpp \
    351356        r3/posix/thread-posix.cpp \
     357        r3/darwin/time-darwin.cpp \
     358        r3/posix/timelocal-posix.cpp \
    352359        r3/posix/utf8-posix.cpp \
    353         r3/darwin/time-darwin.cpp \
    354360        timesup.cpp \
    355361
     
    378384        r3/posix/thread-posix.cpp \
    379385        r3/posix/time-posix.cpp \
     386        r3/posix/timelocal-posix.cpp \
    380387        r3/posix/timer-posix.cpp \
    381388        r3/posix/RTTimeNow-posix.cpp \
     
    399406        generic/RTFileMove-generic.cpp \
    400407        generic/RTLogWriteDebugger-generic.cpp \
     408        generic/RTTimeLocalNow-generic.cpp \
    401409        generic/fs-stubs-generic.cpp \
    402410        generic/pathhost-generic.cpp \
     
    422430        r3/posix/rand-posix.cpp \
    423431        r3/posix/time-posix.cpp \
     432        r3/posix/timelocal-posix.cpp \
    424433        r3/posix/RTTimeNow-posix.cpp \
    425434        timesup.cpp
  • trunk/src/VBox/Runtime/r3/posix/RTTimeNow-posix.cpp

    r1204 r2612  
    3838 * @param   pTime   Where to store the time.
    3939 */
    40 RTR3DECL(PRTTIMESPEC) RTTimeNow(PRTTIMESPEC pTime)
     40RTDECL(PRTTIMESPEC) RTTimeNow(PRTTIMESPEC pTime)
    4141{
    4242    struct timeval tv;
  • trunk/src/VBox/Runtime/r3/win32/time-win32.cpp

    r1 r2612  
    4242#include <iprt/time.h>
    4343#include <iprt/asm.h>
     44#include <iprt/assert.h>
    4445#include "internal/time.h"
    4546
     
    137138 * @param   pTime   Where to store the time.
    138139 */
    139 RTR3DECL(PRTTIMESPEC) RTTimeNow(PRTTIMESPEC pTime)
    140 {
    141     uint64_t u64; /* manual say larger integer, should be safe to assume it's the same. */
     140RTDECL(PRTTIMESPEC) RTTimeNow(PRTTIMESPEC pTime)
     141{
     142    uint64_t u64;
     143    AssertCompile(sizeof(u64) == sizeof(FILETIME));
    142144    GetSystemTimeAsFileTime((LPFILETIME)&u64);
    143145    return RTTimeSpecSetNtTime(pTime, u64);
    144146}
    145147
     148
     149/**
     150 * Gets the current local system time.
     151 *
     152 * @returns pTime.
     153 * @param   pTime   Where to store the local time.
     154 */
     155RTDECL(PRTTIMESPEC) RTTimeLocalNow(PRTTIMESPEC pTime)
     156{
     157    uint64_t u64;
     158    AssertCompile(sizeof(u64) == sizeof(FILETIME));
     159    GetSystemTimeAsFileTime((LPFILETIME)&u64);
     160    uint64_t u64Local;
     161    if (!FileTimeToLocalFileTime((FILETIME const *)&u64, (LPFILETIME)&u64Local))
     162        u64Local = u64;
     163    return RTTimeSpecSetNtTime(pTime, u64);
     164}
     165
     166
     167/**
     168 * Gets the delta between UTC and local time.
     169 *
     170 * @code
     171 *      RTTIMESPEC LocalTime;
     172 *      RTTimeSpecAddNano(RTTimeNow(&LocalTime), RTTimeLocalDeltaNano());
     173 * @endcode
     174 *
     175 * @returns Returns the nanosecond delta between UTC and local time.
     176 */
     177RTDECL(int64_t) RTTimeLocalDeltaNano(void)
     178{
     179    /*
     180     * UCT = local + Tzi.Bias;
     181     * The bias is given in minutes.
     182     */
     183    TIME_ZONE_INFORMATION Tzi;
     184    Tzi.Bias = 0;
     185    if (GetTimeZoneInformation(&Tzi) != TIME_ZONE_ID_INVALID)
     186        return -(int64_t)Tzi.Bias * 60*1000*1000*1000;
     187    return 0;
     188}
     189
     190
     191/**
     192 * Explodes a time spec to the localized timezone.
     193 *
     194 * @returns pTime.
     195 * @param   pTime       Where to store the exploded time.
     196 * @param   pTimeSpec   The time spec to exploded. (UCT)
     197 */
     198RTDECL(PRTTIME) RTTimeLocalExplode(PRTTIME pTime, PCRTTIMESPEC pTimeSpec)
     199{
     200    /*
     201     * FileTimeToLocalFileTime does not do the right thing, so we'll have
     202     * to convert to system time and SystemTimeToTzSpecificLocalTime instead.
     203     */
     204    RTTIMESPEC LocalTime;
     205    SYSTEMTIME SystemTimeIn;
     206    FILETIME FileTime;
     207    if (FileTimeToSystemTime(RTTimeSpecGetNtFileTime(pTimeSpec, &FileTime), &SystemTimeIn))
     208    {
     209        SYSTEMTIME SystemTimeOut;
     210        if (SystemTimeToTzSpecificLocalTime(NULL /* use current TZI */,
     211                                            &SystemTimeIn,
     212                                            &SystemTimeOut))
     213        {
     214            if (SystemTimeToFileTime(&SystemTimeOut, &FileTime))
     215            {
     216                RTTimeSpecSetNtFileTime(&LocalTime, &FileTime);
     217                return RTTimeExplode(pTime, &LocalTime);
     218            }
     219        }
     220    }
     221
     222    /*
     223     * The fallback is to use the current offset.
     224     * (A better fallback would be to use the offset of the same time of the year.)
     225     */
     226    LocalTime = *pTimeSpec;
     227    RTTimeSpecAddNano(&LocalTime, RTTimeLocalDeltaNano());
     228    return RTTimeExplode(pTime, &LocalTime);
     229}
     230
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