question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

First-class support for enforcing full RFC 3339 date-time (mandatory timezone)

See original GitHub issue

RFC 3339 is the standard date/time format used by most popular JSON protocol tools today:

If you look closely however, the date-time ABNF definition in that standard makes the timezone mandatory.

Despite that, JSON deserialization&validation, as offered by most out-of-the-box platforms using Newtonsoft JSON, such as ASP.NET Core, allow timezoneless (so, invalid) date-time values just fine, without informing the client of the problem.

Although there can be use cases where local time is desired (say, flight arrival time at destination, without having to know the timezone offset at that date, as providing this would require complex political knowledge not essential to solving the problem), in a great number of cases allowing the lack of timezone information is undesired, because it is unclear what the local time is supposed to be (browser clients can be in any timezone).

In fact, from my experience, sending a ‘timezoneless’ value will most often be a sign of a bug in the client (someone forgetting to use a proper UTC backed value or forgot to apply correct formatting), while the server accepting such a value will be a bug on the server - insufficient validation. Both of them combined will inevitably lead to a hard-to-spot data corruption. I really feel the library should allow, if not even encourage a design that prevents these common pitfalls, while it currently makes it ‘extremely difficult’, as one StackOverflow user stated.

I understand that it would be a breaking change to just make it the new default, but I feel this library should at least offer a way to enable it, perhaps as a SerializeDateTimeZoneHandling option.

When adopting this though, there would also need to be a consideration for the other DateTime-backed format, the date, which, in turn, doesn’t have the timezone indicator (but strictly speaking should also report invalidity for a value with the time segment). I would think that the easiest-to-use way would be using an attribute on the member, to tell one from another.

Context trivia: I only raised this here after mistakenly assuming it’s OpenAPI’s problem

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
zlammacommented, Mar 19, 2018

Thanks for considering.

Just one question for the general public that are trying to address the problem (e.g. the NSwag guys here - which, BTW, seem to be finding the converter approach still leaving certain use cases problematic).

So, in order to allow addressing this easily in any frameworks based on the JSON SChema or OpenAPI, would you consider a pull request to addresses any of this?

(I’m not sure I will find time myself, but it’d be good to know that the doors are open for a comprehensive fix)

0reactions
JamesNKcommented, Mar 12, 2018

If you really desire an error rather than automatically converting then I suggest you write a date time converter that will error when the given DateTime isn’t valid or the incoming date string is isn’t valid.

If there is more demand in the future I’ll consider adding it as a core feature but for now Json.NET serializes and deserializes as ISO 8601, not the RFC.

Read more comments on GitHub >

github_iconTop Results From Across the Web

foo must be an RFC 3339 date-time
Change the date-time format to comply with RFC 3339. ... errors include using a space to separate the data and time, or omitting...
Read more >
Convert an RFC 3339 time to a standard Python timestamp
Time floats and struct_time aren't timezone aware. Since RFC 3339 requires UTC-compatible time zones, which in Python means non-naive datetime ...
Read more >
JSON with Commas and Comments
"datetime" isn't a universal format specification. 2021-01-10 could be October 1 or January 10. What time zone is this in? Local to the...
Read more >
RFC 3339: Date and Time on the Internet: Timestamps
Abstract This document defines a date and time format for use in Internet protocols that is a profile of the ISO 8601 standard...
Read more >
tzdata-10.1.patch
This is inspired by Internet + RFC 3339 and is more consistent with numeric time zone + abbreviations already used elsewhere. The change...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found