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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.

if (dateToParse.matches("^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\\d|3[01])$")) {
dateToParse += "T00:00:00.000000";
}
return LocalDateTime.parse(dateToParse, DATE_FORMATTER)
.truncatedTo(ChronoUnit.SECONDS)
.atOffset(ZoneOffset.UTC);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,11 @@ private OffsetDateTime parse(String date) {
try {
return OffsetDateTime.parse(date);
} catch (DateTimeParseException e) {
return LocalDateTime.parse(date, DATE_FORMATTER)
var dateToParse = date;
if (dateToParse.matches("^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\\d|3[01])$")) {
dateToParse += "T00:00:00.000000";
}
return LocalDateTime.parse(dateToParse, DATE_FORMATTER)
.truncatedTo(ChronoUnit.SECONDS)
.atOffset(ZoneOffset.UTC);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ void can_parse() {
.name("pdf")
.build())
.uri("uri")
.created("2025-03-19T13:37:05.472970")
.created("2025-03-19")
.lastModified("2025-03-19T13:37:05Z")
.build()))
.contactPoint(List.of(
Expand Down Expand Up @@ -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"))

.modifiedAt(parse("2025-03-19T13:37:05Z"))
.format(ValueLabel.builder()
.value("pdf")
Expand Down