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. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 //
8 #ifndef BOOST_LOCALE_DATE_TIME_FACET_HPP_INCLUDED
9 #define BOOST_LOCALE_DATE_TIME_FACET_HPP_INCLUDED
10 
11 #include <boost/locale/config.hpp>
12 #ifdef BOOST_MSVC
13 # pragma warning(push)
14 # pragma warning(disable : 4275 4251 4231 4660)
15 #endif
16 
17 #include <boost/cstdint.hpp>
18 #include <locale>
19 
20 namespace boost {
21  namespace locale {
25  namespace period {
29  namespace marks {
31  enum period_mark {
33  era,
34  year,
37  day,
47  hour,
55  };
56 
57  } // marks
58 
70  class period_type {
71  public:
76  {
77  }
78 
83  {
84  return mark_;
85  }
86 
90  bool operator==(period_type const &other) const
91  {
92  return mark()==other.mark();
93  }
97  bool operator!=(period_type const &other) const
98  {
99  return mark()!=other.mark();
100  }
101  private:
102  marks::period_mark mark_;
103  };
104 
105  } // namespace period
106 
111  struct posix_time {
112  int64_t seconds;
113  uint32_t nanoseconds;
114  };
115 
121 
123  public:
124 
128  typedef enum {
137  } value_type;
138 
142  typedef enum {
145  } update_type;
146 
150  typedef enum {
154 
158  virtual abstract_calendar *clone() const = 0;
159 
170  virtual void set_value(period::marks::period_mark p,int value) = 0;
171 
175  virtual void normalize() = 0;
176 
180  virtual int get_value(period::marks::period_mark p,value_type v) const = 0;
181 
185  virtual void set_time(posix_time const &p) = 0;
189  virtual posix_time get_time() const = 0;
190 
194  virtual void set_option(calendar_option_type opt,int v) = 0;
198  virtual int get_option(calendar_option_type opt) const = 0;
199 
205 
209  virtual int difference(abstract_calendar const *other,period::marks::period_mark p) const = 0;
210 
214  virtual void set_timezone(std::string const &tz) = 0;
218  virtual std::string get_timezone() const = 0;
219 
223  virtual bool same(abstract_calendar const *other) const = 0;
224 
225  virtual ~abstract_calendar()
226  {
227  }
228 
229  };
230 
234  class BOOST_LOCALE_DECL calendar_facet : public std::locale::facet {
235  public:
239  calendar_facet(size_t refs = 0) : std::locale::facet(refs)
240  {
241  }
245  virtual abstract_calendar *create_calendar() const = 0;
246 
250  static std::locale::id id;
251  };
252 
253  } // locale
254 } // boost
255 
256 #ifdef BOOST_MSVC
257 #pragma warning(pop)
258 #endif
259 
260 
261 #endif
262 // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
263 
period_mark
the type that defines a flag that holds a period identifier
Definition: date_time_facet.hpp:31
virtual void set_value(period::marks::period_mark p, int value)=0
The week number within current month.
Definition: date_time_facet.hpp:53
virtual bool same(abstract_calendar const *other) const =0
Definition: date_time_facet.hpp:44
the facet that generates calendar for specific locale
Definition: date_time_facet.hpp:234
Check if the current time is in daylight time savings.
Definition: date_time_facet.hpp:152
Definition: date_time_facet.hpp:39
Year, it is calendar specific, for example 2011 in Gregorian calendar.
Definition: date_time_facet.hpp:34
calendar_facet(size_t refs=0)
Definition: date_time_facet.hpp:239
Definition: date_time_facet.hpp:133
Actual minimal value for this period.
Definition: date_time_facet.hpp:130
virtual int difference(abstract_calendar const *other, period::marks::period_mark p) const =0
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:135
int64_t seconds
Seconds since epoch.
Definition: date_time_facet.hpp:112
The number of day in year, starting from 1, in Gregorian [1..366].
Definition: date_time_facet.hpp:38
Check if the calendar is Gregorian.
Definition: date_time_facet.hpp:151
calendar_option_type
Definition: date_time_facet.hpp:150
virtual void set_timezone(std::string const &tz)=0
uint32_t nanoseconds
Nanoseconds resolution.
Definition: date_time_facet.hpp:113
virtual int get_value(period::marks::period_mark p, 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:143
Definition: date_time_facet.hpp:122
The week number in the year.
Definition: date_time_facet.hpp:52
24 clock hour [0..23]
Definition: date_time_facet.hpp:47
Special invalid value, should not be used directly.
Definition: date_time_facet.hpp:32
Definition: date_time_facet.hpp:111
The day of month, calendar specific, in Gregorian [1..31].
Definition: date_time_facet.hpp:37
minute [0..59]
Definition: date_time_facet.hpp:50
bool operator!=(period_type const &other) const
Definition: date_time_facet.hpp:97
Absolute possible minimum for the value, for example for day is 1.
Definition: date_time_facet.hpp:129
update_type
Definition: date_time_facet.hpp:142
The month of year, calendar specific, in Gregorian [0..11].
Definition: date_time_facet.hpp:36
Local day of week, for example in France Monday is 1, in US Sunday is 1, [1..7].
Definition: date_time_facet.hpp:46
virtual posix_time get_time() const =0
bool operator==(period_type const &other) const
Definition: date_time_facet.hpp:90
12 clock hour [0..11]
Definition: date_time_facet.hpp:48
virtual void set_option(calendar_option_type opt, int v)=0
am or pm marker [0..1]
Definition: date_time_facet.hpp:49
Maximal value, for Gregorian day it would be 31.
Definition: date_time_facet.hpp:136
virtual void set_time(posix_time const &p)=0
value_type
Definition: date_time_facet.hpp:128
virtual std::string get_timezone() const =0
marks::period_mark mark() const
Definition: date_time_facet.hpp:82
static std::locale::id id
Definition: date_time_facet.hpp:250
Era i.e. AC, BC in Gregorian and Julian calendar, range [0,1].
Definition: date_time_facet.hpp:33
Change the value up or down not effecting others for example 1990-12-31 + 1 day = 1990-12-01...
Definition: date_time_facet.hpp:144
First day of week, constant, for example Sunday in US = 1, Monday in France = 2.
Definition: date_time_facet.hpp:54
Extended year for Gregorian/Julian calendars, where 1 BC == 0, 2 BC == -1.
Definition: date_time_facet.hpp:35
Current value of this period.
Definition: date_time_facet.hpp:132
Maximal minimum value that can be for this period.
Definition: date_time_facet.hpp:131
second [0..59]
Definition: date_time_facet.hpp:51
virtual abstract_calendar * clone() const =0
period_type(marks::period_mark m=marks::invalid)
Definition: date_time_facet.hpp:75
virtual void adjust_value(period::marks::period_mark p, update_type u, int difference)=0
This class holds a type that represents certain period of time like year, hour, second and so on...
Definition: date_time_facet.hpp:70