1 #ifndef DATE_CLOCK_DEVICE_HPP___
2 #define DATE_CLOCK_DEVICE_HPP___
4 /* Copyright (c) 2002,2003,2005 CrystalClear Software, Inc.
5 * Use, modification and distribution is subject to the
6 * Boost Software License, Version 1.0. (See accompanying
7 * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
8 * Author: Jeff Garland, Bart Garst
12 #include "boost/date_time/c_time.hpp"
18 //! A clock providing day level services based on C time_t capabilities
19 /*! This clock uses Posix interfaces as its implementation and hence
20 * uses the timezone settings of the operating system. Incorrect
21 * user settings will result in incorrect results for the calls
24 template<class date_type>
28 typedef typename date_type::ymd_type ymd_type;
29 //! Get the local day as a date type
30 static date_type local_day()
32 return date_type(local_day_ymd());
34 //! Get the local day as a ymd_type
35 static typename date_type::ymd_type local_day_ymd()
38 ::std::tm* curr = get_local_time(result);
39 return ymd_type(static_cast<unsigned short>(curr->tm_year + 1900),
40 static_cast<unsigned short>(curr->tm_mon + 1),
41 static_cast<unsigned short>(curr->tm_mday));
43 //! Get the current day in universal date as a ymd_type
44 static typename date_type::ymd_type universal_day_ymd()
47 ::std::tm* curr = get_universal_time(result);
48 return ymd_type(static_cast<unsigned short>(curr->tm_year + 1900),
49 static_cast<unsigned short>(curr->tm_mon + 1),
50 static_cast<unsigned short>(curr->tm_mday));
52 //! Get the UTC day as a date type
53 static date_type universal_day()
55 return date_type(universal_day_ymd());
59 static ::std::tm* get_local_time(std::tm& result)
63 return c_time::localtime(&t, &result);
65 static ::std::tm* get_universal_time(std::tm& result)
69 return c_time::gmtime(&t, &result);
74 } } //namespace date_time