about summary refs log tree commit diff
path: root/library/std/src/time.rs
diff options
context:
space:
mode:
authorIan Jackson <ijackson@chiark.greenend.org.uk>2023-03-27 12:33:20 +0100
committerIan Jackson <ijackson@chiark.greenend.org.uk>2023-03-27 12:52:19 +0100
commite329b23104177561a11bb675ea8c77553f2fbcc7 (patch)
treeed0f643c139c1a71b50c14ec0cc3d6a87f6aad89 /library/std/src/time.rs
parentf2649cb9613e14a5737334b264f1c0d6cdbfde60 (diff)
downloadrust-e329b23104177561a11bb675ea8c77553f2fbcc7.tar.gz
rust-e329b23104177561a11bb675ea8c77553f2fbcc7.zip
Document that SystemTime does not count leap seconds
Fixes #77994
Diffstat (limited to 'library/std/src/time.rs')
-rw-r--r--library/std/src/time.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/library/std/src/time.rs b/library/std/src/time.rs
index 1aa98436ef6..fae677e5729 100644
--- a/library/std/src/time.rs
+++ b/library/std/src/time.rs
@@ -176,6 +176,14 @@ pub struct Instant(time::Instant);
 /// The size of a `SystemTime` struct may vary depending on the target operating
 /// system.
 ///
+/// A `SystemTime` does not count leap seconds.
+/// `SystemTime::now()`'s behaviour around a leap second
+/// is the same as the operating system's wall clock.
+/// The precise behaviour near a leap second
+/// (e.g. whether the clock appears to run slow or fast, or stop, or jump)
+/// depends on platform and configuration,
+/// so should not be relied on.
+///
 /// Example:
 ///
 /// ```no_run
@@ -471,6 +479,12 @@ impl SystemTime {
     /// measurement lies, and using `UNIX_EPOCH + duration` can be used to create a
     /// `SystemTime` instance to represent another fixed point in time.
     ///
+    /// `duration_since(UNIX_EPOCH).unwrap().as_secs()`
+    /// returns a POSIX `time_t` (as a `u64`):
+    /// the number of non-leap seconds since the start of 1970 UTC.
+    /// This is the same time representation as used in many Internet protocols,
+    /// for example: JWT, CBOR, TOTP, certificate transparency and DNS TSIG/DNSSEC.
+    ///
     /// # Examples
     ///
     /// ```no_run
@@ -630,6 +644,12 @@ impl fmt::Debug for SystemTime {
 /// measurement lies, and using `UNIX_EPOCH + duration` can be used to create a
 /// [`SystemTime`] instance to represent another fixed point in time.
 ///
+/// `duration_since(UNIX_EPOCH).unwrap().as_secs()`
+/// returns a POSIX `time_t` (as a `u64`):
+/// the number of non-leap seconds since the start of 1970 UTC.
+/// This is the same time representation as used in many Internet protocols,
+/// for example: JWT, CBOR, TOTP, certificate transparency and DNS TSIG/DNSSEC.
+///
 /// # Examples
 ///
 /// ```no_run