libzypp: zypp::Date Class Reference

libzypp 17.38.5

zypp::Date Class Reference

Store and operate on date (time_t). More...

`#include <zypp-core/Date.h>`

## Classes
struct | EDateFormatDef
| Date formats for printing (use like 'enum class DateFormat'). More...
struct | ETimeFormatDef
| Time formats for printing (use like 'enum class TimeFormat'). More...
struct | ETimeZoneFormatDef
| Timezone indicator for printing (use like 'enum class TimeZoneFormat'). More...

## Public Types
using | ValueType = time_t
using | Duration = time_t

## Public Member Functions
| Date ()
| Default ctor: 0.
| Date (ValueType date_r)
| Ctor taking time_t value.
| Date (const std::string &seconds_r)
| Ctor taking time_t value as string.
| Date (const std::string &date_str, const std::string &format)
| Ctor from a date_str (in localtime) formatted using format.
| Date (const std::string &date_str, const std::string &format, TimeBase base_r)
| operator ValueType () const
| Conversion to time_t.

## Static Public Member Functions
static Date | now ()
| Return the current time.

## Static Public Attributes
static const ValueType | second = 1
static const ValueType | minute = 60
static const ValueType | hour = 3600
static const ValueType | day = 86400
static const ValueType | month28 = 2419200
static const ValueType | month29 = 2505600
static const ValueType | month30 = 2592000
static const ValueType | month31 = 2678400
static const ValueType | month = month30
static const ValueType | year365 = 31536000
static const ValueType | year366 = 31622400
static const ValueType | year = year365

## Friends
std::ostream & | operator<< (std::ostream &str, const Date &obj)

## Related Symbols
(Note that these are not member symbols.)
std::ostream & | operator<< (std::ostream &str, const Date &obj)
| Stream output.
std::ostream & | dumpAsXmlOn (std::ostream &str, const Date &obj, const std::string &name_r="date") ZYPP_API
| XML output.

## Arithmetic operations.
enum | TimeBase { TB_LOCALTIME , TB_UTC }
Date | operator+ (const time_t rhs) const
Date | operator- (const time_t rhs) const
Date | operator* (const time_t rhs) const
Date | operator/ (const time_t rhs) const
Date & | operator+= (const time_t rhs)
Date & | operator-= (const time_t rhs)
Date & | operator*= (const time_t rhs)
Date & | operator/= (const time_t rhs)
Date & | operator++ ()
Date & | operator-- ()
Date | operator++ (int)
Date | operator-- (int)
std::string | form (const std::string &format_r) const
| Return string representation according to format as localtime.
std::string | form (const std::string &format_r, TimeBase base_r) const
std::string | asString () const
| Default string representation of Date.
std::string | asSeconds () const
| Convert to string representation of calendar time in numeric form (like "1029255142").

## Printing in various predefined formats
using | DateFormat = base::EnumClass<EDateFormatDef>
| 'enum class DateFormat'
using | TimeFormat = base::EnumClass<ETimeFormatDef>
| 'enum class TimeFormat'
using | TimeZoneFormat = base::EnumClass<ETimeZoneFormatDef>
| 'enum class TimeZoneFormat'
ValueType | _date
| Calendar time.
std::string | print (DateFormat dateFormat_r=DateFormat::calendar, TimeFormat timeFormat_r=TimeFormat::seconds, TimeZoneFormat timeZoneFormat_r=TimeZoneFormat::name, TimeBase base_r=TB_LOCALTIME) const
| Default format is '2014-02-07 07:06:41 CET' The default is DateFormat::calendar, TimeFormat::seconds, TimeZoneFormat::name and TB_LOCALTIME.
std::string | print (TimeFormat timeFormat_r, TimeZoneFormat timeZoneFormat_r=TimeZoneFormat::name, TimeBase base_r=TB_LOCALTIME) const
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
std::string | print (DateFormat dateFormat_r, TimeZoneFormat timeZoneFormat_r, TimeBase base_r=TB_LOCALTIME) const
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
std::string | print (DateFormat dateFormat_r, TimeFormat timeFormat_r, TimeBase base_r) const
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
std::string | print (TimeZoneFormat timeZoneFormat_r, TimeBase base_r=TB_LOCALTIME) const
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
std::string | print (TimeFormat timeFormat_r, TimeBase base_r) const
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
std::string | print (DateFormat dateFormat_r, TimeBase base_r) const
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
std::string | print (TimeBase base_r) const
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
std::string | printDate (DateFormat dateFormat_r=DateFormat::calendar, TimeBase base_r=TB_LOCALTIME) const
| Convenience for printing the date only ['2014-02-07'] The default is DateFormat::calendar and TB_LOCALTIME.
std::string | printDate (TimeBase base_r) const
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
std::string | printTime (TimeFormat timeFormat_r=TimeFormat::seconds, TimeZoneFormat timeZoneFormat_r=TimeZoneFormat::name, TimeBase base_r=TB_LOCALTIME) const
| Convenience for printing the time only ['07:06:41 CET'] The default is DateFormat::calendar and TB_LOCALTIME.
std::string | printTime (TimeZoneFormat timeZoneFormat_r, TimeBase base_r=TB_LOCALTIME) const
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
std::string | printTime (TimeFormat timeFormat_r, TimeBase base_r) const
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
std::string | printTime (TimeBase base_r) const
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
std::string | printISO (DateFormat dateFormat_r=DateFormat::calendar, TimeFormat timeFormat_r=TimeFormat::seconds, TimeZoneFormat timeZoneFormat_r=TimeZoneFormat::name, TimeBase base_r=TB_LOCALTIME) const
| Default ISO 8601 format is '2014-02-07T07:06:41+01'.
std::string | printISO (TimeFormat timeFormat_r, TimeZoneFormat timeZoneFormat_r=TimeZoneFormat::name, TimeBase base_r=TB_LOCALTIME) const
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
std::string | printISO (DateFormat dateFormat_r, TimeZoneFormat timeZoneFormat_r, TimeBase base_r=TB_LOCALTIME) const
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
std::string | printISO (DateFormat dateFormat_r, TimeFormat timeFormat_r, TimeBase base_r) const
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
std::string | printISO (TimeZoneFormat timeZoneFormat_r, TimeBase base_r=TB_LOCALTIME) const
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
std::string | printISO (TimeFormat timeFormat_r, TimeBase base_r) const
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
std::string | printISO (DateFormat dateFormat_r, TimeBase base_r) const
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
std::string | printISO (TimeBase base_r) const
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

## Detailed Description

Store and operate on date (time_t).

Definition at line 32 of file Date.h.

## Member Typedef Documentation

## ◆ ValueType

using zypp::Date::ValueType = time_t

Definition at line 38 of file Date.h.

## ◆ Duration

using zypp::Date::Duration = time_t

Definition at line 39 of file Date.h.

## ◆ DateFormat

using zypp::Date::DateFormat = base::EnumClass<EDateFormatDef>

'enum class DateFormat'

Definition at line 142 of file Date.h.

## ◆ TimeFormat

using zypp::Date::TimeFormat = base::EnumClass<ETimeFormatDef>

'enum class TimeFormat'

Definition at line 151 of file Date.h.

## ◆ TimeZoneFormat

using zypp::Date::TimeZoneFormat = base::EnumClass<ETimeZoneFormatDef>

'enum class TimeZoneFormat'

Definition at line 159 of file Date.h.

## Member Enumeration Documentation

## ◆ TimeBase

enum zypp::Date::TimeBase

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Enumerator
TB_LOCALTIME |
TB_UTC |

Definition at line 54 of file Date.h.

## Constructor & Destructor Documentation

## ◆ Date() [1/5]

zypp::Date::Date | ( |  | ) |
| inline

Default ctor: 0.

Definition at line 57 of file Date.h.

## ◆ Date() [2/5]

zypp::Date::Date | ( | ValueType | date_r | ) |
| inline

Ctor taking time_t value.

Definition at line 61 of file Date.h.

## ◆ Date() [3/5]

zypp::Date::Date | ( | const std::string & | seconds_r | ) |
| explicit

Ctor taking time_t value as string.

Definition at line 168 of file Date.cc.

## ◆ Date() [4/5]

zypp::Date::Date | ( | const std::string & | date_str,
|  | const std::string & | format )

Ctor from a date_str (in localtime) formatted using format.

Exceptions

  DateFormatException | in case date_str cannot be parsed according to format.

Definition at line 171 of file Date.cc.

## ◆ Date() [5/5]

zypp::Date::Date | ( | const std::string & | date_str,
|  | const std::string & | format,
|  | Date::TimeBase | base_r )

Definition at line 175 of file Date.cc.

## Member Function Documentation

## ◆ now()

Date zypp::Date::now | ( |  | ) |
| inlinestatic

Return the current time.

Definition at line 78 of file Date.h.

## ◆ operator ValueType()

zypp::Date::operator ValueType | ( |  | ) | const
| inline

Conversion to time_t.

Definition at line 83 of file Date.h.

## ◆ operator+()

Date zypp::Date::operator+ | ( | const time_t | rhs | ) | const
| inline

Definition at line 88 of file Date.h.

## ◆ operator-()

Date zypp::Date::operator- | ( | const time_t | rhs | ) | const
| inline

Definition at line 89 of file Date.h.

## ◆ operator*()

Date zypp::Date::operator* | ( | const time_t | rhs | ) | const
| inline

Definition at line 90 of file Date.h.

## ◆ operator/()

Date zypp::Date::operator/ | ( | const time_t | rhs | ) | const
| inline

Definition at line 91 of file Date.h.

## ◆ operator+=()

Date & zypp::Date::operator+= | ( | const time_t | rhs | ) |
| inline

Definition at line 93 of file Date.h.

## ◆ operator-=()

Date & zypp::Date::operator-= | ( | const time_t | rhs | ) |
| inline

Definition at line 94 of file Date.h.

## ◆ operator*=()

Date & zypp::Date::operator*= | ( | const time_t | rhs | ) |
| inline

Definition at line 95 of file Date.h.

## ◆ operator/=()

Date & zypp::Date::operator/= | ( | const time_t | rhs | ) |
| inline

Definition at line 96 of file Date.h.

## ◆ operator++() [1/2]

Date & zypp::Date::operator++ | ( |  | ) |
| inline

Definition at line 98 of file Date.h.

## ◆ operator--() [1/2]

Date & zypp::Date::operator-- | ( |  | ) |
| inline

Definition at line 99 of file Date.h.

## ◆ operator++() [2/2]

Date zypp::Date::operator++ | ( | int |  | ) |
| inline

Definition at line 101 of file Date.h.

## ◆ operator--() [2/2]

Date zypp::Date::operator-- | ( | int |  | ) |
| inline

Definition at line 102 of file Date.h.

## ◆ form() [1/2]

std::string zypp::Date::form | ( | const std::string & | format_r | ) | const
| inline

Return string representation according to format as localtime.

See also
  'man strftime' (which is used internaly) for valid conversion specifiers in format.

Returns
  An empty string on illegal format, "0" if date is unspecified.

Definition at line 112 of file Date.h.

## ◆ form() [2/2]

std::string zypp::Date::form | ( | const std::string & | format_r,
|  | Date::TimeBase | base_r ) const

Definition at line 190 of file Date.cc.

## ◆ asString()

std::string zypp::Date::asString | ( |  | ) | const
| inline

Default string representation of Date.

The preferred date and time representation for the current locale.

Definition at line 120 of file Date.h.

## ◆ asSeconds()

std::string zypp::Date::asSeconds | ( |  | ) | const
| inline

Convert to string representation of calendar time in numeric form (like "1029255142").

Definition at line 126 of file Date.h.

## ◆ print() [1/8]

std::string zypp::Date::print | ( | DateFormat | dateFormat_r = DateFormat::calendar,
|  | TimeFormat | timeFormat_r = TimeFormat::seconds,
|  | TimeZoneFormat | timeZoneFormat_r = TimeZoneFormat::name,
|  | TimeBase | base_r = TB_LOCALTIME ) const

Default format is '2014-02-07 07:06:41 CET' The default is DateFormat::calendar, TimeFormat::seconds, TimeZoneFormat::name and TB_LOCALTIME.

For other formats you don't have to repeat all the defaults, just pass the values where you differ.

Definition at line 193 of file Date.cc.

## ◆ print() [2/8]

std::string zypp::Date::print | ( | TimeFormat | timeFormat_r,
|  | TimeZoneFormat | timeZoneFormat_r = TimeZoneFormat::name,
|  | TimeBase | base_r = TB_LOCALTIME ) const
| inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 168 of file Date.h.

## ◆ print() [3/8]

std::string zypp::Date::print | ( | DateFormat | dateFormat_r,
|  | TimeZoneFormat | timeZoneFormat_r,
|  | TimeBase | base_r = TB_LOCALTIME ) const
| inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 171 of file Date.h.

## ◆ print() [4/8]

std::string zypp::Date::print | ( | DateFormat | dateFormat_r,
|  | TimeFormat | timeFormat_r,
|  | TimeBase | base_r ) const
| inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 174 of file Date.h.

## ◆ print() [5/8]

std::string zypp::Date::print | ( | TimeZoneFormat | timeZoneFormat_r,
|  | TimeBase | base_r = TB_LOCALTIME ) const
| inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 177 of file Date.h.

## ◆ print() [6/8]

std::string zypp::Date::print | ( | TimeFormat | timeFormat_r,
|  | TimeBase | base_r ) const
| inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 180 of file Date.h.

## ◆ print() [7/8]

std::string zypp::Date::print | ( | DateFormat | dateFormat_r,
|  | TimeBase | base_r ) const
| inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 183 of file Date.h.

## ◆ print() [8/8]

std::string zypp::Date::print | ( | TimeBase | base_r | ) | const
| inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 186 of file Date.h.

## ◆ printDate() [1/2]

std::string zypp::Date::printDate | ( | DateFormat | dateFormat_r = DateFormat::calendar,
|  | TimeBase | base_r = TB_LOCALTIME ) const
| inline

Convenience for printing the date only ['2014-02-07'] The default is DateFormat::calendar and TB_LOCALTIME.

Definition at line 192 of file Date.h.

## ◆ printDate() [2/2]

std::string zypp::Date::printDate | ( | TimeBase | base_r | ) | const
| inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 195 of file Date.h.

## ◆ printTime() [1/4]

std::string zypp::Date::printTime | ( | TimeFormat | timeFormat_r = TimeFormat::seconds,
|  | TimeZoneFormat | timeZoneFormat_r = TimeZoneFormat::name,
|  | TimeBase | base_r = TB_LOCALTIME ) const
| inline

Convenience for printing the time only ['07:06:41 CET'] The default is DateFormat::calendar and TB_LOCALTIME.

Definition at line 201 of file Date.h.

## ◆ printTime() [2/4]

std::string zypp::Date::printTime | ( | TimeZoneFormat | timeZoneFormat_r,
|  | TimeBase | base_r = TB_LOCALTIME ) const
| inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 204 of file Date.h.

## ◆ printTime() [3/4]

std::string zypp::Date::printTime | ( | TimeFormat | timeFormat_r,
|  | TimeBase | base_r ) const
| inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 207 of file Date.h.

## ◆ printTime() [4/4]

std::string zypp::Date::printTime | ( | TimeBase | base_r | ) | const
| inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 210 of file Date.h.

## ◆ printISO() [1/8]

std::string zypp::Date::printISO | ( | DateFormat | dateFormat_r = DateFormat::calendar,
|  | TimeFormat | timeFormat_r = TimeFormat::seconds,
|  | TimeZoneFormat | timeZoneFormat_r = TimeZoneFormat::name,
|  | TimeBase | base_r = TB_LOCALTIME ) const

Default ISO 8601 format is '2014-02-07T07:06:41+01'.

Note
  As timezone names are not used in ISO, TimeZoneFormat::name is the same as TimeZoneFormat::offset when printing in TB_LOCALTIME. When printing TB_UTC it uses a `'Z'` to indicate UTC (Zulu time) rather than printing `'+00'`.

Definition at line 209 of file Date.cc.

## ◆ printISO() [2/8]

std::string zypp::Date::printISO | ( | TimeFormat | timeFormat_r,
|  | TimeZoneFormat | timeZoneFormat_r = TimeZoneFormat::name,
|  | TimeBase | base_r = TB_LOCALTIME ) const
| inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 220 of file Date.h.

## ◆ printISO() [3/8]

std::string zypp::Date::printISO | ( | DateFormat | dateFormat_r,
|  | TimeZoneFormat | timeZoneFormat_r,
|  | TimeBase | base_r = TB_LOCALTIME ) const
| inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 223 of file Date.h.

## ◆ printISO() [4/8]

std::string zypp::Date::printISO | ( | DateFormat | dateFormat_r,
|  | TimeFormat | timeFormat_r,
|  | TimeBase | base_r ) const
| inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 226 of file Date.h.

## ◆ printISO() [5/8]

std::string zypp::Date::printISO | ( | TimeZoneFormat | timeZoneFormat_r,
|  | TimeBase | base_r = TB_LOCALTIME ) const
| inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 229 of file Date.h.

## ◆ printISO() [6/8]

std::string zypp::Date::printISO | ( | TimeFormat | timeFormat_r,
|  | TimeBase | base_r ) const
| inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 232 of file Date.h.

## ◆ printISO() [7/8]

std::string zypp::Date::printISO | ( | DateFormat | dateFormat_r,
|  | TimeBase | base_r ) const
| inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 235 of file Date.h.

## ◆ printISO() [8/8]

std::string zypp::Date::printISO | ( | TimeBase | base_r | ) | const
| inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 238 of file Date.h.

## Friends And Related Symbol Documentation

## ◆ operator<< [1/2]

std::ostream & operator<< | ( | std::ostream & | str,
|  | const Date & | obj )
| friend

## ◆ operator<<() [2/2]

std::ostream & operator<< | ( | std::ostream & | str,
|  | const Date & | obj )
| related

Stream output.

Definition at line 252 of file Date.h.

## ◆ dumpAsXmlOn()

std::ostream & dumpAsXmlOn | ( | std::ostream & | str,
|  | const Date & | obj,
|  | const std::string & | name_r = "date" )
| related

XML output.

Print `time_t` and `text` attribute. Allow alternate node name [date].

Definition at line 238 of file Date.cc.

## Member Data Documentation

## ◆ second

const Date::ValueType zypp::Date::second = 1
| static

Definition at line 41 of file Date.h.

## ◆ minute

const Date::ValueType zypp::Date::minute = 60
| static

Definition at line 42 of file Date.h.

## ◆ hour

const Date::ValueType zypp::Date::hour = 3600
| static

Definition at line 43 of file Date.h.

## ◆ day

const Date::ValueType zypp::Date::day = 86400
| static

Definition at line 44 of file Date.h.

## ◆ month28

const Date::ValueType zypp::Date::month28 = 2419200
| static

Definition at line 45 of file Date.h.

## ◆ month29

const Date::ValueType zypp::Date::month29 = 2505600
| static

Definition at line 46 of file Date.h.

## ◆ month30

const Date::ValueType zypp::Date::month30 = 2592000
| static

Definition at line 47 of file Date.h.

## ◆ month31

const Date::ValueType zypp::Date::month31 = 2678400
| static

Definition at line 48 of file Date.h.

## ◆ month

const Date::ValueType zypp::Date::month = month30
| static

Definition at line 49 of file Date.h.

## ◆ year365

const Date::ValueType zypp::Date::year365 = 31536000
| static

Definition at line 50 of file Date.h.

## ◆ year366

const Date::ValueType zypp::Date::year366 = 31622400
| static

Definition at line 51 of file Date.h.

## ◆ year

const Date::ValueType zypp::Date::year = year365
| static

Definition at line 52 of file Date.h.

## ◆ _date

ValueType zypp::Date::_date
| private

Calendar time.

The number of seconds elapsed since 00:00:00 on January 1, 1970, Coordinated Universal Time (UTC).

Definition at line 247 of file Date.h.

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

- zypp-core/Date.h
- zypp-core/Date.cc