mirror of
https://github.com/HowardHinnant/date.git
synced 2025-08-05 13:44:26 +02:00
Updated Examples and Recipes (markdown)
@@ -1623,20 +1623,27 @@ Turns out not hard at all.
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
using fortnights =
|
using fortnights =
|
||||||
std::chrono::duration<date::weeks::rep, std::ratio_multiply<std::ratio<2>,
|
std::chrono::duration<date::weeks::rep,
|
||||||
date::weeks::period>>;
|
std::ratio_multiply<std::ratio<2>, date::weeks::period>>;
|
||||||
|
|
||||||
using microfortnights =
|
using microfortnights =
|
||||||
std::chrono::duration<std::int64_t, std::ratio_multiply<fortnights::period,
|
std::chrono::duration<std::int64_t, std::ratio_multiply<fortnights::period,
|
||||||
std::micro>>;
|
std::micro>>;
|
||||||
|
|
||||||
|
constexpr
|
||||||
|
inline
|
||||||
|
microfortnights
|
||||||
|
operator"" _ufn(unsigned long long x)
|
||||||
|
{
|
||||||
|
return microfortnights{static_cast<microfortnights::rep>(x)};
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main()
|
main()
|
||||||
{
|
{
|
||||||
using namespace date;
|
using namespace date;
|
||||||
using namespace std::chrono;
|
using namespace std::chrono;
|
||||||
std::cout << format("%F %T\n", sys_days{nov/29/2016} + 15h + 13min +
|
std::cout << format("%F %T\n", sys_days{nov/29/2016} + 15h + 13min + 35_ufn);
|
||||||
microfortnights{35});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
The first thing to do is build your `chrono::duration` that represents a `microfortnight`. This is best done by first building a `fortnight`, and then multiplying that by `std::micro`. This will build some weird `chrono::duration` with a period we don't really have to know, but turns out to be not that far off from a second.
|
The first thing to do is build your `chrono::duration` that represents a `microfortnight`. This is best done by first building a `fortnight`, and then multiplying that by `std::micro`. This will build some weird `chrono::duration` with a period we don't really have to know, but turns out to be not that far off from a second.
|
||||||
|
Reference in New Issue
Block a user