Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:35:23

0001 #ifndef DATE_TIME_FILETIME_FUNCTIONS_HPP__
0002 #define DATE_TIME_FILETIME_FUNCTIONS_HPP__
0003 
0004 /* Copyright (c) 2004 CrystalClear Software, Inc.
0005  * Use, modification and distribution is subject to the
0006  * Boost Software License, Version 1.0. (See accompanying
0007  * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
0008  * Author: Jeff Garland, Bart Garst
0009  * $Date$
0010  */
0011 
0012 /*! @file filetime_functions.hpp
0013  * Function(s) for converting between a FILETIME structure and a
0014  * time object. This file is only available on systems that have
0015  * BOOST_HAS_FTIME defined.
0016  */
0017 
0018 #include <boost/date_time/compiler_config.hpp>
0019 
0020 #if defined(BOOST_HAS_FTIME) // skip this file if no FILETIME
0021 
0022 #include <boost/cstdint.hpp>
0023 #include <boost/date_time/time.hpp>
0024 #include <boost/date_time/date_defs.hpp>
0025 
0026 namespace boost {
0027 
0028 namespace date_time {
0029 
0030 //! Create a time object from an initialized FILETIME struct.
0031 /*!
0032  * Create a time object from an initialized FILETIME struct.
0033  * A FILETIME struct holds 100-nanosecond units (0.0000001). When
0034  * built with microsecond resolution the file_time's sub second value
0035  * will be truncated. Nanosecond resolution has no truncation.
0036  *
0037  * \note The function is templated on the FILETIME type, so that
0038  *       it can be used with both native FILETIME and the ad-hoc
0039  *       boost::detail::winapi::FILETIME_ type.
0040  */
0041 template< typename TimeT, typename FileTimeT >
0042 inline
0043 TimeT time_from_ftime(const FileTimeT& ft)
0044 {
0045     typedef typename TimeT::date_type date_type;
0046     typedef typename TimeT::date_duration_type date_duration_type;
0047     typedef typename TimeT::time_duration_type time_duration_type;
0048 
0049     // https://svn.boost.org/trac/boost/ticket/2523
0050     // Since this function can be called with arbitrary times, including ones that
0051     // are before 1970-Jan-01, we'll have to cast the time a bit differently,
0052     // than it is done in the microsec_clock::file_time_to_microseconds function. This allows to
0053     // avoid integer wrapping for dates before 1970-Jan-01.
0054 
0055     // 100-nanos since 1601-Jan-01
0056     uint64_t ft_as_integer = (static_cast< uint64_t >(ft.dwHighDateTime) << 32) | static_cast< uint64_t >(ft.dwLowDateTime);
0057     uint64_t sec = ft_as_integer / 10000000UL;
0058     uint32_t sub_sec = static_cast< uint32_t >(ft_as_integer % 10000000UL) // 100-nanoseconds since the last second
0059 #if !defined(BOOST_DATE_TIME_POSIX_TIME_STD_CONFIG)
0060         / 10U; // microseconds since the last second
0061 #else
0062         * 100U; // nanoseconds since the last second
0063 #endif
0064 
0065     // split sec into usable chunks: days, hours, minutes, & seconds
0066     const uint32_t sec_per_day = 86400; // seconds per day
0067     uint32_t days = static_cast< uint32_t >(sec / sec_per_day);
0068     uint32_t tmp = static_cast< uint32_t >(sec % sec_per_day);
0069     uint32_t hours = tmp / 3600; // sec_per_hour
0070     tmp %= 3600;
0071     uint32_t minutes = tmp / 60; // sec_per_min
0072     tmp %= 60;
0073     uint32_t seconds = tmp; // seconds
0074 
0075     date_duration_type dd(days);
0076     date_type d = date_type(1601, Jan, 01) + dd;
0077     return TimeT(d, time_duration_type(hours, minutes, seconds, sub_sec));
0078 }
0079 
0080 }} // boost::date_time
0081 
0082 #endif // BOOST_HAS_FTIME
0083 
0084 #endif // DATE_TIME_FILETIME_FUNCTIONS_HPP__