mirror of
https://github.com/HowardHinnant/date.git
synced 2025-08-02 20:24:27 +02:00
Updated Examples and Recipes (markdown)
@@ -1828,32 +1828,34 @@ If you're dealing with quarter-second durations, or frame-durations of 1/60 seco
|
||||
|
||||
Turns out not hard at all.
|
||||
|
||||
#include "date.h"
|
||||
#include <iostream>
|
||||
```c++
|
||||
#include "date.h"
|
||||
#include <iostream>
|
||||
|
||||
using fortnights =
|
||||
std::chrono::duration<date::weeks::rep,
|
||||
std::ratio_multiply<std::ratio<2>, date::weeks::period>>;
|
||||
using fortnights =
|
||||
std::chrono::duration<date::weeks::rep,
|
||||
std::ratio_multiply<std::ratio<2>, date::weeks::period>>;
|
||||
|
||||
using microfortnights =
|
||||
std::chrono::duration<std::int64_t, std::ratio_multiply<fortnights::period,
|
||||
std::micro>>;
|
||||
using microfortnights =
|
||||
std::chrono::duration<std::int64_t, std::ratio_multiply<fortnights::period,
|
||||
std::micro>>;
|
||||
|
||||
constexpr
|
||||
inline
|
||||
microfortnights
|
||||
operator"" _ufn(unsigned long long x)
|
||||
{
|
||||
return microfortnights{static_cast<microfortnights::rep>(x)};
|
||||
}
|
||||
constexpr
|
||||
inline
|
||||
microfortnights
|
||||
operator"" _ufn(unsigned long long x)
|
||||
{
|
||||
return microfortnights{static_cast<microfortnights::rep>(x)};
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
using namespace date;
|
||||
using namespace std::chrono;
|
||||
std::cout << format("%F %T\n", sys_days{nov/29/2016} + 15h + 13min + 35_ufn);
|
||||
}
|
||||
int
|
||||
main()
|
||||
{
|
||||
using namespace date;
|
||||
using namespace std::chrono;
|
||||
std::cout << format("%F %T\n", sys_days{nov/29/2016} + 15h + 13min + 35_ufn);
|
||||
}
|
||||
```
|
||||
|
||||
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.
|
||||
|
||||
@@ -1872,7 +1874,7 @@ If this library can do this so easily with something as crazy as `microfortnight
|
||||
|
||||
The library uses the path `~/Downloads` by default. What if you use a different path for your download directory such as `~/Téléchargements` or `~/Завантаження` and you want your program to automatically find this path ? A solution is to use [xdg_user_dir](https://freedesktop.org/wiki/Software/xdg-user-dirs/). The following code shows you how you can do it :
|
||||
|
||||
```
|
||||
```c++
|
||||
#include "date.h"
|
||||
#include "tz.h"
|
||||
|
||||
|
Reference in New Issue
Block a user