Skip to content

Commit

Permalink
Added missing datetime stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
taxilian committed Sep 30, 2010
1 parent e33daf8 commit 78d5a1f
Show file tree
Hide file tree
Showing 22 changed files with 3,721 additions and 0 deletions.
17 changes: 17 additions & 0 deletions boost/date_time.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef BOOST_DATE_TIME_ALL_HPP___
#define BOOST_DATE_TIME_ALL_HPP___

/* Copyright (c) 2006 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: 2008-02-27 15:00:24 -0500 (Wed, 27 Feb 2008) $
*/

// See www.boost.org/libs/date_time for documentation.

//gregorian and posix time included by indirectly
#include "boost/date_time/local_time/local_time.hpp"

#endif // BOOST_DATE_TIME_ALL_HPP___
66 changes: 66 additions & 0 deletions boost/date_time/c_local_time_adjustor.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#ifndef DATE_TIME_C_LOCAL_TIME_ADJUSTOR_HPP__
#define DATE_TIME_C_LOCAL_TIME_ADJUSTOR_HPP__

/* Copyright (c) 2002,2003,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: 2008-11-12 14:37:53 -0500 (Wed, 12 Nov 2008) $
*/

/*! @file c_local_time_adjustor.hpp
Time adjustment calculations based on machine
*/

#include <stdexcept>
#include <boost/throw_exception.hpp>
#include <boost/date_time/compiler_config.hpp>
#include <boost/date_time/c_time.hpp>

namespace boost {
namespace date_time {

//! Adjust to / from utc using the C API
/*! Warning!!! This class assumes that timezone settings of the
* machine are correct. This can be a very dangerous assumption.
*/
template<class time_type>
class c_local_adjustor {
public:
typedef typename time_type::time_duration_type time_duration_type;
typedef typename time_type::date_type date_type;
typedef typename date_type::duration_type date_duration_type;
//! Convert a utc time to local time
static time_type utc_to_local(const time_type& t)
{
date_type time_t_start_day(1970,1,1);
time_type time_t_start_time(time_t_start_day,time_duration_type(0,0,0));
if (t < time_t_start_time) {
boost::throw_exception(std::out_of_range("Cannot convert dates prior to Jan 1, 1970"));
BOOST_DATE_TIME_UNREACHABLE_EXPRESSION(return time_t_start_time); // should never reach
}
date_duration_type dd = t.date() - time_t_start_day;
time_duration_type td = t.time_of_day();
std::time_t t2 = dd.days()*86400 + td.hours()*3600 + td.minutes()*60 + td.seconds();
std::tm tms, *tms_ptr;
tms_ptr = c_time::localtime(&t2, &tms);
date_type d(static_cast<unsigned short>(tms_ptr->tm_year + 1900),
static_cast<unsigned short>(tms_ptr->tm_mon + 1),
static_cast<unsigned short>(tms_ptr->tm_mday));
time_duration_type td2(tms_ptr->tm_hour,
tms_ptr->tm_min,
tms_ptr->tm_sec,
t.time_of_day().fractional_seconds());

return time_type(d,td2);
}
};



} } //namespace date_time



#endif
75 changes: 75 additions & 0 deletions boost/date_time/dst_transition_generators.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/* Copyright (c) 2002,2003,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
*/
#ifndef DATE_TIME_DATE_DST_TRANSITION_DAY_GEN_HPP__
#define DATE_TIME_DATE_DST_TRANSITION_DAY_GEN_HPP__



namespace boost {
namespace date_time {

//! Defines base interface for calculating start and end date of daylight savings
template<class date_type>
class dst_day_calc_rule
{
public:
typedef typename date_type::year_type year_type;
virtual ~dst_day_calc_rule() {};
virtual date_type start_day(year_type y) const=0;
virtual std::string start_rule_as_string() const=0;
virtual date_type end_day(year_type y) const=0;
virtual std::string end_rule_as_string() const=0;

};

//! Canonical form for a class that provides day rule calculation
/*! This class is used to generate specific sets of dst rules
*
*@param spec Provides a specifiction of the function object types used
* to generate start and end days of daylight savings as well
* as the date type.
*/
template<class spec>
class day_calc_dst_rule : public dst_day_calc_rule<typename spec::date_type>
{
public:
typedef typename spec::date_type date_type;
typedef typename date_type::year_type year_type;
typedef typename spec::start_rule start_rule;
typedef typename spec::end_rule end_rule;
day_calc_dst_rule(start_rule dst_start,
end_rule dst_end) :
dst_start_(dst_start),
dst_end_(dst_end)
{}
virtual date_type start_day(year_type y) const
{
return dst_start_.get_date(y);
}
virtual std::string start_rule_as_string() const
{
return dst_start_.to_string();
}
virtual date_type end_day(year_type y) const
{
return dst_end_.get_date(y);
}
virtual std::string end_rule_as_string() const
{
return dst_end_.to_string();
}
private:
start_rule dst_start_;
end_rule dst_end_;
};


} }//namespace



#endif
Loading

0 comments on commit 78d5a1f

Please sign in to comment.