Skip to content

calendar.h ~ calendar ~ make_duration

Baptiste Thémine edited this page Aug 6, 2020 · 5 revisions
constexpr duration_type make_duration(int year=0, int month=0, int week=0, int day=0, int hour=0, int min=0, int sec=0, int milli=0) noexcept;

Description

Initializes a duration_type structure.

Parameters

(Optional)

  • year --> positive or negative number of years
  • month --> positive or negative number of months
  • week --> positive or negative number of weeks
  • day --> positive or negative number of days
  • hour --> positive or negative number of hours
  • min --> positive or negative number of minutes
  • sec --> positive or negative number of seconds
  • milli --> positive or negative number of milliseconds

Return value

Sums all the specified parameters and returns a duration_type object with all its members initialized. If the sum exceeds the maximum value of a duration_type, returns a default initialized duration_type.

Exceptions

Never throws exception.

Examples

#include <iostream>
#include <JLC/JLC.h>
using namespace JLC;
using typename calendar::duration_type;

int main(){
    constexpr duration_type duration = calendar::make_duration(0,0,123);
    std::cout << "123 weeks = " << duration.year << " years";
    std::cout << " + " << duration.month << " months";
    std::cout << " + " << duration.week << " weeks";
    std::cout << " + " << duration.day << " days" << std::endl;
}
123 weeks = 2 years + 4 months + 1 weeks + 0 days

See also

Clone this wiki locally