about summary refs log tree commit diff
path: root/src/libstd/time.rs
AgeCommit message (Collapse)AuthorLines
2020-02-29correct comment to match behaviorZan Tysor-1/+1
2020-01-28Update links to WASI docs in time.rs moduleJakub Konka-2/+2
Since the docs for the WASI API are now evolving in [WebAssembly/WASI] repo, I thought it might be useful to update the links in the docs to point to that location instead of using the outdated `CraneStation/wasmtime` destination. [WebAssembly/WASI]: https://github.com/WebAssembly/WASI
2020-01-18Fix table of syscalls in docs of std::time::SystemTime.Mara Bos-2/+2
2020-01-18Fix table of syscalls in docs of std::time::Instant.Mara Bos-2/+2
2020-01-12Fix system call docs for time::InstantRuud van Asseldonk-1/+1
The link for UNIX was pointing to the Cloud ABI docs. It should have been pointing to the clock_gettime docs instead. The table is repeated in the docs for SystemTime, but there the UNIX entry was already correct.
2019-12-31Add missing links for insecure_timeLzu Tao-0/+2
2019-12-24Deprecate Error::description for realDavid Tolnay-0/+1
`description` has been documented as soft-deprecated since 1.27.0 (17 months ago). There is no longer any reason to call it or implement it. This commit: - adds #[rustc_deprecated(since = "1.41.0")] to Error::description; - moves description (and cause, which is also deprecated) below the source and backtrace methods in the Error trait; - reduces documentation of description and cause to take up much less vertical real estate in rustdocs, while preserving the example that shows how to render errors without needing to call description; - removes the description function of all *currently unstable* Error impls in the standard library; - marks #[allow(deprecated)] the description function of all *stable* Error impls in the standard library; - replaces miscellaneous uses of description in example code and the compiler.
2019-10-05Fix typo on `now()` commentsBO41-28/+23
2019-09-14Rollup merge of #63846 - DevQps:32626-document-time-system-calls, r=rkruppeMazdak Farrokhzad-0/+46
Added table containing the system calls used by Instant and SystemTime. # Description See #32626 for a discussion on documenting system calls used by Instant and SystemTime. ## Changes - Added a table containing the system calls used by each platform. EDIT: If I can format this table better (due to the large links) please let me know. I'd also be happy to learn a quick command to generate the docs on my host machine! Currently I am using: `python x.py doc --stage 0 src/libstd` but that gives me some `unrecognized intrinsic` errors. Advice is always welcome :) closes #32626
2019-09-13Update src/libstd/time.rsChristian Veenman-1/+1
Co-Authored-By: Robin Kruppe <robin.kruppe@gmail.com>
2019-09-09Changed instant is earlier to instant is laterhman523-1/+1
2019-09-09Added some context on SGX. Lists Darwin separately.Christian-18/+32
2019-09-05Stabilize checked_duration_since for 1.39.0Vitaly _Vi Shukela-4/+2
Resolves #58402.
2019-08-26Update src/libstd/time.rsChristian Veenman-1/+3
Co-Authored-By: lzutao <taolzu@gmail.com>
2019-08-24Added table containing the system calls used by Instant and SystemTime.Christian-0/+30
2019-07-28SystemTime docs: recommend Instant for elapsed timeKornel-2/+8
2019-03-31libstd: deny(elided_lifetimes_in_paths)Mazdak Farrokhzad-3/+3
2019-03-22Make duration_since use checked_duration_sinceLinus Färnstrand-6/+2
2019-03-22Add/rename checked_duration_since testsLinus Färnstrand-6/+9
2019-03-12Make std time tests more robust for platform differencesJethro Beekman-9/+2
2019-02-28libstd => 2018Taiki Endo-8/+8
2019-02-23Rollup merge of #58595 - stjepang:make-duration-consts-associated, r=oli-obkMazdak Farrokhzad-3/+0
Turn duration consts into associated consts As suggested in https://github.com/rust-lang/rust/issues/57391#issuecomment-459658236, I'm moving `Duration` constants (`SECOND`, `MILLISECOND` and so on; currently behind unstable `duration_constants` feature) into the `impl Duration` block. cc @frewsxcv @SimonSapin
2019-02-20Turn duration consts into associated constsStjepan Glavina-3/+0
2019-02-17Rollup merge of #58395 - vi:checked_duration_since, r=dtolnaykennytm-0/+60
Instant::checked_duration_since
2019-02-13Add Instant::saturating_duration_sinceVitaly _Vi Shukela-0/+28
2019-02-13Fix tests for checked_duration_sinceVitaly _Vi Shukela-1/+3
2019-02-13Rollup merge of #58034 - faern:stabilize-time-checked-add, r=alexcrichtonMazdak Farrokhzad-8/+8
Stabilize the time_checked_add feature Closes #55940 Stabilizes `checked_add` and `checked_sub` on `Instant` and `SystemTime`.
2019-02-13Add Instant::checked_duration_since, address #58402.Vitaly _Vi Shukela-0/+30
2019-02-10tests: doc commentsAlexander Regueiro-1/+1
2019-01-31Simplify lambdasLinus Färnstrand-4/+4
2019-01-31Stabilize the time_checked_add featureLinus Färnstrand-4/+4
2019-01-22Simplify units in Duration/Instant math on WindowsAlex Berghage-0/+9
Right now we do unit conversions between PerfCounter measurements and nanoseconds for every add/sub we do between Durations and Instants on Windows machines. This leads to goofy behavior, like this snippet failing: ``` let now = Instant::now(); let offset = Duration::from_millis(5); assert_eq!((now + offset) - now, (now - now) + offset); ``` with precision problems like this: ``` thread 'main' panicked at 'assertion failed: `(left == right)` left: `4.999914ms`, right: `5ms`', src\main.rs:6:5 ``` To fix it, this changeset does the unit conversion once, when we measure the clock, and all the subsequent math in u64 nanoseconds. It also adds an exact associativity test to the `sys/time.rs` test suite to make sure we don't regress on this in the future.
2019-01-08Auto merge of #56988 - alexcrichton:monotonic-instant, r=sfacklerbors-1/+41
std: Force `Instant::now()` to be monotonic This commit is an attempt to force `Instant::now` to be monotonic through any means possible. We tried relying on OS/hardware/clock implementations, but those seem buggy enough that we can't rely on them in practice. This commit implements the same hammer Firefox recently implemented (noted in #56612) which is to just keep whatever the lastest `Instant::now()` return value was in memory, returning that instead of the OS looks like it's moving backwards. Closes #48514 Closes #49281 cc #51648 cc #56560 Closes #56612 Closes #56940
2019-01-07std: Force `Instant::now()` to be monotonicAlex Crichton-1/+41
This commit is an attempt to force `Instant::now` to be monotonic through any means possible. We tried relying on OS/hardware/clock implementations, but those seem buggy enough that we can't rely on them in practice. This commit implements the same hammer Firefox recently implemented (noted in #56612) which is to just keep whatever the lastest `Instant::now()` return value was in memory, returning that instead of the OS looks like it's moving backwards. Closes #48514 Closes #49281 cc #51648 cc #56560 Closes #56612 Closes #56940
2019-01-07Rollup merge of #57375 - stjepang:duration-constants, r=joshtriplettPietro Albini-0/+3
Add duration constants Add constants `SECOND`, `MILLISECOND`, `MICROSECOND`, and `NANOSECOND` to `core::time`. This will make working with durations more ergonomic. Compare: ```rust // Convenient, but deprecated function. thread::sleep_ms(2000); // The current canonical way to sleep for two seconds. thread::sleep(Duration::from_secs(2)); // Sleeping using one of the new constants. thread::sleep(2 * SECOND); ```
2019-01-07Specify the tracking issueStjepan Glavina-1/+1
2019-01-06Re-export constants from core into stdStjepan Glavina-0/+3
2019-01-02Auto merge of #56827 - faern:eliminate-recv-timeout-panic, r=KodrAusbors-0/+12
Eliminate Receiver::recv_timeout panic Fixes #54552. This panic is because `recv_timeout` uses `Instant::now() + timeout` internally. This possible panic is not mentioned in the documentation for this method. Very recently we merged (still unstable) support for checked addition (#56490) of `Instant + Duration`, so it's now finally possible to add these together without risking a panic.
2018-12-25Remove licensesMark Rousskov-10/+0
2018-12-14Add documentation about panicking Add<Duration> implsLinus Färnstrand-0/+12
2018-12-13Add checked_sub for Instant and SystemTimeLinus Färnstrand-2/+22
2018-12-13Add checked_add method to Instant time typeLinus Färnstrand-2/+25
2018-12-07Various minor/cosmetic improvements to codeAlexander Regueiro-1/+1
2018-11-25Auto merge of #55527 - sgeisler:time-checked-add, r=sfacklerbors-0/+21
Implement checked_add_duration for SystemTime [Original discussion on the rust user forum](https://users.rust-lang.org/t/std-systemtime-misses-a-checked-add-function/21785) Since `SystemTime` is opaque there is no way to check if the result of an addition will be in bounds. That makes the `Add<Duration>` trait completely unusable with untrusted data. This is a big problem because adding a `Duration` to `UNIX_EPOCH` is the standard way of constructing a `SystemTime` from a unix timestamp. This PR implements `checked_add_duration(&self, &Duration) -> Option<SystemTime>` for `std::time::SystemTime` and as a prerequisite also for all platform specific time structs. This also led to the refactoring of many `add_duration(&self, &Duration) -> SystemTime` functions to avoid redundancy (they now unwrap the result of `checked_add_duration`). Some basic unit tests for the newly introduced function were added too. I wasn't sure which stabilization attribute to add to the newly introduced function, so I just chose `#[stable(feature = "time_checked_add", since = "1.32.0")]` for now to make it compile. Please let me know how I should change it or if I violated any other conventions. P.S.: I could only test on Linux so far, so I don't necessarily expect it to compile for all platforms.
2018-11-18Increase `Duration` approximate equal threshold to 1usAlex Crichton-1/+1
Previously this threshold when testing was 100ns, but the Windows documentation states: > which is a high resolution (<1us) time stamp which presumably means that we could have up to 1us resolution, which means that 100ns doesn't capture "equivalent" time intervals due to various bits of rounding here and there. It's hoped that this.. Closes #56034
2018-11-17std: Add debugging for a failing test on appveyorAlex Crichton-1/+5
I'm not sure why this is failing, so let's hopefully get some more information to help investigation!
2018-11-15Rename checked_add_duration to checked_add and make it take the duration by ↵Sebastian Geisler-5/+5
value
2018-11-15Implement checked_add_duration for SystemTimeSebastian Geisler-0/+21
Since SystemTime is opaque there is no way to check if the result of an addition will be in bounds. That makes the Add<Duration> trait completely unusable with untrusted data. This is a big problem because adding a Duration to UNIX_EPOCH is the standard way of constructing a SystemTime from a unix timestamp. This commit implements checked_add_duration(&self, &Duration) -> Option<SystemTime> for std::time::SystemTime and as a prerequisite also for all platform specific time structs. This also led to the refactoring of many add_duration(&self, &Duration) -> SystemTime functions to avoid redundancy (they now unwrap the result of checked_add_duration). Some basic unit tests for the newly introduced function were added too.
2018-05-28Stabilize SystemTime::UNIX_EPOCHThayne McCombs-2/+1
2018-03-30Fix doctestSteven Fackler-0/+1