-
Notifications
You must be signed in to change notification settings - Fork 62
Add two more options for returning a DateTime - Instant and Date #26
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,11 +8,10 @@ | |
import graphql.schema.CoercingSerializeException; | ||
import graphql.schema.GraphQLScalarType; | ||
|
||
import java.time.DateTimeException; | ||
import java.time.OffsetDateTime; | ||
import java.time.ZonedDateTime; | ||
import java.time.*; | ||
import java.time.format.DateTimeFormatter; | ||
import java.time.format.DateTimeParseException; | ||
import java.util.Date; | ||
import java.util.function.Function; | ||
|
||
import static graphql.scalars.util.Kit.typeName; | ||
|
@@ -32,6 +31,12 @@ public String serialize(Object input) throws CoercingSerializeException { | |
offsetDateTime = (OffsetDateTime) input; | ||
} else if (input instanceof ZonedDateTime) { | ||
offsetDateTime = ((ZonedDateTime) input).toOffsetDateTime(); | ||
} else if (input instanceof Instant) { | ||
offsetDateTime = ((Instant) input).atOffset(ZoneOffset.UTC); | ||
} else if (input instanceof LocalDateTime) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it makes sense to ever convert a
That's why these methods exist:
Passing a |
||
offsetDateTime = ((LocalDateTime) input).atOffset(ZoneOffset.UTC); | ||
} else if (input instanceof Date) { | ||
offsetDateTime = ((Date) input).toInstant().atOffset(ZoneOffset.UTC); | ||
} else if (input instanceof String) { | ||
offsetDateTime = parseOffsetDateTime(input.toString(), CoercingSerializeException::new); | ||
} else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about the |
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are zero wildcard imports in this repository. I recommend to match the repository's code style.