Skip to content

chrono::MAX_DATETIME is not deserializable via parse_from_rfc3339 #641

@Veetaha

Description

@Veetaha

Steps to Reproduce

Run the following code (playground)

use std::str::FromStr;
use chrono::{DateTime, Utc};

fn main() {
    let max_dt = chrono::MAX_DATETIME;
    
    let str = max_dt.to_rfc3339();
   
    // This works fine though
    assert_eq!(max_dt, DateTime::<Utc>::from_str(&str).unwrap());
    
    // But this panics on `unwrap`
    assert_eq!(max_dt, DateTime::parse_from_rfc3339(&str).unwrap());
}

Context

Our code creates a timestamp with the maximum value to represent a record that never expires and it fails at deserialization. We are going to use regular from_str to workaround the problem, but still I'd expect DateTime::parse_from_rfc3339(dt.to_rfc3339())) to be purely an identity conversion. Is it a bug or is it intended?

Offtopic Context

I am using RFC3339 representation to store the timestamp in a DynamoDB database string property to have it lexicographically sortable. As I see all values after 9999 year have a plus sign and a variable amount of digits in the year. Unfortunately, it messes up the monotonic nature of this format =(. I guess we will have to just accept that we can't have timestamps properly sorted for years more than 9999 just because we will never have such values during our lifespan. Do you have any suggestions for a better solution for this particular problem?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions