C++ Utilities: CppUtilities::Period Class Reference

C++ Utilities 5.34.2 Useful C++ classes and routines such as argument parser, IO and conversion utilities

Loading...
Searching...
No Matches
Public Member Functions | List of all members
CppUtilities::Period Class Reference

Represents a period of time. More...

`#include <period.h>`

## Public Member Functions
constexpr | Period ()
| Period (DateTime begin, DateTime end)
| Constructs a new Period defined by a start DateTime and an end DateTime.
constexpr int | years () const
| Returns the years component of the period represented by the current instance.
constexpr int | months () const
| Returns the months component of the period represented by the current instance.
constexpr int | days () const
| Returns the days component of the period represented by the current instance.

## Detailed Description

Represents a period of time.

In contrast to the TimeSpan class, a Period represents a duration expressed in years, months and days between a concrete starting DateTime and end DateTime. Without that context, the exact duration represented by a Period is not clearly defined as years and month have different lengths.

This is also the reason for the absence of the TimeSpan::totalYears() and TimeSpan::totalMonth() methods as the TimeSpan class is meant to express a duration independently of the concrete starting DateTime and end DateTime.

The Period class, on the other hand, expresses the duration between a concrete starting DateTime and end DateTime as the number of years, month and days which have been passed in that particular order. The accuracy is one day, so the DateTime::timeOfDay() is lost.

Remarks
  The order really matters. For example, the Period between DateTime::fromDateAndTime(1994, 7, 18) and DateTime::fromDateAndTime(2017, 12, 2) is 23 years, 4 month and 14 days. That means 23 years have been passed, then 4 month and finally 14 days. Adding the 14 days first and then the 4 month would make a difference of one day because July has 31 days and November only 30.

Definition at line 8 of file period.h.

## Constructor & Destructor Documentation

## ◆ Period() [1/2]

CppUtilities::Period::Period | ( |  | ) |
| constexpr

Definition at line 22 of file period.h.

## ◆ Period() [2/2]

CppUtilities::Period::Period | ( | DateTime | begin,
|  | DateTime | end )

Constructs a new Period defined by a start DateTime and an end DateTime.

The resulting Period will contain the number of years, month and days which have been passed between begin and end.

Definition at line 33 of file period.cpp.

## Member Function Documentation

## ◆ days()

int CppUtilities::Period::days | ( |  | ) | const
| constexpr

Returns the days component of the period represented by the current instance.

Definition at line 48 of file period.h.

## ◆ months()

int CppUtilities::Period::months | ( |  | ) | const
| constexpr

Returns the months component of the period represented by the current instance.

Definition at line 40 of file period.h.

## ◆ years()

int CppUtilities::Period::years | ( |  | ) | const
| constexpr

Returns the years component of the period represented by the current instance.

Definition at line 32 of file period.h.

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

- chrono/period.h
- chrono/period.cpp