Updated Examples and Recipes (markdown)

bandzaw
2018-03-19 23:14:50 +01:00
parent e0095170d4
commit 970908b0b0

@@ -33,6 +33,7 @@ This page contains examples and recipes contributed by community members. Feel f
- [Find and set UNIX download folder thanks to xdg-user-dir](#set_install_with_xdg_user_dir)
- [Re-using unzoned date/time code for zoned date/time values (and vice versa)](#zoned2unzoned)
- [Thoughts on reloading the IANA tzdb for long running programs](#tzdb_manage)
- [Converting from Unix Time to date::year_month_day](#unixtime2yearmonthday)
***
@@ -2382,6 +2383,23 @@ It isn't the most friendly code to have to write. But on the other hand, it giv
More complex (and expensive) policies could track reference count usage for each tzdb and delete only when that reference count drops to zero. It is completely implementable externally without any privileged hooks into `"tz.h"`. This design is motivated by the "don't pay for what you don't use" philosophy.
<a name="unixtime2yearmonthday"></a>
### The current local time
(by [tommy bandzaw](https://github.com/bandzaw))
When working with APIs that gives you a timestamp as a plain integer, signed or not, for example a Unix Time, and you want to use it with chrono/date/time calculations, here's what one can do (instead of using the time_t & localtime):
```c++
void callback(int unixtime)
{
auto t = std::chrono::seconds(unixtime);
std::chrono::system_clock::time_point tp(t);
auto d = date::floor<date::days>(tp);
date::year_month_day ymd(d);
date::month_day md(ymd.month(), ymd.day());
}
```
***
![CC BY Logo](http://mirrors.creativecommons.org/presskit/buttons/80x15/svg/by.svg) _This work is licensed under a [Creative Commons Attribution 4.0 International License](http://creativecommons.org/licenses/by/4.0/)._