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

DateTimeScalar incorrectly using NANO_OF_SECOND #126

Open
nathanclayton opened this issue Dec 26, 2023 · 2 comments
Open

DateTimeScalar incorrectly using NANO_OF_SECOND #126

nathanclayton opened this issue Dec 26, 2023 · 2 comments

Comments

@nathanclayton
Copy link

Describe the bug
In src/main/java/graphql/scalars/datetime/DateTimeScalar.java, it's incorrectly using three digits of NANO_OF_SECOND in the DateTimeFormatter. If It's a three digit fraction of a second, it should instead be MILLI_OF_SECOND.

Original:

    private static DateTimeFormatter getCustomDateTimeFormatter() {
        return new DateTimeFormatterBuilder()
                .parseCaseInsensitive()
                .append(ISO_LOCAL_DATE)
                .appendLiteral('T')
                .appendValue(HOUR_OF_DAY, 2)
                .appendLiteral(':')
                .appendValue(MINUTE_OF_HOUR, 2)
                .appendLiteral(':')
                .appendValue(SECOND_OF_MINUTE, 2)
                .appendFraction(NANO_OF_SECOND, 3, 3, true)
                .appendOffset("+HH:MM", "Z")
                .toFormatter();
    }

Should be:

    private static DateTimeFormatter getCustomDateTimeFormatter() {
        return new DateTimeFormatterBuilder()
                .parseCaseInsensitive()
                .append(ISO_LOCAL_DATE)
                .appendLiteral('T')
                .appendValue(HOUR_OF_DAY, 2)
                .appendLiteral(':')
                .appendValue(MINUTE_OF_HOUR, 2)
                .appendLiteral(':')
                .appendValue(SECOND_OF_MINUTE, 2)
                .appendFraction(MILLI_OF_SECOND, 3, 3, true)
                .appendOffset("+HH:MM", "Z")
                .toFormatter();
    }
@nathanclayton
Copy link
Author

I understand that appendFraction truncates the string without rounding, giving the same value as using MILLI_OF_SECOND. However, this is a consistency thing than more anything else, as it could be confusing to someone who isn't familiar with the DateTimeFormatterBuilder and the truncation rules of the appendFraction method.

@dondonz
Copy link
Member

dondonz commented Jan 3, 2024

Hello, that's a good point, it's much easier to understand the code to use milliseconds, after all they are meant to be milliseconds there. Otherwise someone might mistakenly think these are nanoseconds.

Would you like to open a PR to improve this?

sachin-bansal added a commit to sachin-bansal/graphql-java-extended-scalars that referenced this issue Feb 29, 2024
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

No branches or pull requests

2 participants