time::util

Function refresh_tz_unchecked

Source
pub unsafe fn refresh_tz_unchecked()
Available on crate feature local-offset only.
Expand description

Update time zone information from the system.

For a version of this function that is guaranteed to be sound, see refresh_tz.

§Safety

This is a system call with specific requirements. The following is from POSIX’s description of tzset:

If a thread accesses tzname, daylight, or timezone directly while another thread is in a call to tzset(), or to any function that is required or allowed to set timezone information as if by calling tzset(), the behavior is undefined.

Effectively, this translates to the requirement that at least one of the following must be true:

  • The operating system provides a thread-safe environment.
  • The process is single-threaded.
  • The process is multi-threaded and no other thread is mutating the environment in any way at the same time a call to a method that obtains the local UTC offset. This includes adding, removing, or modifying an environment variable.

§Soundness is global

You must not only verify this safety conditions for your code, but for all code that will be included in the final binary. Notably, it applies to both direct and transitive dependencies and to both Rust and non-Rust code. For this reason it is not possible for a library to soundly call this method.

§Forward compatibility

This currently only does anything on Unix-like systems. On other systems, it is a no-op. This may change in the future if necessary, expanding the safety requirements. It is expected that, at a minimum, calling this method when the process is single-threaded will remain sound.