std/time/download▲toc

Automatic downloading of time information.

Provides auto download functions to use the latest leap second tables, time zone information, and UT1 tables.

Download a file from url and cache it locally in file cache (=pathstd/os/path/path: (s : string) -> path("")) if that path is not empty. The parse function parses the downloaded content. The optional expirestd/time/utc/expire: (leaps-table) -> instant (={Nothingstd/core/Nothing: forall<a> maybe<a>}) function can return an optional expiration date from the content which is used to check if the downloaded content is newer than the optional current data current (=Nothingstd/core/Nothing: forall<a> maybe<a>). The download-timeout gives the download timeout. The error-prefix is prepended to any error messages (=download failed). Set the optional parameter verbose to Truestd/core/True: bool to see trace messages on downloads or errors.

Load a file from a cached file fname or URL url. The file is parsed with the parse function. Given the result of parse, a future expiration date may be given by the file through the expirestd/time/utc/expire: (leaps-table) -> instant function. This is used for example in leap second files to prevent downloading too often. There may also be a current value that is returned if any error occurs. The download-timeout gives the download time out, while the download-delay gives the minimum amount of time that must have passed before a newer file is downloaded again. The error-prefix is prepended to any error messages (=load cached). Set the optional parameter verbose to Truestd/core/True: bool to see trace messages on downloads or errors.
The function first checks if the current data is not yet expired and returns it directly if it is still valid. Otherwise, it attempts to read and parse the file from fname. If it is valid and newer than current and not yet expired, it is returned. Otherwise, if url is not empty, it calls download-lateststd/time/download/download-latest: forall<a> (url : string, parse : (string) -> maybe<a>, expire : ?(a) -> maybe<instant>, cache : ?path, current : ?maybe<a>, download-timeout : ?duration, error-prefix : ?string, verbose : ?bool) -> <ndet,file,net,async,exn> a to download and cache the file.

Load the latest leap second information from file fname (= "config/leap-seconds.list" in the application directory). If the file is not present, it will be downloaded from url. The default url is:
https://​www.​ietf.​org/​timezones/​data/​leap-​seconds.​list
Set the url to the empty string to suppress automatic downloading. If the file is older than download-delay (=4.weeksstd/time/duration/weeks: (n : int) -> duration) the file is automatically refreshed from url. The download-timeout (=5.seconds) gives the maximum time for downloading to finish. Set the optional parameter verbose to Truestd/core/True: bool to see trace messages on downloads or errors.

Construct a UTC time scale using the latest IERS leap second information from file fname (= "config/leap-seconds.list" in the application directory). If the file is not present, it will be downloaded from url. The default url is:
https://​www.​ietf.​org/​timezones/​data/​leap-​seconds.​list
Set the url to the empty string to suppress automatic downloading. If the file is older than download-delay (=4.weeksstd/time/duration/weeks: (n : int) -> duration) the file is automatically refreshed from url. The download-timeout (=5.seconds) gives the maximum time for downloading to finish. Set the optional parameter verbose to Truestd/core/True: bool to see trace messages on downloads or errors.