about summary refs log tree commit diff
path: root/src/libstd/time.rs
AgeCommit message (Collapse)AuthorLines
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
2018-03-30Make UNIX_EPOCH an associated constant of SystemTimeSteven Fackler-0/+22
It's not very discoverable as a separate const in the module.
2018-03-24Add backticksPhlosioneer-2/+2
2018-03-11Remove "and may change between Rust releases"Phlosioneer-2/+2
2018-03-11Document when types have OS-dependent sizesPhlosioneer-0/+6
As per issue #43601, types that can change size depending on the target operating system should say so in their documentation. I used this template when adding doc comments: The size of a(n) <name> struct may vary depending on the target operating system, and may change between Rust releases. For enums, I used "instance" instead of "struct".
2018-01-29Move time::Duration to libcoreClar Charr-0/+565
2013-05-22libstd: Rename libcore to libstd and libstd to libextra; update makefiles.Patrick Walton-1268/+0
This only changes the directory names; it does not change the "real" metadata names.
2013-05-20Remove all unnecessary allocations (as flagged by lint)Alex Crichton-13/+13
2013-05-19Use assert_eq! rather than assert! where possibleCorey Richardson-47/+47
2013-05-16syntax: deprecate #[auto_{en,de}code] in favour of #[deriving({En,De}codable)].Huon Wilson-6/+2
Replace all instances of #[auto_*code] with the appropriate #[deriving] attribute and remove the majority of the actual code, leaving stubs to refer the user to the new syntax.
2013-05-10renamed str::from_slice to str::to_ownedYoungsoo Son-4/+4
2013-05-09libstd: rename vec::each(var) to var.eachYoungmin Yoo-9/+8
2013-04-27only use #[no_core] in libcoreDaniel Micay-9/+0
2013-04-20std: remove unused 'mut' variablesAlex Crichton-2/+2
2013-04-16libcore,std,syntax,rustc: move tests into `mod tests`, make them private (no ↵Huon Wilson-11/+11
pub mod or pub fn).
2013-04-08Removing no longer needed unsafe blocksAlex Crichton-6/+2
2013-03-29librustc: Remove `fail_unless!`Patrick Walton-182/+182