Updated Examples and Recipes (markdown)

Howard Hinnant
2017-10-28 12:13:05 -04:00
parent 850c2f46cb
commit 85dc536b7f

@@ -2248,6 +2248,37 @@ tzdb_manager(std::atomic<bool>& run)
}
}
```
The above assumes a build with `DAUTO_DOWNLOAD=0`. That is, the tz lib won't automatically download the IANA tzdb for you. If you want to build with `DAUTO_DOWNLOAD=1` (which is the default on macOS and Linux), the code above can be simplified a bit by changing:
```c++
auto rv = remote_version();
if (rv != get_tzdb().version)
{
// download, install and load the new tzdb
if (remote_download(rv))
{
if (remote_install(rv))
{
reload_tzdb();
// Schedule cleanup of the old tzdb for 10 days from now
clean_at = check_at + days{10};
}
}
// if anything failed, we just try again tomorrow morning
}
```
to
```c++
auto rv = remote_version();
if (rv != get_tzdb().version)
{
// download, install and load the new tzdb
reload_tzdb();
// Schedule cleanup of the old tzdb for 10 days from now
clean_at = check_at + days{10};
// if anything failed, we just try again tomorrow morning
}
```
It isn't the most friendly code to have to write. But on the other hand, it gives you complete discretion on your `tzdb` delete policy and doesn't penalize clients that have no need to update their `tzdb` database.