Chris@16: #ifndef DATE_TIME_TIME_CLOCK_HPP___ Chris@16: #define DATE_TIME_TIME_CLOCK_HPP___ Chris@16: Chris@16: /* Copyright (c) 2002,2003,2005 CrystalClear Software, Inc. Chris@16: * Use, modification and distribution is subject to the Chris@16: * Boost Software License, Version 1.0. (See accompanying Chris@16: * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) Chris@16: * Author: Jeff Garland, Bart Garst Chris@101: * $Date$ Chris@16: */ Chris@16: Chris@16: /*! @file time_clock.hpp Chris@16: This file contains the interface for clock devices. Chris@16: */ Chris@16: Chris@16: #include "boost/date_time/c_time.hpp" Chris@16: #include "boost/shared_ptr.hpp" Chris@16: Chris@16: namespace boost { Chris@16: namespace date_time { Chris@16: Chris@16: Chris@16: //! A clock providing time level services based on C time_t capabilities Chris@16: /*! This clock provides resolution to the 1 second level Chris@16: */ Chris@16: template Chris@16: class second_clock Chris@16: { Chris@16: public: Chris@16: typedef typename time_type::date_type date_type; Chris@16: typedef typename time_type::time_duration_type time_duration_type; Chris@16: Chris@16: static time_type local_time() Chris@16: { Chris@16: ::std::time_t t; Chris@16: ::std::time(&t); Chris@16: ::std::tm curr, *curr_ptr; Chris@16: //curr_ptr = ::std::localtime(&t); Chris@16: curr_ptr = c_time::localtime(&t, &curr); Chris@16: return create_time(curr_ptr); Chris@16: } Chris@16: Chris@16: Chris@16: //! Get the current day in universal date as a ymd_type Chris@16: static time_type universal_time() Chris@16: { Chris@16: Chris@16: ::std::time_t t; Chris@16: ::std::time(&t); Chris@16: ::std::tm curr, *curr_ptr; Chris@16: //curr_ptr = ::std::gmtime(&t); Chris@16: curr_ptr = c_time::gmtime(&t, &curr); Chris@16: return create_time(curr_ptr); Chris@16: } Chris@16: Chris@16: template Chris@16: static time_type local_time(boost::shared_ptr tz_ptr) Chris@16: { Chris@16: typedef typename time_type::utc_time_type utc_time_type; Chris@16: utc_time_type utc_time = second_clock::universal_time(); Chris@16: return time_type(utc_time, tz_ptr); Chris@16: } Chris@16: Chris@16: Chris@16: private: Chris@16: static time_type create_time(::std::tm* current) Chris@16: { Chris@16: date_type d(static_cast(current->tm_year + 1900), Chris@16: static_cast(current->tm_mon + 1), Chris@16: static_cast(current->tm_mday)); Chris@16: time_duration_type td(current->tm_hour, Chris@16: current->tm_min, Chris@16: current->tm_sec); Chris@16: return time_type(d,td); Chris@16: } Chris@16: Chris@16: }; Chris@16: Chris@16: Chris@16: } } //namespace date_time Chris@16: Chris@16: Chris@16: #endif