mirror of
https://github.com/HowardHinnant/date.git
synced 2025-08-03 20:54:27 +02:00
Updated Examples and Recipes (markdown)
@@ -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.
|
||||
|
||||
|
Reference in New Issue
Block a user