diff options
author | Remko Tronçon <git@el-tramo.be> | 2010-04-11 18:19:17 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2010-04-11 19:20:07 (GMT) |
commit | 857e44c156a1dbefcb49bb5792c4384cebd8762a (patch) | |
tree | 11947fb81ad9c502627f1b2bb8f090fb8d53c107 /3rdParty/Boost/src/boost/date_time/gregorian/conversion.hpp | |
parent | 77d4eb7588e113beaa03f3347523b26adefdeb06 (diff) | |
download | swift-857e44c156a1dbefcb49bb5792c4384cebd8762a.zip swift-857e44c156a1dbefcb49bb5792c4384cebd8762a.tar.bz2 |
Updated Boost to 1.42.
Diffstat (limited to '3rdParty/Boost/src/boost/date_time/gregorian/conversion.hpp')
-rw-r--r-- | 3rdParty/Boost/src/boost/date_time/gregorian/conversion.hpp | 66 |
1 files changed, 28 insertions, 38 deletions
diff --git a/3rdParty/Boost/src/boost/date_time/gregorian/conversion.hpp b/3rdParty/Boost/src/boost/date_time/gregorian/conversion.hpp index 4428c05..f35796e 100644 --- a/3rdParty/Boost/src/boost/date_time/gregorian/conversion.hpp +++ b/3rdParty/Boost/src/boost/date_time/gregorian/conversion.hpp @@ -2,75 +2,65 @@ #define _GREGORIAN__CONVERSION_HPP___ /* Copyright (c) 2004-2005 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 - * $Date: 2008-11-12 14:37:53 -0500 (Wed, 12 Nov 2008) $ + * $Date: 2009-06-06 07:27:35 -0400 (Sat, 06 Jun 2009) $ */ #include <string> #include <stdexcept> #include <boost/throw_exception.hpp> -#include <boost/date_time/gregorian/gregorian_types.hpp> #include <boost/date_time/c_time.hpp> -#if defined(USE_DATE_TIME_PRE_1_33_FACET_IO) -# if defined(BOOST_DATE_TIME_INCLUDE_LIMITED_HEADERS) -# include <boost/date_time/gregorian/formatters_limited.hpp> -# else -# include <boost/date_time/gregorian/formatters.hpp> -# endif // BOOST_DATE_TIME_INCLUDE_LIMITED_HEADERS -#else -# include <sstream> -# include <boost/date_time/gregorian/gregorian_io.hpp> -#endif // USE_DATE_TIME_PRE_1_33_FACET_IO +#include <boost/date_time/special_defs.hpp> +#include <boost/date_time/gregorian/gregorian_types.hpp> namespace boost { namespace gregorian { - //! Converts a date to a tm struct. Throws out_of_range exception if date is a special value inline - std::tm to_tm(const date& d) + std::tm to_tm(const date& d) { - if(d.is_pos_infinity() || d.is_neg_infinity() || d.is_not_a_date()){ - std::string s = "tm unable to handle date value of "; -#if defined(USE_DATE_TIME_PRE_1_33_FACET_IO) - s += to_simple_string(d); -#else - std::ostringstream ss; - ss << d; - s += ss.str(); -#endif // USE_DATE_TIME_PRE_1_33_FACET_IO - boost::throw_exception(std::out_of_range(s)); + if (d.is_special()) + { + std::string s = "tm unable to handle "; + switch (d.as_special()) + { + case date_time::not_a_date_time: + s += "not-a-date-time value"; break; + case date_time::neg_infin: + s += "-infinity date value"; break; + case date_time::pos_infin: + s += "+infinity date value"; break; + default: + s += "a special date value"; break; + } + boost::throw_exception(std::out_of_range(s)); } - std::tm datetm; + + std::tm datetm = {}; // zero initialization is needed for extension members, like tm_zone boost::gregorian::date::ymd_type ymd = d.year_month_day(); - datetm.tm_year = ymd.year-1900; - datetm.tm_mon = ymd.month-1; + datetm.tm_year = ymd.year - 1900; + datetm.tm_mon = ymd.month - 1; datetm.tm_mday = ymd.day; datetm.tm_wday = d.day_of_week(); - datetm.tm_yday = d.day_of_year()-1; - datetm.tm_hour = datetm.tm_min = datetm.tm_sec = 0; + datetm.tm_yday = d.day_of_year() - 1; datetm.tm_isdst = -1; // negative because not enough info to set tm_isdst return datetm; } //! Converts a tm structure into a date dropping the any time values. inline - date date_from_tm(const std::tm& datetm) + date date_from_tm(const std::tm& datetm) { - return date(static_cast<unsigned short>(datetm.tm_year+1900), - static_cast<unsigned short>(datetm.tm_mon+1), + return date(static_cast<unsigned short>(datetm.tm_year+1900), + static_cast<unsigned short>(datetm.tm_mon+1), static_cast<unsigned short>(datetm.tm_mday)); } - } } //namespace boost::gregorian - - - #endif - |