Questions tagged [rust-chrono]

Date and time handling for Rust. (also known as rust-chrono) It aims to be a feature-complete superset of the time library.

Chrono is a date and time handling for Rust. In particular,

  • Chrono strictly adheres to ISO 8601.
  • Chrono is timezone-aware by default, with separate timezone-naive types.
  • Chrono is space-optimal and (while not being the primary goal) reasonably efficient.

Links:

83 questions
1
vote
1 answer

Why is my RFC 2822 date not parsed by chrono?

I'm writing some code to parse RSS feeds but I have trouble with the Abstruse Goose RSS feed. If you look in that feed, dates are encoded as Mon, 06 Aug 2018 00:00:00 UTC. To me, it looks like RFC 2822. I tried to parse it using chrono's…
Riduidel
  • 22,052
  • 14
  • 85
  • 185
0
votes
1 answer

Creating a Datetime Column in Polars DataFrame from i64 Vector in Rust

I'm working with the Polars library in Rust and am struggling to find documentation related to its dtype-datetime feature, especially when compared to its Python counterpart which seems a lot richer with examples. My goal is to create a dataframe…
deepvalue
  • 81
  • 3
0
votes
3 answers

Can I tell if Chrono consumed the full format string?

Consider the following use chrono; fn main() { println!("{:?}", chrono::NaiveDate::parse_from_str("1978-01-12 01:00:23", "%Y-%m-%d %H:%M:%S")) } The string contains year-month-day-hour-minute-second, but chrono only parsed year-month-day. As…
ignoring_gravity
  • 6,677
  • 4
  • 32
  • 65
0
votes
1 answer

How to ignore zero padding for parsing the timezone offset using Chrono in Rust?

I want to parse the following example string with Chrono: "03:00 +3" where +3 is the timezone offset, i.e. the format %#z or %:::z but without leading zeros. I have already tried the format specifiers %z, %:z, %::z, %:::z and %#z %-z, %-:z, %-::z,…
trivicious
  • 186
  • 1
  • 8
0
votes
0 answers

Query Date Range in Rust MongoDB

I tried using mongodb pipeline to aggregate document but always returning empty list, already tried using naivedatetime and datetime from chrono package but still the same and I always give 1 week for both start time and endtime so UTC conversion is…
Tony Hart
  • 145
  • 1
  • 12
0
votes
1 answer

rust chrono Utc add year, month using Add triats or better way

// Cargo.toml chrono = { version = "0.4", features = ["serde", "rustc-serialize"] } let mut date: DateTime = DateTime::default(); date += Duration::years(1000); // no Duration::years() date += Duration::months(1000); // no…
mycatgib
  • 23
  • 4
0
votes
1 answer

How to catch panic error from DelayedFormat?

I have this script: use chrono::{NaiveDateTime}; fn func(fmt: &str) -> Result<(), String>{ let date_str = "2020-01-01 00:00"; let dt = NaiveDateTime::parse_from_str(date_str, "%Y-%m-%d %H:%M").unwrap(); let formatted = format!("{}",…
ignoring_gravity
  • 6,677
  • 4
  • 32
  • 65
0
votes
1 answer

Define variable of type TimeZone

The following compiles and runs fine: use chrono_tz::Tz; use chrono::{TimeZone, NaiveDate}; use arrow2::temporal_conversions::parse_offset; fn my_func(tz: &str) -> (){ let ndt = NaiveDate::from_ymd_opt(2018, 9, 28).unwrap().and_hms_opt(2, 30,…
ignoring_gravity
  • 6,677
  • 4
  • 32
  • 65
0
votes
0 answers

Parse either fixed offset or Area/Location timezone

Here's my src/main.rs file: use chrono_tz::Tz; fn parse_ts(ts: &str) -> Tz { ts.parse().unwrap() } fn main() { let ts: &str = "UTC"; println!("parsed: {:?}", parse_ts(ts)); } It runs fine! But if I replace "UTC" with "+00:00", then it…
ignoring_gravity
  • 6,677
  • 4
  • 32
  • 65
0
votes
1 answer

How to convert a unix timestamp to a String with timezone in rust?

For example, I have a timestamp 1662012433 and I want to convert it to a String with a local timezone (Hong Kong time UTC+8) which would be 2022-09-01 14:07:13 UTC+0800 or 2022-09-01 14:07:13 HKT.
dexhunter
  • 578
  • 8
  • 24
0
votes
1 answer

Call to NaiveDateTime::parse_from_str fails when invoked at one place but works from other point

I am trying to implement a routine that reads a file that has "@timestamp" key in JSON's. I need to convert the timestamp from a format similar to "2022-01-19T18:15:36.283Z" into a epoch time (msec since Jan 1, 1970). The Rust code is as…
0
votes
0 answers

How do I add a month to a NaiveDate with chronoutil?

I've been going through the documentation for chrono and chronoutil for Rust but I think I am missing something when trying to add a month to a NaiveDate. I have a very simple Rust program: use chrono::NaiveDate; use…
TheLovelySausage
  • 3,838
  • 15
  • 56
  • 106
0
votes
1 answer

How do I update the year in a chrono DateTime instance?

How do I change the year in a DateTime instance (from the rust crate chrono)? That is, create a new instance of DateTime that copies the month and day from the old instance. In other words, how would I complete the…
JamesThomasMoon
  • 6,169
  • 7
  • 37
  • 63
0
votes
0 answers

chrono::format::strftime doesn't work with UNIX timestamp

use chrono::format::{parse, Item, Parsed}; static SUPPORTED_DATETIME_FORMATS: &[&'static str] = &["%s",]; static ref PARSED_DATETIME_FORMATS : Vec>> = SUPPORTED_DATETIME_FORMATS .iter() .map(|format|…
Renya Karasuma
  • 1,044
  • 4
  • 11
  • 18
0
votes
0 answers

How to get a struct to own an chrono::format::Item?

I have a struct that contains a string that is used to format dates with chrono::DateTime.format(): struct DateThingy { format: String, } impl DateThingy { fn new(format: String) -> Self { Self { format } } } This is a bit of a…
Anders
  • 8,307
  • 9
  • 56
  • 88