BVB Source Codes

mars Show date_clock_device.hpp Source code

Return Download mars: download date_clock_device.hpp Source code - Download mars Source code - Type:.hpp
  1. #ifndef DATE_CLOCK_DEVICE_HPP___
  2. #define DATE_CLOCK_DEVICE_HPP___
  3.  
  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
  9.  * $Date$
  10.  */
  11.  
  12. #include "boost/date_time/c_time.hpp"
  13.  
  14.  
  15. namespace mars_boost {} namespace boost = mars_boost; namespace mars_boost {
  16. namespace date_time {
  17.  
  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
  22.    *  to local_day.
  23.    */
  24.   template<class date_type>
  25.   class day_clock
  26.   {
  27.   public:
  28.     typedef typename date_type::ymd_type ymd_type;
  29.     //! Get the local day as a date type
  30.     static date_type local_day()
  31.     {
  32.       return date_type(local_day_ymd());
  33.     }
  34.     //! Get the local day as a ymd_type
  35.     static typename date_type::ymd_type local_day_ymd()
  36.     {
  37.       ::std::tm result;
  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));
  42.     }
  43.     //! Get the current day in universal date as a ymd_type
  44.     static typename date_type::ymd_type universal_day_ymd()
  45.     {
  46.       ::std::tm result;
  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));
  51.     }
  52.     //! Get the UTC day as a date type
  53.     static date_type universal_day()
  54.     {
  55.       return date_type(universal_day_ymd());
  56.     }
  57.  
  58.   private:
  59.     static ::std::tm* get_local_time(std::tm& result)
  60.     {
  61.       ::std::time_t t;
  62.       ::std::time(&t);
  63.       return c_time::localtime(&t, &result);
  64.     }
  65.     static ::std::tm* get_universal_time(std::tm& result)
  66.     {
  67.       ::std::time_t t;
  68.       ::std::time(&t);
  69.       return c_time::gmtime(&t, &result);
  70.     }
  71.  
  72.   };
  73.  
  74. } } //namespace date_time
  75.  
  76.  
  77. #endif
  78.  
downloaddate_clock_device.hpp Source code - Download mars Source code
Related Source Codes/Software:
Hero - Elegant transition library for iOS & tvOS 2017-06-09
deep-photo-styletransfer - Code and data for paper "Deep Photo Style Transfer... 2017-06-09
mastodon - A GNU Social-compatible microblogging server ... 2017-06-09
plyr - A simple HTML5, YouTube and Vimeo player ... 2017-06-08
prepack - Prepack is a partial evaluator for JavaScript. Pre... 2017-06-08
Public-APIs - 2017-06-09
lottie-ios - An iOS library to natively render After Effects ve... 2017-06-09
Awesome-Hacking - A collection of various awesome lists for hackers,... 2017-06-09
algorithms - Minimal examples of data structures and algorithms... 2017-06-10
lectures - Oxford Deep NLP 2017 course 2017-06-10
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top