Changeset 2612 in vbox for trunk/src/VBox
- Timestamp:
- May 14, 2007 7:19:07 AM (18 years ago)
- Location:
- trunk/src/VBox/Runtime
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/Makefile.kmk
r2604 r2612 173 173 md5.cpp \ 174 174 path.cpp \ 175 175 req.cpp \ 176 176 r3/alloc-ef.cpp \ 177 177 r3/alloc.cpp \ … … 263 263 generic/RTFileMove-generic.cpp \ 264 264 generic/RTLogWriteDebugger-generic.cpp \ 265 generic/RTTimeLocalNow-generic.cpp \ 265 266 generic/RTTimerCreate-generic.cpp \ 266 267 r3/posix/RTTimeNow-posix.cpp \ … … 280 281 r3/posix/thread-posix.cpp \ 281 282 r3/linux/time-linux.cpp \ 283 r3/posix/timelocal-posix.cpp \ 282 284 r3/posix/timer-posix.cpp \ 283 285 generic/utf16locale-generic.cpp \ … … 296 298 generic/RTFileMove-generic.cpp \ 297 299 generic/RTLogWriteDebugger-generic.cpp \ 300 generic/RTTimeLocalNow-generic.cpp \ 298 301 generic/RTTimerCreate-generic.cpp \ 299 302 os2/RTErrConvertFromOS2.cpp \ … … 316 319 generic/sched-generic.cpp \ 317 320 r3/os2/time-os2.cpp \ 321 r3/posix/timelocal-posix.cpp \ 318 322 generic/timer-generic.cpp \ 319 323 r3/posix/RTTimeNow-posix.cpp \ … … 331 335 generic/RTFileMove-generic.cpp \ 332 336 generic/RTLogWriteDebugger-generic.cpp \ 337 generic/RTTimeLocalNow-generic.cpp \ 333 338 generic/RTTimerCreate-generic.cpp \ 334 339 generic/pathhost-generic.cpp \ … … 350 355 r3/posix/system-posix.cpp \ 351 356 r3/posix/thread-posix.cpp \ 357 r3/darwin/time-darwin.cpp \ 358 r3/posix/timelocal-posix.cpp \ 352 359 r3/posix/utf8-posix.cpp \ 353 r3/darwin/time-darwin.cpp \354 360 timesup.cpp \ 355 361 … … 378 384 r3/posix/thread-posix.cpp \ 379 385 r3/posix/time-posix.cpp \ 386 r3/posix/timelocal-posix.cpp \ 380 387 r3/posix/timer-posix.cpp \ 381 388 r3/posix/RTTimeNow-posix.cpp \ … … 399 406 generic/RTFileMove-generic.cpp \ 400 407 generic/RTLogWriteDebugger-generic.cpp \ 408 generic/RTTimeLocalNow-generic.cpp \ 401 409 generic/fs-stubs-generic.cpp \ 402 410 generic/pathhost-generic.cpp \ … … 422 430 r3/posix/rand-posix.cpp \ 423 431 r3/posix/time-posix.cpp \ 432 r3/posix/timelocal-posix.cpp \ 424 433 r3/posix/RTTimeNow-posix.cpp \ 425 434 timesup.cpp -
trunk/src/VBox/Runtime/r3/posix/RTTimeNow-posix.cpp
r1204 r2612 38 38 * @param pTime Where to store the time. 39 39 */ 40 RT R3DECL(PRTTIMESPEC) RTTimeNow(PRTTIMESPEC pTime)40 RTDECL(PRTTIMESPEC) RTTimeNow(PRTTIMESPEC pTime) 41 41 { 42 42 struct timeval tv; -
trunk/src/VBox/Runtime/r3/win32/time-win32.cpp
r1 r2612 42 42 #include <iprt/time.h> 43 43 #include <iprt/asm.h> 44 #include <iprt/assert.h> 44 45 #include "internal/time.h" 45 46 … … 137 138 * @param pTime Where to store the time. 138 139 */ 139 RTR3DECL(PRTTIMESPEC) RTTimeNow(PRTTIMESPEC pTime) 140 { 141 uint64_t u64; /* manual say larger integer, should be safe to assume it's the same. */ 140 RTDECL(PRTTIMESPEC) RTTimeNow(PRTTIMESPEC pTime) 141 { 142 uint64_t u64; 143 AssertCompile(sizeof(u64) == sizeof(FILETIME)); 142 144 GetSystemTimeAsFileTime((LPFILETIME)&u64); 143 145 return RTTimeSpecSetNtTime(pTime, u64); 144 146 } 145 147 148 149 /** 150 * Gets the current local system time. 151 * 152 * @returns pTime. 153 * @param pTime Where to store the local time. 154 */ 155 RTDECL(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 */ 177 RTDECL(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 */ 198 RTDECL(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.