boost中date_time源码解析

date

是year_month_day_base 的实例
date<T, calendar, duration_type_>
gregorian_calendar_base<ymd_type_, date_int_type_>
gregorian_calendar
year_month_day_base<YearType, MonthType, DayType>
greg_year_month_day

gregorian_calendar_base

gregorian_calendar:是date的模板类型参数calendar的一个实现
gregorian_calendar_base:ymd_type表示日历年月日的表示类型,需要是算术类型,date_int_type_是日期计数类型,也必须是算术类型
ymd_type的基础模板类为year_month_day_base
greg_year_month_day:是格林威治年月日类型,是year_month_day_base的模板实例类

greg_year_month_day 的类依赖关系

greg_year_month_day
greg_year
greg_month
greg_day
greg_year_rep
greg_month_rep
greg_day_rep
constrained_value<value_policies>
simple_exception_policy<rep_type, min_value, max_value, exception_type>
greg_day_policies
greg_year_policies
greg_month_policies

greg_year_rep:是constrained_value的模板实例类,类型为greg_year_policies
greg_month_rep:是constrained_value的模板实例类,类型为greg_month_policies
greg_day_rep :是constrained_value的模板实例类,类型为greg_day_policies
greg_day_policies:是simple_exception_policy的模板实例类,类型为unsigned short, 1, 31, bad_day_of_month
greg_month_policies:是simple_exception_policy的模板实例类,类型为unsigned short, 1, 12, bad_month
greg_year_policies:是simple_exception_policy的模板实例类,类型为unsigned short, 1400, 10000, bad_year
gregorian_calendar_base模板参数date_int_type_是在int_adapter中定义的类型,也是int_adapter的模板参数
int_adapter其支持正无穷大,负无穷大,以及非值

int_adapter<int_type_>

int_adapter中定义的类型有

typedef int_type_ int_type;

date_duration

date_duration<duration_rep_traits>
-duration_rep days_
duration_traits_long
duration_traits_adapted
weeks_duration<duration_config>
months_duration<base_config>
years_duration<base_config>
greg_durations_config

date_duration中定义了两个类型,其是模板类型参数duration_rep_traits中定义的

typedef typename duration_rep_traits::int_type duration_rep_type
typedef typename duration_rep_traits::impl_type duration_rep;

date_duration依赖的模板类型参数duration_rep_traits,有两个实现类型,
一个是duration_traits_long,另外一个是duration_traits_adapted。
duration_traits_long和duration_traits_adapted的int_type是long,duration_traits_long的impl_type是long,duration_traits_adapted的impl_type是int_adapter
years_duration和months_duration的模板类型参数base_config,在gregorian的类型实例为greg_durations_config
weeks_duration:用来表示有相隔多少个7天
months_duration:用来表示相隔多少个月
years_duration:用来表示相隔多少个年

period

用来表示日期区间,是左闭右开区间。

period<point_rep, duration_rep>
-point_rep begin_
-point_rep last_
period_formatter<CharT, OutItrT>
+put_period(OutItrT next, ios_base& a_ios, char_type a_fill, const period_type& p, const facet_type& facet)
period_parser<date_type, CharT>
+get_period(stream_itr_type& sitr, stream_itr_type& stream_end, ios_base& a_ios, const period_type& , const duration_type& dur_unit, const facet_type& facet)
date_facet
date_duration

period:设计成模板,支持point_rep为年,月,日,周等,duration_rep为对应的区间类型
period_formatter:其模板成员方法put_period会依赖于period和date_facet类型,其默认格式为[date1/date2]或者[date1/date2),闭区间形式和左闭右开区间形式

迭代器

«abstract»
date_itr_base<date_type>
-date_type current_
+duration_type get_offset(const date_type& current)
+duration_type get_neg_offset(const date_type& current)
date_itr<offset_functor, date_type>
-offset_functor of_
day_functor<date_type>
month_functor<date_type>
week_functor<date_type>
year_functor<date_type>

其中date_itr_base的get_offset和get_neg_offset为抽象方法
date_itr中的offset_functor 可能为day_functor,month_functor,week_functor或者year_functor中的一种

date_facet

为日期类型提供基于 I/O 方面的格式

date_facet<date_type, CharT, OutItrT>
# string_type m_format
# string_type m_month_format
# string_type m_weekday_format
# period_formatter_type m_period_formatter
#date_gen_formatter_type m_date_gen_formatter
#special_values_formatter_type m_special_values_formatter
#input_collection_type m_month_short_names
#input_collection_type m_month_long_names
#input_collection_type m_weekday_short_names
#input_collection_type m_weekday_long_names
#OutItrT do_put_special(OutItrT next,ios_base& /*a_ios*/, char_type /*fill_char*/, const special_values sv)
#OutItrT do_put_tm(OutItrT next,ios_base& a_ios,char_type fill_char,const tm& tm_value,string_type a_format)
period_formatter<CharT, OutItrT>
special_values_formatter<CharT, OutItrT>
date_generator_formatter<date_type, CharT, OutItrT>
date_input_facet<date_type, CharT, InItrT>
#string_type m_format
# string_type m_month_format
# string_type m_weekday_format
# string_type m_year_format
#format_date_parser_type m_parser
#date_gen_parser_type m_date_gen_parser
#period_parser_type m_period_parser
#special_values_parser_type m_sv_parser
period_parser<date_type, CharT>
special_values_parser<date_type, CharT>
format_date_parser<date_type, CharT>
date_generator_parser<date_type, CharT>
facet

date_facet内部的类型定义

    typedef typename date_type::duration_type duration_type;
    // greg_weekday is gregorian_calendar::day_of_week_type
    typedef typename date_type::day_of_week_type day_of_week_type;
    typedef typename date_type::day_type day_type;
    typedef typename date_type::month_type month_type;
    typedef boost::date_time::period<date_type,duration_type> period_type;
    typedef std::basic_string<CharT> string_type;
    typedef CharT                    char_type;
    typedef boost::date_time::period_formatter<CharT>  period_formatter_type;
    typedef boost::date_time::special_values_formatter<CharT>  special_values_formatter_type;
    typedef std::vector<std::basic_string<CharT> > input_collection_type;
    // used for the output of the date_generators
    typedef date_generator_formatter<date_type, CharT> date_gen_formatter_type;
    typedef partial_date<date_type>          partial_date_type;
    typedef nth_kday_of_month<date_type>     nth_kday_type;
    typedef first_kday_of_month<date_type>   first_kday_type;
    typedef last_kday_of_month<date_type>    last_kday_type;
    typedef first_kday_after<date_type>      kday_after_type;
    typedef first_kday_before<date_type>     kday_before_type;

date_input_facet内部的类型定义

    typedef typename date_type::duration_type duration_type;
    // greg_weekday is gregorian_calendar::day_of_week_type
    typedef typename date_type::day_of_week_type day_of_week_type;
    typedef typename date_type::day_type day_type;
    typedef typename date_type::month_type month_type;
    typedef typename date_type::year_type year_type;
    typedef boost::date_time::period<date_type,duration_type> period_type;
    typedef std::basic_string<CharT> string_type;
    typedef CharT                    char_type;
    typedef boost::date_time::period_parser<date_type, CharT>  period_parser_type;
    typedef boost::date_time::special_values_parser<date_type,CharT> special_values_parser_type;
    typedef std::vector<std::basic_string<CharT> > input_collection_type;
    typedef format_date_parser<date_type, CharT> format_date_parser_type;
    // date_generators stuff goes here
    typedef date_generator_parser<date_type, CharT> date_gen_parser_type;
    typedef partial_date<date_type>          partial_date_type;
    typedef nth_kday_of_month<date_type>     nth_kday_type;
    typedef first_kday_of_month<date_type>   first_kday_type;
    typedef last_kday_of_month<date_type>    last_kday_type;
    typedef first_kday_after<date_type>      kday_after_type;
    typedef first_kday_before<date_type>     kday_before_type;

gregorian

date

gregorian::date
date_time::date

date_duration

gregorian::date_duration
date_time::date_duration

gregorian_calendar

gregorian::gregorian_calendar
date_time::gregorian_calendar_base

time

base_time<T, time_system>
split_timedate_system<config>
counted_time_system<time_rep>

microsec_clock

微秒时钟,依赖于模板参数time_type

microsec_clock<time_type>

time_duration

time_duration<T, rep_type>
time_resolution_traits

time_resolution_traits

time_resolution_traits<frac_sec_type, time_resolutions res, typename frac_sec_type::int_type resolution_adjust, unsigned short frac_digits, typename v_type = boost::int32_t>

frac_sec_type:表示时间分辨就率特点类型
res:是时间分辨率枚举类型,支持的有

  enum time_resolutions {
    sec,
    tenth,
    hundreth, // deprecated misspelled version of hundredth
    hundredth = hundreth,
    milli,
    ten_thousandth,
    micro,
    nano,
    NumResolutions
  };

resolution_adjust:是frac_sec_type中定义的int_type类型

posix_time使用的是

typedef date_time::time_resolution_traits<
    boost::date_time::time_resolution_traits_adapted64_impl, boost::date_time::micro,
                                            1000000, 6 > time_res_traits

工具

ctime

提供将time_t转为tm,也支持多线程

ctime
std::tm* localtime(const std::time_t* t, std::tm* result)
std::tm* gmtime(const std::time_t* t, std::tm* result)

值约束以及策略

constrained_value<value_policies>
simple_exception_policy<rep_type, min_value, max_value, exception_type>

其中min_value和max_value表示类型为rep_type的最小值,最大值

day_clock

提供天级别的时间服务,基于time_t,转为tm

day_clock<date_type>
+date_type local_day()
+ymd_type local_day_ymd()
+ymd_type universal_day_ymd()
+date_type universal_day()
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

kgduu

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值