Back to home page

EIC code displayed by LXR

 
 

    


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 /* 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 /*! @file time_clock.hpp
0013   This file contains the interface for clock devices.
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   //! A clock providing time level services based on C time_t capabilities
0024   /*! This clock provides resolution to the 1 second level
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       //curr_ptr = ::std::localtime(&t);
0039       curr_ptr = c_time::localtime(&t, &curr);
0040       return create_time(curr_ptr);
0041     }
0042 
0043 
0044     //! Get the current day in universal date as a ymd_type
0045     static time_type universal_time()
0046     {
0047 
0048       ::std::time_t t;
0049       ::std::time(&t);
0050       ::std::tm curr, *curr_ptr;
0051       //curr_ptr = ::std::gmtime(&t);
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 } } //namespace date_time
0081 
0082 
0083 #endif