Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:35:21

0001 #ifndef DATE_CLOCK_DEVICE_HPP___
0002 #define DATE_CLOCK_DEVICE_HPP___
0003 
0004 /* Copyright (c) 2002,2003,2005 CrystalClear Software, Inc.
0005  * Use, modification and distribution is subject to the 
0006  * Boost Software License, Version 1.0. (See accompanying
0007  * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
0008  * Author: Jeff Garland, Bart Garst
0009  * $Date$
0010  */
0011 
0012 #include "boost/date_time/c_time.hpp"
0013 
0014 
0015 namespace boost {
0016 namespace date_time {
0017 
0018   //! A clock providing day level services based on C time_t capabilities
0019   /*! This clock uses Posix interfaces as its implementation and hence
0020    *  uses the timezone settings of the operating system.  Incorrect
0021    *  user settings will result in incorrect results for the calls
0022    *  to local_day.
0023    */
0024   template<class date_type> 
0025   class day_clock
0026   {
0027   public:
0028     typedef typename date_type::ymd_type ymd_type;
0029     //! Get the local day as a date type
0030     static date_type local_day() 
0031     {
0032       return date_type(local_day_ymd());
0033     }
0034     //! Get the local day as a ymd_type
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     //! Get the current day in universal date as a ymd_type
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     //! Get the UTC day as a date type
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 } } //namespace date_time
0075 
0076 
0077 #endif