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 { namespace locale {
20 
22  namespace period {
23 
25  namespace marks {
26 
28  enum period_mark {
30  era,
31  year,
34  day,
44  hour,
52  };
53 
54  } // namespace marks
55 
65  class period_type {
66  public:
69 
71  marks::period_mark mark() const { return mark_; }
72 
74  bool operator==(const period_type& other) const { return mark() == other.mark(); }
76  bool operator!=(const period_type& other) const { return mark() != other.mark(); }
77 
78  private:
79  marks::period_mark mark_;
80  };
81 
82  } // namespace period
83 
86  struct posix_time {
87  int64_t seconds;
88  uint32_t nanoseconds;
89  };
90 
94  class BOOST_LOCALE_DECL abstract_calendar {
95  public:
97  enum value_type {
102  least_maximum,
103  actual_maximum,
106  };
107 
109  enum update_type {
112  };
113 
117  is_dst
118  };
119 
121  virtual abstract_calendar* clone() const = 0;
122 
131  virtual void set_value(period::marks::period_mark m, int value) = 0;
132 
134  virtual void normalize() = 0;
135 
137  virtual int get_value(period::marks::period_mark m, value_type v) const = 0;
138 
140  virtual void set_time(const posix_time& p) = 0;
142  virtual posix_time get_time() const = 0;
144  virtual double get_time_ms() const = 0;
145 
147  virtual void set_option(calendar_option_type opt, int v) = 0;
149  virtual int get_option(calendar_option_type opt) const = 0;
150 
153  virtual void adjust_value(period::marks::period_mark m, update_type u, int difference) = 0;
154 
156  virtual int difference(const abstract_calendar& other, period::marks::period_mark m) const = 0;
157 
159  virtual void set_timezone(const std::string& tz) = 0;
161  virtual std::string get_timezone() const = 0;
162 
164  virtual bool same(const abstract_calendar* other) const = 0;
165 
166  virtual ~abstract_calendar();
167  };
168 
170  class BOOST_LOCALE_DECL calendar_facet : public std::locale::facet {
171  public:
173  calendar_facet(size_t refs = 0) : std::locale::facet(refs) {}
174  ~calendar_facet();
176  virtual abstract_calendar* create_calendar() const = 0;
177 
179  static std::locale::id id;
180  };
181 
182 }} // namespace boost::locale
183 
184 #ifdef BOOST_MSVC
185 # pragma warning(pop)
186 #endif
187 
188 #endif
period_mark
the type that defines a flag that holds a period identifier
Definition: date_time_facet.hpp:28
The week number within current month.
Definition: date_time_facet.hpp:50
Definition: date_time_facet.hpp:41
the facet that generates calendar for specific locale
Definition: date_time_facet.hpp:170
std::basic_string< CharType > normalize(const CharType *begin, const CharType *end, norm_type n=norm_default, const std::locale &loc=std::locale())
Definition: conversion.hpp:127
marks::period_mark mark() const
Get the value of marks::period_mark it was created with.
Definition: date_time_facet.hpp:71
Definition: date_time_facet.hpp:36
Year, it is calendar specific, for example 2011 in Gregorian calendar.
Definition: date_time_facet.hpp:31
calendar_facet(size_t refs=0)
Basic constructor.
Definition: date_time_facet.hpp:173
Actual minimal value for this period.
Definition: date_time_facet.hpp:99
bool operator==(const period_type &other) const
Check if two periods are the same.
Definition: date_time_facet.hpp:74
int64_t seconds
Seconds since epoch.
Definition: date_time_facet.hpp:87
The number of day in year, starting from 1, in Gregorian [1..366].
Definition: date_time_facet.hpp:35
Check if the calendar is Gregorian.
Definition: date_time_facet.hpp:116
bool operator!=(const period_type &other) const
Check if two periods are different.
Definition: date_time_facet.hpp:76
calendar_option_type
Information about calendar.
Definition: date_time_facet.hpp:115
uint32_t nanoseconds
Nanoseconds resolution.
Definition: date_time_facet.hpp:88
Change the value up or down effecting others for example 1990-12-31 + 1 day = 1991-01-01.
Definition: date_time_facet.hpp:110
Definition: date_time_facet.hpp:94
The week number in the year.
Definition: date_time_facet.hpp:49
24 clock hour [0..23]
Definition: date_time_facet.hpp:44
Special invalid value, should not be used directly.
Definition: date_time_facet.hpp:29
Definition: date_time_facet.hpp:86
The day of month, calendar specific, in Gregorian [1..31].
Definition: date_time_facet.hpp:34
minute [0..59]
Definition: date_time_facet.hpp:47
Absolute possible minimum for the value, for example for day is 1.
Definition: date_time_facet.hpp:98
update_type
A way to update the value.
Definition: date_time_facet.hpp:109
The month of year, calendar specific, in Gregorian [0..11].
Definition: date_time_facet.hpp:33
Local day of week, for example in France Monday is 1, in US Sunday is 1, [1..7].
Definition: date_time_facet.hpp:43
12 clock hour [0..11]
Definition: date_time_facet.hpp:45
am or pm marker [0..1]
Definition: date_time_facet.hpp:46
Maximal value, for Gregorian day it would be 31.
Definition: date_time_facet.hpp:105
value_type
Type that defines how to fetch the value.
Definition: date_time_facet.hpp:97
static std::locale::id id
Locale id (needed to work with std::locale)
Definition: date_time_facet.hpp:179
Era i.e. AC, BC in Gregorian and Julian calendar, range [0,1].
Definition: date_time_facet.hpp:30
Change the value up or down not effecting others for example 1990-12-31 + 1 day = 1990-12-01.
Definition: date_time_facet.hpp:111
First day of week, constant, for example Sunday in US = 1, Monday in France = 2.
Definition: date_time_facet.hpp:51
Extended year for Gregorian/Julian calendars, where 1 BC == 0, 2 BC == -1.
Definition: date_time_facet.hpp:32
Current value of this period.
Definition: date_time_facet.hpp:101
Maximal minimum value that can be for this period.
Definition: date_time_facet.hpp:100
second [0..59]
Definition: date_time_facet.hpp:48
period_type(marks::period_mark m=marks::invalid)
Create a period of specific type, default is invalid.
Definition: date_time_facet.hpp:68
This class holds a type that represents certain period of time like year, hour, second and so on.
Definition: date_time_facet.hpp:65