BVB Source Codes

mars Show date_formatting_limited.hpp Source code

Return Download mars: download date_formatting_limited.hpp Source code - Download mars Source code - Type:.hpp
  1. #ifndef DATE_TIME_DATE_FORMATTING_LIMITED_HPP___
  2. #define DATE_TIME_DATE_FORMATTING_LIMITED_HPP___
  3.  
  4. /* Copyright (c) 2002-2004 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/iso_format.hpp"
  13. #include "boost/date_time/compiler_config.hpp"
  14. #include <string>
  15. #include <sstream>
  16. #include <iomanip>
  17.  
  18.  
  19. namespace mars_boost {} namespace boost = mars_boost; namespace mars_boost {
  20. namespace date_time {
  21.  
  22.   //! Formats a month as as string into an ostream
  23.   template<class month_type, class format_type>
  24.   class month_formatter
  25.   {
  26.   public:
  27.     //! Formats a month as as string into an ostream
  28.     /*! This function demands that month_type provide
  29.      *  functions for converting to short and long strings
  30.      *  if that capability is used.
  31.      */
  32.     static std::ostream& format_month(const month_type& month,
  33.                                       std::ostream& os)
  34.     {
  35.       switch (format_type::month_format())
  36.       {
  37.         case month_as_short_string:
  38.         {
  39.           os << month.as_short_string();
  40.           break;
  41.         }
  42.         case month_as_long_string:
  43.         {
  44.           os << month.as_long_string();
  45.           break;
  46.         }
  47.         case month_as_integer:
  48.         {
  49.           os << std::setw(2) << std::setfill('0') << month.as_number();
  50.           break;
  51.         }
  52.      
  53.       }
  54.       return os;
  55.     } // format_month
  56.   };
  57.  
  58.  
  59.   //! Convert ymd to a standard string formatting policies
  60.   template<class ymd_type, class format_type>
  61.   class ymd_formatter
  62.   {
  63.   public:
  64.     //! Convert ymd to a standard string formatting policies
  65.     /*! This is standard code for handling date formatting with
  66.      *  year-month-day based date information.  This function
  67.      *  uses the format_type to control whether the string will
  68.      *  contain separator characters, and if so what the character
  69.      *  will be.  In addtion, it can format the month as either
  70.      *  an integer or a string as controled by the formatting
  71.      *  policy
  72.      */
  73.     static std::string ymd_to_string(ymd_type ymd)
  74.     {
  75.       typedef typename ymd_type::month_type month_type;
  76.       std::ostringstream ss;
  77.       ss << ymd.year;
  78.       if (format_type::has_date_sep_chars()) {
  79.         ss << format_type::month_sep_char();
  80.       }
  81.       //this name is a bit ugly, oh well....
  82.       month_formatter<month_type,format_type>::format_month(ymd.month, ss);
  83.       if (format_type::has_date_sep_chars()) {
  84.         ss << format_type::day_sep_char();
  85.       }
  86.       ss  << std::setw(2) << std::setfill('0')
  87.           << ymd.day;
  88.       return ss.str();
  89.     }
  90.   };
  91.  
  92.  
  93.   //! Convert a date to string using format policies
  94.   template<class date_type, class format_type>
  95.   class date_formatter
  96.   {
  97.   public:
  98.     //! Convert to a date to standard string using format policies
  99.     static std::string date_to_string(date_type d)
  100.     {
  101.       typedef typename date_type::ymd_type ymd_type;
  102.       if (d.is_not_a_date()) {
  103.         return format_type::not_a_date();
  104.       }
  105.       if (d.is_neg_infinity()) {
  106.         return format_type::neg_infinity();
  107.       }
  108.       if (d.is_pos_infinity()) {
  109.         return format_type::pos_infinity();
  110.       }
  111.       ymd_type ymd = d.year_month_day();
  112.       return ymd_formatter<ymd_type, format_type>::ymd_to_string(ymd);
  113.     }    
  114.   };
  115.  
  116.  
  117. } } //namespace date_time
  118.  
  119.  
  120. #endif
  121.  
  122.  
downloaddate_formatting_limited.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