2

The method I'm trying to use is documented here.

Here is the code I'm trying to use it in:

use chrono::{DateTime, Utc};

struct Attributes {
    time: Option<DateTime<Utc>>,
}


impl Default for Attributes {
    fn default() -> Self {
        Attributes {
            time: Some(chrono::offset::Utc::now()),
        }
    }
}

And here is the error I get on running cargo build:

error[E0599]: no function or associated item named `now` found for struct `chrono::offset::utc::Utc` in the current scope
   --> src/event/v03/attributes.rs:165:45
    |
165 |             time: Some(chrono::offset::Utc::now()),
    |                                             ^^^ function or associated item not found in `chrono::offset::utc::Utc`

I'm not sure where the issue is, but I'm sure the method exists. Any insight would be much appreciated.

Stargateur
  • 24,473
  • 8
  • 65
  • 91
Pranav Bhatt
  • 125
  • 1
  • 11
  • 1
    you are doing something wrong, https://stackoverflow.com/a/44710935/7076153, check your version, your code compile with last chrono version https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=28b01d00688fc26653cb5c639163d7a8 – Stargateur Nov 06 '20 at 21:52
  • Thanks! Turns out the error was that I was trying t use the no_std version of the library, and forgot to enable the `clock` feature. – Pranav Bhatt Nov 07 '20 at 06:45

1 Answers1

3

This was quite a silly mistake on my end. I overlooked the fact that I was using chrono with the std feature turned off. This required me disabling all other default features, including the feature clock which facilitates chrono::offset::Utc::now().

Pranav Bhatt
  • 125
  • 1
  • 11