1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/ossrv_pub/boost_apis/boost/date_time/date.hpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,197 @@
1.4 +#ifndef DATE_TIME_DATE_HPP___
1.5 +#define DATE_TIME_DATE_HPP___
1.6 +
1.7 +/* Copyright (c) 2002,2003 CrystalClear Software, Inc.
1.8 + * Use, modification and distribution is subject to the
1.9 + * Boost Software License, Version 1.0. (See accompanying
1.10 + * file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
1.11 + * Author: Jeff Garland, Bart Garst
1.12 + * $Date: 2004/01/11 17:41:21 $
1.13 + */
1.14 +
1.15 +#include "boost/date_time/year_month_day.hpp"
1.16 +#include "boost/date_time/special_defs.hpp"
1.17 +#include "boost/operators.hpp"
1.18 +
1.19 +namespace boost {
1.20 +namespace date_time {
1.21 +
1.22 + //!Representation of timepoint at the one day level resolution.
1.23 + /*!
1.24 + The date template represents an interface shell for a date class
1.25 + that is based on a year-month-day system such as the gregorian
1.26 + or iso systems. It provides basic operations to enable calculation
1.27 + and comparisons.
1.28 +
1.29 + <b>Theory</b>
1.30 +
1.31 + This date representation fundamentally departs from the C tm struct
1.32 + approach. The goal for this type is to provide efficient date
1.33 + operations (add, subtract) and storage (minimize space to represent)
1.34 + in a concrete class. Thus, the date uses a count internally to
1.35 + represent a particular date. The calendar parameter defines
1.36 + the policies for converting the the year-month-day and internal
1.37 + counted form here. Applications that need to perform heavy
1.38 + formatting of the same date repeatedly will perform better
1.39 + by using the year-month-day representation.
1.40 +
1.41 + Internally the date uses a day number to represent the date.
1.42 + This is a monotonic time representation. This representation
1.43 + allows for fast comparison as well as simplifying
1.44 + the creation of writing numeric operations. Essentially, the
1.45 + internal day number is like adjusted julian day. The adjustment
1.46 + is determined by the Epoch date which is represented as day 1 of
1.47 + the calendar. Day 0 is reserved for negative infinity so that
1.48 + any actual date is automatically greater than negative infinity.
1.49 + When a date is constructed from a date or formatted for output,
1.50 + the appropriate conversions are applied to create the year, month,
1.51 + day representations.
1.52 + */
1.53 +
1.54 +
1.55 + template<class T, class calendar, class duration_type_>
1.56 + class date : private
1.57 + boost::less_than_comparable<T
1.58 + , boost::equality_comparable<T
1.59 + > >
1.60 + {
1.61 + public:
1.62 + typedef T date_type;
1.63 + typedef calendar calendar_type;
1.64 + typedef typename calendar::date_traits_type traits_type;
1.65 + typedef duration_type_ duration_type;
1.66 + typedef typename calendar::year_type year_type;
1.67 + typedef typename calendar::month_type month_type;
1.68 + typedef typename calendar::day_type day_type;
1.69 + typedef typename calendar::ymd_type ymd_type;
1.70 + typedef typename calendar::date_rep_type date_rep_type;
1.71 + typedef typename calendar::date_int_type date_int_type;
1.72 + typedef typename calendar::day_of_week_type day_of_week_type;
1.73 + date(year_type y, month_type m, day_type d)
1.74 + : days_(calendar::day_number(ymd_type(y, m, d)))
1.75 + {}
1.76 + date(const ymd_type& ymd)
1.77 + : days_(calendar::day_number(ymd))
1.78 + {}
1.79 + //let the compiler write copy, assignment, and destructor
1.80 + year_type year() const
1.81 + {
1.82 + ymd_type ymd = calendar::from_day_number(days_);
1.83 + return ymd.year;
1.84 + }
1.85 + month_type month() const
1.86 + {
1.87 + ymd_type ymd = calendar::from_day_number(days_);
1.88 + return ymd.month;
1.89 + }
1.90 + day_type day() const
1.91 + {
1.92 + ymd_type ymd = calendar::from_day_number(days_);
1.93 + return ymd.day;
1.94 + }
1.95 + day_of_week_type day_of_week() const
1.96 + {
1.97 + ymd_type ymd = calendar::from_day_number(days_);
1.98 + return calendar::day_of_week(ymd);
1.99 + }
1.100 + ymd_type year_month_day() const
1.101 + {
1.102 + return calendar::from_day_number(days_);
1.103 + }
1.104 + bool operator<(const date_type& rhs) const
1.105 + {
1.106 + return days_ < rhs.days_;
1.107 + }
1.108 + bool operator==(const date_type& rhs) const
1.109 + {
1.110 + return days_ == rhs.days_;
1.111 + }
1.112 + //! check to see if date is a special value
1.113 + bool is_special()const
1.114 + {
1.115 + return(is_not_a_date() || is_infinity());
1.116 + }
1.117 + //! check to see if date is not a value
1.118 + bool is_not_a_date() const
1.119 + {
1.120 + return traits_type::is_not_a_number(days_);
1.121 + }
1.122 + //! check to see if date is one of the infinity values
1.123 + bool is_infinity() const
1.124 + {
1.125 + return traits_type::is_inf(days_);
1.126 + }
1.127 + //! check to see if date is greater than all possible dates
1.128 + bool is_pos_infinity() const
1.129 + {
1.130 + return traits_type::is_pos_inf(days_);
1.131 + }
1.132 + //! check to see if date is greater than all possible dates
1.133 + bool is_neg_infinity() const
1.134 + {
1.135 + return traits_type::is_neg_inf(days_);
1.136 + }
1.137 + //! return as a special value or a not_special if a normal date
1.138 + special_values as_special() const
1.139 + {
1.140 + return traits_type::to_special(days_);
1.141 + }
1.142 + duration_type operator-(const date_type& d) const
1.143 + {
1.144 + date_rep_type val = date_rep_type(days_) - date_rep_type(d.days_);
1.145 + return duration_type(val.as_number());
1.146 + }
1.147 +
1.148 + date_type operator-(const duration_type& dd) const
1.149 + {
1.150 + if(dd.is_special())
1.151 + {
1.152 + return date_type(date_rep_type(days_) - dd.get_rep());
1.153 + }
1.154 + return date_type(date_rep_type(days_) - dd.days());
1.155 + }
1.156 + date_type operator-=(const duration_type& dd)
1.157 + {
1.158 + *this = *this - dd;
1.159 + return date_type(days_);
1.160 + }
1.161 + date_rep_type day_count() const
1.162 + {
1.163 + return days_;
1.164 + };
1.165 + //allow internal access from operators
1.166 + date_type operator+(const duration_type& dd) const
1.167 + {
1.168 + if(dd.is_special())
1.169 + {
1.170 + return date_type(date_rep_type(days_) + dd.get_rep());
1.171 + }
1.172 + return date_type(date_rep_type(days_) + dd.days());
1.173 + }
1.174 + date_type operator+=(const duration_type& dd)
1.175 + {
1.176 + *this = *this + dd;
1.177 + return date_type(days_);
1.178 + }
1.179 +
1.180 + //see reference
1.181 + protected:
1.182 + /*! This is a private constructor which allows for the creation of new
1.183 + dates. It is not exposed to users since that would require class
1.184 + users to understand the inner workings of the date class.
1.185 + */
1.186 + explicit date(date_int_type days) : days_(days) {};
1.187 + explicit date(date_rep_type days) : days_(days.as_number()) {};
1.188 + date_int_type days_;
1.189 +
1.190 + };
1.191 +
1.192 +
1.193 +
1.194 +
1.195 +} } // namespace date_time
1.196 +
1.197 +
1.198 +
1.199 +
1.200 +#endif