HowardHinnant / date

A date and time library based on the C++11/14/17 <chrono> header
Other
3.14k stars 675 forks source link

Run time specification of tzdb location with environment variable #788

Open samuel-emrys opened 1 year ago

samuel-emrys commented 1 year ago

Hi Howard/all,

Summary

To facilitate package management, I think it would be very useful to add an environment variable specifying the location of either a binary or a source database, which is read at runtime to discover the location of the database. This has the following benefits:

Context

I'm currently in the process of uplifting the conan date package to use the newly added tz package, which packages the tzdb. Currently it only supports a binary package, but can be uplifted to also package the source distribution.

The challenge I'm facing is that conan stores it packages in the conan cache, ~/.conan/p. Conan provides the facilities to make these packages available at runtime to consumer libraries via environmental scripts, which would be a convenient way to manage the tzdb to ensure that it remains modern, and distribute it with software releases. The challenge is that there doesn't seem to be a flexible way to tell date that this is where the tzdb lives.

To illustrate this, I thought I'd enumerate the ways that currently exist to customise tzdb location and talk about why these are unsuitable from a packaging perspective.

USE_SYSTEM_TZ_DB=1

The problem for package management

Because the location of the database can't be defined, it's not possible to use this to point at a portable version of a compiled database in a custom location.

I could look at attempting to install tzdb from conan into the system locations here, but I don't feel this would be wise - this is the domain of system package management and I'm not sure what effect this would have on system package managers.

MANUAL_TZ_DB=1

The problem for package management

MANUAL_TZ_DB=0 and USE_SYSTEM_TZ_DB=0

The problem for package management

Offloads management of tzdata as a dependency to the date library, rather than managed by the dependency (package) manager. Not a problem in and of itself, but orthogonal to the philosophy of using a package manager to manage dependencies.

Related issues

Customisation/management of these locations seems like an oft-requested feature:

These seem to have been stagnant for a few years now - in particular #611 seems to be the closest to what would be required here. Is there any intention to add this kind of customisation to the date library or is this kind of thing not being considered now that there's been acceptance of this into stdlib?

samuel-emrys commented 9 months ago

@HowardHinnant do you have any thoughts on whether this can be supported?

HowardHinnant commented 9 months ago

I'm sure it could be. I don't have the time to do it, or even to review someone else's work. Plus I am encouraging migration off of this library to C++20 chrono. I know that implementations are lagging, but MSVC is up to date, and gcc will be with gcc-14. Adding this feature (which does not exist in C++20 chrono) would hamper such migration.

I would have no objection whatsoever to someone forking this repository and providing this functionality on their own fork. I'd even be willing to link to it on my readme.

samuel-emrys commented 9 months ago

No problems, thanks for providing your position. I'll see if I can put some time into an implementation of this - I think the easiest way for me to handle this would be to submit a PR against this repo and use that as a patch for the conan recipe. Appreciate you may not have time to review and it sounds like acceptance might be counter to your aims of promoting chrono migration; if that position doesn't change then anybody who wants to use the patch they can use my fork (or, hopefully the conan package).

As for the migration - I'm fully on board with a desire to move to chrono and will as soon as it satisfies my requirements. The following are currently my blockers:

So, until the relevant chrono implementations reach sufficient maturity to unblock the above, there will still be a use case for using date for us.