Boost.Locale
date_time_facet.hpp
1 //
2 // Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
3 //
4 // Distributed under the Boost Software License, Version 1.0.
5 // https://www.boost.org/LICENSE_1_0.txt
6 
7 #ifndef BOOST_LOCALE_DATE_TIME_FACET_HPP_INCLUDED
8 #define BOOST_LOCALE_DATE_TIME_FACET_HPP_INCLUDED
9 
10 #include <boost/locale/config.hpp>
11 #include <boost/cstdint.hpp>
12 #include <locale>
13 
14 #ifdef BOOST_MSVC
15 # pragma warning(push)
16 # pragma warning(disable : 4275 4251 4231 4660)
17 #endif
18 
19 namespace boost {
20  namespace locale {
24  namespace period {
28  namespace marks {
30  enum period_mark {
32  era,
33  year,
36  day,
46  hour,
54  };
55 
56  } // marks
57 
69  class period_type {
70  public:
75  {
76  }
77 
82  {
83  return mark_;
84  }
85 
89  bool operator==(period_type const &other) const
90  {
91  return mark()==other.mark();
92  }
96  bool operator!=(period_type const &other) const
97  {
98  return mark()!=other.mark();
99  }
100  private:
101  marks::period_mark mark_;
102  };
103 
104  } // namespace period
105 
110  struct posix_time {
111  int64_t seconds;
112  uint32_t nanoseconds;
113  };
114 
120 
122  public:
123 
127  typedef enum {
136  } value_type;
137 
141  typedef enum {
144  } update_type;
145 
149  typedef enum {
153 
157  virtual abstract_calendar *clone() const = 0;
158 
169  virtual void set_value(period::marks::period_mark m,int value) = 0;
170 
174  virtual void normalize() = 0;
175 
179  virtual int get_value(period::marks::period_mark m,value_type v) const = 0;
180 
184  virtual void set_time(posix_time const &p) = 0;
188  virtual posix_time get_time() const = 0;
189 
193  virtual void set_option(calendar_option_type opt,int v) = 0;
197  virtual int get_option(calendar_option_type opt) const = 0;
198 
204 
208  virtual int difference(abstract_calendar const *other,period::marks::period_mark m) const = 0;
209 
213  virtual void set_timezone(std::string const &tz) = 0;
217  virtual std::string get_timezone() const = 0;
218 
222  virtual bool same(abstract_calendar const *other) const = 0;
223 
224  virtual ~abstract_calendar() {}
225  };
226 
230  class BOOST_LOCALE_DECL calendar_facet : public std::locale::facet {
231  public:
235  calendar_facet(size_t refs = 0) : std::locale::facet(refs)
236  {
237  }
241  virtual abstract_calendar *create_calendar() const = 0;
242 
246  static std::locale::id id;
247  };
248 
249  } // locale
250 } // boost
251 
252 #ifdef BOOST_MSVC
253 #pragma warning(pop)
254 #endif
255 
256 
257 #endif
258 
period_mark
the type that defines a flag that holds a period identifier
Definition: date_time_facet.hpp:30
bool operator==(period_type const &other) const
Definition: date_time_facet.hpp:89
The week number within current month.
Definition: date_time_facet.hpp:52
virtual bool same(abstract_calendar const *other) const =0
Definition: date_time_facet.hpp:43
the facet that generates calendar for specific locale
Definition: date_time_facet.hpp:230
Check if the current time is in daylight time savings.
Definition: date_time_facet.hpp:151
bool operator!=(period_type const &other) const
Definition: date_time_facet.hpp:96
marks::period_mark mark() const
Definition: date_time_facet.hpp:81
Definition: date_time_facet.hpp:38
Year, it is calendar specific, for example 2011 in Gregorian calendar.
Definition: date_time_facet.hpp:33
calendar_facet(size_t refs=0)
Definition: date_time_facet.hpp:235
Definition: date_time_facet.hpp:132
Actual minimal value for this period.
Definition: date_time_facet.hpp:129
virtual int get_option(calendar_option_type opt) const =0
Actual maximum, for it can be 28, 29, 30, 31 for day according to current month.
Definition: date_time_facet.hpp:134
int64_t seconds
Seconds since epoch.
Definition: date_time_facet.hpp:111
The number of day in year, starting from 1, in Gregorian [1..366].
Definition: date_time_facet.hpp:37
Check if the calendar is Gregorian.
Definition: date_time_facet.hpp:150
virtual void adjust_value(period::marks::period_mark m, update_type u, int difference)=0
calendar_option_type
Definition: date_time_facet.hpp:149
virtual void set_timezone(std::string const &tz)=0
uint32_t nanoseconds
Nanoseconds resolution.
Definition: date_time_facet.hpp:112
virtual int get_value(period::marks::period_mark m, value_type v) const =0
Change the value up or down effecting others for example 1990-12-31 + 1 day = 1991-01-01.
Definition: date_time_facet.hpp:142
virtual int difference(abstract_calendar const *other, period::marks::period_mark m) const =0
Definition: date_time_facet.hpp:121
The week number in the year.
Definition: date_time_facet.hpp:51
24 clock hour [0..23]
Definition: date_time_facet.hpp:46
Special invalid value, should not be used directly.
Definition: date_time_facet.hpp:31
Definition: date_time_facet.hpp:110
The day of month, calendar specific, in Gregorian [1..31].
Definition: date_time_facet.hpp:36
minute [0..59]
Definition: date_time_facet.hpp:49
Absolute possible minimum for the value, for example for day is 1.
Definition: date_time_facet.hpp:128
update_type
Definition: date_time_facet.hpp:141
The month of year, calendar specific, in Gregorian [0..11].
Definition: date_time_facet.hpp:35
Local day of week, for example in France Monday is 1, in US Sunday is 1, [1..7].
Definition: date_time_facet.hpp:45
virtual posix_time get_time() const =0
12 clock hour [0..11]
Definition: date_time_facet.hpp:47
virtual void set_option(calendar_option_type opt, int v)=0
am or pm marker [0..1]
Definition: date_time_facet.hpp:48
Maximal value, for Gregorian day it would be 31.
Definition: date_time_facet.hpp:135
virtual void set_time(posix_time const &p)=0
value_type
Definition: date_time_facet.hpp:127
virtual std::string get_timezone() const =0
static std::locale::id id
Definition: date_time_facet.hpp:246
Era i.e. AC, BC in Gregorian and Julian calendar, range [0,1].
Definition: date_time_facet.hpp:32
Change the value up or down not effecting others for example 1990-12-31 + 1 day = 1990-12-01.
Definition: date_time_facet.hpp:143
First day of week, constant, for example Sunday in US = 1, Monday in France = 2.
Definition: date_time_facet.hpp:53
Extended year for Gregorian/Julian calendars, where 1 BC == 0, 2 BC == -1.
Definition: date_time_facet.hpp:34
Current value of this period.
Definition: date_time_facet.hpp:131
Maximal minimum value that can be for this period.
Definition: date_time_facet.hpp:130
second [0..59]
Definition: date_time_facet.hpp:50
virtual abstract_calendar * clone() const =0
period_type(marks::period_mark m=marks::invalid)
Definition: date_time_facet.hpp:74
virtual void set_value(period::marks::period_mark m, int value)=0
This class holds a type that represents certain period of time like year, hour, second and so on.
Definition: date_time_facet.hpp:69