Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

strptime does not populate all time::Tm fields #92

Closed
octplane opened this issue Apr 18, 2015 · 3 comments
Closed

strptime does not populate all time::Tm fields #92

octplane opened this issue Apr 18, 2015 · 3 comments

Comments

@octplane
Copy link

This sample code does not what's expected:

extern crate time;
fn main() {

  let t = time::at(time::Timespec::new(236928791,113000000));
  let format = "%Y-%m-%d %T.%f";

  let witness = "1977-07-05 07:33:11.113000000";
  assert_eq!(time::strftime(format, &t).ok().unwrap(), witness);

  assert_eq!(time::strptime(witness.as_ref(), format).unwrap(), t);

}

I wonder if I'm doing something wrong or the library is behaving wrong... ?

@nerdrew
Copy link

nerdrew commented Jun 20, 2015

I see something similar. wday and yday are not set when parsing a date. I can add a PR if the behavior is wrong.

@DoumanAsh
Copy link

Saw something similar with my attempts to parse time from log file:
11/05/15 22:08:14 becomes a proper Tm struct, but when i convert to timespec i get:
Timespec { sec: -1708998706, nsec: 0 }

Due to that you cannot compare strptime() Tm with normally initialized ones.
But not sure how ``strptime` should behave?

I suppose it is also important to understand if time should be UTC or local.

@willi-kappler
Copy link

Same here:

extern crate time;

use time::{strptime, Duration};

fn main() {
    let t1 = strptime("2016-02-05 16:52:21", "%Y-%m-%d %H:%M:%S").unwrap();
    let t2 = strptime("2016-02-05 16:52:22", "%Y-%m-%d %H:%M:%S").unwrap();

    // This fails, because tm_wday and tm_yday are not set using strptime:
   assert_eq!(t1 + Duration::seconds(1), t2);

    // This runs as a work around:
    assert_eq!(t1 + Duration::seconds(1), t2 + Duration::seconds(0));
}

Any news on that ?

I know time is deprecated and I'll move to chrono when I have more time.
(And chrono uses time internally ? At least there is a dependency in its Cargo.toml)

Thanks!

@jhpratt jhpratt added the v0.1 label Oct 1, 2019
@jhpratt jhpratt closed this as completed Oct 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants