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

Adds implementation for local date time #123

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

craigedmunds
Copy link
Contributor

@craigedmunds craigedmunds commented Feb 7, 2025

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.

@craigedmunds craigedmunds force-pushed the feature/local-date-time branch from 071d9d4 to 3b197f0 Compare February 7, 2025 13:23
@craigedmunds craigedmunds force-pushed the feature/local-date-time branch from 9b2e790 to e806e98 Compare February 7, 2025 14:02
@craigedmunds craigedmunds force-pushed the feature/local-date-time branch from e806e98 to 2bff8a2 Compare February 7, 2025 14:02

namespace Btms.Model;

public class LocalDateTimeJsonConverter : JsonConverter<DateTime>
Copy link
Contributor

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));
Copy link
Contributor

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}\"";
Copy link
Contributor

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"));
Copy link
Contributor

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

@craigedmunds craigedmunds changed the title Adds test case for local date time Adds implementation for local date time Feb 7, 2025
Copy link

sonarqubecloud bot commented Feb 7, 2025

Quality Gate Failed Quality Gate failed

Failed conditions
1 New Major Issues (required ≤ 0)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

Copy link

github-actions bot commented Feb 7, 2025

Code Coverage

Package Line Rate Branch Rate Health
Btms.Consumers 86% 77%
Btms.Azure 43% 100%
Btms.Business 82% 74%
Btms.Types.Alvs.Mapping.V1.Tests 0% 0%
Btms.Types.Ipaffs 95% 62%
Btms.Types.Gvms 61% 100%
Btms.Types.Alvs.Mapping 81% 0%
Btms.Backend 62% 39%
Btms.Types.Gvms.Mapping 38% 25%
Btms.Model 91% 94%
Btms.Common 74% 56%
TestGenerator.IntegrationTesting.Backend 83% 71%
TestDataGenerator 86% 80%
Btms.Types.Ipaffs.Mapping 77% 50%
Btms.BlobService 39% 27%
Btms.Metrics 84% 0%
Btms.Backend.Data 64% 58%
Btms.Analytics 74% 73%
Btms.Types.Alvs 85% 67%
Btms.SensitiveData 79% 83%
Btms.SyncJob 63% 45%
Btms.Emf 11% 0%
Summary 79% (10085 / 12844) 63% (1021 / 1633)

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

Successfully merging this pull request may close these issues.

2 participants