Ticket #1740: date_time.patch

File date_time.patch, 6.8 KB (added by emilm@…, 14 years ago)
  • boost/date_time/filetime_functions.hpp

     
    1717
    1818#include <boost/date_time/compiler_config.hpp>
    1919#if defined(BOOST_HAS_FTIME) // skip this file if no FILETIME
    20 #include <windows.h>
     20
     21#       if defined( BOOST_USE_WINDOWS_H )
     22#               include <windows.h>
     23#       else
     24
     25struct _FILETIME;
     26typedef struct _FILETIME FILETIME;
     27
     28#       endif // !BOOST_USE_WINDOWS_H
     29
    2130#include <boost/cstdint.hpp>
    2231#include <boost/date_time/time.hpp>
    2332
     
    4554    const uint64_t OFFSET = (c1 << 32) + c2;
    4655    const long sec_pr_day = 86400; // seconds per day
    4756
    48     uint64_t filetime = ft.dwHighDateTime;
    49     filetime <<= 32;
    50     filetime += ft.dwLowDateTime;
     57    uint64_t filetime = *reinterpret_cast<const uint64_t*>(&ft);
     58    //filetime <<= 32;
     59    //filetime += ft.dwLowDateTime;
    5160    filetime -= OFFSET; // filetime is now 100-nanos since 1970-Jan-01
    5261
    5362    uint64_t sec = filetime / 10000000;
  • boost/date_time/microsec_time_clock.hpp

     
    2121#include "boost/shared_ptr.hpp"
    2222
    2323#ifdef BOOST_HAS_FTIME
    24 #include <windows.h>
    25 #endif
     24#       if defined( BOOST_USE_WINDOWS_H )
     25#               include <windows.h>
     26#       else
     27
     28struct _FILETIME;
     29struct _SYSTEMTIME;
     30
     31typedef struct _FILETIME FILETIME;
     32
     33typedef struct _FILETIME *PFILETIME;
     34
     35typedef struct _FILETIME *LPFILETIME;
     36
     37typedef struct _SYSTEMTIME SYSTEMTIME;
     38
     39typedef struct _SYSTEMTIME *PSYSTEMTIME;
     40
     41typedef struct _SYSTEMTIME *LPSYSTEMTIME;
     42
     43extern "C" __declspec(dllimport) void __stdcall GetSystemTimeAsFileTime(
     44        LPFILETIME lpSystemTimeAsFileTime
     45        );
     46
     47extern "C" __declspec(dllimport) int __stdcall FileTimeToLocalFileTime(
     48        const FILETIME *lpFileTime,
     49        LPFILETIME lpLocalFileTime
     50        );
     51
     52extern "C" __declspec(dllimport) void __stdcall GetSystemTime(
     53        LPSYSTEMTIME lpSystemTime
     54        );
     55
     56extern "C" __declspec(dllimport) int __stdcall SystemTimeToFileTime(
     57        const SYSTEMTIME *lpSystemTime,
     58        LPFILETIME lpFileTime
     59        );
     60#       endif // !BOOST_USE_WINDOWS_H
     61#endif //BOOST_HAS_FTIME
    2662
    2763#ifdef BOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK
    2864
     
    66102  private:
    67103    // we want this enum available for both platforms yet still private
    68104    enum TZ_FOR_CREATE { LOCAL, GMT };
    69    
     105
    70106  public:
    71107
    72108#ifdef BOOST_HAS_GETTIMEOFDAY
     
    82118    }
    83119
    84120  private:
    85     static time_type create_time(TZ_FOR_CREATE tz) {
     121          static time_type create_time(TZ_FOR_CREATE tz) {
    86122      timeval tv;
    87123      gettimeofday(&tv, 0); //gettimeofday does not support TZ adjust on Linux.
    88124      std::time_t t = tv.tv_sec;
     
    114150#ifdef BOOST_HAS_FTIME
    115151    //! Return the local time based on computer clock settings
    116152    static time_type local_time() {
    117       FILETIME ft;
     153      FAKE_FILETIME ft;
    118154      #if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3205))
    119155      // Some runtime library implementations expect local times as the norm for ctime.
    120       FILETIME ft_utc;
    121       GetSystemTimeAsFileTime(&ft_utc);
    122       FileTimeToLocalFileTime(&ft_utc,&ft);
     156      FAKE_FILETIME ft_utc;
     157      GetSystemTimeAsFileTime( reinterpret_cast<FILETIME*>(&ft_utc) );
     158      FileTimeToLocalFileTime( reinterpret_cast<FILETIME*>(&ft_utc), reinterpret_cast<FILETIME*>(&ft) );
    123159      #elif defined(BOOST_NO_GETSYSTEMTIMEASFILETIME)
    124       SYSTEMTIME st;
     160      FAKE_SYSTEMTIME st;
    125161      GetSystemTime( &st );
    126       SystemTimeToFileTime( &st, &ft );
     162      SystemTimeToFileTime( reinterpret_cast<SYSTEMTIME*>(&st), reinterpret_cast<FILETIME*>(&ft) );
    127163      #else
    128       GetSystemTimeAsFileTime(&ft);
     164      GetSystemTimeAsFileTime( reinterpret_cast<FILETIME*>(&ft) );
    129165      #endif
    130       return create_time(ft, LOCAL);
     166      return create_time( reinterpret_cast<FILETIME&>(ft), LOCAL);
    131167    }
    132168   
    133169    //! Return the UTC time based on computer settings
    134170    static time_type universal_time() {
    135       FILETIME ft;
     171      FAKE_FILETIME ft;
    136172      #if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3205))
    137173      // Some runtime library implementations expect local times as the norm for ctime.
    138       FILETIME ft_utc;
    139       GetSystemTimeAsFileTime(&ft_utc);
    140       FileTimeToLocalFileTime(&ft_utc,&ft);
     174      FAKE_FILETIME ft_utc;
     175      GetSystemTimeAsFileTime( reinterpret_cast<FILETIME*>(&ft_utc) );
     176      FileTimeToLocalFileTime( reinterpret_cast<FILETIME*>(&ft_utc), reinterpret_cast<FILETIME*>(&ft) );
    141177      #elif defined(BOOST_NO_GETSYSTEMTIMEASFILETIME)
    142       SYSTEMTIME st;
    143       GetSystemTime( &st );
    144       SystemTimeToFileTime( &st, &ft );
     178      FAKE_SYSTEMTIME st;
     179      GetSystemTime( reinterpret_cast<SYSTEMTIME*>(&st) );
     180      SystemTimeToFileTime( reinterpret_cast<SYSTEMTIME*>(&st), reinterpret_cast<FILETIME*>(&ft) );
    145181      #else
    146       GetSystemTimeAsFileTime(&ft);
     182      GetSystemTimeAsFileTime( reinterpret_cast<FILETIME*>(&ft) );
    147183      #endif
    148       return create_time(ft, GMT);
     184      return create_time( reinterpret_cast<FILETIME&>(ft), GMT);
    149185    }
    150186
    151187  private:
    152     static time_type create_time(FILETIME& ft, TZ_FOR_CREATE tz) {
     188#if defined( BOOST_USE_WINDOWS_H )
     189        typedef FILETIME FAKE_FILETIME;
     190        typedef SYSTEMTIME FAKE_SYSTEMTIME;
     191#else
     192          struct FAKE_FILETIME {
     193                  unsigned long dwLowDateTime;
     194                  unsigned long dwHighDateTime;
     195          };
     196
     197          struct FAKE_SYSTEMTIME {
     198                  unsigned short wYear;
     199                  unsigned short wMonth;
     200                  unsigned short wDayOfWeek;
     201                  unsigned short wDay;
     202                  unsigned short wHour;
     203                  unsigned short wMinute;
     204                  unsigned short wSecond;
     205                  unsigned short wMilliseconds;
     206          };
     207#endif
     208
     209         static time_type create_time(FILETIME& ft, TZ_FOR_CREATE tz) {
    153210      // offset is difference (in 100-nanoseconds) from
    154211      // 1970-Jan-01 to 1601-Jan-01
    155212      boost::uint64_t c1 = 27111902;
    156213      boost::uint64_t c2 = 3577643008UL; // 'UL' removes compiler warnings
    157214      const boost::uint64_t OFFSET = (c1 << 32) + c2;
    158215
    159       boost::uint64_t filetime = ft.dwHighDateTime;
    160       filetime = filetime << 32;
    161       filetime += ft.dwLowDateTime;
     216      boost::uint64_t filetime = *reinterpret_cast<boost::uint64_t*>(&ft);
     217      //filetime = filetime << 32;
     218      //filetime += ft.dwLowDateTime;
    162219      filetime -= OFFSET;
    163220      // filetime now holds 100-nanoseconds since 1970-Jan-01
    164221
  • libs/date_time/test/posix_time/testmicrosec_time_clock.cpp

     
    99#include "boost/date_time/microsec_time_clock.hpp"
    1010#include "boost/date_time/testfrmwk.hpp"
    1111
     12//For SYSTEMTIME and GetSystemTime definitions
     13#if defined(BOOST_HAS_FTIME)
     14#   include <windows.h>   
     15#endif
    1216
    1317int
    1418main()