about summary refs log tree commit diff
path: root/src/libstd/time.rs
AgeCommit message (Collapse)AuthorLines
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
2013-03-23replace impls with `deriving` where applicableAndrew Paseltiner-25/+2
2013-03-22librustc: Remove the `const` declaration form everywherePatrick Walton-3/+3
2013-03-22libstd: Remove all uses of `pure` from libstd. rs=depurePatrick Walton-17/+17
2013-03-22librustc: Remove all uses of `static` from functions. rs=destaticPatrick Walton-1/+1
2013-03-20libsyntax: Never use `::<>` in the type grammarPatrick Walton-2/+2
2013-03-13Revamp foreign code not to consider the Rust modes. This requiresNiko Matsakis-8/+8
adjusting a few foreign functions that were declared with by-ref mode. This also allows us to remove by-val mode in the near future. With copy mode, though, we have to be careful because Rust will implicitly pass somethings by pointer but this may not be the C ABI rules. For example, rust will pass a struct Foo as a Foo*. So I added some code into the adapters to fix this (though the C ABI rules may put the pointer back, oh well). This patch also includes a lint mode for the use of by-ref mode in foreign functions as the semantics of this have changed.
2013-03-07test: Fix tests.Patrick Walton-8/+8
2013-03-07librustc: Convert all uses of `assert` over to `fail_unless!`Patrick Walton-184/+184
2013-03-07libstd: Remove `extern mod { ... }` from libstd. rs=deexterningPatrick Walton-12/+20
2013-03-07De-implicit-self libstdBen Striegel-9/+9
2013-03-04Remove unused imports throughout src/Alex Crichton-3/+0
2013-02-28Fix implicit leaks of imports throughout librariesAlex Crichton-8/+7
Also touch up use of 'pub' and move some tests around so the tested functions don't have to be 'pub'
2013-02-28librustc: Mark all type implementations public. rs=impl-publicityPatrick Walton-2/+2
2013-02-26Removed deprecated `str()` functions in int-template.rs and uint-template.rsMarvin Löbel-10/+10
2013-02-15libstd: Get rid of `move`.Luqman Aden-7/+7
2013-02-14librustc: Replace `impl Type : Trait` with `impl Trait for Type`. ↵Patrick Walton-3/+3
rs=implflipping
2013-02-13Remove die!, raplace invocations with fail! Issue #4524 pt 3Nick Desaulniers-2/+2
2013-02-07Make ~fn non-copyable, make &fn copyable, split barefn/closure types,Niko Matsakis-2/+0
correct handling of moves for struct-record update. Part of #3678. Fixes #2828, #3904, #4719.
2013-02-03Fixed `fmt!`, tests, doc-tests.Marvin Löbel-1/+1
2013-01-31Replace most invocations of fail keyword with die! macroNick Desaulniers-2/+2
2013-01-29libstd: De-export libstd. rs=deexportPatrick Walton-21/+18
2013-01-24time tests are racing on tzset, so merge the tests together.Erick Tryzelaar-12/+16
This attempts to fix issue #3327.
2013-01-22std: un-ignore strptime test; fix bug introduced by 1a226f instead.Graydon Hoare-2/+1
2013-01-22std: Ignore time::tests::test_strptime, it's failing for some reasonTim Chevalier-0/+1
I'll file an issue.
2013-01-22Merge pull request #4466 from ScriptDevil/masterTim Chevalier-33/+34
Range checking and miscellaneous fixes tin time library
2013-01-21Add Timespec comment and assert about negative nsecChris Peterson-0/+11
2013-01-20Merge pull request #4519 from cpeterso/impl-timespec-ordTim Chevalier-2/+46
Implement Ord trait for Timespec