You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
let start_dt: chrono::DateTime<Utc> = DateTimeBefore(EN,Utc::now()).fake();
println!("{}", start_dt);
let end_dt: chrono::DateTime<Utc> = DateTimeAfter(EN,Utc::now()).fake();
println!("{}", end_dt);
let between: chrono::DateTime<Utc> = DateTimeBetween(EN, start_dt, end_dt).fake();
println!("{}", between);
But that appears to generate random times between random dates. I need to do something more like this:
let three_days_ago = Utc::now() - Duration::days(3);let now = Utc::now();let start_time: chrono::DateTime<Utc> = DateTimeBetween(three_days_ago, now).fake();
But I get an error:
note: expected `OffsetDateTime`, found `DateTime<Utc>`
Full error
error[E0308]: arguments to this function are incorrect
--> src/main.rs:80:45
|
77 | let three_days_ago = Utc::now() - Duration::days(3);
| ------------------------------ here the type of `three_days_ago` is inferred to be `chrono::DateTime<Utc>`
...
80 | let start_time: chrono::DateTime<Utc> = DateTimeBetween(three_days_ago, now).fake();
| ^^^^^^^^^^^^^^^
|
note: expected `OffsetDateTime`, found `DateTime<Utc>`
--> src/main.rs:80:61
|
80 | let start_time: chrono::DateTime<Utc> = DateTimeBetween(three_days_ago, now).fake();
| ^^^^^^^^^^^^^^
= note: expected struct `time::offset_date_time::OffsetDateTime`
found struct `chrono::DateTime<Utc>`
note: expected `OffsetDateTime`, found `DateTime<Utc>`
--> src/main.rs:80:77
|
80 | let start_time: chrono::DateTime<Utc> = DateTimeBetween(three_days_ago, now).fake();
| ^^^
= note: expected struct `time::offset_date_time::OffsetDateTime`
found struct `chrono::DateTime<Utc>`
note: function defined here
--> /home/nick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/fake-2.9.2/src/faker/mod.rs:118:9
|
118 | DateTimeBetween(start: time::OffsetDateTime, end: time::OffsetDateTime);
| ^^^^^^^^^^^^^^^
error[E0277]: the trait bound `chrono::DateTime<Utc>: Dummy<fake::faker::time::raw::DateTimeBetween<EN>>` is not satisfied
--> src/main.rs:80:82
|
80 | let start_time: chrono::DateTime<Utc> = DateTimeBetween(three_days_ago, now).fake();
| ^^^^ the trait `Dummy<fake::faker::time::raw::DateTimeBetween<EN>>` is not implemented for `chrono::DateTime<Utc>`
|
= help: the following other types implement trait `Dummy<T>`:
<chrono::DateTime<Utc> as Dummy<fake::faker::chrono::raw::DateTimeBefore<L>>>
<chrono::DateTime<Utc> as Dummy<fake::faker::chrono::raw::DateTimeAfter<L>>>
<chrono::DateTime<Utc> as Dummy<fake::faker::chrono::raw::DateTimeBetween<L>>>
= note: required for `fake::faker::time::raw::DateTimeBetween<EN>` to implement `fake::private::FakeBase<chrono::DateTime<Utc>>`
note: required by a bound in `fake`
--> /home/nick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/fake-2.9.2/src/lib.rs:202:15
|
200 | fn fake<U>(&self) -> U
| ---- required by a bound in this associated function
201 | where
202 | Self: private::FakeBase<U>,
| ^^^^^^^^^^^^^^^^^^^^ required by this bound in `Fake::fake`
Some errors have detailed explanations: E0277, E0308.
For more information about an error, try `rustc --explain E0277`.
It appears that I must use the OffsetDateTime from the time crate like so:
let three_days_ago = OffsetDateTime::from(OffsetDateTime::now_utc() - Duration::days(3));let now = OffsetDateTime::now_utc();let start_time:OffsetDateTime = DateTimeBetween(three_days_ago, now).fake();
Would it be much effort to support chrono::DateTime?
The text was updated successfully, but these errors were encountered:
NickLarsenNZ
changed the title
More support for chrono DateTime
More support for chrono::DateTime
Feb 29, 2024
I'm trying to generate random times between now and some days ago.
I see the example here:
fake-rs/fake/examples/fakers.rs
Lines 398 to 405 in b2cb752
But that appears to generate random times between random dates. I need to do something more like this:
But I get an error:
Full error
It appears that I must use the
OffsetDateTime
from thetime
crate like so:Would it be much effort to support
chrono::DateTime
?The text was updated successfully, but these errors were encountered: