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

Cleanup after UI migration, updated docs, fixed retransmission bug #1786

Merged
merged 8 commits into from
Nov 29, 2023

Conversation

szczygiel-m
Copy link
Contributor

No description provided.

}

private void initializeTimestamps(String startTimestamp, String endTimestamp) {
if (startTimestamp == null || endTimestamp == null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

question: If only one timestamp (either start or end) is null, then both properties should have null value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually it doesn't matter, because the validation will evoke 400 from an endpoint with message that timestamp cannot be null.

try {
this.startTimestamp = Instant.parse(startTimestamp);
this.endTimestamp = Instant.parse(endTimestamp);
} catch (Exception e) {
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Catching Exception can be too wide in this case - DateTimeParseException could be a better fit.

this.startTimestamp = Instant.from(DateTimeFormatter.ofPattern(ALTERNATE_DATE_FORMAT)
.withZone(ZoneId.of("UTC"))
.parse(startTimestamp));
this.endTimestamp = Instant.from(DateTimeFormatter.ofPattern(ALTERNATE_DATE_FORMAT)
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Remove code repetition by extracting DateTimeFormatter creation to private final value.

initializeTimestamps(startTimestamp, endTimestamp);
}

private void initializeTimestamps(String startTimestamp, String endTimestamp) {
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: I've refactored this method to:

private void initializeTimestamps(String startTimestamp, String endTimestamp) {
    if (startTimestamp == null || endTimestamp == null) {
        this.startTimestamp = null;
        this.endTimestamp = null;
        return;
    }

    for (DateTimeFormatter formatter : formatters) {
        try {
            this.startTimestamp = formatter.parse(startTimestamp, Instant::from);
            this.endTimestamp = formatter.parse(endTimestamp, Instant::from);
            break;
        } catch (DateTimeParseException ignored) {}
    }
}

where formatters is:

private final List<DateTimeFormatter> formatters = List.of(
        DateTimeFormatter.ISO_INSTANT,
        DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm'Z'").withZone(ZoneId.of("UTC"))
);

What do you think about it?

pitagoras3
pitagoras3 previously approved these changes Nov 28, 2023
@moscicky moscicky self-assigned this Nov 28, 2023

private void initializeTimestamps(String startTimestamp, String endTimestamp) {
if (startTimestamp == null || endTimestamp == null) {
this.startTimestamp = null;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Aren't lines 45 and 46 redundant?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thats right, we could just assign one of them and the validation will fail, but I decided to do it for both to be more consistent and clear.

@szczygiel-m szczygiel-m merged commit fb7aa8d into master Nov 29, 2023
26 checks passed
@szczygiel-m szczygiel-m deleted the cleanup_angular_ui branch November 29, 2023 09:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants