| Boost.Locale

Public Member Functions | List of all members
boost::locale::date_time Class Reference
Date, Time, Timezone and Calendar manipulations

this class represents a date time and allows to perform various operation according to the locale settings. More...

`#include <boost/locale/date_time.hpp>`

## Public Member Functions
| date_time ()
| date_time (const date_time &other)
| Copy a date_time.
| date_time (date_time &&) noexcept=default
| date_time (const date_time &other, const date_time_period_set &set)
| copy date_time and change some fields according to the set
date_time & | operator= (const date_time &other)
| assign the date_time
date_time & | operator= (date_time &&) noexcept=default
| date_time (double time)
| date_time (double time, const calendar &cal)
| Create a date_time object using POSIX time time and calendar cal.
| date_time (const calendar &cal)
| Create a date_time object using calendar cal and initializes it to current time.
| date_time (const date_time_period_set &set)
| date_time (const date_time_period_set &set, const calendar &cal)
| Create a date_time object using calendar cal and define values given in set.
date_time & | operator= (const date_time_period_set &f)
| assign values to various periods in set f
void | set (period::period_type f, int v)
| set specific period f value to v
int | get (period::period_type f) const
| get specific period f value
int | operator/ (period::period_type f) const
| syntactic sugar for get(f)
date_time | operator+ (period::period_type f) const
| add single period f to the current date_time
date_time | operator- (period::period_type f) const
| subtract single period f from the current date_time
date_time & | operator+= (period::period_type f)
| add single period f to the current date_time
date_time & | operator-= (period::period_type f)
| subtract single period f from the current date_time
date_time | operator<< (period::period_type f) const
| roll forward a date by single period f.
date_time | operator>> (period::period_type f) const
| roll backward a date by single period f.
date_time & | operator<<= (period::period_type f)
| roll forward a date by single period f.
date_time & | operator>>= (period::period_type f)
| roll backward a date by single period f.
date_time | operator+ (const date_time_period &v) const
| add date_time_period to the current date_time
date_time | operator- (const date_time_period &v) const
| subtract date_time_period from the current date_time
date_time & | operator+= (const date_time_period &v)
| add date_time_period to the current date_time
date_time & | operator-= (const date_time_period &v)
| subtract date_time_period from the current date_time
date_time | operator<< (const date_time_period &v) const
| roll current date_time forward by date_time_period v
date_time | operator>> (const date_time_period &v) const
| roll current date_time backward by date_time_period v
date_time & | operator<<= (const date_time_period &v)
| roll current date_time forward by date_time_period v
date_time & | operator>>= (const date_time_period &v)
| roll current date_time backward by date_time_period v
date_time | operator+ (const date_time_period_set &v) const
| add date_time_period_set v to the current date_time
date_time | operator- (const date_time_period_set &v) const
| subtract date_time_period_set v from the current date_time
date_time & | operator+= (const date_time_period_set &v)
| add date_time_period_set v to the current date_time
date_time & | operator-= (const date_time_period_set &v)
| subtract date_time_period_set v from the current date_time
date_time | operator<< (const date_time_period_set &v) const
| roll current date_time forward by date_time_period_set v
date_time | operator>> (const date_time_period_set &v) const
| roll current date_time backward by date_time_period_set v
date_time & | operator<<= (const date_time_period_set &v)
| roll current date_time forward by date_time_period_set v
date_time & | operator>>= (const date_time_period_set &v)
| roll current date_time backward by date_time_period_set v
double | time () const
void | time (double v)
std::string | timezone () const
| Get the name of the associated timezone.
bool | operator== (const date_time &other) const
| compare date_time in the timeline (ignores difference in calendar, timezone etc)
bool | operator!= (const date_time &other) const
| compare date_time in the timeline (ignores difference in calendar, timezone etc)
bool | operator< (const date_time &other) const
| compare date_time in the timeline (ignores difference in calendar, timezone etc)
bool | operator> (const date_time &other) const
| compare date_time in the timeline (ignores difference in calendar, timezone etc)
bool | operator<= (const date_time &other) const
| compare date_time in the timeline (ignores difference in calendar, timezone etc)
bool | operator>= (const date_time &other) const
| compare date_time in the timeline (ignores difference in calendar, timezone etc)
void | swap (date_time &other) noexcept
| swaps two dates - efficient, does not throw
int | difference (const date_time &other, period::period_type f) const
| calculate the distance from this date_time to other in terms of periods f
int | minimum (period::period_type f) const
| Get minimal possible value for *this time point for a period f.
int | maximum (period::period_type f) const
bool | is_in_daylight_saving_time () const
| Check if *this time point is in daylight saving time.

## Detailed Description

this class represents a date time and allows to perform various operation according to the locale settings.

This class allows to manipulate various aspects of dates and times easily using arithmetic operations with periods.

General arithmetic functions:

- date_time + date_time_period_set = date_time: move time point forward by specific periods like date_time + month;
- date_time - date_time_period_set = date_time: move time point backward by specific periods like date_time - month;
- 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"
- 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"
- date_time / period_type = int - current period value: like "2010-12-21" / month == 12. "2010-12-21" / year = 2010
- (date_time - date_time) / period_type = int: distance between dates in period_type. Like ("2010-12-01" - "2008-12-01") / month = 24.

You can also assign specific periods using assignment operator like: some_time = year * 1995 that sets the year to 1995.

Examples
  calendar.cpp.

## Constructor & Destructor Documentation

## ◆ date_time() [1/3]

boost::locale::date_time::date_time | ( |  | ) |

Default constructor, uses default calendar initialized date_time object to current time.

Exceptions

  std::bad_cast | Global locale does not have calendar_facet facet installed

## ◆ date_time() [2/3]

boost::locale::date_time::date_time | ( | double | time | ) |

Create a date_time object using POSIX time time and default calendar

Exceptions

  std::bad_cast | Global locale does not have calendar_facet facet installed

## ◆ date_time() [3/3]

boost::locale::date_time::date_time | ( | const date_time_period_set & | set | ) |

Create a date_time object using default calendar and define values given in set

Exceptions

  std::bad_cast | Global locale does not have calendar_facet facet installed

## Member Function Documentation

## ◆ maximum()

int boost::locale::date_time::maximum | ( | period::period_type | f | ) | const

Get minimal possible value for *this time point for a period f. For example in February maximum(day) may be 28 or 29, in January maximum(day)==31

Examples
  calendar.cpp.

## ◆ time() [1/2]

double boost::locale::date_time::time | ( |  | ) | const

Get POSIX time

The POSIX time is number of seconds since January 1st, 1970 00:00 UTC, ignoring leap seconds.

## ◆ time() [2/2]

void boost::locale::date_time::time | ( | double | v | ) |

Set POSIX time

The POSIX time is number of seconds since January 1st, 1970 00:00 UTC, ignoring leap seconds. This time can be fetched from Operating system clock using C function time, gettimeofday and others.

The documentation for this class was generated from the following file:

- boost/locale/date_time.hpp

- © Copyright 2009-2012 Artyom Beilis, Distributed under the Boost Software License, Version 1.0.