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
2
votes
1 answer

how to get the timestamp with timezone in rust

I am using this rust code to get the timestamp, but the time without time zone: use std::time::Duration; use chrono::{DateTime, FixedOffset, Local, NaiveDateTime, TimeZone, Utc}; use diesel::sql_types::Timestamptz; use…
Dolphin
  • 29,069
  • 61
  • 260
  • 539
2
votes
1 answer

Compare DateTime with fixed offset to DateTime with time zone

How does one convert between DateTime and DateTime, in order to subtract to get a duration, compare inequality, or reassign? use chrono::DateTime; use chrono_tz::America::New_York; fn main() { let mut a =…
Test
  • 962
  • 9
  • 26
2
votes
1 answer

How to localize chrono days?

I have a code https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=cde949e0a59445ee9beb01964a3ab903 use chrono::Datelike; use chrono::Duration; use chrono::Local; fn main() { let now = Local::now(); …
jim7475
  • 43
  • 4
2
votes
1 answer

How do I convert from Local timezone to UTC in Rust

I am trying to convert my local time to UTC as below fn main() { let nd_local = NaiveDate::from_ymd(2020,10,10).and_hms(10,10,10); let time_at_kolkata = Kolkata.from_local_datetime(&nd_local); println!("KOLKATA_TIME {:?}",…
Asnim P Ansari
  • 1,932
  • 1
  • 18
  • 41
2
votes
1 answer

No function or associated item named `now` found for struct `chrono::offset::utc::Utc` in the current scope

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>, } impl Default for Attributes { fn default() -> Self { …
Pranav Bhatt
  • 125
  • 1
  • 11
2
votes
3 answers

How to use a date in the url with Rocket.rs?

How would you alter the example from Rocket's website to take a date rather than an age/u8? The example from the website: #![feature(proc_macro_hygiene, decl_macro)] #[macro_use] extern crate rocket; #[get("/hello//")] fn hello(name:…
pandark
  • 313
  • 1
  • 10
2
votes
1 answer

How to find the difference between 2 NaiveDateTimes?

I am using chrono. I have now() and some other NaiveDateTime. How can I find a difference between them? let now = Utc::now().naive_utc(); let dt1 = get_my_naive_datetime();
Kurama
  • 447
  • 1
  • 5
  • 5
1
vote
1 answer

Do Rust S3 SDK Datetimes work with Chrono?

I am writing a CLI application to "restore" deleted and overwritten object versions in S3 using the SDK from AWS as my first "real" Rust Project. One part of this is allowing the user to pass in a start and end date between which file changes should…
Jonathan
  • 13
  • 4
1
vote
1 answer

chrono::offset::FixedOffset cannot be used by Crate clap due to it does not implement the FromStr trait

I'm writing code for a command line tool in Rust. I'm using Crate clap to get and parse command line arguments, I need to get three arguments: --date, --time and --timezone. For --date and --time I'm using types chrono::NaiveDate and…
Guiu Mateu
  • 11
  • 3
1
vote
1 answer

The latest chrono 0.4 crate uses time 0.1 which has a potential segfault - how to fix?

I'm writing an app in Rust that uses a PostgreSQL client connection pool with Chrono (0.4.22) features for date time calculations. So my Cargo.toml has these lines: [dependencies] postgres = {version = "0.19", features = ["with-chrono-0_4"]} chrono…
Code4R7
  • 2,600
  • 1
  • 19
  • 42
1
vote
1 answer

How to use chrono::DateTime with schemars::JsonSchema?

I'm trying to implement JsonSchema for a struct like this: use chrono::{DateTime, Utc}; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize, Default, Clone, JsonSchema)] pub struct ArticleResponse { …
Dolphin
  • 29,069
  • 61
  • 260
  • 539
1
vote
1 answer

Rust chrono::NaiveTime::parse_from_str() fails to parse PM

While parsing strings with Rust chrono::NaiveTime::parse_from_str(), it appears that parsing AM works but PM doesn't work (returns ParseErrorKind::Impossible). Is there a reason for the following failure? The first example time_am is a time string…
walkair
  • 502
  • 4
  • 12
1
vote
0 answers

How can I stop a generic TimeZone from "bleeding" into other structs?

Hi Rustaceans of Stack Overflow, I am continuing my new project in Rust and I am still having trouble around the clock trait that I have been trying to build. For reference, I went with the second solution (the one recommended to me). My challenge…
Luke Sneeringer
  • 9,270
  • 2
  • 35
  • 32
1
vote
1 answer

How do I pass a chrono::DateTime of one particular timezone to a function?

I am trying to pass a date in a particular timezone to a function and try to print it: use chrono::{DateTime, TimeZone, Utc}; use chrono_tz::Asia::Kolkata; fn print_ist_time(date_time: DateTime) { println!("Time in IST {:?}",…
Asnim P Ansari
  • 1,932
  • 1
  • 18
  • 41
1
vote
1 answer

How to get a DateTime at a specified date and time in a specified timezone with rust chrono

I have a timezone name, like "America/New_York" and the year, month, day, hour, minute and second in that timezone, for a particular time. How can I get a timezone aware DateTime object for that time in that timezone. Like a Local object, but with…
Ian
  • 2,078
  • 2
  • 19
  • 19