Skip to content

Commit e329b23

Browse files
committed
Document that SystemTime does not count leap seconds
Fixes #77994
1 parent f2649cb commit e329b23

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

library/std/src/time.rs

+20
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,14 @@ pub struct Instant(time::Instant);
176176
/// The size of a `SystemTime` struct may vary depending on the target operating
177177
/// system.
178178
///
179+
/// A `SystemTime` does not count leap seconds.
180+
/// `SystemTime::now()`'s behaviour around a leap second
181+
/// is the same as the operating system's wall clock.
182+
/// The precise behaviour near a leap second
183+
/// (e.g. whether the clock appears to run slow or fast, or stop, or jump)
184+
/// depends on platform and configuration,
185+
/// so should not be relied on.
186+
///
179187
/// Example:
180188
///
181189
/// ```no_run
@@ -471,6 +479,12 @@ impl SystemTime {
471479
/// measurement lies, and using `UNIX_EPOCH + duration` can be used to create a
472480
/// `SystemTime` instance to represent another fixed point in time.
473481
///
482+
/// `duration_since(UNIX_EPOCH).unwrap().as_secs()`
483+
/// returns a POSIX `time_t` (as a `u64`):
484+
/// the number of non-leap seconds since the start of 1970 UTC.
485+
/// This is the same time representation as used in many Internet protocols,
486+
/// for example: JWT, CBOR, TOTP, certificate transparency and DNS TSIG/DNSSEC.
487+
///
474488
/// # Examples
475489
///
476490
/// ```no_run
@@ -630,6 +644,12 @@ impl fmt::Debug for SystemTime {
630644
/// measurement lies, and using `UNIX_EPOCH + duration` can be used to create a
631645
/// [`SystemTime`] instance to represent another fixed point in time.
632646
///
647+
/// `duration_since(UNIX_EPOCH).unwrap().as_secs()`
648+
/// returns a POSIX `time_t` (as a `u64`):
649+
/// the number of non-leap seconds since the start of 1970 UTC.
650+
/// This is the same time representation as used in many Internet protocols,
651+
/// for example: JWT, CBOR, TOTP, certificate transparency and DNS TSIG/DNSSEC.
652+
///
633653
/// # Examples
634654
///
635655
/// ```no_run

0 commit comments

Comments
 (0)