2 // Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
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)
8 #ifndef BOOST_LOCALE_DATE_TIME_HPP_INCLUDED
9 #define BOOST_LOCALE_DATE_TIME_HPP_INCLUDED
11 #include <boost/locale/config.hpp>
13 # pragma warning(push)
14 # pragma warning(disable : 4275 4251 4231 4660)
17 #include <boost/locale/hold_ptr.hpp>
18 #include <boost/locale/date_time_facet.hpp>
19 #include <boost/locale/formatting.hpp>
20 #include <boost/locale/time_zone.hpp>
29 /// \defgroup date_time Date, Time, Timezone and Calendar manipulations
31 /// This module provides various calendar, timezone and date time services
37 /// \brief This error is thrown in case of invalid state that occurred
39 class BOOST_SYMBOL_VISIBLE date_time_error : public std::runtime_error {
42 /// Constructor of date_time_error class
44 date_time_error(std::string const &e) : std::runtime_error(e) {}
49 /// \brief This class represents a pair of period_type and the integer
50 /// values that describes its amount. For example 3 days or 4 years.
52 /// Usually obtained as product of period_type and integer or
53 /// my calling a representative functions
54 /// For example day()*3 == date_time_period(day(),3) == day(3)
56 struct date_time_period
58 period::period_type type; ///< The type of period, i.e. era, year, day etc.
59 int value; ///< The value the actual number of \a periods
61 /// Operator + returns copy of itself
63 date_time_period operator+() const { return *this; }
65 /// Operator -, switches the sign of period
67 date_time_period operator-() const { return date_time_period(type,-value); }
70 /// Constructor that creates date_time_period from period_type \a f and a value \a v -- default 1.
72 date_time_period(period::period_type f=period::period_type(),int v=1) : type(f), value(v) {}
77 /// Get period_type for: special invalid value, should not be used directly
79 inline period_type invalid(){ return period_type(marks::invalid); }
81 /// Get period_type for: Era i.e. AC, BC in Gregorian and Julian calendar, range [0,1]
83 inline period_type era(){ return period_type(marks::era); }
85 /// Get period_type for: Year, it is calendar specific, for example 2011 in Gregorian calendar.
87 inline period_type year(){ return period_type(marks::year); }
89 /// Get period_type for: Extended year for Gregorian/Julian calendars, where 1 BC == 0, 2 BC == -1.
91 inline period_type extended_year(){ return period_type(marks::extended_year); }
93 /// Get period_type for: The month of year, calendar specific, in Gregorian [0..11]
95 inline period_type month(){ return period_type(marks::month); }
97 /// Get period_type for: The day of month, calendar specific, in Gregorian [1..31]
99 inline period_type day(){ return period_type(marks::day); }
101 /// Get period_type for: The number of day in year, starting from 1, in Gregorian [1..366]
103 inline period_type day_of_year(){ return period_type(marks::day_of_year); }
105 /// Get period_type for: Day of week, Sunday=1, Monday=2,..., Saturday=7.
107 /// Note that updating this value respects local day of week, so for example,
108 /// If first day of week is Monday and the current day is Tuesday then setting
109 /// the value to Sunday (1) would forward the date by 5 days forward and not backward
110 /// by two days as it could be expected if the numbers were taken as is.
112 inline period_type day_of_week(){ return period_type(marks::day_of_week); }
114 /// Get period_type for: Original number of the day of the week in month. For example 1st Sunday,
115 /// 2nd Sunday, etc. in Gregorian [1..5]
117 inline period_type day_of_week_in_month(){ return period_type(marks::day_of_week_in_month); }
119 /// Get period_type for: Local day of week, for example in France Monday is 1, in US Sunday is 1, [1..7]
121 inline period_type day_of_week_local(){ return period_type(marks::day_of_week_local); }
123 /// Get period_type for: 24 clock hour [0..23]
125 inline period_type hour(){ return period_type(marks::hour); }
127 /// Get period_type for: 12 clock hour [0..11]
129 inline period_type hour_12(){ return period_type(marks::hour_12); }
131 /// Get period_type for: am or pm marker [0..1]
133 inline period_type am_pm(){ return period_type(marks::am_pm); }
135 /// Get period_type for: minute [0..59]
137 inline period_type minute(){ return period_type(marks::minute); }
139 /// Get period_type for: second [0..59]
141 inline period_type second(){ return period_type(marks::second); }
143 /// Get period_type for: The week number in the year
145 inline period_type week_of_year(){ return period_type(marks::week_of_year); }
147 /// Get period_type for: The week number within current month
149 inline period_type week_of_month(){ return period_type(marks::week_of_month); }
151 /// Get period_type for: First day of week, constant, for example Sunday in US = 1, Monday in France = 2
153 inline period_type first_day_of_week(){ return period_type(marks::first_day_of_week); }
156 /// Get date_time_period for: Era i.e. AC, BC in Gregorian and Julian calendar, range [0,1]
158 inline date_time_period era(int v) { return date_time_period(era(),v); }
160 /// Get date_time_period for: Year, it is calendar specific, for example 2011 in Gregorian calendar.
162 inline date_time_period year(int v) { return date_time_period(year(),v); }
164 /// Get date_time_period for: Extended year for Gregorian/Julian calendars, where 1 BC == 0, 2 BC == -1.
166 inline date_time_period extended_year(int v) { return date_time_period(extended_year(),v); }
168 /// Get date_time_period for: The month of year, calendar specific, in Gregorian [0..11]
170 inline date_time_period month(int v) { return date_time_period(month(),v); }
172 /// Get date_time_period for: The day of month, calendar specific, in Gregorian [1..31]
174 inline date_time_period day(int v) { return date_time_period(day(),v); }
176 /// Get date_time_period for: The number of day in year, starting from 1, in Gregorian [1..366]
178 inline date_time_period day_of_year(int v) { return date_time_period(day_of_year(),v); }
180 /// Get date_time_period for: Day of week, Sunday=1, Monday=2,..., Saturday=7.
182 /// Note that updating this value respects local day of week, so for example,
183 /// If first day of week is Monday and the current day is Tuesday then setting
184 /// the value to Sunday (1) would forward the date by 5 days forward and not backward
185 /// by two days as it could be expected if the numbers were taken as is.
187 inline date_time_period day_of_week(int v) { return date_time_period(day_of_week(),v); }
189 /// Get date_time_period for: Original number of the day of the week in month. For example 1st Sunday,
190 /// 2nd Sunday, etc. in Gregorian [1..5]
192 inline date_time_period day_of_week_in_month(int v) { return date_time_period(day_of_week_in_month(),v); }
194 /// Get date_time_period for: Local day of week, for example in France Monday is 1, in US Sunday is 1, [1..7]
196 inline date_time_period day_of_week_local(int v) { return date_time_period(day_of_week_local(),v); }
198 /// Get date_time_period for: 24 clock hour [0..23]
200 inline date_time_period hour(int v) { return date_time_period(hour(),v); }
202 /// Get date_time_period for: 12 clock hour [0..11]
204 inline date_time_period hour_12(int v) { return date_time_period(hour_12(),v); }
206 /// Get date_time_period for: am or pm marker [0..1]
208 inline date_time_period am_pm(int v) { return date_time_period(am_pm(),v); }
210 /// Get date_time_period for: minute [0..59]
212 inline date_time_period minute(int v) { return date_time_period(minute(),v); }
214 /// Get date_time_period for: second [0..59]
216 inline date_time_period second(int v) { return date_time_period(second(),v); }
218 /// Get date_time_period for: The week number in the year
220 inline date_time_period week_of_year(int v) { return date_time_period(week_of_year(),v); }
222 /// Get date_time_period for: The week number within current month
224 inline date_time_period week_of_month(int v) { return date_time_period(week_of_month(),v); }
226 /// Get date_time_period for: First day of week, constant, for example Sunday in US = 1, Monday in France = 2
228 inline date_time_period first_day_of_week(int v) { return date_time_period(first_day_of_week(),v); }
231 /// Get predefined constant for January
233 inline date_time_period january() { return date_time_period(month(),0); }
235 /// Get predefined constant for February
237 inline date_time_period february() { return date_time_period(month(),1); }
239 /// Get predefined constant for March
241 inline date_time_period march() { return date_time_period(month(),2); }
243 /// Get predefined constant for April
245 inline date_time_period april() { return date_time_period(month(),3); }
247 /// Get predefined constant for May
249 inline date_time_period may() { return date_time_period(month(),4); }
251 /// Get predefined constant for June
253 inline date_time_period june() { return date_time_period(month(),5); }
255 /// Get predefined constant for July
257 inline date_time_period july() { return date_time_period(month(),6); }
259 /// Get predefined constant for August
261 inline date_time_period august() { return date_time_period(month(),7); }
263 /// Get predefined constant for September
265 inline date_time_period september() { return date_time_period(month(),8); }
267 /// Get predefined constant for October
269 inline date_time_period october() { return date_time_period(month(),9); }
271 /// Get predefined constant for November
273 inline date_time_period november() { return date_time_period(month(),10); }
275 /// Get predefined constant for December
277 inline date_time_period december() { return date_time_period(month(),11); }
280 /// Get predefined constant for Sunday
282 inline date_time_period sunday() { return date_time_period(day_of_week(),1); }
284 /// Get predefined constant for Monday
286 inline date_time_period monday() { return date_time_period(day_of_week(),2); }
288 /// Get predefined constant for Tuesday
290 inline date_time_period tuesday() { return date_time_period(day_of_week(),3); }
292 /// Get predefined constant for Wednesday
294 inline date_time_period wednesday() { return date_time_period(day_of_week(),4); }
296 /// Get predefined constant for Thursday
298 inline date_time_period thursday() { return date_time_period(day_of_week(),5); }
300 /// Get predefined constant for Friday
302 inline date_time_period friday() { return date_time_period(day_of_week(),6); }
304 /// Get predefined constant for Saturday
306 inline date_time_period saturday() { return date_time_period(day_of_week(),7); }
308 /// Get predefined constant for AM (Ante Meridiem)
310 inline date_time_period am() { return date_time_period(am_pm(),0); }
312 /// Get predefined constant for PM (Post Meridiem)
314 inline date_time_period pm() { return date_time_period(am_pm(),1); }
317 /// convert period_type to date_time_period(f,1)
319 inline date_time_period operator+(period::period_type f)
321 return date_time_period(f);
324 /// convert period_type to date_time_period(f,-1)
326 inline date_time_period operator-(period::period_type f)
328 return date_time_period(f,-1);
332 /// Create date_time_period of type \a f with value \a v.
335 date_time_period operator*(period::period_type f,T v)
337 return date_time_period(f,v);
341 /// Create date_time_period of type \a f with value \a v.
344 date_time_period operator*(T v,period::period_type f)
346 return date_time_period(f,v);
349 /// Create date_time_period of type \a f with value \a v.
352 date_time_period operator*(T v,date_time_period f)
354 return date_time_period(f.type,f.value*v);
358 /// Create date_time_period of type \a f with value \a v.
361 date_time_period operator*(date_time_period f,T v)
363 return date_time_period(f.type,f.value*v);
371 /// \brief this class that represents a set of periods,
373 /// It is generally created by operations on periods:
374 /// 1995*year + 3*month + 1*day. Note: operations are not commutative.
376 class date_time_period_set {
380 /// Default constructor - empty set
382 date_time_period_set()
386 /// Create a set of single period with value 1
388 date_time_period_set(period::period_type f)
390 basic_[0]=date_time_period(f);
393 /// Create a set of single period \a fl
395 date_time_period_set(date_time_period const &fl)
400 /// Append date_time_period \a f to the set
402 void add(date_time_period f)
408 periods_.push_back(f);
411 /// Get number if items in list
415 if(basic_[0].type == period::period_type())
417 if(basic_[1].type == period::period_type())
419 if(basic_[2].type == period::period_type())
421 if(basic_[3].type == period::period_type())
423 return 4+periods_.size();
426 /// Get item at position \a n the set, n should be in range [0,size)
428 date_time_period const &operator[](size_t n) const
431 throw std::out_of_range("Invalid index to date_time_period");
435 return periods_[n-4];
438 date_time_period basic_[4];
439 std::vector<date_time_period> periods_;
444 /// Append two periods sets. Note this operator is not commutative
446 inline date_time_period_set operator+(date_time_period_set const &a,date_time_period_set const &b)
448 date_time_period_set s(a);
449 for(unsigned i=0;i<b.size();i++)
455 /// Append two period sets when all periods of set \b change their sign
457 inline date_time_period_set operator-(date_time_period_set const &a,date_time_period_set const &b)
459 date_time_period_set s(a);
460 for(unsigned i=0;i<b.size();i++)
467 /// \brief this class provides an access to general calendar information.
469 /// This information is not connected to specific date but generic to locale, and timezone.
470 /// It is used in obtaining general information about calendar and is essential for creation of
471 /// date_time objects.
473 class BOOST_LOCALE_DECL calendar {
477 /// Create calendar taking locale and timezone information from ios_base instance.
479 /// \note throws std::bad_cast if ios does not have a locale with installed \ref calendar_facet
482 calendar(std::ios_base &ios);
484 /// Create calendar with locale \a l and time_zone \a zone
486 /// \note throws std::bad_cast if loc does not have \ref calendar_facet facet installed
488 calendar(std::locale const &l,std::string const &zone);
490 /// Create calendar with locale \a l and default timezone
492 /// \note throws std::bad_cast if loc does not have \ref calendar_facet facet installed
494 calendar(std::locale const &l);
496 /// Create calendar with default locale and timezone \a zone
498 /// \note throws std::bad_cast if global locale does not have \ref calendar_facet facet installed
500 calendar(std::string const &zone);
502 /// Create calendar with default locale and timezone
504 /// \note throws std::bad_cast if global locale does not have \ref calendar_facet facet installed
512 calendar(calendar const &other);
516 calendar const &operator=(calendar const &other);
519 /// Get minimum value for period f, For example for period::day it is 1.
521 int minimum(period::period_type f) const;
523 /// Get greatest possible minimum value for period f, For example for period::day it is 1, but may be different for other calendars.
525 int greatest_minimum(period::period_type f) const;
527 /// Get maximum value for period f, For example for Gregorian calendar's maximum period::day it is 31.
529 int maximum(period::period_type f) const;
531 /// Get least maximum value for period f, For example for Gregorian calendar's maximum period::day it is 28.
533 int least_maximum(period::period_type f) const;
536 /// Get first day of week for specific calendar, for example for US it is 1 - Sunday for France it is 2 - Monday
537 int first_day_of_week() const;
540 /// get calendar's locale
542 std::locale get_locale() const;
544 /// get calendar's time zone
546 std::string get_time_zone() const;
549 /// Check if the calendar is Gregorian
551 bool is_gregorian() const;
554 /// Compare calendars for equivalence: i.e. calendar types, time zones etc.
556 bool operator==(calendar const &other) const;
560 bool operator!=(calendar const &other) const;
563 friend class date_time;
566 hold_ptr<abstract_calendar> impl_;
570 /// \brief this class represents a date time and allows to perform various operation according to the
573 /// This class allows to manipulate various aspects of dates and times easily using arithmetic operations with
576 /// General arithmetic functions:
578 /// - date_time + date_time_period_set = date_time: move time point forward by specific periods like date_time + month;
579 /// - date_time - date_time_period_set = date_time: move time point backward by specific periods like date_time - month;
580 /// - date_time << date_time_period_set = date_time: roll time point forward by specific periods with rolling to begin if overflows: like "2010-01-31" << 2* day == "2010-01-02" instead of "2010-02-02"
581 /// - date_time >> date_time_period_set = date_time: roll time point backward by specific periods with rolling to end if overflows: like "2010-01-02" >> 2* day == "2010-01-31" instead of "2009-12-30"
582 /// - date_time / period_type = int - current period value: like "2010-12-21" / month == 12. "2010-12-21" / year = 2010
583 /// - (date_time - date_time) / period_type = int: distance between dates in period_type. Like ("2010-12-01" - "2008-12-01") / month = 24.
585 /// You can also assign specific periods using assignment operator like:
586 /// some_time = year * 1995 that sets the year to 1995.
590 class BOOST_LOCALE_DECL date_time {
594 /// Dafault constructor, uses default calendar initialized date_time object to current time.
596 /// \note throws std::bad_cast if the global locale does not have \ref calendar_facet facet installed
602 date_time(date_time const &other);
604 /// copy date_time and change some fields according to the \a set
606 date_time(date_time const &other,date_time_period_set const &set);
608 /// assign the date_time
610 date_time const &operator=(date_time const &other);
614 /// Create a date_time object using POSIX time \a time and default calendar
616 /// \note throws std::bad_cast if the global locale does not have \ref calendar_facet facet installed
618 date_time(double time);
620 /// Create a date_time object using POSIX time \a time and calendar \a cal
622 date_time(double time,calendar const &cal);
624 /// Create a date_time object using calendar \a cal and initializes it to current time.
626 date_time(calendar const &cal);
629 /// Create a date_time object using default calendar and define values given in \a set
631 /// \note throws std::bad_cast if the global locale does not have \ref calendar_facet facet installed
633 date_time(date_time_period_set const &set);
635 /// Create a date_time object using calendar \a cal and define values given in \a set
637 date_time(date_time_period_set const &set,calendar const &cal);
641 /// assign values to various periods in set \a f
643 date_time const &operator=(date_time_period_set const &f);
646 /// set specific period \a f value to \a v
648 void set(period::period_type f,int v);
650 /// get specific period \a f value
652 int get(period::period_type f) const;
655 /// syntactic sugar for get(f)
657 int operator/(period::period_type f) const
663 /// add single period f to the current date_time
665 date_time operator+(period::period_type f) const
667 return *this+date_time_period(f);
671 /// subtract single period f from the current date_time
673 date_time operator-(period::period_type f) const
675 return *this-date_time_period(f);
679 /// add single period f to the current date_time
681 date_time const &operator+=(period::period_type f)
683 return *this+=date_time_period(f);
686 /// subtract single period f from the current date_time
688 date_time const &operator-=(period::period_type f)
690 return *this-=date_time_period(f);
694 /// roll forward a date by single period f.
696 date_time operator<<(period::period_type f) const
698 return *this<<date_time_period(f);
702 /// roll backward a date by single period f.
704 date_time operator>>(period::period_type f) const
706 return *this>>date_time_period(f);
710 /// roll forward a date by single period f.
712 date_time const &operator<<=(period::period_type f)
714 return *this<<=date_time_period(f);
717 /// roll backward a date by single period f.
719 date_time const &operator>>=(period::period_type f)
721 return *this>>=date_time_period(f);
725 /// add date_time_period to the current date_time
727 date_time operator+(date_time_period const &v) const;
729 /// subtract date_time_period from the current date_time
731 date_time operator-(date_time_period const &v) const;
733 /// add date_time_period to the current date_time
735 date_time const &operator+=(date_time_period const &v);
737 /// subtract date_time_period from the current date_time
739 date_time const &operator-=(date_time_period const &v);
742 /// roll current date_time forward by date_time_period v
744 date_time operator<<(date_time_period const &v) const;
746 /// roll current date_time backward by date_time_period v
748 date_time operator>>(date_time_period const &v) const ;
750 /// roll current date_time forward by date_time_period v
752 date_time const &operator<<=(date_time_period const &v);
754 /// roll current date_time backward by date_time_period v
756 date_time const &operator>>=(date_time_period const &v);
759 /// add date_time_period_set v to the current date_time
761 date_time operator+(date_time_period_set const &v) const;
763 /// subtract date_time_period_set v from the current date_time
765 date_time operator-(date_time_period_set const &v) const;
767 /// add date_time_period_set v to the current date_time
769 date_time const &operator+=(date_time_period_set const &v);
771 /// subtract date_time_period_set v from the current date_time
773 date_time const &operator-=(date_time_period_set const &v);
776 /// roll current date_time forward by date_time_period_set v
778 date_time operator<<(date_time_period_set const &v) const;
780 /// roll current date_time backward by date_time_period_set v
782 date_time operator>>(date_time_period_set const &v) const ;
784 /// roll current date_time forward by date_time_period_set v
786 date_time const &operator<<=(date_time_period_set const &v);
788 /// roll current date_time backward by date_time_period_set v
790 date_time const &operator>>=(date_time_period_set const &v);
795 /// The POSIX time is number of seconds since January 1st, 1970 00:00 UTC, ignoring leap seconds.
801 /// The POSIX time is number of seconds since January 1st, 1970 00:00 UTC, ignoring leap seconds.
802 /// This time can be fetched from Operating system clock using C function time, gettimeofday and others.
807 /// compare date_time in the timeline (ignores difference in calendar, timezone etc)
809 bool operator==(date_time const &other) const;
811 /// compare date_time in the timeline (ignores difference in calendar, timezone etc)
813 bool operator!=(date_time const &other) const;
815 /// compare date_time in the timeline (ignores difference in calendar, timezone etc)
817 bool operator<(date_time const &other) const;
819 /// compare date_time in the timeline (ignores difference in calendar, timezone etc)
821 bool operator>(date_time const &other) const;
823 /// compare date_time in the timeline (ignores difference in calendar, timezone etc)
825 bool operator<=(date_time const &other) const;
827 /// compare date_time in the timeline (ignores difference in calendar, timezone etc)
829 bool operator>=(date_time const &other) const;
832 /// swaps two dates - efficient, does not throw
834 void swap(date_time &other);
837 /// calculate the distance from this date_time to \a other in terms of perios \a f
839 int difference(date_time const &other,period::period_type f) const;
842 /// Get minimal possible value for *this time point for a period \a f.
844 int minimum(period::period_type f) const;
846 /// Get minimal possible value for *this time point for a period \a f. For example
847 /// in February maximum(day) may be 28 or 29, in January maximum(day)==31
849 int maximum(period::period_type f) const;
852 /// Check if *this time point is in daylight saving time
854 bool is_in_daylight_saving_time() const;
857 hold_ptr<abstract_calendar> impl_;
861 /// Writes date_time \a t to output stream \a out.
863 /// This function uses locale, calendar and time zone of the target stream \a in.
867 /// date_time now(time(0),hebrew_calendar)
868 /// cout << "Year: " << period::year(now) <<" Full Date:"<< now;
871 /// The output may be Year:5770 Full Date:Jan 1, 2010
873 template<typename CharType>
874 std::basic_ostream<CharType> &operator<<(std::basic_ostream<CharType> &out,date_time const &t)
876 double time_point = t.time();
877 uint64_t display_flags = ios_info::get(out).display_flags();
879 display_flags == flags::date
880 || display_flags == flags::time
881 || display_flags == flags::datetime
882 || display_flags == flags::strftime
888 ios_info::get(out).display_flags(flags::datetime);
890 ios_info::get(out).display_flags(display_flags);
896 /// Reads date_time \a t from output stream \a in
898 /// This function uses locale, calendar and time zone of the source stream \a in.
900 template<typename CharType>
901 std::basic_istream<CharType> &operator>>(std::basic_istream<CharType> &in,date_time &t)
904 uint64_t display_flags = ios_info::get(in).display_flags();
906 display_flags == flags::date
907 || display_flags == flags::time
908 || display_flags == flags::datetime
909 || display_flags == flags::strftime
915 ios_info::get(in).display_flags(flags::datetime);
917 ios_info::get(in).display_flags(display_flags);
925 /// \brief This class represents a period: a pair of two date_time objects.
927 /// It is generally used as syntactic sugar to calculate difference between two dates.
929 /// Note: it stores references to the original objects, so it is not recommended to be used
930 /// outside of the equation you calculate the difference in.
932 class date_time_duration {
936 /// Create an object were \a first represents earlier point on time line and \a second is later
939 date_time_duration(date_time const &first,date_time const &second) :
946 /// find a difference in terms of period_type \a f
948 int get(period::period_type f) const
950 return start().difference(end(),f);
954 /// Syntactic sugar for get(f)
956 int operator / (period::period_type f) const
958 return start().difference(end(),f);
962 /// Get starting point
964 date_time const &start() const { return s_; }
968 date_time const &end() const { return e_; }
975 /// Calculates the difference between two dates, the left operand is a later point on time line.
976 /// Returns date_time_duration object.
978 inline date_time_duration operator-(date_time const &later,date_time const &earlier)
980 return date_time_duration(earlier,later);
986 /// Extract from date_time numerical value of Era i.e. AC, BC in Gregorian and Julian calendar, range [0,1]
988 inline int era(date_time const &dt) { return dt.get(era()); }
990 /// Extract from date_time numerical value of Year, it is calendar specific, for example 2011 in Gregorian calendar.
992 inline int year(date_time const &dt) { return dt.get(year()); }
994 /// Extract from date_time numerical value of Extended year for Gregorian/Julian calendars, where 1 BC == 0, 2 BC == -1.
996 inline int extended_year(date_time const &dt) { return dt.get(extended_year()); }
998 /// Extract from date_time numerical value of The month of year, calendar specific, in Gregorian [0..11]
1000 inline int month(date_time const &dt) { return dt.get(month()); }
1002 /// Extract from date_time numerical value of The day of month, calendar specific, in Gregorian [1..31]
1004 inline int day(date_time const &dt) { return dt.get(day()); }
1006 /// Extract from date_time numerical value of The number of day in year, starting from 1, in Gregorian [1..366]
1008 inline int day_of_year(date_time const &dt) { return dt.get(day_of_year()); }
1010 /// Extract from date_time numerical value of Day of week, Sunday=1, Monday=2,..., Saturday=7.
1012 /// Note that updating this value respects local day of week, so for example,
1013 /// If first day of week is Monday and the current day is Tuesday then setting
1014 /// the value to Sunday (1) would forward the date by 5 days forward and not backward
1015 /// by two days as it could be expected if the numbers were taken as is.
1017 inline int day_of_week(date_time const &dt) { return dt.get(day_of_week()); }
1019 /// Extract from date_time numerical value of Original number of the day of the week in month. For example 1st Sunday,
1020 /// 2nd Sunday, etc. in Gregorian [1..5]
1022 inline int day_of_week_in_month(date_time const &dt) { return dt.get(day_of_week_in_month()); }
1024 /// Extract from date_time numerical value of Local day of week, for example in France Monday is 1, in US Sunday is 1, [1..7]
1026 inline int day_of_week_local(date_time const &dt) { return dt.get(day_of_week_local()); }
1028 /// Extract from date_time numerical value of 24 clock hour [0..23]
1030 inline int hour(date_time const &dt) { return dt.get(hour()); }
1032 /// Extract from date_time numerical value of 12 clock hour [0..11]
1034 inline int hour_12(date_time const &dt) { return dt.get(hour_12()); }
1036 /// Extract from date_time numerical value of am or pm marker [0..1]
1038 inline int am_pm(date_time const &dt) { return dt.get(am_pm()); }
1040 /// Extract from date_time numerical value of minute [0..59]
1042 inline int minute(date_time const &dt) { return dt.get(minute()); }
1044 /// Extract from date_time numerical value of second [0..59]
1046 inline int second(date_time const &dt) { return dt.get(second()); }
1048 /// Extract from date_time numerical value of The week number in the year
1050 inline int week_of_year(date_time const &dt) { return dt.get(week_of_year()); }
1052 /// Extract from date_time numerical value of The week number within current month
1054 inline int week_of_month(date_time const &dt) { return dt.get(week_of_month()); }
1056 /// Extract from date_time numerical value of First day of week, constant, for example Sunday in US = 1, Monday in France = 2
1058 inline int first_day_of_week(date_time const &dt) { return dt.get(first_day_of_week()); }
1061 /// Extract from date_time_duration numerical value of duration in Era i.e. AC, BC in Gregorian and Julian calendar, range [0,1]
1063 inline int era(date_time_duration const &dt) { return dt.get(era()); }
1065 /// Extract from date_time_duration numerical value of duration in years
1067 inline int year(date_time_duration const &dt) { return dt.get(year()); }
1069 /// Extract from date_time_duration numerical value of duration in extended years (for Gregorian/Julian calendars, where 1 BC == 0, 2 BC == -1).
1071 inline int extended_year(date_time_duration const &dt) { return dt.get(extended_year()); }
1073 /// Extract from date_time_duration numerical value of duration in months
1075 inline int month(date_time_duration const &dt) { return dt.get(month()); }
1077 /// Extract from date_time_duration numerical value of duration in days of month
1079 inline int day(date_time_duration const &dt) { return dt.get(day()); }
1081 /// Extract from date_time_duration numerical value of duration in days of year
1083 inline int day_of_year(date_time_duration const &dt) { return dt.get(day_of_year()); }
1085 /// Extract from date_time_duration numerical value of duration in days of week
1087 inline int day_of_week(date_time_duration const &dt) { return dt.get(day_of_week()); }
1089 /// Extract from date_time_duration numerical value of duration in original number of the day of the week in month
1091 inline int day_of_week_in_month(date_time_duration const &dt) { return dt.get(day_of_week_in_month()); }
1093 /// Extract from date_time_duration numerical value of duration in local day of week
1095 inline int day_of_week_local(date_time_duration const &dt) { return dt.get(day_of_week_local()); }
1097 /// Extract from date_time_duration numerical value of duration in hours
1099 inline int hour(date_time_duration const &dt) { return dt.get(hour()); }
1101 /// Extract from date_time_duration numerical value of duration in 12 clock hours
1103 inline int hour_12(date_time_duration const &dt) { return dt.get(hour_12()); }
1105 /// Extract from date_time_duration numerical value of duration in am or pm markers
1107 inline int am_pm(date_time_duration const &dt) { return dt.get(am_pm()); }
1109 /// Extract from date_time_duration numerical value of duration in minutes
1111 inline int minute(date_time_duration const &dt) { return dt.get(minute()); }
1113 /// Extract from date_time_duration numerical value of duration in seconds
1115 inline int second(date_time_duration const &dt) { return dt.get(second()); }
1117 /// Extract from date_time_duration numerical value of duration in the week number in the year
1119 inline int week_of_year(date_time_duration const &dt) { return dt.get(week_of_year()); }
1121 /// Extract from date_time_duration numerical value of duration in The week number within current month
1123 inline int week_of_month(date_time_duration const &dt) { return dt.get(week_of_month()); }
1125 /// Extract from date_time_duration numerical value of duration in the first day of week
1127 inline int first_day_of_week(date_time_duration const &dt) { return dt.get(first_day_of_week()); }
1139 #pragma warning(pop)
1145 /// \example calendar.cpp
1147 /// Example of using date_time functions for generating calendar for current year.
1150 // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4