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

fix: accept date without time #125

Merged
merged 1 commit into from
Sep 26, 2024
Merged

Conversation

brunopacheco1
Copy link
Collaborator

@brunopacheco1 brunopacheco1 commented Sep 26, 2024

We were required to accept from CKAN both issued and modified_at, as they are part of DCAT-AP. The problem now is there are three date format for these fields.

This hotfix will accept all these three format, as we have to decouple the deployment of this component.

The issue GenomicDataInfrastructure/gdi-userportal-ckanext-gdi-userportal/95 on CKAN was created to unify datetime format.

The issue ART-9689 was create in Jira to remove this code duplication.

Summary by Sourcery

Fix date parsing to accept date strings without time components by appending a default time value, ensuring compatibility with multiple date formats as required by DCAT-AP. Update tests to cover the new date handling logic.

Bug Fixes:

  • Allow parsing of date strings without time components by appending a default time value, ensuring compatibility with multiple date formats.

Tests:

  • Update tests to verify the parsing of date strings without time components, ensuring correct functionality of the new date handling logic.

We were required to accept from CKAN both `issued` and `modified_at`, as they are part of DCAT-AP. The problem now is there are three date format for these fields.

This hotfix will accept all these three format, as we have to decouple the deployment of this component.

The issue GenomicDataInfrastructure/gdi-userportal-ckanext-gdi-userportal/95 on CKAN was created to unify datetime format

The issue ART-9689 was create in Jira to remove this code duplication.
Copy link

sourcery-ai bot commented Sep 26, 2024

Reviewer's Guide by Sourcery

This pull request addresses an issue with date parsing in the CKAN dataset repository. It modifies the code to accept three different date formats for the 'issued' and 'modified_at' fields, including dates without time information. The changes are implemented in two Java classes and one test class.

Sequence Diagram

sequenceDiagram
    participant C as Caller
    participant P as Parser
    C->>P: parse(date)
    alt date is in OffsetDateTime format
        P->>P: OffsetDateTime.parse(date)
        P-->>C: Return parsed OffsetDateTime
    else date is not in OffsetDateTime format
        P->>P: Check if date is date-only format
        alt date is date-only format
            P->>P: Append default time
        end
        P->>P: LocalDateTime.parse(dateToParse, DATE_FORMATTER)
        P->>P: Convert to OffsetDateTime
        P-->>C: Return parsed OffsetDateTime
    end
Loading

File-Level Changes

Change Details Files
Modified date parsing logic to handle dates without time information
  • Added a check for date-only format using regex
  • Appended default time '00:00:00.000000' to date-only strings
  • Updated parsing logic to use the modified date string
src/main/java/io/github/genomicdatainfrastructure/discovery/datasets/infrastructure/ckan/persistence/CkanDatasetsRepository.java
src/main/java/io/github/genomicdatainfrastructure/discovery/utils/PackageShowMapper.java
Updated test case to reflect new date parsing behavior
  • Changed test input date from '2025-03-19T13:37:05.472970' to '2025-03-19'
  • Updated expected parsed date to '2025-03-19T00:00Z'
src/test/java/io/github/genomicdatainfrastructure/discovery/services/PackageShowMapperTest.java

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @brunopacheco1 - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider using a more robust date parsing library in the future to handle various date formats more elegantly and avoid potential timezone-related issues.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟡 Testing: 1 issue found
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

@@ -162,7 +162,11 @@ private OffsetDateTime parse(String date) {
try {
return OffsetDateTime.parse(date);
} catch (DateTimeParseException e) {
return LocalDateTime.parse(date, DATE_FORMATTER)
var dateToParse = date;
Copy link

Choose a reason for hiding this comment

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

suggestion: Consider extracting date parsing logic to a common utility method

This same date parsing logic appears in both CkanDatasetsRepository and PackageShowMapper. To improve maintainability and reduce duplication, consider creating a shared utility method for this date parsing operation.

@@ -194,7 +194,7 @@ void can_parse() {
.id("resource_id")
.title("resource_name")
.description("resource_description")
.createdAt(parse("2025-03-19T13:37:05Z"))
.createdAt(parse("2025-03-19T00:00Z"))
Copy link

Choose a reason for hiding this comment

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

suggestion (testing): Test case updated to cover new date format, but edge cases are missing

While the test has been updated to use the new date format without time, it would be beneficial to add more test cases covering all three date formats mentioned in the PR description. This ensures that the new parsing logic handles all scenarios correctly.

                                        .name("pdf")
                                        .build())
                                .uri("uri")
                                .created("2025-03-19")
                                .lastModified("2025-03-19T13:37:05Z")
                                .build()))
                .contactPoint(List.of(
                                .id("resource_id")
                                .title("resource_name")
                                .description("resource_description")
                                .createdAt(parse("2025-03-19T00:00Z"))
                                .createdAt(parse("2025-03-19T13:37:05Z"))
                                .createdAt(parse("2025-03-19"))

@brunopacheco1 brunopacheco1 merged commit 3415b7b into main Sep 26, 2024
3 checks passed
@brunopacheco1 brunopacheco1 deleted the bugfix-accept-date-without-time branch September 26, 2024 15:34
@brunopacheco1
Copy link
Collaborator Author

@hcvdwerf I merged the PR, as it is a hotfix to the current version. Let's talk tomorrow or on Monday to find out the best solution for this problem.

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