summaryrefslogtreecommitdiff
path: root/boost/date_time
diff options
context:
space:
mode:
authorDongHun Kwak <dh0128.kwak@samsung.com>2019-12-05 15:11:01 +0900
committerDongHun Kwak <dh0128.kwak@samsung.com>2019-12-05 15:11:01 +0900
commit3fdc3e5ee96dca5b11d1694975a65200787eab86 (patch)
tree5c1733853892b8397d67706fa453a9bd978d2102 /boost/date_time
parent88e602c57797660ebe0f9e15dbd64c1ff16dead3 (diff)
downloadboost-3fdc3e5ee96dca5b11d1694975a65200787eab86.tar.gz
boost-3fdc3e5ee96dca5b11d1694975a65200787eab86.tar.bz2
boost-3fdc3e5ee96dca5b11d1694975a65200787eab86.zip
Imported Upstream version 1.66.0upstream/1.66.0
Diffstat (limited to 'boost/date_time')
-rw-r--r--boost/date_time/adjust_functors.hpp40
-rw-r--r--boost/date_time/filetime_functions.hpp102
-rw-r--r--boost/date_time/gregorian/greg_day.hpp6
-rw-r--r--boost/date_time/gregorian/greg_month.hpp6
-rw-r--r--boost/date_time/gregorian/greg_weekday.hpp4
-rw-r--r--boost/date_time/gregorian/greg_year.hpp8
-rw-r--r--boost/date_time/microsec_time_clock.hpp41
-rw-r--r--boost/date_time/posix_time/conversion.hpp2
8 files changed, 75 insertions, 134 deletions
diff --git a/boost/date_time/adjust_functors.hpp b/boost/date_time/adjust_functors.hpp
index f6c5a04c4d..7911b7971e 100644
--- a/boost/date_time/adjust_functors.hpp
+++ b/boost/date_time/adjust_functors.hpp
@@ -2,7 +2,7 @@
#define _DATE_TIME_ADJUST_FUNCTORS_HPP___
/* Copyright (c) 2002,2003 CrystalClear Software, Inc.
- * Use, modification and distribution is subject to the
+ * Use, modification and distribution is subject to the
* Boost Software License, Version 1.0. (See accompanying
* file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
* Author: Jeff Garland, Bart Garst
@@ -14,23 +14,23 @@
namespace boost {
namespace date_time {
-
+
//! Functor to iterate a fixed number of days
template<class date_type>
- class day_functor
+ class day_functor
{
public:
typedef typename date_type::duration_type duration_type;
day_functor(int f) : f_(f) {}
- duration_type get_offset(const date_type& d) const
+ duration_type get_offset(const date_type& d) const
{
// why is 'd' a parameter???
// fix compiler warnings
d.year();
return duration_type(f_);
}
- duration_type get_neg_offset(const date_type& d) const
+ duration_type get_neg_offset(const date_type& d) const
{
// fix compiler warnings
d.year();
@@ -43,7 +43,7 @@ namespace date_time {
//! Provides calculation to find next nth month given a date
/*! This adjustment function provides the logic for 'month-based'
- * advancement on a ymd based calendar. The policy it uses
+ * advancement on a ymd based calendar. The policy it uses
* to handle the non existant end of month days is to back
* up to the last day of the month. Also, if the starting
* date is the last day of a month, this functor will attempt
@@ -51,7 +51,7 @@ namespace date_time {
*/
template<class date_type>
- class month_functor
+ class month_functor
{
public:
typedef typename date_type::duration_type duration_type;
@@ -60,7 +60,7 @@ namespace date_time {
typedef typename cal_type::day_type day_type;
month_functor(int f) : f_(f), origDayOfMonth_(0) {}
- duration_type get_offset(const date_type& d) const
+ duration_type get_offset(const date_type& d) const
{
ymd_type ymd(d.year_month_day());
if (origDayOfMonth_ == 0) {
@@ -71,11 +71,9 @@ namespace date_time {
}
}
typedef date_time::wrapping_int2<short,1,12> wrap_int2;
- typedef typename wrap_int2::int_type int_type;
wrap_int2 wi(ymd.month);
//calc the year wrap around, add() returns 0 or 1 if wrapped
- int_type year = wi.add(static_cast<int_type>(f_));
- year = static_cast<int_type>(year + ymd.year); //calculate resulting year
+ const typename ymd_type::year_type year(static_cast<typename ymd_type::year_type::value_type>(ymd.year + wi.add(f_)));
// std::cout << "trace wi: " << wi.as_int() << std::endl;
// std::cout << "trace year: " << year << std::endl;
//find the last day for the new month
@@ -91,7 +89,7 @@ namespace date_time {
return date_type(year, wi.as_int(), dayOfMonth) - d;
}
//! Returns a negative duration_type
- duration_type get_neg_offset(const date_type& d) const
+ duration_type get_neg_offset(const date_type& d) const
{
ymd_type ymd(d.year_month_day());
if (origDayOfMonth_ == 0) {
@@ -102,11 +100,9 @@ namespace date_time {
}
}
typedef date_time::wrapping_int2<short,1,12> wrap_int2;
- typedef typename wrap_int2::int_type int_type;
wrap_int2 wi(ymd.month);
//calc the year wrap around, add() returns 0 or 1 if wrapped
- int_type year = wi.subtract(static_cast<int_type>(f_));
- year = static_cast<int_type>(year + ymd.year); //calculate resulting year
+ const typename ymd_type::year_type year(static_cast<typename ymd_type::year_type::value_type>(ymd.year + wi.subtract(f_)));
//find the last day for the new month
day_type resultingEndOfMonthDay(cal_type::end_of_month_day(year, wi.as_int()));
//original was the end of month -- force to last day of month
@@ -127,20 +123,20 @@ namespace date_time {
//! Functor to iterate a over weeks
template<class date_type>
- class week_functor
+ class week_functor
{
public:
typedef typename date_type::duration_type duration_type;
typedef typename date_type::calendar_type calendar_type;
week_functor(int f) : f_(f) {}
- duration_type get_offset(const date_type& d) const
+ duration_type get_offset(const date_type& d) const
{
// why is 'd' a parameter???
// fix compiler warnings
d.year();
return duration_type(f_*calendar_type::days_in_week());
}
- duration_type get_neg_offset(const date_type& d) const
+ duration_type get_neg_offset(const date_type& d) const
{
// fix compiler warnings
d.year();
@@ -152,17 +148,17 @@ namespace date_time {
//! Functor to iterate by a year adjusting for leap years
template<class date_type>
- class year_functor
+ class year_functor
{
public:
//typedef typename date_type::year_type year_type;
typedef typename date_type::duration_type duration_type;
year_functor(int f) : _mf(f * 12) {}
- duration_type get_offset(const date_type& d) const
+ duration_type get_offset(const date_type& d) const
{
return _mf.get_offset(d);
}
- duration_type get_neg_offset(const date_type& d) const
+ duration_type get_neg_offset(const date_type& d) const
{
return _mf.get_neg_offset(d);
}
@@ -170,7 +166,7 @@ namespace date_time {
month_functor<date_type> _mf;
};
-
+
} }//namespace date_time
diff --git a/boost/date_time/filetime_functions.hpp b/boost/date_time/filetime_functions.hpp
index ca5a1ad933..f5ef7bfb5e 100644
--- a/boost/date_time/filetime_functions.hpp
+++ b/boost/date_time/filetime_functions.hpp
@@ -19,10 +19,6 @@
#if defined(BOOST_HAS_FTIME) // skip this file if no FILETIME
-#if defined(BOOST_USE_WINDOWS_H)
-# include <windows.h>
-#endif
-
#include <boost/cstdint.hpp>
#include <boost/date_time/time.hpp>
#include <boost/date_time/date_defs.hpp>
@@ -31,85 +27,6 @@ namespace boost {
namespace date_time {
-namespace winapi {
-
-#if !defined(BOOST_USE_WINDOWS_H)
-
- extern "C" {
-
- struct FILETIME
- {
- boost::uint32_t dwLowDateTime;
- boost::uint32_t dwHighDateTime;
- };
- struct SYSTEMTIME
- {
- boost::uint16_t wYear;
- boost::uint16_t wMonth;
- boost::uint16_t wDayOfWeek;
- boost::uint16_t wDay;
- boost::uint16_t wHour;
- boost::uint16_t wMinute;
- boost::uint16_t wSecond;
- boost::uint16_t wMilliseconds;
- };
-
- __declspec(dllimport) void __stdcall GetSystemTimeAsFileTime(FILETIME* lpFileTime);
- __declspec(dllimport) int __stdcall FileTimeToLocalFileTime(const FILETIME* lpFileTime, FILETIME* lpLocalFileTime);
- __declspec(dllimport) void __stdcall GetSystemTime(SYSTEMTIME* lpSystemTime);
- __declspec(dllimport) int __stdcall SystemTimeToFileTime(const SYSTEMTIME* lpSystemTime, FILETIME* lpFileTime);
-
- } // extern "C"
-
-#endif // defined(BOOST_USE_WINDOWS_H)
-
- typedef FILETIME file_time;
- typedef SYSTEMTIME system_time;
-
- inline void get_system_time_as_file_time(file_time& ft)
- {
-#if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3205))
- // Some runtime library implementations expect local times as the norm for ctime.
- file_time ft_utc;
- GetSystemTimeAsFileTime(&ft_utc);
- FileTimeToLocalFileTime(&ft_utc, &ft);
-#elif defined(BOOST_HAS_GETSYSTEMTIMEASFILETIME)
- GetSystemTimeAsFileTime(&ft);
-#else
- system_time st;
- GetSystemTime(&st);
- SystemTimeToFileTime(&st, &ft);
-#endif
- }
-
- /*!
- * The function converts file_time into number of microseconds elapsed since 1970-Jan-01
- *
- * \note Only dates after 1970-Jan-01 are supported. Dates before will be wrapped.
- *
- * \note The function is templated on the FILETIME type, so that
- * it can be used with both native FILETIME and the ad-hoc
- * boost::date_time::winapi::file_time type.
- */
- template< typename FileTimeT >
- inline boost::uint64_t file_time_to_microseconds(FileTimeT const& ft)
- {
- /* shift is difference between 1970-Jan-01 & 1601-Jan-01
- * in 100-nanosecond intervals */
- const uint64_t shift = 116444736000000000ULL; // (27111902 << 32) + 3577643008
-
- union {
- FileTimeT as_file_time;
- uint64_t as_integer; // 100-nanos since 1601-Jan-01
- } caster;
- caster.as_file_time = ft;
-
- caster.as_integer -= shift; // filetime is now 100-nanos since 1970-Jan-01
- return (caster.as_integer / 10); // truncate to microseconds
- }
-
-} // namespace winapi
-
//! Create a time object from an initialized FILETIME struct.
/*!
* Create a time object from an initialized FILETIME struct.
@@ -119,7 +36,7 @@ namespace winapi {
*
* \note The function is templated on the FILETIME type, so that
* it can be used with both native FILETIME and the ad-hoc
- * boost::date_time::winapi::file_time type.
+ * boost::detail::winapi::FILETIME_ type.
*/
template< typename TimeT, typename FileTimeT >
inline
@@ -132,20 +49,17 @@ TimeT time_from_ftime(const FileTimeT& ft)
// https://svn.boost.org/trac/boost/ticket/2523
// Since this function can be called with arbitrary times, including ones that
// are before 1970-Jan-01, we'll have to cast the time a bit differently,
- // than it is done in the file_time_to_microseconds function. This allows to
+ // than it is done in the microsec_clock::file_time_to_microseconds function. This allows to
// avoid integer wrapping for dates before 1970-Jan-01.
- union {
- FileTimeT as_file_time;
- uint64_t as_integer; // 100-nanos since 1601-Jan-01
- } caster;
- caster.as_file_time = ft;
- uint64_t sec = caster.as_integer / 10000000UL;
- uint32_t sub_sec = (caster.as_integer % 10000000UL) // 100-nanoseconds since the last second
+ // 100-nanos since 1601-Jan-01
+ uint64_t ft_as_integer = (static_cast< uint64_t >(ft.dwHighDateTime) << 32) | static_cast< uint64_t >(ft.dwLowDateTime);
+ uint64_t sec = ft_as_integer / 10000000UL;
+ uint32_t sub_sec = static_cast< uint32_t >(ft_as_integer % 10000000UL) // 100-nanoseconds since the last second
#if !defined(BOOST_DATE_TIME_POSIX_TIME_STD_CONFIG)
- / 10; // microseconds since the last second
+ / 10U; // microseconds since the last second
#else
- * 100; // nanoseconds since the last second
+ * 100U; // nanoseconds since the last second
#endif
// split sec into usable chunks: days, hours, minutes, & seconds
diff --git a/boost/date_time/gregorian/greg_day.hpp b/boost/date_time/gregorian/greg_day.hpp
index 8cadc6c7e5..014abfbda0 100644
--- a/boost/date_time/gregorian/greg_day.hpp
+++ b/boost/date_time/gregorian/greg_day.hpp
@@ -42,9 +42,9 @@ namespace gregorian {
*/
class BOOST_SYMBOL_VISIBLE greg_day : public greg_day_rep {
public:
- greg_day(unsigned short day_of_month) : greg_day_rep(day_of_month) {}
- unsigned short as_number() const {return value_;}
- operator unsigned short() const {return value_;}
+ greg_day(value_type day_of_month) : greg_day_rep(day_of_month) {}
+ value_type as_number() const {return value_;}
+ operator value_type() const {return value_;}
private:
};
diff --git a/boost/date_time/gregorian/greg_month.hpp b/boost/date_time/gregorian/greg_month.hpp
index d46343353f..be0f93e13b 100644
--- a/boost/date_time/gregorian/greg_month.hpp
+++ b/boost/date_time/gregorian/greg_month.hpp
@@ -61,11 +61,11 @@ namespace gregorian {
greg_month(month_enum theMonth) :
greg_month_rep(static_cast<greg_month_rep::value_type>(theMonth)) {}
//! Construct from a short value
- greg_month(unsigned short theMonth) : greg_month_rep(theMonth) {}
+ greg_month(value_type theMonth) : greg_month_rep(theMonth) {}
//! Convert the value back to a short
- operator unsigned short() const {return value_;}
+ operator value_type() const {return value_;}
//! Returns month as number from 1 to 12
- unsigned short as_number() const {return value_;}
+ value_type as_number() const {return value_;}
month_enum as_enum() const {return static_cast<month_enum>(value_);}
const char* as_short_string() const;
const char* as_long_string() const;
diff --git a/boost/date_time/gregorian/greg_weekday.hpp b/boost/date_time/gregorian/greg_weekday.hpp
index 263ef5df99..815051ede4 100644
--- a/boost/date_time/gregorian/greg_weekday.hpp
+++ b/boost/date_time/gregorian/greg_weekday.hpp
@@ -41,11 +41,11 @@ namespace gregorian {
class BOOST_DATE_TIME_DECL greg_weekday : public greg_weekday_rep {
public:
typedef boost::date_time::weekdays weekday_enum;
- greg_weekday(unsigned short day_of_week_num) :
+ greg_weekday(value_type day_of_week_num) :
greg_weekday_rep(day_of_week_num)
{}
- unsigned short as_number() const {return value_;}
+ value_type as_number() const {return value_;}
const char* as_short_string() const;
const char* as_long_string() const;
#ifndef BOOST_NO_STD_WSTRING
diff --git a/boost/date_time/gregorian/greg_year.hpp b/boost/date_time/gregorian/greg_year.hpp
index ebcb49e206..3245518474 100644
--- a/boost/date_time/gregorian/greg_year.hpp
+++ b/boost/date_time/gregorian/greg_year.hpp
@@ -30,17 +30,17 @@ namespace gregorian {
//! Generated representation for gregorian year
typedef CV::constrained_value<greg_year_policies> greg_year_rep;
- //! Represent a day of the month (range 1900 - 10000)
+ //! Represent a year (range 1400 - 10000)
/*! This small class allows for simple conversion an integer value into
a year for the gregorian calendar. This currently only allows a
- range of 1900 to 10000. Both ends of the range are a bit arbitrary
+ range of 1400 to 10000. Both ends of the range are a bit arbitrary
at the moment, but they are the limits of current testing of the
library. As such they may be increased in the future.
*/
class BOOST_SYMBOL_VISIBLE greg_year : public greg_year_rep {
public:
- greg_year(unsigned short year) : greg_year_rep(year) {}
- operator unsigned short() const {return value_;}
+ greg_year(value_type year) : greg_year_rep(year) {}
+ operator value_type() const {return value_;}
};
diff --git a/boost/date_time/microsec_time_clock.hpp b/boost/date_time/microsec_time_clock.hpp
index 1dd08ffebf..42a918b53a 100644
--- a/boost/date_time/microsec_time_clock.hpp
+++ b/boost/date_time/microsec_time_clock.hpp
@@ -20,7 +20,9 @@
#include <boost/date_time/compiler_config.hpp>
#include <boost/date_time/c_time.hpp>
#include <boost/date_time/time_clock.hpp>
-#include <boost/date_time/filetime_functions.hpp>
+#if defined(BOOST_HAS_FTIME)
+#include <boost/winapi/time.hpp>
+#endif
#ifdef BOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK
@@ -85,10 +87,19 @@ namespace date_time {
std::time_t t = tv.tv_sec;
boost::uint32_t sub_sec = tv.tv_usec;
#elif defined(BOOST_HAS_FTIME)
- winapi::file_time ft;
- winapi::get_system_time_as_file_time(ft);
- uint64_t micros = winapi::file_time_to_microseconds(ft); // it will not wrap, since ft is the current time
- // and cannot be before 1970-Jan-01
+ boost::winapi::FILETIME_ ft;
+ boost::winapi::GetSystemTimeAsFileTime(&ft);
+#if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3205))
+ // Some runtime library implementations expect local times as the norm for ctime functions.
+ {
+ boost::winapi::FILETIME_ local_ft;
+ boost::winapi::FileTimeToLocalFileTime(&ft, &local_ft);
+ ft = local_ft;
+ }
+#endif
+
+ boost::uint64_t micros = file_time_to_microseconds(ft); // it will not wrap, since ft is the current time
+ // and cannot be before 1970-Jan-01
std::time_t t = static_cast<std::time_t>(micros / 1000000UL); // seconds since epoch
// microseconds -- static casts suppress warnings
boost::uint32_t sub_sec = static_cast<boost::uint32_t>(micros % 1000000UL);
@@ -115,6 +126,26 @@ namespace date_time {
return time_type(d,td);
}
+
+#if defined(BOOST_HAS_FTIME)
+ /*!
+ * The function converts file_time into number of microseconds elapsed since 1970-Jan-01
+ *
+ * \note Only dates after 1970-Jan-01 are supported. Dates before will be wrapped.
+ */
+ static boost::uint64_t file_time_to_microseconds(boost::winapi::FILETIME_ const& ft)
+ {
+ // shift is difference between 1970-Jan-01 & 1601-Jan-01
+ // in 100-nanosecond units
+ const boost::uint64_t shift = 116444736000000000ULL; // (27111902 << 32) + 3577643008
+
+ // 100-nanos since 1601-Jan-01
+ boost::uint64_t ft_as_integer = (static_cast< boost::uint64_t >(ft.dwHighDateTime) << 32) | static_cast< boost::uint64_t >(ft.dwLowDateTime);
+
+ ft_as_integer -= shift; // filetime is now 100-nanos since 1970-Jan-01
+ return (ft_as_integer / 10U); // truncate to microseconds
+ }
+#endif
};
diff --git a/boost/date_time/posix_time/conversion.hpp b/boost/date_time/posix_time/conversion.hpp
index 42a9894af7..cdff4b76fd 100644
--- a/boost/date_time/posix_time/conversion.hpp
+++ b/boost/date_time/posix_time/conversion.hpp
@@ -80,7 +80,7 @@ namespace posix_time {
*
* \note The function is templated on the FILETIME type, so that
* it can be used with both native FILETIME and the ad-hoc
- * boost::date_time::winapi::file_time type.
+ * boost::detail::winapi::FILETIME_ type.
*/
template< typename TimeT, typename FileTimeT >
inline