File indexing completed on 2025-01-18 09:30:39
0001 #ifndef DATE_TIME_TIME_CLOCK_HPP___
0002 #define DATE_TIME_TIME_CLOCK_HPP___
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #include "boost/date_time/c_time.hpp"
0017 #include "boost/shared_ptr.hpp"
0018
0019 namespace boost {
0020 namespace date_time {
0021
0022
0023
0024
0025
0026 template<class time_type>
0027 class second_clock
0028 {
0029 public:
0030 typedef typename time_type::date_type date_type;
0031 typedef typename time_type::time_duration_type time_duration_type;
0032
0033 static time_type local_time()
0034 {
0035 ::std::time_t t;
0036 ::std::time(&t);
0037 ::std::tm curr, *curr_ptr;
0038
0039 curr_ptr = c_time::localtime(&t, &curr);
0040 return create_time(curr_ptr);
0041 }
0042
0043
0044
0045 static time_type universal_time()
0046 {
0047
0048 ::std::time_t t;
0049 ::std::time(&t);
0050 ::std::tm curr, *curr_ptr;
0051
0052 curr_ptr = c_time::gmtime(&t, &curr);
0053 return create_time(curr_ptr);
0054 }
0055
0056 template<class time_zone_type>
0057 static time_type local_time(boost::shared_ptr<time_zone_type> tz_ptr)
0058 {
0059 typedef typename time_type::utc_time_type utc_time_type;
0060 utc_time_type utc_time = second_clock<utc_time_type>::universal_time();
0061 return time_type(utc_time, tz_ptr);
0062 }
0063
0064
0065 private:
0066 static time_type create_time(::std::tm* current)
0067 {
0068 date_type d(static_cast<unsigned short>(current->tm_year + 1900),
0069 static_cast<unsigned short>(current->tm_mon + 1),
0070 static_cast<unsigned short>(current->tm_mday));
0071 time_duration_type td(current->tm_hour,
0072 current->tm_min,
0073 current->tm_sec);
0074 return time_type(d,td);
0075 }
0076
0077 };
0078
0079
0080 } }
0081
0082
0083 #endif