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

feat: Add DateOnly and TimeOnly converters #503

Merged
merged 3 commits into from
Oct 12, 2023

Conversation

hjgraca
Copy link
Contributor

@hjgraca hjgraca commented Oct 11, 2023

Please provide the issue number

Issue number: #501

Summary

.NET 6 is missing DateOnly and TimeOnly Json converters. This is causing issues serializing these two types.

Changes

Please provide a summary of what's being changed

Added two new converters for DateOnly and TimeOnly.

User experience

Please share what the user experience looks like before and after this change

Logging will handle DateOnly fields without any additional or custom logic from application developers.

Checklist

Please leave checklist items unchecked if they do not apply to your change.

Is this a breaking change?

RFC issue number:

Checklist:

  • Migration process documented
  • Implement warnings (if it can live side by side)

Acknowledgment

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@hjgraca hjgraca self-assigned this Oct 11, 2023
@auto-assign auto-assign bot requested a review from amirkaws October 11, 2023 10:49
@boring-cyborg boring-cyborg bot added area/logging Core logging utility tests labels Oct 11, 2023
@auto-assign auto-assign bot requested a review from sliedig October 11, 2023 10:49
@pull-request-size pull-request-size bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Oct 11, 2023
@hjgraca hjgraca linked an issue Oct 11, 2023 that may be closed by this pull request
2 tasks
@github-actions github-actions bot added the feature New features or minor changes label Oct 11, 2023
/// <returns></returns>
public override DateOnly Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
return DateOnly.ParseExact(reader.GetString()!, DateFormat, 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 don't think if we need to read, you could also throw not implemented exception, but no harm to leave the logic.

/// <returns></returns>
public override TimeOnly Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
return TimeOnly.ParseExact(reader.GetString()!, TimeFormat, 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 don't think if we need to read, you could also throw not implemented exception, but no harm to leave the logic.

@sonarcloud
Copy link

sonarcloud bot commented Oct 12, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@hjgraca hjgraca requested a review from amirkaws October 12, 2023 09:18
Copy link
Contributor

@amirkaws amirkaws left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@hjgraca hjgraca merged commit 654de19 into aws-powertools:develop Oct 12, 2023
6 checks passed
@hjgraca hjgraca deleted the dateonly-converter branch October 12, 2023 14:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/logging Core logging utility feature New features or minor changes size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: Add DateOnly Converter to Logging JsonSerializer
2 participants