date_time_facet.h
//
// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOSTER_LOCALE_DATE_TIME_FACET_H_INCLUDED
#define BOOSTER_LOCALE_DATE_TIME_FACET_H_INCLUDED
#include <booster/config.h>
#ifdef BOOSTER_MSVC
# pragma warning(push)
# pragma warning(disable : 4275 4251 4231 4660)
#endif
#include <booster/cstdint.h>
#include <locale>
namespace booster {
namespace locale {
namespace period {
namespace marks {
enum period_mark {
invalid,
era,
year,
extended_year,
month,
day,
day_of_year,
day_of_week,
day_of_week_in_month,
day_of_week_local,
hour,
hour_12,
am_pm,
minute,
second,
week_of_year,
week_of_month,
first_day_of_week,
};
} // marks
class period_type {
public:
period_type(marks::period_mark m = marks::invalid) : mark_(m)
{
}
marks::period_mark mark() const
{
return mark_;
}
bool operator==(period_type const &other) const
{
return mark()==other.mark();
}
bool operator!=(period_type const &other) const
{
return mark()!=other.mark();
}
private:
marks::period_mark mark_;
};
} // namespace period
struct posix_time {
int64_t seconds;
uint32_t nanoseconds;
};
class abstract_calendar {
public:
typedef enum {
absolute_minimum,
actual_minimum,
greatest_minimum,
current,
least_maximum,
actual_maximum,
absolute_maximum,
} value_type;
typedef enum {
move,
roll,
} update_type;
typedef enum {
is_gregorian,
is_dst
} calendar_option_type;
virtual abstract_calendar *clone() const = 0;
virtual void set_value(period::marks::period_mark p,int value) = 0;
virtual void normalize() = 0;
virtual int get_value(period::marks::period_mark p,value_type v) const = 0;
virtual void set_time(posix_time const &p) = 0;
virtual posix_time get_time() const = 0;
virtual void set_option(calendar_option_type opt,int v) = 0;
virtual int get_option(calendar_option_type opt) const = 0;
virtual void adjust_value(period::marks::period_mark p,update_type u,int difference) = 0;
virtual int difference(abstract_calendar const *other,period::marks::period_mark p) const = 0;
virtual void set_timezone(std::string const &tz) = 0;
virtual std::string get_timezone() const = 0;
virtual bool same(abstract_calendar const *other) const = 0;
virtual ~abstract_calendar()
{
}
};
class BOOSTER_API calendar_facet : public std::locale::facet {
public:
calendar_facet(size_t refs = 0) : std::locale::facet(refs)
{
}
virtual abstract_calendar *create_calendar() const = 0;
static std::locale::id id;
};
} // locale
} // boost
#ifdef BOOSTER_MSVC
#pragma warning(pop)
#endif
#endif
// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
booster::locale::abstract_calendar::normalize
virtual void normalize()=0
booster::locale::abstract_calendar::roll
Change the value up or down not effecting others for example 1990-12-31 + 1 day = 1990-12-01...
Definition: date_time_facet.h:144
booster::locale::period::marks::minute
minute [0..59]
Definition: date_time_facet.h:50
booster::locale::period::marks::week_of_year
The week number in the year.
Definition: date_time_facet.h:52
booster::locale::abstract_calendar::adjust_value
virtual void adjust_value(period::marks::period_mark p, update_type u, int difference)=0
booster::locale::period::marks::second
second [0..59]
Definition: date_time_facet.h:51
booster::locale::period::marks::week_of_month
The week number within current month.
Definition: date_time_facet.h:53
booster::locale::abstract_calendar::set_option
virtual void set_option(calendar_option_type opt, int v)=0
booster::locale::abstract_calendar::difference
virtual int difference(abstract_calendar const *other, period::marks::period_mark p) const =0
booster::locale::period::period_type::mark
marks::period_mark mark() const
Definition: date_time_facet.h:82
booster::locale::period::marks::period_mark
period_mark
the type that defines a flag that holds a period identifier
Definition: date_time_facet.h:31
booster::locale::abstract_calendar::value_type
value_type
Definition: date_time_facet.h:128
booster::locale::posix_time::nanoseconds
uint32_t nanoseconds
Nanoseconds resolution.
Definition: date_time_facet.h:113
booster::locale::abstract_calendar::get_option
virtual int get_option(calendar_option_type opt) const =0
booster::locale::abstract_calendar::get_value
virtual int get_value(period::marks::period_mark p, value_type v) const =0
booster::locale::period::marks::day
The day of month, calendar specific, in Gregorian [1..31].
Definition: date_time_facet.h:37
booster::locale::period::marks::hour
24 clock hour [0..23]
Definition: date_time_facet.h:47
booster::locale::abstract_calendar
Definition: date_time_facet.h:122
booster::locale::abstract_calendar::is_dst
Check if the current time is in daylight time savings.
Definition: date_time_facet.h:152
booster::locale::abstract_calendar::clone
virtual abstract_calendar * clone() const =0
booster::locale::period::marks::day_of_week_local
Local day of week, for example in France Monday is 1, in US Sunday is 1, [1..7].
Definition: date_time_facet.h:46
booster::locale::abstract_calendar::least_maximum
Definition: date_time_facet.h:133
booster::locale::period::marks::first_day_of_week
First day of week, constant, for example Sunday in US = 1, Monday in France = 2.
Definition: date_time_facet.h:54
booster::locale::abstract_calendar::absolute_maximum
Maximal value, for Gregorian day it would be 31.
Definition: date_time_facet.h:136
booster::locale::posix_time::seconds
int64_t seconds
Seconds since epoch.
Definition: date_time_facet.h:112
booster::locale::abstract_calendar::move
Change the value up or down effecting others for example 1990-12-31 + 1 day = 1991-01-01.
Definition: date_time_facet.h:143
booster::locale::period::marks::year
Year, it is calendar specific, for example 2011 in Gregorian calendar.
Definition: date_time_facet.h:34
booster::locale::calendar_facet::id
static std::locale::id id
Definition: date_time_facet.h:250
booster::locale::period::marks::extended_year
Extended year for Gregorian/Julian calendars, where 1 BC == 0, 2 BC == -1.
Definition: date_time_facet.h:35
booster::locale::period::marks::invalid
Special invalid value, should not be used directly.
Definition: date_time_facet.h:32
booster::locale::abstract_calendar::actual_maximum
Actual maximum, for it can be 28, 29, 30, 31 for day according to current month.
Definition: date_time_facet.h:135
booster::locale::posix_time
Definition: date_time_facet.h:111
booster::locale::period::marks::hour_12
12 clock hour [0..11]
Definition: date_time_facet.h:48
booster::locale::period::marks::day_of_year
The number of day in year, starting from 1, in Gregorian [1..366].
Definition: date_time_facet.h:38
booster::locale::abstract_calendar::greatest_minimum
Maximal minimum value that can be for this period.
Definition: date_time_facet.h:131
booster::locale::period::period_type::period_type
period_type(marks::period_mark m=marks::invalid)
Definition: date_time_facet.h:75
booster::locale::period::marks::day_of_week
Definition: date_time_facet.h:39
booster::locale::period::period_type
This class holds a type that represents certain period of time like year, hour, second and so on...
Definition: date_time_facet.h:70
booster::locale::period::marks::am_pm
am or pm marker [0..1]
Definition: date_time_facet.h:49
booster::locale::abstract_calendar::is_gregorian
Check if the calendar is Gregorian.
Definition: date_time_facet.h:151
booster::locale::abstract_calendar::actual_minimum
Actual minimal value for this period.
Definition: date_time_facet.h:130
booster::locale::abstract_calendar::set_time
virtual void set_time(posix_time const &p)=0
booster::locale::period::period_type::operator!=
bool operator!=(period_type const &other) const
Definition: date_time_facet.h:97
booster::locale::period::marks::day_of_week_in_month
Definition: date_time_facet.h:44
booster::locale::period::period_type::operator==
bool operator==(period_type const &other) const
Definition: date_time_facet.h:90
booster::locale::abstract_calendar::current
Current value of this period.
Definition: date_time_facet.h:132
booster::locale::abstract_calendar::get_timezone
virtual std::string get_timezone() const =0
booster::locale::abstract_calendar::get_time
virtual posix_time get_time() const =0
booster::locale::period::marks::era
Era i.e. AC, BC in Gregorian and Julian calendar, range [0,1].
Definition: date_time_facet.h:33
booster::locale::abstract_calendar::update_type
update_type
Definition: date_time_facet.h:142
booster::locale::calendar_facet
the facet that generates calendar for specific locale
Definition: date_time_facet.h:234
booster::locale::abstract_calendar::calendar_option_type
calendar_option_type
Definition: date_time_facet.h:150
booster::locale::period::marks::month
The month of year, calendar specific, in Gregorian [0..11].
Definition: date_time_facet.h:36
booster::locale::abstract_calendar::absolute_minimum
Absolute possible minimum for the value, for example for day is 1.
Definition: date_time_facet.h:129
booster::locale::abstract_calendar::set_timezone
virtual void set_timezone(std::string const &tz)=0
booster::locale::abstract_calendar::same
virtual bool same(abstract_calendar const *other) const =0
booster::locale::calendar_facet::calendar_facet
calendar_facet(size_t refs=0)
Definition: date_time_facet.h:239
booster::locale::abstract_calendar::set_value
virtual void set_value(period::marks::period_mark p, int value)=0