Skip to content
This repository has been archived by the owner on Sep 24, 2022. It is now read-only.

Chrono integration. #289

Closed

Conversation

quadrupleslap
Copy link

@quadrupleslap quadrupleslap commented Feb 16, 2019

This isn't a breaking change, and it fixes #159.

Concerns:

  • This is still wrong because it doesn't treat the date types as separate types so, for example, it allows both a date and a date-time in the same array.
  • Chrono's subsecond output doesn't truncate zeros (it always pads to a length that's a multiple of three) so I changed some test cases.
  • The date parser still has no error messages.
  • Chrono capitalizes the T in DateTime (and so does the TOML spec), but toml-rs doesn't.

@ehuss
Copy link
Collaborator

ehuss commented Feb 19, 2019

Can this be done so that the dependency on chrono is optional?

@quadrupleslap
Copy link
Author

quadrupleslap commented Feb 19, 2019

Probably? The bigger problem is that

it's pretty obvious that they are different types (and hence cannot be mixed in arrays), since they are listed as different types in the spec.

so apparently the rules when de/serializing arrays and stuff also needs to be changed to distinguish between the different time types.

@ehuss
Copy link
Collaborator

ehuss commented Feb 19, 2019

Thinking about this more... Is the goal to be able to natively handle deserializing to types like struct S { ndt: chrono:NaiveDateTime }? If that's the goal, would it be possible to go the simple route of adding something like this to ValueDeserializer:

    fn deserialize_str<V>(self, visitor: V) -> Result<V::Value, Self::Error>
    where
        V: de::Visitor<'de>,
    {
        match self.value.e {
            E::Datetime(s) => visitor.visit_str(s),
            _ => self.deserialize_any(visitor),
        }
    }

Chrono's serde support should pick that up.

Or are you more concerned about accessing chrono types from toml::Value?

I'm not too concerned about the homogeneous array case. With the above approach, if you have the type Vec<chrono::NaiveTime>, then chrono will handle rejecting mixed time types.

@quadrupleslap
Copy link
Author

quadrupleslap commented Feb 19, 2019

Yeah, toml::Value is the problem. Also, what about the serialization side? chrono would just serialize it to a string.

Edit: Not to mention the fact that chrono requires T, and doesn't support (space) as the date-time separator, and is more lax in many cases, which means it accepts some tests cases that it should reject.

@epage
Copy link
Member

epage commented Sep 23, 2022

toml-rs has moved to https://github.com/toml-rs/toml_edit. Feel free to rebase your PR against that repo and open a new issue there.

@epage epage closed this Sep 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add time/chrono to access date/time values
3 participants