C++ Utilities  4.6.1
Common C++ classes and routines used by my applications such as argument parser, IO and conversion utilities
period.cpp
Go to the documentation of this file.
1 #include "./period.h"
2 
3 namespace ChronoUtilities {
4 
13 Period::Period(const DateTime &beg, const DateTime &end)
14 {
15  m_years = end.year() - beg.year();
16  m_months = end.month() - beg.month();
17  m_days = end.day() - beg.day();
18  if (end.hour() < beg.hour()) {
19  --m_days;
20  }
21  if (m_days < 0) {
22  m_days += DateTime::daysInMonth(beg.year(), beg.month());
23  --m_months;
24  }
25  if (m_months < 0) {
26  m_months += 12;
27  --m_years;
28  }
29 }
30 
31 }
32 
33 
int year() const
Gets the year component of the date represented by this instance.
Definition: datetime.h:212
static int daysInMonth(int year, int month)
Returns the number of days in the specified month and year.
Definition: datetime.h:330
Represents an instant in time, typically expressed as a date and time of day.
Definition: datetime.h:55
Contains classes providing a means for handling date and time information.
Definition: datetime.h:12
int day() const
Gets the day component of the date represented by this instance.
Definition: datetime.h:228
int month() const
Gets the month component of the date represented by this instance.
Definition: datetime.h:220
Period(const DateTime &beg, const DateTime &end)
Constructs a new Period defined by a start DateTime and an end DateTime.
Definition: period.cpp:13
constexpr int hour() const
Gets the hour component of the date represented by this instance.
Definition: datetime.h:253