-
Notifications
You must be signed in to change notification settings - Fork 1
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
Adds implementation for local date time #123
base: main
Are you sure you want to change the base?
Conversation
071d9d4
to
3b197f0
Compare
9b2e790
to
e806e98
Compare
e806e98
to
2bff8a2
Compare
|
||
namespace Btms.Model; | ||
|
||
public class LocalDateTimeJsonConverter : JsonConverter<DateTime> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit - naming of this as it means Local in terms of originating system. But perhaps such detail could be covered in the summary comment
|
||
public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options) | ||
{ | ||
writer.WriteStringValue(value.ToString(JsonFormat, CultureInfo.InvariantCulture)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did mean to add logic to the converter I had, but we could enforce only an Unspecified DateTime value can be serialised here? Anything else would be unexpected and therefore an exception should be thrown
"api/import-notifications?fields[import-notifications]=partOne"); | ||
|
||
var expectedDateString = | ||
$"\"departedOn\": \"{ExpectedDateTime:yyyy-MM-ddTHH:mm:ss}\""; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The edge case of not wanting seconds in relation to GVMS data still stands, although that can be an easy mod on top of the decisions made in this PR
|
||
//Mongo stores things as UTC, not ideal but it is what it is! | ||
result["cursor"]["firstBatch"][0]["partOne"]["departedOn"].ToString() | ||
.Should().Be(ExpectedDateTime.ToString("yyyy-MM-ddTHH:mm:ssZ")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Closing my eyes here! :D
|
|
Some data we receive from source systems has no timezone information. Some data might be the timezone local to the person providing it, or that takes the action it relates to, or it might be related to where a consignment is at a point in time, and it could be anywhere in the world.
MongoDB stores all dates as datetimes with UTC timezone
We favour retaining strong typing in our internal model, and date related operations at the DB level so this change allows us to specify at the field level, and through the schema mapper code generator, those fields for which we expect to not know the timezone, so that we can convert them in and out of the database & JSON API correctly.