File indexing completed on 2025-01-30 09:35:21
0001 #ifndef DATE_CLOCK_DEVICE_HPP___
0002 #define DATE_CLOCK_DEVICE_HPP___
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #include "boost/date_time/c_time.hpp"
0013
0014
0015 namespace boost {
0016 namespace date_time {
0017
0018
0019
0020
0021
0022
0023
0024 template<class date_type>
0025 class day_clock
0026 {
0027 public:
0028 typedef typename date_type::ymd_type ymd_type;
0029
0030 static date_type local_day()
0031 {
0032 return date_type(local_day_ymd());
0033 }
0034
0035 static typename date_type::ymd_type local_day_ymd()
0036 {
0037 ::std::tm result;
0038 ::std::tm* curr = get_local_time(result);
0039 return ymd_type(static_cast<unsigned short>(curr->tm_year + 1900),
0040 static_cast<unsigned short>(curr->tm_mon + 1),
0041 static_cast<unsigned short>(curr->tm_mday));
0042 }
0043
0044 static typename date_type::ymd_type universal_day_ymd()
0045 {
0046 ::std::tm result;
0047 ::std::tm* curr = get_universal_time(result);
0048 return ymd_type(static_cast<unsigned short>(curr->tm_year + 1900),
0049 static_cast<unsigned short>(curr->tm_mon + 1),
0050 static_cast<unsigned short>(curr->tm_mday));
0051 }
0052
0053 static date_type universal_day()
0054 {
0055 return date_type(universal_day_ymd());
0056 }
0057
0058 private:
0059 static ::std::tm* get_local_time(std::tm& result)
0060 {
0061 ::std::time_t t;
0062 ::std::time(&t);
0063 return c_time::localtime(&t, &result);
0064 }
0065 static ::std::tm* get_universal_time(std::tm& result)
0066 {
0067 ::std::time_t t;
0068 ::std::time(&t);
0069 return c_time::gmtime(&t, &result);
0070 }
0071
0072 };
0073
0074 } }
0075
0076
0077 #endif