Commit Graph

177 Commits

Author SHA1 Message Date
BO41
318ff305ea Fix typo on now() comments 2019-10-05 12:23:10 +02:00
Mazdak Farrokhzad
baaaea3de3 Rollup merge of #63846 - DevQps:32626-document-time-system-calls, r=rkruppe
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-14 16:42:19 +02:00
Christian Veenman
b3b671366b Update src/libstd/time.rs
Co-Authored-By: Robin Kruppe <robin.kruppe@gmail.com>
2019-09-13 16:29:06 +02:00
hman523
79263afb3e Changed instant is earlier to instant is later 2019-09-09 21:19:01 -05:00
Christian
3dd0e2b89e Added some context on SGX. Lists Darwin separately. 2019-09-09 22:10:53 +02:00
Vitaly _Vi Shukela
843fba3ed1 Stabilize checked_duration_since for 1.39.0
Resolves #58402.
2019-09-05 01:58:37 +03:00
Christian Veenman
1478ef4528 Update src/libstd/time.rs
Co-Authored-By: lzutao <taolzu@gmail.com>
2019-08-26 22:05:26 +02:00
Christian
33788c252c Added table containing the system calls used by Instant and SystemTime. 2019-08-24 14:49:17 +02:00
Kornel
55c07b39ae SystemTime docs: recommend Instant for elapsed time 2019-07-28 11:08:39 +01:00
Mazdak Farrokhzad
379c380a60 libstd: deny(elided_lifetimes_in_paths) 2019-03-31 12:56:51 +02:00
Linus Färnstrand
d56b1fd0e7 Make duration_since use checked_duration_since 2019-03-22 22:53:07 +01:00
Linus Färnstrand
37cfeb2710 Add/rename checked_duration_since tests 2019-03-22 22:53:07 +01:00
Jethro Beekman
adbd0a6645 Make std time tests more robust for platform differences 2019-03-12 17:51:39 -07:00
Taiki Endo
93b6d9e086 libstd => 2018 2019-02-28 04:06:15 +09:00
Mazdak Farrokhzad
73e661a0a5 Rollup merge of #58595 - stjepang:make-duration-consts-associated, r=oli-obk
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-23 09:25:29 +01:00
Stjepan Glavina
8e219e7eb5 Turn duration consts into associated consts 2019-02-20 14:21:15 +01:00
kennytm
17b07f99e8 Rollup merge of #58395 - vi:checked_duration_since, r=dtolnay
Instant::checked_duration_since
2019-02-17 14:52:23 +08:00
Vitaly _Vi Shukela
91f67fd1a7 Add Instant::saturating_duration_since 2019-02-13 15:08:44 +03:00
Vitaly _Vi Shukela
d15c358000 Fix tests for checked_duration_since 2019-02-13 13:17:33 +03:00
Mazdak Farrokhzad
0ab1057a56 Rollup merge of #58034 - faern:stabilize-time-checked-add, r=alexcrichton
Stabilize the time_checked_add feature

Closes #55940

Stabilizes `checked_add` and `checked_sub` on `Instant` and `SystemTime`.
2019-02-13 04:36:58 +01:00
Vitaly _Vi Shukela
7b2a08cf49 Add Instant::checked_duration_since, address #58402. 2019-02-13 00:49:48 +03:00
Alexander Regueiro
b87363e763 tests: doc comments 2019-02-10 23:42:32 +00:00
Linus Färnstrand
2f2d49523a Simplify lambdas 2019-01-31 23:18:07 +01:00
Linus Färnstrand
f841ff4a7b Stabilize the time_checked_add feature 2019-01-31 20:46:11 +01:00
Alex Berghage
55dea0edec Simplify units in Duration/Instant math on Windows
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-22 19:18:28 -07:00
bors
2f19f8cec9 Auto merge of #56988 - alexcrichton:monotonic-instant, r=sfackler
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-08 11:30:19 +00:00
Alex Crichton
255a3f3e18 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-07 08:00:47 -08:00
Pietro Albini
bc38143ad2 Rollup merge of #57375 - stjepang:duration-constants, r=joshtriplett
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-07 16:25:40 +01:00
Stjepan Glavina
8c902b6633 Specify the tracking issue 2019-01-07 11:39:22 +01:00
Stjepan Glavina
72ec5aa080 Re-export constants from core into std 2019-01-06 14:04:07 +01:00
bors
96530344ef Auto merge of #56827 - faern:eliminate-recv-timeout-panic, r=KodrAus
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.
2019-01-02 02:03:15 +00:00
Mark Rousskov
2a663555dd Remove licenses 2018-12-25 21:08:33 -07:00
Linus Färnstrand
496f547af6 Add documentation about panicking Add<Duration> impls 2018-12-14 21:49:50 +01:00
Linus Färnstrand
f5a99c321b Add checked_sub for Instant and SystemTime 2018-12-13 15:25:14 +01:00
Linus Färnstrand
13f0463a19 Add checked_add method to Instant time type 2018-12-13 15:25:14 +01:00
Alexander Regueiro
ee89c088b0 Various minor/cosmetic improvements to code 2018-12-07 23:53:34 +00:00
bors
6acbb5b65c Auto merge of #55527 - sgeisler:time-checked-add, r=sfackler
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-25 19:01:35 +00:00
Alex Crichton
86073253d5 Increase Duration approximate equal threshold to 1us
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-18 19:08:06 -08:00
Alex Crichton
7a99b6db15 std: Add debugging for a failing test on appveyor
I'm not sure why this is failing, so let's hopefully get some more
information to help investigation!
2018-11-17 19:38:53 -08:00
Sebastian Geisler
86ef38b3b7 Rename checked_add_duration to checked_add and make it take the duration by value 2018-11-15 22:55:27 -08:00
Sebastian Geisler
6d40b7232e Implement checked_add_duration for SystemTime
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-11-15 22:55:24 -08:00
Thayne McCombs
855ec8b6d5 Stabilize SystemTime::UNIX_EPOCH 2018-05-28 18:24:01 -06:00
Steven Fackler
df2e238d1a Fix doctest 2018-03-30 15:35:36 +02:00
Steven Fackler
dfde231eca Make UNIX_EPOCH an associated constant of SystemTime
It's not very discoverable as a separate const in the module.
2018-03-30 12:44:32 +02:00
Phlosioneer
efd04423c3 Add backticks 2018-03-24 23:41:34 -04:00
Phlosioneer
e63b1a0e36 Remove "and may change between Rust releases" 2018-03-11 17:17:18 -04:00
Phlosioneer
908328fca0 Document when types have OS-dependent sizes
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-03-11 07:53:19 -04:00
Clar Charr
aab712cbc8 Move time::Duration to libcore 2018-01-29 18:16:43 -05:00
Patrick Walton
0c820d4123 libstd: Rename libcore to libstd and libstd to libextra; update makefiles.
This only changes the directory names; it does not change the "real"
metadata names.
2013-05-22 21:57:05 -07:00
Alex Crichton
82fa0018c8 Remove all unnecessary allocations (as flagged by lint) 2013-05-20 16:10:40 -05:00