1 //
2 //  For conditions of distribution and use, see copyright notice
3 //  in Flashpix.h
4 //
5 //  Copyright (c) 1999 Digital Imaging Group, Inc.
6 //
7 #include "../../h/storage.h"
8 #include "time.hxx"
9 #include <limits.h>
10 #include <assert.h>
11 
12 // Number of seconds difference betwen FILETIME (since 1601 00:00:00)
13 // and time_t (since 1970 00:00:00)
14 //
15 // This should be a constant difference between the 2 time formats
16 //
17 const LONGLONG ci64DiffFTtoTT=11644473600;
18 
FileTimeToTimeT(const FILETIME * pft,time_t * ptt)19 STDAPI_(void) FileTimeToTimeT(const FILETIME *pft, time_t *ptt)
20 {
21     ULONGLONG llFT = pft->dwHighDateTime;
22     llFT = (llFT << 32) | (pft->dwLowDateTime);
23     // convert to seconds
24     // (note that all fractions of seconds will be lost)
25     llFT = llFT/10000000;
26     llFT -= ci64DiffFTtoTT;         // convert to time_t
27     assert(llFT <= ULONG_MAX);
28     *ptt = (time_t) llFT;
29 }
30 
TimeTToFileTime(const time_t * ptt,FILETIME * pft)31 STDAPI_(void) TimeTToFileTime(const time_t *ptt, FILETIME *pft)
32 {
33     ULONGLONG llFT = *ptt;
34     llFT += ci64DiffFTtoTT;         // convert to file time
35     // convert to nano-seconds
36     for (int i=0; i<7; i++)         // mulitply by 10 7 times
37     {
38         llFT = llFT << 1;           // llFT = 2x
39         llFT += (llFT << 2);        // llFT = 4*2x + 2x = 10x
40     }
41     pft->dwLowDateTime  = (DWORD) (llFT & 0xffffffff);
42     pft->dwHighDateTime = (DWORD) (llFT >> 32);
43 }
44 
45 #pragma warning(disable:4514)
46 // disable warning about unreferenced inline functions
47