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

Are LocalDate, LocalTime, LocalDateTime and DateTime different types? #596

Closed
quadrupleslap opened this issue Feb 15, 2019 · 6 comments
Closed

Comments

@quadrupleslap
Copy link

quadrupleslap commented Feb 15, 2019

toml-rs treats them as the same type (for the purpose of forbidding heterogeneous arrays), but that doesn't sound like the correct behavior.

@quadrupleslap
Copy link
Author

Also, why are they called Local* when their interpretation is actually undefined? Doesn't Naive* make more sense?

@eksortso
Copy link
Contributor

Good question! My first take was that, for the sake of making arrays heterogenous, all Datetime subtypes are the same. (Historically, there was only one Datetime type in TOML.)

Changing all the subtypes into distinct types makes sense to me. But my reasoning has more to do with type translations between TOML and programming languages, and less to do with preserving homogeneity in arrays.

@ChristianSi
Copy link
Contributor

ChristianSi commented Feb 18, 2019

I'd say 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.

If Offset Date-Time and Local Date-Time are mixed in an array that's probably a mistake – either one should be used consistently. The only potential use case I see where mixing date types might be useful is a combination of Local Date-Time and Local Date with an (app-specific) convention such as "Local Date represents that day at (local) midnight" – or possibly Offset Date-Time and Local Date-Time with "Local Date represents that day at UTC midnight". But that's all a bit fuzzy and probably better avoided.

From a user's viewpoint, it would be more useful if Integers and Floats could be mixed (with ints optionally autoconverted to floats by parsers in strongly typed languages), so that series such as [0, 0.5, 1, 1.5] could be written in a natural fashion. But that's a different matter.

@quadrupleslap
Copy link
Author

@ChristianSi you're right, it looks like most parsers already treat the date types as separate types, and the spec does, too.

@quadrupleslap
Copy link
Author

Closing this issue because "it's pretty obvious that they are different types". Thanks @ChristianSi.

@eksortso
Copy link
Contributor

Just curious, @quadrupleslap: do you have a real-life requirement of homogenous arrays of date/time values?

Asking because of discussion surrounding arrays recently.

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

3 participants