整理
This commit is contained in:
100
include/boost/date_time/posix_time/conversion.hpp
Normal file
100
include/boost/date_time/posix_time/conversion.hpp
Normal file
@@ -0,0 +1,100 @@
|
||||
#ifndef POSIX_TIME_CONVERSION_HPP___
|
||||
#define POSIX_TIME_CONVERSION_HPP___
|
||||
|
||||
/* Copyright (c) 2002-2005 CrystalClear Software, Inc.
|
||||
* 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
|
||||
* $Date$
|
||||
*/
|
||||
|
||||
#include <cstring>
|
||||
#include <boost/cstdint.hpp>
|
||||
#include <boost/date_time/posix_time/ptime.hpp>
|
||||
#include <boost/date_time/posix_time/posix_time_duration.hpp>
|
||||
#include <boost/date_time/filetime_functions.hpp>
|
||||
#include <boost/date_time/c_time.hpp>
|
||||
#include <boost/date_time/time_resolution_traits.hpp> // absolute_value
|
||||
#include <boost/date_time/gregorian/conversion.hpp>
|
||||
|
||||
namespace boost {
|
||||
|
||||
namespace posix_time {
|
||||
|
||||
//! Function that converts a time_t into a ptime.
|
||||
inline
|
||||
ptime from_time_t(std::time_t t)
|
||||
{
|
||||
return ptime(gregorian::date(1970,1,1)) + seconds(t);
|
||||
}
|
||||
|
||||
//! Function that converts a ptime into a time_t
|
||||
inline
|
||||
std::time_t to_time_t(ptime pt)
|
||||
{
|
||||
return (pt - ptime(gregorian::date(1970,1,1))).total_seconds();
|
||||
}
|
||||
|
||||
//! Convert a time to a tm structure truncating any fractional seconds
|
||||
inline
|
||||
std::tm to_tm(const boost::posix_time::ptime& t) {
|
||||
std::tm timetm = boost::gregorian::to_tm(t.date());
|
||||
boost::posix_time::time_duration td = t.time_of_day();
|
||||
timetm.tm_hour = static_cast<int>(td.hours());
|
||||
timetm.tm_min = static_cast<int>(td.minutes());
|
||||
timetm.tm_sec = static_cast<int>(td.seconds());
|
||||
timetm.tm_isdst = -1; // -1 used when dst info is unknown
|
||||
return timetm;
|
||||
}
|
||||
//! Convert a time_duration to a tm structure truncating any fractional seconds and zeroing fields for date components
|
||||
inline
|
||||
std::tm to_tm(const boost::posix_time::time_duration& td) {
|
||||
std::tm timetm;
|
||||
std::memset(&timetm, 0, sizeof(timetm));
|
||||
timetm.tm_hour = static_cast<int>(date_time::absolute_value(td.hours()));
|
||||
timetm.tm_min = static_cast<int>(date_time::absolute_value(td.minutes()));
|
||||
timetm.tm_sec = static_cast<int>(date_time::absolute_value(td.seconds()));
|
||||
timetm.tm_isdst = -1; // -1 used when dst info is unknown
|
||||
return timetm;
|
||||
}
|
||||
|
||||
//! Convert a tm struct to a ptime ignoring is_dst flag
|
||||
inline
|
||||
ptime ptime_from_tm(const std::tm& timetm) {
|
||||
boost::gregorian::date d = boost::gregorian::date_from_tm(timetm);
|
||||
return ptime(d, time_duration(timetm.tm_hour, timetm.tm_min, timetm.tm_sec));
|
||||
}
|
||||
|
||||
|
||||
#if defined(BOOST_HAS_FTIME)
|
||||
|
||||
//! Function to create a time object from an initialized FILETIME struct.
|
||||
/*! Function to create a time object from an initialized FILETIME struct.
|
||||
* A FILETIME struct holds 100-nanosecond units (0.0000001). When
|
||||
* built with microsecond resolution the FILETIME's sub second value
|
||||
* will be truncated. Nanosecond resolution has no truncation.
|
||||
*
|
||||
* \note FILETIME is part of the Win32 API, so it is not portable to non-windows
|
||||
* platforms.
|
||||
*
|
||||
* \note The function is templated on the FILETIME type, so that
|
||||
* it can be used with both native FILETIME and the ad-hoc
|
||||
* boost::detail::winapi::FILETIME_ type.
|
||||
*/
|
||||
template< typename TimeT, typename FileTimeT >
|
||||
inline
|
||||
TimeT from_ftime(const FileTimeT& ft)
|
||||
{
|
||||
return boost::date_time::time_from_ftime<TimeT>(ft);
|
||||
}
|
||||
|
||||
#endif // BOOST_HAS_FTIME
|
||||
|
||||
} } //namespace boost::posix_time
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
114
include/boost/date_time/posix_time/date_duration_operators.hpp
Normal file
114
include/boost/date_time/posix_time/date_duration_operators.hpp
Normal file
@@ -0,0 +1,114 @@
|
||||
#ifndef DATE_DURATION_OPERATORS_HPP___
|
||||
#define DATE_DURATION_OPERATORS_HPP___
|
||||
|
||||
/* Copyright (c) 2004 CrystalClear Software, Inc.
|
||||
* 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
|
||||
* $Date$
|
||||
*/
|
||||
|
||||
#include "boost/date_time/gregorian/greg_duration_types.hpp"
|
||||
#include "boost/date_time/posix_time/ptime.hpp"
|
||||
|
||||
namespace boost {
|
||||
namespace posix_time {
|
||||
|
||||
/*!@file date_duration_operators.hpp Operators for ptime and
|
||||
* optional gregorian types. Operators use snap-to-end-of-month behavior.
|
||||
* Further details on this behavior can be found in reference for
|
||||
* date_time/date_duration_types.hpp and documentation for
|
||||
* month and year iterators.
|
||||
*/
|
||||
|
||||
|
||||
/*! Adds a months object and a ptime. Result will be same
|
||||
* day-of-month as ptime unless original day was the last day of month.
|
||||
* see date_time::months_duration for more details */
|
||||
inline BOOST_CXX14_CONSTEXPR
|
||||
ptime
|
||||
operator+(const ptime& t, const boost::gregorian::months& m)
|
||||
{
|
||||
return t + m.get_offset(t.date());
|
||||
}
|
||||
|
||||
/*! Adds a months object to a ptime. Result will be same
|
||||
* day-of-month as ptime unless original day was the last day of month.
|
||||
* see date_time::months_duration for more details */
|
||||
inline BOOST_CXX14_CONSTEXPR
|
||||
ptime
|
||||
operator+=(ptime& t, const boost::gregorian::months& m)
|
||||
{
|
||||
// get_neg_offset returns a negative duration, so we add
|
||||
return t += m.get_offset(t.date());
|
||||
}
|
||||
|
||||
/*! Subtracts a months object and a ptime. Result will be same
|
||||
* day-of-month as ptime unless original day was the last day of month.
|
||||
* see date_time::months_duration for more details */
|
||||
inline BOOST_CXX14_CONSTEXPR
|
||||
ptime
|
||||
operator-(const ptime& t, const boost::gregorian::months& m)
|
||||
{
|
||||
// get_neg_offset returns a negative duration, so we add
|
||||
return t + m.get_neg_offset(t.date());
|
||||
}
|
||||
|
||||
/*! Subtracts a months object from a ptime. Result will be same
|
||||
* day-of-month as ptime unless original day was the last day of month.
|
||||
* see date_time::months_duration for more details */
|
||||
inline BOOST_CXX14_CONSTEXPR
|
||||
ptime
|
||||
operator-=(ptime& t, const boost::gregorian::months& m)
|
||||
{
|
||||
return t += m.get_neg_offset(t.date());
|
||||
}
|
||||
|
||||
// ptime & years
|
||||
|
||||
/*! Adds a years object and a ptime. Result will be same
|
||||
* month and day-of-month as ptime unless original day was the
|
||||
* last day of month. see date_time::years_duration for more details */
|
||||
inline BOOST_CXX14_CONSTEXPR
|
||||
ptime
|
||||
operator+(const ptime& t, const boost::gregorian::years& y)
|
||||
{
|
||||
return t + y.get_offset(t.date());
|
||||
}
|
||||
|
||||
/*! Adds a years object to a ptime. Result will be same
|
||||
* month and day-of-month as ptime unless original day was the
|
||||
* last day of month. see date_time::years_duration for more details */
|
||||
inline BOOST_CXX14_CONSTEXPR
|
||||
ptime
|
||||
operator+=(ptime& t, const boost::gregorian::years& y)
|
||||
{
|
||||
return t += y.get_offset(t.date());
|
||||
}
|
||||
|
||||
/*! Subtracts a years object and a ptime. Result will be same
|
||||
* month and day-of-month as ptime unless original day was the
|
||||
* last day of month. see date_time::years_duration for more details */
|
||||
inline BOOST_CXX14_CONSTEXPR
|
||||
ptime
|
||||
operator-(const ptime& t, const boost::gregorian::years& y)
|
||||
{
|
||||
// get_neg_offset returns a negative duration, so we add
|
||||
return t + y.get_neg_offset(t.date());
|
||||
}
|
||||
|
||||
/*! Subtracts a years object from a ptime. Result will be same
|
||||
* month and day-of-month as ptime unless original day was the
|
||||
* last day of month. see date_time::years_duration for more details */
|
||||
inline BOOST_CXX14_CONSTEXPR
|
||||
ptime
|
||||
operator-=(ptime& t, const boost::gregorian::years& y)
|
||||
{
|
||||
// get_neg_offset returns a negative duration, so we add
|
||||
return t += y.get_neg_offset(t.date());
|
||||
}
|
||||
|
||||
}} // namespaces
|
||||
|
||||
#endif // DATE_DURATION_OPERATORS_HPP___
|
||||
39
include/boost/date_time/posix_time/posix_time.hpp
Normal file
39
include/boost/date_time/posix_time/posix_time.hpp
Normal file
@@ -0,0 +1,39 @@
|
||||
#ifndef POSIX_TIME_HPP___
|
||||
#define POSIX_TIME_HPP___
|
||||
|
||||
/* Copyright (c) 2002-2005 CrystalClear Software, Inc.
|
||||
* 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
|
||||
* $Date$
|
||||
*/
|
||||
/*!@file posix_time.hpp Global header file to get all of posix time types
|
||||
*/
|
||||
|
||||
#include "boost/date_time/compiler_config.hpp"
|
||||
#include "boost/date_time/posix_time/ptime.hpp"
|
||||
#if defined(BOOST_DATE_TIME_OPTIONAL_GREGORIAN_TYPES)
|
||||
#include "boost/date_time/posix_time/date_duration_operators.hpp"
|
||||
#endif
|
||||
|
||||
// output functions
|
||||
#if defined(BOOST_DATE_TIME_INCLUDE_LIMITED_HEADERS)
|
||||
#include "boost/date_time/posix_time/time_formatters_limited.hpp"
|
||||
#else
|
||||
#include "boost/date_time/posix_time/time_formatters.hpp"
|
||||
#endif // BOOST_DATE_TIME_INCLUDE_LIMITED_HEADERS
|
||||
|
||||
// streaming operators
|
||||
#if defined(USE_DATE_TIME_PRE_1_33_FACET_IO)
|
||||
#include "boost/date_time/posix_time/posix_time_legacy_io.hpp"
|
||||
#else
|
||||
#include "boost/date_time/posix_time/posix_time_io.hpp"
|
||||
#endif // USE_DATE_TIME_PRE_1_33_FACET_IO
|
||||
|
||||
#include "boost/date_time/posix_time/time_parsers.hpp"
|
||||
#include "boost/date_time/posix_time/conversion.hpp"
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
165
include/boost/date_time/posix_time/posix_time_config.hpp
Normal file
165
include/boost/date_time/posix_time/posix_time_config.hpp
Normal file
@@ -0,0 +1,165 @@
|
||||
#ifndef POSIX_TIME_CONFIG_HPP___
|
||||
#define POSIX_TIME_CONFIG_HPP___
|
||||
|
||||
/* Copyright (c) 2002,2003,2005,2020 CrystalClear Software, Inc.
|
||||
* 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
|
||||
* $Date$
|
||||
*/
|
||||
|
||||
#include <cstdlib> //for MCW 7.2 std::abs(long long)
|
||||
#include <boost/limits.hpp>
|
||||
#include <boost/cstdint.hpp>
|
||||
#include <boost/config/no_tr1/cmath.hpp>
|
||||
#include <boost/date_time/time_duration.hpp>
|
||||
#include <boost/date_time/time_resolution_traits.hpp>
|
||||
#include <boost/date_time/gregorian/gregorian_types.hpp>
|
||||
#include <boost/date_time/wrapping_int.hpp>
|
||||
#include <boost/date_time/compiler_config.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace posix_time {
|
||||
|
||||
|
||||
#ifdef BOOST_DATE_TIME_POSIX_TIME_STD_CONFIG
|
||||
// set up conditional test compilations
|
||||
#define BOOST_DATE_TIME_HAS_NANOSECONDS
|
||||
typedef date_time::time_resolution_traits<boost::date_time::time_resolution_traits_adapted64_impl, boost::date_time::nano,
|
||||
1000000000, 9 > time_res_traits;
|
||||
#else
|
||||
// set up conditional test compilations
|
||||
#undef BOOST_DATE_TIME_HAS_NANOSECONDS
|
||||
typedef date_time::time_resolution_traits<
|
||||
boost::date_time::time_resolution_traits_adapted64_impl, boost::date_time::micro,
|
||||
1000000, 6 > time_res_traits;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
//! Base time duration type
|
||||
/*! \ingroup time_basics
|
||||
*/
|
||||
class BOOST_SYMBOL_VISIBLE time_duration :
|
||||
public date_time::time_duration<time_duration, time_res_traits>
|
||||
{
|
||||
public:
|
||||
typedef time_res_traits rep_type;
|
||||
typedef time_res_traits::day_type day_type;
|
||||
typedef time_res_traits::hour_type hour_type;
|
||||
typedef time_res_traits::min_type min_type;
|
||||
typedef time_res_traits::sec_type sec_type;
|
||||
typedef time_res_traits::fractional_seconds_type fractional_seconds_type;
|
||||
typedef time_res_traits::tick_type tick_type;
|
||||
typedef time_res_traits::impl_type impl_type;
|
||||
BOOST_CXX14_CONSTEXPR time_duration(hour_type hour,
|
||||
min_type min,
|
||||
sec_type sec,
|
||||
fractional_seconds_type fs=0) :
|
||||
date_time::time_duration<time_duration, time_res_traits>(hour,min,sec,fs)
|
||||
{}
|
||||
BOOST_CXX14_CONSTEXPR time_duration() :
|
||||
date_time::time_duration<time_duration, time_res_traits>(0,0,0)
|
||||
{}
|
||||
//! Construct from special_values
|
||||
BOOST_CXX14_CONSTEXPR time_duration(boost::date_time::special_values sv) :
|
||||
date_time::time_duration<time_duration, time_res_traits>(sv)
|
||||
{}
|
||||
//Give duration access to ticks constructor -- hide from users
|
||||
friend class date_time::time_duration<time_duration, time_res_traits>;
|
||||
protected:
|
||||
BOOST_CXX14_CONSTEXPR explicit time_duration(impl_type tick_count) :
|
||||
date_time::time_duration<time_duration, time_res_traits>(tick_count)
|
||||
{}
|
||||
};
|
||||
|
||||
#ifdef BOOST_DATE_TIME_POSIX_TIME_STD_CONFIG
|
||||
|
||||
//! Simple implementation for the time rep
|
||||
struct simple_time_rep
|
||||
{
|
||||
typedef gregorian::date date_type;
|
||||
typedef time_duration time_duration_type;
|
||||
BOOST_CXX14_CONSTEXPR simple_time_rep(date_type d, time_duration_type tod) :
|
||||
day(d),
|
||||
time_of_day(tod)
|
||||
{
|
||||
// make sure we have sane values for date & time
|
||||
if(!day.is_special() && !time_of_day.is_special()){
|
||||
if(time_of_day >= time_duration_type(24,0,0)) {
|
||||
while(time_of_day >= time_duration_type(24,0,0)) {
|
||||
day += date_type::duration_type(1);
|
||||
time_of_day -= time_duration_type(24,0,0);
|
||||
}
|
||||
}
|
||||
else if(time_of_day.is_negative()) {
|
||||
while(time_of_day.is_negative()) {
|
||||
day -= date_type::duration_type(1);
|
||||
time_of_day += time_duration_type(24,0,0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
date_type day;
|
||||
time_duration_type time_of_day;
|
||||
BOOST_CXX14_CONSTEXPR bool is_special()const
|
||||
{
|
||||
return(is_pos_infinity() || is_neg_infinity() || is_not_a_date_time());
|
||||
}
|
||||
BOOST_CXX14_CONSTEXPR bool is_pos_infinity()const
|
||||
{
|
||||
return(day.is_pos_infinity() || time_of_day.is_pos_infinity());
|
||||
}
|
||||
BOOST_CXX14_CONSTEXPR bool is_neg_infinity()const
|
||||
{
|
||||
return(day.is_neg_infinity() || time_of_day.is_neg_infinity());
|
||||
}
|
||||
BOOST_CXX14_CONSTEXPR bool is_not_a_date_time()const
|
||||
{
|
||||
return(day.is_not_a_date() || time_of_day.is_not_a_date_time());
|
||||
}
|
||||
};
|
||||
|
||||
class BOOST_SYMBOL_VISIBLE posix_time_system_config
|
||||
{
|
||||
public:
|
||||
typedef simple_time_rep time_rep_type;
|
||||
typedef gregorian::date date_type;
|
||||
typedef gregorian::date_duration date_duration_type;
|
||||
typedef time_duration time_duration_type;
|
||||
typedef time_res_traits::tick_type int_type;
|
||||
typedef time_res_traits resolution_traits;
|
||||
#if (defined(BOOST_DATE_TIME_NO_MEMBER_INIT)) //help bad compilers
|
||||
#else
|
||||
BOOST_STATIC_CONSTANT(boost::int64_t, tick_per_second = 1000000000);
|
||||
#endif
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
class millisec_posix_time_system_config
|
||||
{
|
||||
public:
|
||||
typedef boost::int64_t time_rep_type;
|
||||
//typedef time_res_traits::tick_type time_rep_type;
|
||||
typedef gregorian::date date_type;
|
||||
typedef gregorian::date_duration date_duration_type;
|
||||
typedef time_duration time_duration_type;
|
||||
typedef time_res_traits::tick_type int_type;
|
||||
typedef time_res_traits::impl_type impl_type;
|
||||
typedef time_res_traits resolution_traits;
|
||||
#if (defined(BOOST_DATE_TIME_NO_MEMBER_INIT)) //help bad compilers
|
||||
#else
|
||||
BOOST_STATIC_CONSTANT(boost::int64_t, tick_per_second = 1000000);
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
} }//namespace posix_time
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
91
include/boost/date_time/posix_time/posix_time_duration.hpp
Normal file
91
include/boost/date_time/posix_time/posix_time_duration.hpp
Normal file
@@ -0,0 +1,91 @@
|
||||
#ifndef POSIX_TIME_DURATION_HPP___
|
||||
#define POSIX_TIME_DURATION_HPP___
|
||||
|
||||
/* Copyright (c) 2002,2003, 2020 CrystalClear Software, Inc.
|
||||
* 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
|
||||
* $Date$
|
||||
*/
|
||||
|
||||
#include <boost/core/enable_if.hpp>
|
||||
#include <boost/date_time/compiler_config.hpp>
|
||||
#include <boost/date_time/posix_time/posix_time_config.hpp>
|
||||
#include <boost/numeric/conversion/cast.hpp>
|
||||
#include <boost/type_traits/is_integral.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace posix_time {
|
||||
|
||||
//! Allows expression of durations as an hour count
|
||||
//! The argument must be an integral type
|
||||
/*! \ingroup time_basics
|
||||
*/
|
||||
class BOOST_SYMBOL_VISIBLE hours : public time_duration
|
||||
{
|
||||
public:
|
||||
template <typename T>
|
||||
BOOST_CXX14_CONSTEXPR explicit hours(T const& h,
|
||||
typename boost::enable_if<boost::is_integral<T>, void>::type* = BOOST_DATE_TIME_NULLPTR) :
|
||||
time_duration(numeric_cast<hour_type>(h), 0, 0)
|
||||
{}
|
||||
};
|
||||
|
||||
//! Allows expression of durations as a minute count
|
||||
//! The argument must be an integral type
|
||||
/*! \ingroup time_basics
|
||||
*/
|
||||
class BOOST_SYMBOL_VISIBLE minutes : public time_duration
|
||||
{
|
||||
public:
|
||||
template <typename T>
|
||||
BOOST_CXX14_CONSTEXPR explicit minutes(T const& m,
|
||||
typename boost::enable_if<boost::is_integral<T>, void>::type* = BOOST_DATE_TIME_NULLPTR) :
|
||||
time_duration(0, numeric_cast<min_type>(m),0)
|
||||
{}
|
||||
};
|
||||
|
||||
//! Allows expression of durations as a seconds count
|
||||
//! The argument must be an integral type
|
||||
/*! \ingroup time_basics
|
||||
*/
|
||||
class BOOST_SYMBOL_VISIBLE seconds : public time_duration
|
||||
{
|
||||
public:
|
||||
template <typename T>
|
||||
BOOST_CXX14_CONSTEXPR explicit seconds(T const& s,
|
||||
typename boost::enable_if<boost::is_integral<T>, void>::type* = BOOST_DATE_TIME_NULLPTR) :
|
||||
time_duration(0,0, numeric_cast<sec_type>(s))
|
||||
{}
|
||||
};
|
||||
|
||||
|
||||
//! Allows expression of durations as milli seconds
|
||||
/*! \ingroup time_basics
|
||||
*/
|
||||
typedef date_time::subsecond_duration<time_duration,1000> millisec;
|
||||
typedef date_time::subsecond_duration<time_duration,1000> milliseconds;
|
||||
|
||||
//! Allows expression of durations as micro seconds
|
||||
/*! \ingroup time_basics
|
||||
*/
|
||||
typedef date_time::subsecond_duration<time_duration,1000000> microsec;
|
||||
typedef date_time::subsecond_duration<time_duration,1000000> microseconds;
|
||||
|
||||
//This is probably not needed anymore...
|
||||
#if defined(BOOST_DATE_TIME_HAS_NANOSECONDS)
|
||||
|
||||
//! Allows expression of durations as nano seconds
|
||||
/*! \ingroup time_basics
|
||||
*/
|
||||
typedef date_time::subsecond_duration<time_duration,1000000000> nanosec;
|
||||
typedef date_time::subsecond_duration<time_duration,1000000000> nanoseconds;
|
||||
|
||||
#endif
|
||||
|
||||
} }//namespace posix_time
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
236
include/boost/date_time/posix_time/posix_time_io.hpp
Normal file
236
include/boost/date_time/posix_time/posix_time_io.hpp
Normal file
@@ -0,0 +1,236 @@
|
||||
#ifndef DATE_TIME_POSIX_TIME_IO_HPP__
|
||||
#define DATE_TIME_POSIX_TIME_IO_HPP__
|
||||
|
||||
/* Copyright (c) 2004-2005 CrystalClear Software, Inc.
|
||||
* 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
|
||||
* $Date$
|
||||
*/
|
||||
|
||||
#include <locale>
|
||||
#include <iostream>
|
||||
#include <iterator> // i/ostreambuf_iterator
|
||||
#include <boost/io/ios_state.hpp>
|
||||
#include <boost/date_time/time_facet.hpp>
|
||||
#include <boost/date_time/period_formatter.hpp>
|
||||
#include <boost/date_time/posix_time/ptime.hpp>
|
||||
#include <boost/date_time/posix_time/time_period.hpp>
|
||||
#include <boost/date_time/posix_time/posix_time_duration.hpp>
|
||||
#include <boost/date_time/posix_time/conversion.hpp> // to_tm will be needed in the facets
|
||||
|
||||
namespace boost {
|
||||
namespace posix_time {
|
||||
|
||||
|
||||
//! wptime_facet is depricated and will be phased out. use wtime_facet instead
|
||||
//typedef boost::date_time::time_facet<ptime, wchar_t> wptime_facet;
|
||||
//! ptime_facet is depricated and will be phased out. use time_facet instead
|
||||
//typedef boost::date_time::time_facet<ptime, char> ptime_facet;
|
||||
|
||||
//! wptime_input_facet is depricated and will be phased out. use wtime_input_facet instead
|
||||
//typedef boost::date_time::time_input_facet<ptime,wchar_t> wptime_input_facet;
|
||||
//! ptime_input_facet is depricated and will be phased out. use time_input_facet instead
|
||||
//typedef boost::date_time::time_input_facet<ptime,char> ptime_input_facet;
|
||||
|
||||
typedef boost::date_time::time_facet<ptime, wchar_t> wtime_facet;
|
||||
typedef boost::date_time::time_facet<ptime, char> time_facet;
|
||||
|
||||
typedef boost::date_time::time_input_facet<ptime, wchar_t> wtime_input_facet;
|
||||
typedef boost::date_time::time_input_facet<ptime, char> time_input_facet;
|
||||
|
||||
template <class CharT, class TraitsT>
|
||||
inline
|
||||
std::basic_ostream<CharT, TraitsT>&
|
||||
operator<<(std::basic_ostream<CharT, TraitsT>& os,
|
||||
const ptime& p) {
|
||||
boost::io::ios_flags_saver iflags(os);
|
||||
typedef boost::date_time::time_facet<ptime, CharT> custom_ptime_facet;
|
||||
std::ostreambuf_iterator<CharT> oitr(os);
|
||||
if (std::has_facet<custom_ptime_facet>(os.getloc()))
|
||||
std::use_facet<custom_ptime_facet>(os.getloc()).put(oitr, os, os.fill(), p);
|
||||
else {
|
||||
//instantiate a custom facet for dealing with times since the user
|
||||
//has not put one in the stream so far. This is for efficiency
|
||||
//since we would always need to reconstruct for every time period
|
||||
//if the locale did not already exist. Of course this will be overridden
|
||||
//if the user imbues as some later point.
|
||||
custom_ptime_facet* f = new custom_ptime_facet();
|
||||
std::locale l = std::locale(os.getloc(), f);
|
||||
os.imbue(l);
|
||||
f->put(oitr, os, os.fill(), p);
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
//! input operator for ptime
|
||||
template <class CharT, class Traits>
|
||||
inline
|
||||
std::basic_istream<CharT, Traits>&
|
||||
operator>>(std::basic_istream<CharT, Traits>& is, ptime& pt)
|
||||
{
|
||||
boost::io::ios_flags_saver iflags(is);
|
||||
typename std::basic_istream<CharT, Traits>::sentry strm_sentry(is, false);
|
||||
if (strm_sentry) {
|
||||
try {
|
||||
typedef typename date_time::time_input_facet<ptime, CharT> time_input_facet_local;
|
||||
std::istreambuf_iterator<CharT,Traits> sit(is), str_end;
|
||||
if(std::has_facet<time_input_facet_local>(is.getloc())) {
|
||||
std::use_facet<time_input_facet_local>(is.getloc()).get(sit, str_end, is, pt);
|
||||
}
|
||||
else {
|
||||
time_input_facet_local* f = new time_input_facet_local();
|
||||
std::locale l = std::locale(is.getloc(), f);
|
||||
is.imbue(l);
|
||||
f->get(sit, str_end, is, pt);
|
||||
}
|
||||
}
|
||||
catch(...) {
|
||||
// mask tells us what exceptions are turned on
|
||||
std::ios_base::iostate exception_mask = is.exceptions();
|
||||
// if the user wants exceptions on failbit, we'll rethrow our
|
||||
// date_time exception & set the failbit
|
||||
if(std::ios_base::failbit & exception_mask) {
|
||||
try { is.setstate(std::ios_base::failbit); }
|
||||
catch(std::ios_base::failure&) {} // ignore this one
|
||||
throw; // rethrow original exception
|
||||
}
|
||||
else {
|
||||
// if the user wants to fail quietly, we simply set the failbit
|
||||
is.setstate(std::ios_base::failbit);
|
||||
}
|
||||
}
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
|
||||
template <class CharT, class TraitsT>
|
||||
inline
|
||||
std::basic_ostream<CharT, TraitsT>&
|
||||
operator<<(std::basic_ostream<CharT, TraitsT>& os,
|
||||
const boost::posix_time::time_period& p) {
|
||||
boost::io::ios_flags_saver iflags(os);
|
||||
typedef boost::date_time::time_facet<ptime, CharT> custom_ptime_facet;
|
||||
std::ostreambuf_iterator<CharT> oitr(os);
|
||||
if (std::has_facet<custom_ptime_facet>(os.getloc())) {
|
||||
std::use_facet<custom_ptime_facet>(os.getloc()).put(oitr, os, os.fill(), p);
|
||||
}
|
||||
else {
|
||||
//instantiate a custom facet for dealing with periods since the user
|
||||
//has not put one in the stream so far. This is for efficiency
|
||||
//since we would always need to reconstruct for every time period
|
||||
//if the local did not already exist. Of course this will be overridden
|
||||
//if the user imbues as some later point.
|
||||
custom_ptime_facet* f = new custom_ptime_facet();
|
||||
std::locale l = std::locale(os.getloc(), f);
|
||||
os.imbue(l);
|
||||
f->put(oitr, os, os.fill(), p);
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
//! input operator for time_period
|
||||
template <class CharT, class Traits>
|
||||
inline
|
||||
std::basic_istream<CharT, Traits>&
|
||||
operator>>(std::basic_istream<CharT, Traits>& is, time_period& tp)
|
||||
{
|
||||
boost::io::ios_flags_saver iflags(is);
|
||||
typename std::basic_istream<CharT, Traits>::sentry strm_sentry(is, false);
|
||||
if (strm_sentry) {
|
||||
try {
|
||||
typedef typename date_time::time_input_facet<ptime, CharT> time_input_facet_local;
|
||||
std::istreambuf_iterator<CharT,Traits> sit(is), str_end;
|
||||
if(std::has_facet<time_input_facet_local>(is.getloc())) {
|
||||
std::use_facet<time_input_facet_local>(is.getloc()).get(sit, str_end, is, tp);
|
||||
}
|
||||
else {
|
||||
time_input_facet_local* f = new time_input_facet_local();
|
||||
std::locale l = std::locale(is.getloc(), f);
|
||||
is.imbue(l);
|
||||
f->get(sit, str_end, is, tp);
|
||||
}
|
||||
}
|
||||
catch(...) {
|
||||
std::ios_base::iostate exception_mask = is.exceptions();
|
||||
if(std::ios_base::failbit & exception_mask) {
|
||||
try { is.setstate(std::ios_base::failbit); }
|
||||
catch(std::ios_base::failure&) {}
|
||||
throw; // rethrow original exception
|
||||
}
|
||||
else {
|
||||
is.setstate(std::ios_base::failbit);
|
||||
}
|
||||
}
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
|
||||
//! ostream operator for posix_time::time_duration
|
||||
// todo fix to use facet -- place holder for now...
|
||||
template <class CharT, class Traits>
|
||||
inline
|
||||
std::basic_ostream<CharT, Traits>&
|
||||
operator<<(std::basic_ostream<CharT, Traits>& os, const time_duration& td)
|
||||
{
|
||||
boost::io::ios_flags_saver iflags(os);
|
||||
typedef boost::date_time::time_facet<ptime, CharT> custom_ptime_facet;
|
||||
std::ostreambuf_iterator<CharT> oitr(os);
|
||||
if (std::has_facet<custom_ptime_facet>(os.getloc()))
|
||||
std::use_facet<custom_ptime_facet>(os.getloc()).put(oitr, os, os.fill(), td);
|
||||
else {
|
||||
//instantiate a custom facet for dealing with times since the user
|
||||
//has not put one in the stream so far. This is for efficiency
|
||||
//since we would always need to reconstruct for every time period
|
||||
//if the locale did not already exist. Of course this will be overridden
|
||||
//if the user imbues as some later point.
|
||||
custom_ptime_facet* f = new custom_ptime_facet();
|
||||
std::locale l = std::locale(os.getloc(), f);
|
||||
os.imbue(l);
|
||||
f->put(oitr, os, os.fill(), td);
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
//! input operator for time_duration
|
||||
template <class CharT, class Traits>
|
||||
inline
|
||||
std::basic_istream<CharT, Traits>&
|
||||
operator>>(std::basic_istream<CharT, Traits>& is, time_duration& td)
|
||||
{
|
||||
boost::io::ios_flags_saver iflags(is);
|
||||
typename std::basic_istream<CharT, Traits>::sentry strm_sentry(is, false);
|
||||
if (strm_sentry) {
|
||||
try {
|
||||
typedef typename date_time::time_input_facet<ptime, CharT> time_input_facet_local;
|
||||
std::istreambuf_iterator<CharT,Traits> sit(is), str_end;
|
||||
if(std::has_facet<time_input_facet_local>(is.getloc())) {
|
||||
std::use_facet<time_input_facet_local>(is.getloc()).get(sit, str_end, is, td);
|
||||
}
|
||||
else {
|
||||
time_input_facet_local* f = new time_input_facet_local();
|
||||
std::locale l = std::locale(is.getloc(), f);
|
||||
is.imbue(l);
|
||||
f->get(sit, str_end, is, td);
|
||||
}
|
||||
}
|
||||
catch(...) {
|
||||
std::ios_base::iostate exception_mask = is.exceptions();
|
||||
if(std::ios_base::failbit & exception_mask) {
|
||||
try { is.setstate(std::ios_base::failbit); }
|
||||
catch(std::ios_base::failure&) {}
|
||||
throw; // rethrow original exception
|
||||
}
|
||||
else {
|
||||
is.setstate(std::ios_base::failbit);
|
||||
}
|
||||
}
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
} } // namespaces
|
||||
#endif // DATE_TIME_POSIX_TIME_IO_HPP__
|
||||
153
include/boost/date_time/posix_time/posix_time_legacy_io.hpp
Normal file
153
include/boost/date_time/posix_time/posix_time_legacy_io.hpp
Normal file
@@ -0,0 +1,153 @@
|
||||
#ifndef POSIX_TIME_PRE133_OPERATORS_HPP___
|
||||
#define POSIX_TIME_PRE133_OPERATORS_HPP___
|
||||
|
||||
/* Copyright (c) 2002-2004 CrystalClear Software, Inc.
|
||||
* 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
|
||||
* $Date$
|
||||
*/
|
||||
|
||||
/*! @file posix_time_pre133_operators.hpp
|
||||
* These input and output operators are for use with the
|
||||
* pre 1.33 version of the date_time libraries io facet code.
|
||||
* The operators used in version 1.33 and later can be found
|
||||
* in posix_time_io.hpp */
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include "boost/date_time/compiler_config.hpp"
|
||||
#include "boost/date_time/gregorian/gregorian.hpp"
|
||||
#include "boost/date_time/posix_time/posix_time_duration.hpp"
|
||||
#include "boost/date_time/posix_time/ptime.hpp"
|
||||
#include "boost/date_time/posix_time/time_period.hpp"
|
||||
#include "boost/date_time/time_parsing.hpp"
|
||||
|
||||
namespace boost {
|
||||
namespace posix_time {
|
||||
|
||||
|
||||
//The following code is removed for configurations with poor std::locale support (eg: MSVC6, gcc 2.9x)
|
||||
#ifndef BOOST_DATE_TIME_NO_LOCALE
|
||||
#if defined(USE_DATE_TIME_PRE_1_33_FACET_IO)
|
||||
//! ostream operator for posix_time::time_duration
|
||||
template <class charT, class traits>
|
||||
inline
|
||||
std::basic_ostream<charT, traits>&
|
||||
operator<<(std::basic_ostream<charT, traits>& os, const time_duration& td)
|
||||
{
|
||||
typedef boost::date_time::ostream_time_duration_formatter<time_duration, charT> duration_formatter;
|
||||
duration_formatter::duration_put(td, os);
|
||||
return os;
|
||||
}
|
||||
|
||||
//! ostream operator for posix_time::ptime
|
||||
template <class charT, class traits>
|
||||
inline
|
||||
std::basic_ostream<charT, traits>&
|
||||
operator<<(std::basic_ostream<charT, traits>& os, const ptime& t)
|
||||
{
|
||||
typedef boost::date_time::ostream_time_formatter<ptime, charT> time_formatter;
|
||||
time_formatter::time_put(t, os);
|
||||
return os;
|
||||
}
|
||||
|
||||
//! ostream operator for posix_time::time_period
|
||||
template <class charT, class traits>
|
||||
inline
|
||||
std::basic_ostream<charT, traits>&
|
||||
operator<<(std::basic_ostream<charT, traits>& os, const time_period& tp)
|
||||
{
|
||||
typedef boost::date_time::ostream_time_period_formatter<time_period, charT> period_formatter;
|
||||
period_formatter::period_put(tp, os);
|
||||
return os;
|
||||
}
|
||||
#endif // USE_DATE_TIME_PRE_1_33_FACET_IO
|
||||
/******** input streaming ********/
|
||||
template<class charT>
|
||||
inline
|
||||
std::basic_istream<charT>& operator>>(std::basic_istream<charT>& is, time_duration& td)
|
||||
{
|
||||
// need to create a std::string and parse it
|
||||
std::basic_string<charT> inp_s;
|
||||
std::stringstream out_ss;
|
||||
is >> inp_s;
|
||||
typename std::basic_string<charT>::iterator b = inp_s.begin();
|
||||
// need to use both iterators because there is no requirement
|
||||
// for the data held by a std::basic_string<> be terminated with
|
||||
// any marker (such as '\0').
|
||||
typename std::basic_string<charT>::iterator e = inp_s.end();
|
||||
while(b != e){
|
||||
out_ss << is.narrow(*b, 0);
|
||||
++b;
|
||||
}
|
||||
|
||||
td = date_time::parse_delimited_time_duration<time_duration>(out_ss.str());
|
||||
return is;
|
||||
}
|
||||
|
||||
template<class charT>
|
||||
inline
|
||||
std::basic_istream<charT>& operator>>(std::basic_istream<charT>& is, ptime& pt)
|
||||
{
|
||||
gregorian::date d(not_a_date_time);
|
||||
time_duration td(0,0,0);
|
||||
is >> d >> td;
|
||||
pt = ptime(d, td);
|
||||
|
||||
return is;
|
||||
}
|
||||
|
||||
/** operator>> for time_period. time_period must be in
|
||||
* "[date time_duration/date time_duration]" format. */
|
||||
template<class charT>
|
||||
inline
|
||||
std::basic_istream<charT>& operator>>(std::basic_istream<charT>& is, time_period& tp)
|
||||
{
|
||||
gregorian::date d(not_a_date_time);
|
||||
time_duration td(0,0,0);
|
||||
ptime beg(d, td);
|
||||
ptime end(beg);
|
||||
std::basic_string<charT> s;
|
||||
// get first date string and remove leading '['
|
||||
is >> s;
|
||||
{
|
||||
std::basic_stringstream<charT> ss;
|
||||
ss << s.substr(s.find('[')+1);
|
||||
ss >> d;
|
||||
}
|
||||
// get first time_duration & second date string, remove the '/'
|
||||
// and split into 2 strings
|
||||
is >> s;
|
||||
{
|
||||
std::basic_stringstream<charT> ss;
|
||||
ss << s.substr(0, s.find('/'));
|
||||
ss >> td;
|
||||
}
|
||||
beg = ptime(d, td);
|
||||
{
|
||||
std::basic_stringstream<charT> ss;
|
||||
ss << s.substr(s.find('/')+1);
|
||||
ss >> d;
|
||||
}
|
||||
// get last time_duration and remove the trailing ']'
|
||||
is >> s;
|
||||
{
|
||||
std::basic_stringstream<charT> ss;
|
||||
ss << s.substr(0, s.find(']'));
|
||||
ss >> td;
|
||||
}
|
||||
end = ptime(d, td);
|
||||
|
||||
tp = time_period(beg,end);
|
||||
return is;
|
||||
}
|
||||
|
||||
|
||||
#endif //BOOST_DATE_TIME_NO_LOCALE
|
||||
|
||||
} } // namespaces
|
||||
|
||||
#endif // POSIX_TIME_PRE133_OPERATORS_HPP___
|
||||
68
include/boost/date_time/posix_time/posix_time_system.hpp
Normal file
68
include/boost/date_time/posix_time/posix_time_system.hpp
Normal file
@@ -0,0 +1,68 @@
|
||||
#ifndef POSIX_TIME_SYSTEM_HPP___
|
||||
#define POSIX_TIME_SYSTEM_HPP___
|
||||
|
||||
/* Copyright (c) 2002,2003 CrystalClear Software, Inc.
|
||||
* 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
|
||||
* $Date$
|
||||
*/
|
||||
|
||||
|
||||
#include "boost/date_time/posix_time/posix_time_config.hpp"
|
||||
#include "boost/date_time/time_system_split.hpp"
|
||||
#include "boost/date_time/time_system_counted.hpp"
|
||||
#include "boost/date_time/compiler_config.hpp"
|
||||
|
||||
|
||||
namespace boost {
|
||||
namespace posix_time {
|
||||
|
||||
#ifdef BOOST_DATE_TIME_POSIX_TIME_STD_CONFIG
|
||||
|
||||
#if (defined(BOOST_DATE_TIME_NO_MEMBER_INIT)) //help bad compilers
|
||||
typedef date_time::split_timedate_system<posix_time_system_config, 1000000000> posix_time_system;
|
||||
#else
|
||||
typedef date_time::split_timedate_system<posix_time_system_config> posix_time_system;
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
typedef date_time::counted_time_rep<millisec_posix_time_system_config> int64_time_rep;
|
||||
typedef date_time::counted_time_system<int64_time_rep> posix_time_system;
|
||||
|
||||
#endif
|
||||
|
||||
} }//namespace posix_time
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
55
include/boost/date_time/posix_time/posix_time_types.hpp
Normal file
55
include/boost/date_time/posix_time/posix_time_types.hpp
Normal file
@@ -0,0 +1,55 @@
|
||||
/* Copyright (c) 2002,2003 CrystalClear Software, Inc.
|
||||
* 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
|
||||
*/
|
||||
#ifndef POSIX_TIME_TYPES_HPP___
|
||||
#define POSIX_TIME_TYPES_HPP___
|
||||
|
||||
#include "boost/date_time/time_clock.hpp"
|
||||
#include "boost/date_time/microsec_time_clock.hpp"
|
||||
#include "boost/date_time/posix_time/ptime.hpp"
|
||||
#if defined(BOOST_DATE_TIME_OPTIONAL_GREGORIAN_TYPES)
|
||||
#include "boost/date_time/posix_time/date_duration_operators.hpp"
|
||||
#endif
|
||||
#include "boost/date_time/posix_time/posix_time_duration.hpp"
|
||||
#include "boost/date_time/posix_time/posix_time_system.hpp"
|
||||
#include "boost/date_time/posix_time/time_period.hpp"
|
||||
#include "boost/date_time/time_iterator.hpp"
|
||||
#include "boost/date_time/dst_rules.hpp"
|
||||
|
||||
namespace boost {
|
||||
|
||||
//!Defines a non-adjusted time system with nano-second resolution and stable calculation properties
|
||||
namespace posix_time {
|
||||
|
||||
//! Iterator over a defined time duration
|
||||
/*! \ingroup time_basics
|
||||
*/
|
||||
typedef date_time::time_itr<ptime> time_iterator;
|
||||
//! A time clock that has a resolution of one second
|
||||
/*! \ingroup time_basics
|
||||
*/
|
||||
typedef date_time::second_clock<ptime> second_clock;
|
||||
|
||||
#ifdef BOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK
|
||||
//! A time clock that has a resolution of one microsecond
|
||||
/*! \ingroup time_basics
|
||||
*/
|
||||
typedef date_time::microsec_clock<ptime> microsec_clock;
|
||||
#endif
|
||||
|
||||
//! Define a dst null dst rule for the posix_time system
|
||||
typedef date_time::null_dst_rules<ptime::date_type, time_duration> no_dst;
|
||||
//! Define US dst rule calculator for the posix_time system
|
||||
typedef date_time::us_dst_rules<ptime::date_type, time_duration> us_dst;
|
||||
|
||||
|
||||
} } //namespace posix_time
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
84
include/boost/date_time/posix_time/ptime.hpp
Normal file
84
include/boost/date_time/posix_time/ptime.hpp
Normal file
@@ -0,0 +1,84 @@
|
||||
#ifndef POSIX_PTIME_HPP___
|
||||
#define POSIX_PTIME_HPP___
|
||||
|
||||
/* Copyright (c) 2002,2003 CrystalClear Software, Inc.
|
||||
* 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
|
||||
* $Date$
|
||||
*/
|
||||
|
||||
#include <boost/date_time/posix_time/posix_time_system.hpp>
|
||||
#include <boost/date_time/time.hpp>
|
||||
#include <boost/date_time/compiler_config.hpp>
|
||||
|
||||
namespace boost {
|
||||
|
||||
namespace posix_time {
|
||||
|
||||
//bring special enum values into the namespace
|
||||
using date_time::special_values;
|
||||
using date_time::not_special;
|
||||
using date_time::neg_infin;
|
||||
using date_time::pos_infin;
|
||||
using date_time::not_a_date_time;
|
||||
using date_time::max_date_time;
|
||||
using date_time::min_date_time;
|
||||
|
||||
//! Time type with no timezone or other adjustments
|
||||
/*! \ingroup time_basics
|
||||
*/
|
||||
class BOOST_SYMBOL_VISIBLE ptime : public date_time::base_time<ptime, posix_time_system>
|
||||
{
|
||||
public:
|
||||
typedef posix_time_system time_system_type;
|
||||
typedef time_system_type::time_rep_type time_rep_type;
|
||||
typedef time_system_type::time_duration_type time_duration_type;
|
||||
typedef ptime time_type;
|
||||
//! Construct with date and offset in day
|
||||
BOOST_CXX14_CONSTEXPR
|
||||
ptime(gregorian::date d,time_duration_type td) :
|
||||
date_time::base_time<time_type,time_system_type>(d,td)
|
||||
{}
|
||||
//! Construct a time at start of the given day (midnight)
|
||||
BOOST_CXX14_CONSTEXPR
|
||||
explicit ptime(gregorian::date d) :
|
||||
date_time::base_time<time_type,time_system_type>(d,time_duration_type(0,0,0))
|
||||
{}
|
||||
//! Copy from time_rep
|
||||
BOOST_CXX14_CONSTEXPR
|
||||
ptime(const time_rep_type& rhs):
|
||||
date_time::base_time<time_type,time_system_type>(rhs)
|
||||
{}
|
||||
//! Construct from special value
|
||||
BOOST_CXX14_CONSTEXPR
|
||||
ptime(const special_values sv) :
|
||||
date_time::base_time<time_type,time_system_type>(sv)
|
||||
{}
|
||||
#if !defined(DATE_TIME_NO_DEFAULT_CONSTRUCTOR)
|
||||
// Default constructor constructs to not_a_date_time
|
||||
BOOST_CXX14_CONSTEXPR
|
||||
ptime() :
|
||||
date_time::base_time<time_type,time_system_type>(gregorian::date(not_a_date_time),
|
||||
time_duration_type(not_a_date_time))
|
||||
{}
|
||||
#endif // DATE_TIME_NO_DEFAULT_CONSTRUCTOR
|
||||
|
||||
friend BOOST_CXX14_CONSTEXPR
|
||||
bool operator==(const ptime& lhs, const ptime& rhs);
|
||||
|
||||
};
|
||||
|
||||
inline BOOST_CXX14_CONSTEXPR
|
||||
bool operator==(const ptime& lhs, const ptime& rhs)
|
||||
{
|
||||
return ptime::time_system_type::is_equal(lhs.time_,rhs.time_);
|
||||
}
|
||||
|
||||
|
||||
} }//namespace posix_time
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
289
include/boost/date_time/posix_time/time_formatters.hpp
Normal file
289
include/boost/date_time/posix_time/time_formatters.hpp
Normal file
@@ -0,0 +1,289 @@
|
||||
#ifndef POSIXTIME_FORMATTERS_HPP___
|
||||
#define POSIXTIME_FORMATTERS_HPP___
|
||||
|
||||
/* Copyright (c) 2002-2004 CrystalClear Software, Inc.
|
||||
* 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
|
||||
* $Date$
|
||||
*/
|
||||
|
||||
#include <boost/date_time/gregorian/gregorian.hpp>
|
||||
#include <boost/date_time/compiler_config.hpp>
|
||||
#include <boost/date_time/iso_format.hpp>
|
||||
#include <boost/date_time/date_format_simple.hpp>
|
||||
#include <boost/date_time/posix_time/posix_time_types.hpp>
|
||||
#include <boost/date_time/time_formatting_streams.hpp>
|
||||
#include <boost/date_time/time_resolution_traits.hpp> // absolute_value
|
||||
#include <boost/date_time/time_parsing.hpp>
|
||||
|
||||
/* NOTE: The "to_*_string" code for older compilers, ones that define
|
||||
* BOOST_DATE_TIME_INCLUDE_LIMITED_HEADERS, is located in
|
||||
* formatters_limited.hpp
|
||||
*/
|
||||
|
||||
namespace boost {
|
||||
|
||||
namespace posix_time {
|
||||
|
||||
// template function called by wrapper functions:
|
||||
// to_*_string(time_duration) & to_*_wstring(time_duration)
|
||||
template<class charT>
|
||||
inline std::basic_string<charT> to_simple_string_type(time_duration td) {
|
||||
std::basic_ostringstream<charT> ss;
|
||||
if(td.is_special()) {
|
||||
/* simply using 'ss << td.get_rep()' won't work on compilers
|
||||
* that don't support locales. This way does. */
|
||||
// switch copied from date_names_put.hpp
|
||||
switch(td.get_rep().as_special())
|
||||
{
|
||||
case not_a_date_time:
|
||||
//ss << "not-a-number";
|
||||
ss << "not-a-date-time";
|
||||
break;
|
||||
case pos_infin:
|
||||
ss << "+infinity";
|
||||
break;
|
||||
case neg_infin:
|
||||
ss << "-infinity";
|
||||
break;
|
||||
default:
|
||||
ss << "";
|
||||
}
|
||||
}
|
||||
else {
|
||||
charT fill_char = '0';
|
||||
if(td.is_negative()) {
|
||||
ss << '-';
|
||||
}
|
||||
ss << std::setw(2) << std::setfill(fill_char)
|
||||
<< date_time::absolute_value(td.hours()) << ":";
|
||||
ss << std::setw(2) << std::setfill(fill_char)
|
||||
<< date_time::absolute_value(td.minutes()) << ":";
|
||||
ss << std::setw(2) << std::setfill(fill_char)
|
||||
<< date_time::absolute_value(td.seconds());
|
||||
//TODO the following is totally non-generic, yelling FIXME
|
||||
#if (defined(BOOST_MSVC) && (_MSC_VER < 1300))
|
||||
boost::int64_t frac_sec =
|
||||
date_time::absolute_value(td.fractional_seconds());
|
||||
// JDG [7/6/02 VC++ compatibility]
|
||||
charT buff[32];
|
||||
_i64toa(frac_sec, buff, 10);
|
||||
#else
|
||||
time_duration::fractional_seconds_type frac_sec =
|
||||
date_time::absolute_value(td.fractional_seconds());
|
||||
#endif
|
||||
if (frac_sec != 0) {
|
||||
ss << "." << std::setw(time_duration::num_fractional_digits())
|
||||
<< std::setfill(fill_char)
|
||||
|
||||
// JDG [7/6/02 VC++ compatibility]
|
||||
#if (defined(BOOST_MSVC) && (_MSC_VER < 1300))
|
||||
<< buff;
|
||||
#else
|
||||
<< frac_sec;
|
||||
#endif
|
||||
}
|
||||
}// else
|
||||
return ss.str();
|
||||
}
|
||||
//! Time duration to string -hh::mm::ss.fffffff. Example: 10:09:03.0123456
|
||||
/*!\ingroup time_format
|
||||
*/
|
||||
inline std::string to_simple_string(time_duration td) {
|
||||
return to_simple_string_type<char>(td);
|
||||
}
|
||||
|
||||
|
||||
// template function called by wrapper functions:
|
||||
// to_*_string(time_duration) & to_*_wstring(time_duration)
|
||||
template<class charT>
|
||||
inline std::basic_string<charT> to_iso_string_type(time_duration td)
|
||||
{
|
||||
std::basic_ostringstream<charT> ss;
|
||||
if(td.is_special()) {
|
||||
/* simply using 'ss << td.get_rep()' won't work on compilers
|
||||
* that don't support locales. This way does. */
|
||||
// switch copied from date_names_put.hpp
|
||||
switch(td.get_rep().as_special()) {
|
||||
case not_a_date_time:
|
||||
//ss << "not-a-number";
|
||||
ss << "not-a-date-time";
|
||||
break;
|
||||
case pos_infin:
|
||||
ss << "+infinity";
|
||||
break;
|
||||
case neg_infin:
|
||||
ss << "-infinity";
|
||||
break;
|
||||
default:
|
||||
ss << "";
|
||||
}
|
||||
}
|
||||
else {
|
||||
charT fill_char = '0';
|
||||
if(td.is_negative()) {
|
||||
ss << '-';
|
||||
}
|
||||
ss << std::setw(2) << std::setfill(fill_char)
|
||||
<< date_time::absolute_value(td.hours());
|
||||
ss << std::setw(2) << std::setfill(fill_char)
|
||||
<< date_time::absolute_value(td.minutes());
|
||||
ss << std::setw(2) << std::setfill(fill_char)
|
||||
<< date_time::absolute_value(td.seconds());
|
||||
//TODO the following is totally non-generic, yelling FIXME
|
||||
#if (defined(BOOST_MSVC) && (_MSC_VER < 1300))
|
||||
boost::int64_t frac_sec =
|
||||
date_time::absolute_value(td.fractional_seconds());
|
||||
// JDG [7/6/02 VC++ compatibility]
|
||||
charT buff[32];
|
||||
_i64toa(frac_sec, buff, 10);
|
||||
#else
|
||||
time_duration::fractional_seconds_type frac_sec =
|
||||
date_time::absolute_value(td.fractional_seconds());
|
||||
#endif
|
||||
if (frac_sec != 0) {
|
||||
ss << "." << std::setw(time_duration::num_fractional_digits())
|
||||
<< std::setfill(fill_char)
|
||||
|
||||
// JDG [7/6/02 VC++ compatibility]
|
||||
#if (defined(BOOST_MSVC) && (_MSC_VER < 1300))
|
||||
<< buff;
|
||||
#else
|
||||
<< frac_sec;
|
||||
#endif
|
||||
}
|
||||
}// else
|
||||
return ss.str();
|
||||
}
|
||||
//! Time duration in ISO 8601 format -hhmmss.fffffff. Example: 10:09:03.0123456
|
||||
/*!\ingroup time_format
|
||||
*/
|
||||
inline std::string to_iso_string(time_duration td){
|
||||
return to_iso_string_type<char>(td);
|
||||
}
|
||||
|
||||
//! Time to simple format CCYY-mmm-dd hh:mm:ss.fffffff
|
||||
/*!\ingroup time_format
|
||||
*/
|
||||
template<class charT>
|
||||
inline std::basic_string<charT> to_simple_string_type(ptime t)
|
||||
{
|
||||
// can't use this w/gcc295, no to_simple_string_type<>(td) available
|
||||
std::basic_string<charT> ts = gregorian::to_simple_string_type<charT>(t.date());// + " ";
|
||||
if(!t.time_of_day().is_special()) {
|
||||
charT space = ' ';
|
||||
return ts + space + to_simple_string_type<charT>(t.time_of_day());
|
||||
}
|
||||
else {
|
||||
return ts;
|
||||
}
|
||||
}
|
||||
inline std::string to_simple_string(ptime t){
|
||||
return to_simple_string_type<char>(t);
|
||||
}
|
||||
|
||||
// function called by wrapper functions to_*_string(time_period)
|
||||
// & to_*_wstring(time_period)
|
||||
template<class charT>
|
||||
inline std::basic_string<charT> to_simple_string_type(time_period tp)
|
||||
{
|
||||
charT beg = '[', mid = '/', end = ']';
|
||||
std::basic_string<charT> d1(to_simple_string_type<charT>(tp.begin()));
|
||||
std::basic_string<charT> d2(to_simple_string_type<charT>(tp.last()));
|
||||
return std::basic_string<charT>(beg + d1 + mid + d2 + end);
|
||||
}
|
||||
//! Convert to string of form [YYYY-mmm-DD HH:MM::SS.ffffff/YYYY-mmm-DD HH:MM::SS.fffffff]
|
||||
/*!\ingroup time_format
|
||||
*/
|
||||
inline std::string to_simple_string(time_period tp){
|
||||
return to_simple_string_type<char>(tp);
|
||||
}
|
||||
|
||||
// function called by wrapper functions to_*_string(time_period)
|
||||
// & to_*_wstring(time_period)
|
||||
template<class charT>
|
||||
inline std::basic_string<charT> to_iso_string_type(ptime t)
|
||||
{
|
||||
std::basic_string<charT> ts = gregorian::to_iso_string_type<charT>(t.date());// + "T";
|
||||
if(!t.time_of_day().is_special()) {
|
||||
charT sep = 'T';
|
||||
return ts + sep + to_iso_string_type<charT>(t.time_of_day());
|
||||
}
|
||||
else {
|
||||
return ts;
|
||||
}
|
||||
}
|
||||
//! Convert ISO 8601 short form YYYYMMDDTHHMMSS where T is the date-time separator
|
||||
/*!\ingroup time_format
|
||||
*/
|
||||
inline std::string to_iso_string(ptime t){
|
||||
return to_iso_string_type<char>(t);
|
||||
}
|
||||
|
||||
|
||||
// function called by wrapper functions to_*_string(time_period)
|
||||
// & to_*_wstring(time_period)
|
||||
template<class charT>
|
||||
inline std::basic_string<charT> to_iso_extended_string_type(ptime t)
|
||||
{
|
||||
std::basic_string<charT> ts = gregorian::to_iso_extended_string_type<charT>(t.date());// + "T";
|
||||
if(!t.time_of_day().is_special()) {
|
||||
charT sep = 'T';
|
||||
return ts + sep + to_simple_string_type<charT>(t.time_of_day());
|
||||
}
|
||||
else {
|
||||
return ts;
|
||||
}
|
||||
}
|
||||
//! Convert to form YYYY-MM-DDTHH:MM:SS where T is the date-time separator
|
||||
/*!\ingroup time_format
|
||||
*/
|
||||
inline std::string to_iso_extended_string(ptime t){
|
||||
return to_iso_extended_string_type<char>(t);
|
||||
}
|
||||
|
||||
#if !defined(BOOST_NO_STD_WSTRING)
|
||||
//! Time duration to wstring -hh::mm::ss.fffffff. Example: 10:09:03.0123456
|
||||
/*!\ingroup time_format
|
||||
*/
|
||||
inline std::wstring to_simple_wstring(time_duration td) {
|
||||
return to_simple_string_type<wchar_t>(td);
|
||||
}
|
||||
//! Time duration in ISO 8601 format -hhmmss.fffffff. Example: 10:09:03.0123456
|
||||
/*!\ingroup time_format
|
||||
*/
|
||||
inline std::wstring to_iso_wstring(time_duration td){
|
||||
return to_iso_string_type<wchar_t>(td);
|
||||
}
|
||||
inline std::wstring to_simple_wstring(ptime t){
|
||||
return to_simple_string_type<wchar_t>(t);
|
||||
}
|
||||
//! Convert to wstring of form [YYYY-mmm-DD HH:MM::SS.ffffff/YYYY-mmm-DD HH:MM::SS.fffffff]
|
||||
/*!\ingroup time_format
|
||||
*/
|
||||
inline std::wstring to_simple_wstring(time_period tp){
|
||||
return to_simple_string_type<wchar_t>(tp);
|
||||
}
|
||||
//! Convert ISO 8601 short form YYYYMMDDTHHMMSS where T is the date-time separator
|
||||
/*!\ingroup time_format
|
||||
*/
|
||||
inline std::wstring to_iso_wstring(ptime t){
|
||||
return to_iso_string_type<wchar_t>(t);
|
||||
}
|
||||
//! Convert to form YYYY-MM-DDTHH:MM:SS where T is the date-time separator
|
||||
/*!\ingroup time_format
|
||||
*/
|
||||
inline std::wstring to_iso_extended_wstring(ptime t){
|
||||
return to_iso_extended_string_type<wchar_t>(t);
|
||||
}
|
||||
|
||||
#endif // BOOST_NO_STD_WSTRING
|
||||
|
||||
|
||||
} } //namespace posix_time
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
212
include/boost/date_time/posix_time/time_formatters_limited.hpp
Normal file
212
include/boost/date_time/posix_time/time_formatters_limited.hpp
Normal file
@@ -0,0 +1,212 @@
|
||||
#ifndef POSIXTIME_FORMATTERS_LIMITED_HPP___
|
||||
#define POSIXTIME_FORMATTERS_LIMITED_HPP___
|
||||
|
||||
/* Copyright (c) 2002,2003 CrystalClear Software, Inc.
|
||||
* 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
|
||||
* $Date$
|
||||
*/
|
||||
|
||||
#include <boost/date_time/gregorian/gregorian.hpp>
|
||||
#include <boost/date_time/compiler_config.hpp>
|
||||
#include <boost/date_time/iso_format.hpp>
|
||||
#include <boost/date_time/date_format_simple.hpp>
|
||||
#include <boost/date_time/posix_time/posix_time_types.hpp>
|
||||
#include <boost/date_time/time_formatting_streams.hpp>
|
||||
#include <boost/date_time/time_resolution_traits.hpp> // absolute_value
|
||||
|
||||
namespace boost {
|
||||
|
||||
namespace posix_time {
|
||||
|
||||
//! Time duration to string -hh::mm::ss.fffffff. Example: 10:09:03.0123456
|
||||
/*!\ingroup time_format
|
||||
*/
|
||||
inline std::string to_simple_string(time_duration td) {
|
||||
std::ostringstream ss;
|
||||
if(td.is_special()) {
|
||||
/* simply using 'ss << td.get_rep()' won't work on compilers
|
||||
* that don't support locales. This way does. */
|
||||
// switch copied from date_names_put.hpp
|
||||
switch(td.get_rep().as_special())
|
||||
{
|
||||
case not_a_date_time:
|
||||
//ss << "not-a-number";
|
||||
ss << "not-a-date-time";
|
||||
break;
|
||||
case pos_infin:
|
||||
ss << "+infinity";
|
||||
break;
|
||||
case neg_infin:
|
||||
ss << "-infinity";
|
||||
break;
|
||||
default:
|
||||
ss << "";
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(td.is_negative()) {
|
||||
ss << '-';
|
||||
}
|
||||
ss << std::setw(2) << std::setfill('0')
|
||||
<< date_time::absolute_value(td.hours()) << ":";
|
||||
ss << std::setw(2) << std::setfill('0')
|
||||
<< date_time::absolute_value(td.minutes()) << ":";
|
||||
ss << std::setw(2) << std::setfill('0')
|
||||
<< date_time::absolute_value(td.seconds());
|
||||
//TODO the following is totally non-generic, yelling FIXME
|
||||
#if (defined(BOOST_MSVC) && (_MSC_VER < 1300))
|
||||
boost::int64_t frac_sec =
|
||||
date_time::absolute_value(td.fractional_seconds());
|
||||
// JDG [7/6/02 VC++ compatibility]
|
||||
char buff[32];
|
||||
_i64toa(frac_sec, buff, 10);
|
||||
#else
|
||||
time_duration::fractional_seconds_type frac_sec =
|
||||
date_time::absolute_value(td.fractional_seconds());
|
||||
#endif
|
||||
if (frac_sec != 0) {
|
||||
ss << "." << std::setw(time_duration::num_fractional_digits())
|
||||
<< std::setfill('0')
|
||||
|
||||
// JDG [7/6/02 VC++ compatibility]
|
||||
#if (defined(BOOST_MSVC) && (_MSC_VER < 1300))
|
||||
<< buff;
|
||||
#else
|
||||
<< frac_sec;
|
||||
#endif
|
||||
}
|
||||
}// else
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
//! Time duration in ISO 8601 format -hhmmss.fffffff. Example: 10:09:03.0123456
|
||||
/*!\ingroup time_format
|
||||
*/
|
||||
inline
|
||||
std::string
|
||||
to_iso_string(time_duration td)
|
||||
{
|
||||
std::ostringstream ss;
|
||||
if(td.is_special()) {
|
||||
/* simply using 'ss << td.get_rep()' won't work on compilers
|
||||
* that don't support locales. This way does. */
|
||||
// switch copied from date_names_put.hpp
|
||||
switch(td.get_rep().as_special()) {
|
||||
case not_a_date_time:
|
||||
//ss << "not-a-number";
|
||||
ss << "not-a-date-time";
|
||||
break;
|
||||
case pos_infin:
|
||||
ss << "+infinity";
|
||||
break;
|
||||
case neg_infin:
|
||||
ss << "-infinity";
|
||||
break;
|
||||
default:
|
||||
ss << "";
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(td.is_negative()) {
|
||||
ss << '-';
|
||||
}
|
||||
ss << std::setw(2) << std::setfill('0')
|
||||
<< date_time::absolute_value(td.hours());
|
||||
ss << std::setw(2) << std::setfill('0')
|
||||
<< date_time::absolute_value(td.minutes());
|
||||
ss << std::setw(2) << std::setfill('0')
|
||||
<< date_time::absolute_value(td.seconds());
|
||||
//TODO the following is totally non-generic, yelling FIXME
|
||||
#if (defined(BOOST_MSVC) && (_MSC_VER < 1300))
|
||||
boost::int64_t frac_sec =
|
||||
date_time::absolute_value(td.fractional_seconds());
|
||||
// JDG [7/6/02 VC++ compatibility]
|
||||
char buff[32];
|
||||
_i64toa(frac_sec, buff, 10);
|
||||
#else
|
||||
time_duration::fractional_seconds_type frac_sec =
|
||||
date_time::absolute_value(td.fractional_seconds());
|
||||
#endif
|
||||
if (frac_sec != 0) {
|
||||
ss << "." << std::setw(time_duration::num_fractional_digits())
|
||||
<< std::setfill('0')
|
||||
|
||||
// JDG [7/6/02 VC++ compatibility]
|
||||
#if (defined(BOOST_MSVC) && (_MSC_VER < 1300))
|
||||
<< buff;
|
||||
#else
|
||||
<< frac_sec;
|
||||
#endif
|
||||
}
|
||||
}// else
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
//! Time to simple format CCYY-mmm-dd hh:mm:ss.fffffff
|
||||
/*!\ingroup time_format
|
||||
*/
|
||||
inline
|
||||
std::string
|
||||
to_simple_string(ptime t)
|
||||
{
|
||||
std::string ts = gregorian::to_simple_string(t.date());// + " ";
|
||||
if(!t.time_of_day().is_special()) {
|
||||
return ts + " " + to_simple_string(t.time_of_day());
|
||||
}
|
||||
else {
|
||||
return ts;
|
||||
}
|
||||
}
|
||||
|
||||
//! Convert to string of form [YYYY-mmm-DD HH:MM::SS.ffffff/YYYY-mmm-DD HH:MM::SS.fffffff]
|
||||
/*!\ingroup time_format
|
||||
*/
|
||||
inline
|
||||
std::string
|
||||
to_simple_string(time_period tp)
|
||||
{
|
||||
std::string d1(to_simple_string(tp.begin()));
|
||||
std::string d2(to_simple_string(tp.last()));
|
||||
return std::string("[" + d1 + "/" + d2 +"]");
|
||||
}
|
||||
|
||||
//! Convert ISO 8601 short form YYYYMMDDTHHMMSS where T is the date-time separator
|
||||
/*!\ingroup time_format
|
||||
*/
|
||||
inline
|
||||
std::string to_iso_string(ptime t)
|
||||
{
|
||||
std::string ts = gregorian::to_iso_string(t.date());// + "T";
|
||||
if(!t.time_of_day().is_special()) {
|
||||
return ts + "T" + to_iso_string(t.time_of_day());
|
||||
}
|
||||
else {
|
||||
return ts;
|
||||
}
|
||||
}
|
||||
|
||||
//! Convert to form YYYY-MM-DDTHH:MM:SS where T is the date-time separator
|
||||
/*!\ingroup time_format
|
||||
*/
|
||||
inline
|
||||
std::string
|
||||
to_iso_extended_string(ptime t)
|
||||
{
|
||||
std::string ts = gregorian::to_iso_extended_string(t.date());// + "T";
|
||||
if(!t.time_of_day().is_special()) {
|
||||
return ts + "T" + to_simple_string(t.time_of_day());
|
||||
}
|
||||
else {
|
||||
return ts;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} } //namespace posix_time
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
52
include/boost/date_time/posix_time/time_parsers.hpp
Normal file
52
include/boost/date_time/posix_time/time_parsers.hpp
Normal file
@@ -0,0 +1,52 @@
|
||||
#ifndef POSIXTIME_PARSERS_HPP___
|
||||
#define POSIXTIME_PARSERS_HPP___
|
||||
|
||||
/* Copyright (c) 2002,2003 CrystalClear Software, Inc.
|
||||
* 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
|
||||
* $Date$
|
||||
*/
|
||||
|
||||
#include "boost/date_time/gregorian/gregorian.hpp"
|
||||
#include "boost/date_time/time_parsing.hpp"
|
||||
#include "boost/date_time/posix_time/posix_time_types.hpp"
|
||||
|
||||
|
||||
namespace boost {
|
||||
|
||||
namespace posix_time {
|
||||
|
||||
//! Creates a time_duration object from a delimited string
|
||||
/*! Expected format for string is "[-]h[h][:mm][:ss][.fff]".
|
||||
* A negative duration will be created if the first character in
|
||||
* string is a '-', all other '-' will be treated as delimiters.
|
||||
* Accepted delimiters are "-:,.". */
|
||||
inline time_duration duration_from_string(const std::string& s) {
|
||||
return date_time::parse_delimited_time_duration<time_duration>(s);
|
||||
}
|
||||
|
||||
inline ptime time_from_string(const std::string& s) {
|
||||
return date_time::parse_delimited_time<ptime>(s, ' ');
|
||||
}
|
||||
|
||||
inline ptime from_iso_string(const std::string& s) {
|
||||
return date_time::parse_iso_time<ptime>(s, 'T');
|
||||
}
|
||||
|
||||
inline ptime from_iso_extended_string(const std::string& s) {
|
||||
if (s.size() == 10) { //assume we just have a date which is 10 chars
|
||||
gregorian::date d = gregorian::from_simple_string(s);
|
||||
return ptime( d );
|
||||
}
|
||||
return date_time::parse_delimited_time<ptime>(s, 'T');
|
||||
}
|
||||
|
||||
|
||||
|
||||
} } //namespace posix_time
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
29
include/boost/date_time/posix_time/time_period.hpp
Normal file
29
include/boost/date_time/posix_time/time_period.hpp
Normal file
@@ -0,0 +1,29 @@
|
||||
#ifndef POSIX_TIME_PERIOD_HPP___
|
||||
#define POSIX_TIME_PERIOD_HPP___
|
||||
|
||||
/* Copyright (c) 2002,2003 CrystalClear Software, Inc.
|
||||
* 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
|
||||
* $Date$
|
||||
*/
|
||||
|
||||
#include "boost/date_time/period.hpp"
|
||||
#include "boost/date_time/posix_time/posix_time_duration.hpp"
|
||||
#include "boost/date_time/posix_time/ptime.hpp"
|
||||
|
||||
namespace boost {
|
||||
namespace posix_time {
|
||||
|
||||
//! Time period type
|
||||
/*! \ingroup time_basics
|
||||
*/
|
||||
typedef date_time::period<ptime, time_duration> time_period;
|
||||
|
||||
|
||||
} }//namespace posix_time
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
262
include/boost/date_time/posix_time/time_serialize.hpp
Normal file
262
include/boost/date_time/posix_time/time_serialize.hpp
Normal file
@@ -0,0 +1,262 @@
|
||||
#ifndef POSIX_TIME_SERIALIZE_HPP___
|
||||
#define POSIX_TIME_SERIALIZE_HPP___
|
||||
|
||||
/* Copyright (c) 2004-2005 CrystalClear Software, Inc.
|
||||
* 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
|
||||
* $Date$
|
||||
*/
|
||||
|
||||
#include "boost/date_time/posix_time/posix_time.hpp"
|
||||
#include "boost/date_time/gregorian/greg_serialize.hpp"
|
||||
#include "boost/core/nvp.hpp"
|
||||
#include "boost/numeric/conversion/cast.hpp"
|
||||
#include "boost/type_traits/integral_constant.hpp"
|
||||
|
||||
// Define versions for serialization compatibility
|
||||
// alows the unit tests to make an older version to check compatibility
|
||||
#ifndef BOOST_DATE_TIME_POSIX_TIME_DURATION_VERSION
|
||||
#define BOOST_DATE_TIME_POSIX_TIME_DURATION_VERSION 1
|
||||
#endif
|
||||
|
||||
namespace boost {
|
||||
namespace serialization {
|
||||
|
||||
template<typename T>
|
||||
struct version;
|
||||
|
||||
template<>
|
||||
struct version<boost::posix_time::time_duration>
|
||||
: integral_constant<int, BOOST_DATE_TIME_POSIX_TIME_DURATION_VERSION>
|
||||
{
|
||||
};
|
||||
|
||||
// A macro to split serialize functions into save & load functions.
|
||||
// It is here to avoid dependency on Boost.Serialization just for the
|
||||
// BOOST_SERIALIZATION_SPLIT_FREE macro
|
||||
#define BOOST_DATE_TIME_SPLIT_FREE(T) \
|
||||
template<class Archive> \
|
||||
inline void serialize(Archive & ar, \
|
||||
T & t, \
|
||||
const unsigned int file_version) \
|
||||
{ \
|
||||
split_free(ar, t, file_version); \
|
||||
}
|
||||
|
||||
BOOST_DATE_TIME_SPLIT_FREE(boost::posix_time::ptime)
|
||||
BOOST_DATE_TIME_SPLIT_FREE(boost::posix_time::time_duration)
|
||||
BOOST_DATE_TIME_SPLIT_FREE(boost::posix_time::time_period)
|
||||
|
||||
#undef BOOST_DATE_TIME_SPLIT_FREE
|
||||
|
||||
/*** time_duration ***/
|
||||
|
||||
//! Function to save posix_time::time_duration objects using serialization lib
|
||||
/*! time_duration objects are broken down into 4 parts for serialization:
|
||||
* types are hour_type, min_type, sec_type, and fractional_seconds_type
|
||||
* as defined in the time_duration class
|
||||
*/
|
||||
template<class TimeResTraitsSize, class Archive>
|
||||
void save_td(Archive& ar, const posix_time::time_duration& td)
|
||||
{
|
||||
TimeResTraitsSize h = boost::numeric_cast<TimeResTraitsSize>(td.hours());
|
||||
TimeResTraitsSize m = boost::numeric_cast<TimeResTraitsSize>(td.minutes());
|
||||
TimeResTraitsSize s = boost::numeric_cast<TimeResTraitsSize>(td.seconds());
|
||||
posix_time::time_duration::fractional_seconds_type fs = td.fractional_seconds();
|
||||
ar & make_nvp("time_duration_hours", h);
|
||||
ar & make_nvp("time_duration_minutes", m);
|
||||
ar & make_nvp("time_duration_seconds", s);
|
||||
ar & make_nvp("time_duration_fractional_seconds", fs);
|
||||
}
|
||||
|
||||
template<class Archive>
|
||||
void save(Archive & ar,
|
||||
const posix_time::time_duration& td,
|
||||
unsigned int version)
|
||||
{
|
||||
// serialize a bool so we know how to read this back in later
|
||||
bool is_special = td.is_special();
|
||||
ar & make_nvp("is_special", is_special);
|
||||
if(is_special) {
|
||||
std::string s = to_simple_string(td);
|
||||
ar & make_nvp("sv_time_duration", s);
|
||||
}
|
||||
else {
|
||||
// Write support for earlier versions allows for upgrade compatibility testing
|
||||
// See load comments for version information
|
||||
if (version == 0) {
|
||||
save_td<int32_t>(ar, td);
|
||||
} else {
|
||||
save_td<int64_t>(ar, td);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//! Function to load posix_time::time_duration objects using serialization lib
|
||||
/*! time_duration objects are broken down into 4 parts for serialization:
|
||||
* types are hour_type, min_type, sec_type, and fractional_seconds_type
|
||||
* as defined in the time_duration class
|
||||
*/
|
||||
template<class TimeResTraitsSize, class Archive>
|
||||
void load_td(Archive& ar, posix_time::time_duration& td)
|
||||
{
|
||||
TimeResTraitsSize h(0);
|
||||
TimeResTraitsSize m(0);
|
||||
TimeResTraitsSize s(0);
|
||||
posix_time::time_duration::fractional_seconds_type fs(0);
|
||||
ar & make_nvp("time_duration_hours", h);
|
||||
ar & make_nvp("time_duration_minutes", m);
|
||||
ar & make_nvp("time_duration_seconds", s);
|
||||
ar & make_nvp("time_duration_fractional_seconds", fs);
|
||||
td = posix_time::time_duration(h, m, s, fs);
|
||||
}
|
||||
|
||||
template<class Archive>
|
||||
void load(Archive & ar,
|
||||
posix_time::time_duration & td,
|
||||
unsigned int version)
|
||||
{
|
||||
bool is_special = false;
|
||||
ar & make_nvp("is_special", is_special);
|
||||
if(is_special) {
|
||||
std::string s;
|
||||
ar & make_nvp("sv_time_duration", s);
|
||||
posix_time::special_values sv = gregorian::special_value_from_string(s);
|
||||
td = posix_time::time_duration(sv);
|
||||
}
|
||||
else {
|
||||
// Version "0" (Boost 1.65.1 or earlier, which used int32_t for day/hour/minute/second and
|
||||
// therefore suffered from the year 2038 issue.)
|
||||
// Version "0.5" (Boost 1.66.0 changed to std::time_t but did not increase the version;
|
||||
// it was missed in the original change, all code reviews, and there were no
|
||||
// static assertions to protect the code; further std::time_t can be 32-bit
|
||||
// or 64-bit so it reduced portability. This makes 1.66.0 hard to handle...)
|
||||
// Version "1" (Boost 1.67.0 or later uses int64_t and is properly versioned)
|
||||
|
||||
// If the size of any of these items changes, a new version is needed.
|
||||
BOOST_STATIC_ASSERT(sizeof(posix_time::time_duration::hour_type) == sizeof(boost::int64_t));
|
||||
BOOST_STATIC_ASSERT(sizeof(posix_time::time_duration::min_type) == sizeof(boost::int64_t));
|
||||
BOOST_STATIC_ASSERT(sizeof(posix_time::time_duration::sec_type) == sizeof(boost::int64_t));
|
||||
BOOST_STATIC_ASSERT(sizeof(posix_time::time_duration::fractional_seconds_type) == sizeof(boost::int64_t));
|
||||
|
||||
if (version == 0) {
|
||||
load_td<int32_t>(ar, td);
|
||||
} else {
|
||||
load_td<int64_t>(ar, td);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// no load_construct_data function provided as time_duration provides a
|
||||
// default constructor
|
||||
|
||||
/*** ptime ***/
|
||||
|
||||
//! Function to save posix_time::ptime objects using serialization lib
|
||||
/*! ptime objects are broken down into 2 parts for serialization:
|
||||
* a date object and a time_duration onject
|
||||
*/
|
||||
template<class Archive>
|
||||
void save(Archive & ar,
|
||||
const posix_time::ptime& pt,
|
||||
unsigned int /*version*/)
|
||||
{
|
||||
// from_iso_string does not include fractional seconds
|
||||
// therefore date and time_duration are used
|
||||
posix_time::ptime::date_type d = pt.date();
|
||||
ar & make_nvp("ptime_date", d);
|
||||
if(!pt.is_special()) {
|
||||
posix_time::ptime::time_duration_type td = pt.time_of_day();
|
||||
ar & make_nvp("ptime_time_duration", td);
|
||||
}
|
||||
}
|
||||
|
||||
//! Function to load posix_time::ptime objects using serialization lib
|
||||
/*! ptime objects are broken down into 2 parts for serialization:
|
||||
* a date object and a time_duration onject
|
||||
*/
|
||||
template<class Archive>
|
||||
void load(Archive & ar,
|
||||
posix_time::ptime & pt,
|
||||
unsigned int /*version*/)
|
||||
{
|
||||
// from_iso_string does not include fractional seconds
|
||||
// therefore date and time_duration are used
|
||||
posix_time::ptime::date_type d(posix_time::not_a_date_time);
|
||||
posix_time::ptime::time_duration_type td;
|
||||
ar & make_nvp("ptime_date", d);
|
||||
if(!d.is_special()) {
|
||||
ar & make_nvp("ptime_time_duration", td);
|
||||
pt = boost::posix_time::ptime(d,td);
|
||||
}
|
||||
else {
|
||||
pt = boost::posix_time::ptime(d.as_special());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//!override needed b/c no default constructor
|
||||
template<class Archive>
|
||||
inline void load_construct_data(Archive & /*ar*/,
|
||||
posix_time::ptime* pt,
|
||||
const unsigned int /*file_version*/)
|
||||
{
|
||||
// retrieve data from archive required to construct new
|
||||
// invoke inplace constructor to initialize instance of date
|
||||
new(pt) boost::posix_time::ptime(boost::posix_time::not_a_date_time);
|
||||
}
|
||||
|
||||
/*** time_period ***/
|
||||
|
||||
//! Function to save posix_time::time_period objects using serialization lib
|
||||
/*! time_period objects are broken down into 2 parts for serialization:
|
||||
* a begining ptime object and an ending ptime object
|
||||
*/
|
||||
template<class Archive>
|
||||
void save(Archive & ar,
|
||||
const posix_time::time_period& tp,
|
||||
unsigned int /*version*/)
|
||||
{
|
||||
posix_time::ptime beg(tp.begin().date(), tp.begin().time_of_day());
|
||||
posix_time::ptime end(tp.end().date(), tp.end().time_of_day());
|
||||
ar & make_nvp("time_period_begin", beg);
|
||||
ar & make_nvp("time_period_end", end);
|
||||
}
|
||||
|
||||
//! Function to load posix_time::time_period objects using serialization lib
|
||||
/*! time_period objects are broken down into 2 parts for serialization:
|
||||
* a begining ptime object and an ending ptime object
|
||||
*/
|
||||
template<class Archive>
|
||||
void load(Archive & ar,
|
||||
boost::posix_time::time_period & tp,
|
||||
unsigned int /*version*/)
|
||||
{
|
||||
posix_time::time_duration td(1,0,0);
|
||||
gregorian::date d(gregorian::not_a_date_time);
|
||||
posix_time::ptime beg(d,td);
|
||||
posix_time::ptime end(d,td);
|
||||
ar & make_nvp("time_period_begin", beg);
|
||||
ar & make_nvp("time_period_end", end);
|
||||
tp = boost::posix_time::time_period(beg, end);
|
||||
}
|
||||
|
||||
//!override needed b/c no default constructor
|
||||
template<class Archive>
|
||||
inline void load_construct_data(Archive & /*ar*/,
|
||||
boost::posix_time::time_period* tp,
|
||||
const unsigned int /*file_version*/)
|
||||
{
|
||||
posix_time::time_duration td(1,0,0);
|
||||
gregorian::date d(gregorian::not_a_date_time);
|
||||
posix_time::ptime beg(d,td);
|
||||
posix_time::ptime end(d,td);
|
||||
new(tp) boost::posix_time::time_period(beg,end);
|
||||
}
|
||||
|
||||
} // namespace serialization
|
||||
} // namespace boost
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user