| Disk ARchive 2.8.1 Full featured and portable backup and archiving tool

Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
libdar::datetime Class Reference
API

stores time information More...

`#include <datetime.hpp>`

## Public Types
enum | time_unit { tu_nanosecond , tu_microsecond , tu_second }

## Public Member Functions
| datetime (const infinint &value=0)
| constructor based on the number of second ellasped since the end of 1969
| datetime (time_t second, time_t subsec, time_unit unit)
| general constructor
| datetime (generic_file &x, archive_version ver)
| constructor reading data dump() into a generic_file
| datetime (const datetime &ref)=default
| datetime (datetime &&ref) noexcept=default
datetime & | operator= (const datetime &ref)=default
datetime & | operator= (datetime &&ref) noexcept=default
bool | operator< (const datetime &ref) const
bool | operator== (const datetime &ref) const
bool | operator!= (const datetime &ref) const
bool | operator>= (const datetime &ref) const
bool | operator> (const datetime &ref) const
bool | operator<= (const datetime &ref) const
void | operator-= (const datetime &ref)
void | operator+= (const datetime &ref)
datetime | operator- (const datetime &ref) const
datetime | operator+ (const datetime &ref) const
bool | loose_equal (const datetime &ref) const
| equivalent to operator == but if compared object use different time unit, do the comparison rounding up the values to the largest unit
datetime | loose_diff (const datetime &ref) const
| at the difference of operator - provides the difference using the less precise unit used between the two elements
infinint | get_second_value () const
| return the integer number of second
infinint | get_subsecond_value (time_unit unit) const
| return the subsecond time fraction expressed in the given time unit
time_unit | get_unit () const
| returns the time unit used internally to store the subsecond time fraction
bool | get_value (time_t &second, time_t &subsecond, time_unit unit) const
| return a time as time_t arguments
void | dump (generic_file &x) const
| write down this to file
void | read (generic_file &f, archive_version ver)
| read this from file
bool | is_null () const
| return true if the datetime is exactly January 1st, 1970, 0 h 0 mn 0 s
bool | is_integer_second () const
| return true if the datetime is an integer number of second (subsecond part is zero)
infinint | get_storage_size () const
| return the storage it would require to dump this object
void | nullify ()
| set to null (zero)

## Static Public Member Functions
static std::string | unit_symbol (time_unit tu)
| return the SI symbol of the time unit (s, ms, us (should be mu greek letter), ns)

## Private Member Functions
void | reduce_to_largest_unit () const
| reduce the value to the largest unit possible
void | get_value (infinint &sec, infinint &sub, time_unit unit) const
void | build (const infinint &sec, const infinint &sub, time_unit unit)

## Static Private Member Functions
static time_unit | min (time_unit a, time_unit b)
static time_unit | max (time_unit a, time_unit b)
static char | time_unit_to_char (time_unit a)
static time_unit | char_to_time_unit (const char a)
static const infinint & | get_scaling_factor (time_unit source, time_unit dest)
| return the factor between two units

## Private Attributes
infinint | val
| the date expressed in the "uni" time unit
time_unit | uni
| the time unit used to store the subsecond fraction of the timestamp.

## Detailed Description

stores time information

Definition at line 58 of file datetime.hpp.

## Member Enumeration Documentation

## ◆ time_unit

enum libdar::datetime::time_unit

Definition at line 63 of file datetime.hpp.

## Constructor & Destructor Documentation

## ◆ datetime() [1/2]

libdar::datetime::datetime | ( | const infinint & | value = 0 | ) |
| inline

constructor based on the number of second ellasped since the end of 1969

Definition at line 66 of file datetime.hpp.

References uni, and val.

## ◆ datetime() [2/2]

libdar::datetime::datetime | ( | time_t | second,
|  | time_t | subsec,
|  | time_unit | unit )

general constructor

Parameters

  [in] | second | the number of second since the dawn of computer time (1970)
  [in] | subsec | the fraction of the time below 1 second expressed in the time unit given as next argument
  [in] | unit | the time unit in which is expressed the previous argument

## Member Function Documentation

## ◆ get_scaling_factor()

static const infinint & libdar::datetime::get_scaling_factor | ( | time_unit | source,
|  | time_unit | dest )
| staticprivate

return the factor between two units

Note
  "source" must be larger than "dest" (source >= dest), else an exception is thrown

Returns
  the factor f, which makes the following to be true: source = f*dest

## ◆ get_second_value()

infinint libdar::datetime::get_second_value | ( |  | ) | const
| inline

return the integer number of second

Definition at line 107 of file datetime.hpp.

References get_value(), and uni.

## ◆ get_unit()

time_unit libdar::datetime::get_unit | ( |  | ) | const
| inline

returns the time unit used internally to store the subsecond time fraction

Definition at line 113 of file datetime.hpp.

References uni.

## ◆ get_value()

bool libdar::datetime::get_value | ( | time_t & | second,
|  | time_t & | subsecond,
|  | time_unit | unit ) const

return a time as time_t arguments

Parameters

  [out] | second | the time value in second
  [out] | subsecond | is the remaining time fraction as expressed in the unit given as next argument
  [in] | unit | the unit of the subsecond fraction of the timestamp

Returns
  true upon success, false if the value cannot be represented by system types (overflow)

Referenced by libdar::list_entry::get_last_access(), libdar::list_entry::get_last_change(), libdar::list_entry::get_last_modif(), and get_second_value().

## ◆ is_integer_second()

bool libdar::datetime::is_integer_second | ( |  | ) | const
| inline

return true if the datetime is an integer number of second (subsecond part is zero)

Definition at line 134 of file datetime.hpp.

References uni.

## ◆ is_null()

bool libdar::datetime::is_null | ( |  | ) | const
| inline

return true if the datetime is exactly January 1st, 1970, 0 h 0 mn 0 s

Definition at line 131 of file datetime.hpp.

References libdar::infinint::is_zero(), and val.

## ◆ nullify()

void libdar::datetime::nullify | ( |  | ) |
| inline

set to null (zero)

Definition at line 140 of file datetime.hpp.

References uni, and val.

## ◆ operator!=()

bool libdar::datetime::operator!= | ( | const datetime & | ref | ) | const
| inline

Definition at line 89 of file datetime.hpp.

## ◆ operator+()

datetime libdar::datetime::operator+ | ( | const datetime & | ref | ) | const
| inline

Definition at line 98 of file datetime.hpp.

## ◆ operator-()

datetime libdar::datetime::operator- | ( | const datetime & | ref | ) | const
| inline

Definition at line 97 of file datetime.hpp.

## ◆ operator<=()

bool libdar::datetime::operator<= | ( | const datetime & | ref | ) | const
| inline

Definition at line 92 of file datetime.hpp.

## ◆ operator>()

bool libdar::datetime::operator> | ( | const datetime & | ref | ) | const
| inline

Definition at line 91 of file datetime.hpp.

## ◆ operator>=()

bool libdar::datetime::operator>= | ( | const datetime & | ref | ) | const
| inline

Definition at line 90 of file datetime.hpp.

## Member Data Documentation

## ◆ uni

time_unit libdar::datetime::uni
| private

the time unit used to store the subsecond fraction of the timestamp.

Definition at line 153 of file datetime.hpp.

Referenced by datetime(), get_second_value(), get_unit(), is_integer_second(), and nullify().

## ◆ val

infinint libdar::datetime::val
| private

the date expressed in the "uni" time unit

Definition at line 152 of file datetime.hpp.

Referenced by datetime(), is_null(), and nullify().

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

- datetime.hpp