-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #338 from MTES-MCT/dates-utc
fix(dates): store in UTC but display in local french
- Loading branch information
Showing
191 changed files
with
2,131 additions
and
1,342 deletions.
There are no files selected for viewing
84 changes: 84 additions & 0 deletions
84
backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/config/GraphQLConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package fr.gouv.dgampa.rapportnav.config | ||
|
||
import graphql.language.StringValue | ||
import graphql.schema.* | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
import java.time.Instant | ||
import java.time.format.DateTimeParseException | ||
|
||
/** | ||
* Configuration class to define custom GraphQL scalar types. | ||
*/ | ||
@Configuration | ||
class GraphQLConfig { | ||
|
||
/** | ||
* Defines a custom GraphQL scalar type for Java's `Instant` class. | ||
* | ||
* @return A `GraphQLScalarType` representing the `Instant` type. | ||
* The scalar handles the serialization and deserialization of | ||
* `Instant` values from ISO-8601 formatted strings or long epoch timestamps. | ||
*/ | ||
@Bean | ||
fun instantScalar(): GraphQLScalarType { | ||
return GraphQLScalarType.newScalar() | ||
.name("Instant") | ||
.description("Java Instant scalar") | ||
.coercing(object : Coercing<Instant, String> { | ||
|
||
/** | ||
* Serializes an `Instant` object into a string for GraphQL responses. | ||
* | ||
* @param dataFetcherResult The `Instant` object to serialize. | ||
* @return The serialized `Instant` as an ISO-8601 formatted string. | ||
* @throws CoercingSerializeException If the input is not an `Instant` object. | ||
*/ | ||
override fun serialize(dataFetcherResult: Any): String { | ||
return (dataFetcherResult as? Instant)?.toString() | ||
?: throw CoercingSerializeException("Expected an Instant object.") | ||
} | ||
|
||
/** | ||
* Parses a value (from a variable or direct input) into an `Instant` object. | ||
* Accepts ISO-8601 formatted strings or long epoch timestamps. | ||
* | ||
* @param input The input value to parse. | ||
* @return The parsed `Instant` object. | ||
* @throws CoercingParseValueException If the input is not a valid String or Long, | ||
* or if it cannot be parsed into an `Instant`. | ||
*/ | ||
override fun parseValue(input: Any): Instant { | ||
return try { | ||
when (input) { | ||
is String -> Instant.parse(input) | ||
is Long -> Instant.ofEpochMilli(input) | ||
else -> throw CoercingParseValueException("Expected a String or Long") | ||
} | ||
} catch (e: DateTimeParseException) { | ||
throw CoercingParseValueException("Invalid ISO-8601 format", e) | ||
} | ||
} | ||
|
||
/** | ||
* Parses a literal value (from a GraphQL query) into an `Instant` object. | ||
* The input must be an ISO-8601 formatted string. | ||
* | ||
* @param input The literal value from the GraphQL query. | ||
* @return The parsed `Instant` object. | ||
* @throws CoercingParseLiteralException If the input is not a valid ISO-8601 formatted string, | ||
* or cannot be parsed into an `Instant`. | ||
*/ | ||
override fun parseLiteral(input: Any): Instant { | ||
val value = (input as? StringValue)?.value | ||
?: throw CoercingParseLiteralException("Expected an ISO-8601 formatted String") | ||
return try { | ||
Instant.parse(value) | ||
} catch (e: DateTimeParseException) { | ||
throw CoercingParseLiteralException("Invalid ISO-8601 format", e) | ||
} | ||
} | ||
}) | ||
.build() | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/config/GraphQLSchemaConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package fr.gouv.dgampa.rapportnav.config | ||
|
||
import graphql.schema.GraphQLScalarType | ||
import graphql.schema.idl.RuntimeWiring | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
import org.springframework.graphql.execution.RuntimeWiringConfigurer | ||
|
||
/** | ||
* Configuration class that integrates custom scalars into the GraphQL schema. | ||
*/ | ||
@Configuration | ||
class GraphQLSchemaConfig { | ||
|
||
/** | ||
* Registers a custom `GraphQLScalarType`, such as `Instant`, into the GraphQL schema's runtime wiring. | ||
* | ||
* @param instantScalar The custom scalar type, typically an `Instant` scalar, to be registered. | ||
* @return A `RuntimeWiringConfigurer` that adds the scalar to the GraphQL schema wiring. | ||
*/ | ||
@Bean | ||
fun runtimeWiringConfigurer(instantScalar: GraphQLScalarType): RuntimeWiringConfigurer { | ||
return RuntimeWiringConfigurer { builder: RuntimeWiring.Builder -> | ||
builder.scalar(instantScalar) | ||
} | ||
} | ||
} |
19 changes: 0 additions & 19 deletions
19
backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/config/ZonedDateTimeTypeAdapter.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
...n/fr/gouv/dgampa/rapportnav/domain/entities/mission/env/envActions/EnvActionNoteEntity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
...gouv/dgampa/rapportnav/domain/entities/mission/env/envActions/PatchableEnvActionEntity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
package fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions | ||
|
||
import java.time.ZonedDateTime | ||
import java.time.Instant | ||
import java.util.* | ||
|
||
data class PatchedEnvActionEntity( | ||
val id: UUID, | ||
val actionStartDateTimeUtc: ZonedDateTime? = null, | ||
val actionEndDateTimeUtc: ZonedDateTime? = null, | ||
val actionStartDateTimeUtc: Instant? = null, | ||
val actionEndDateTimeUtc: Instant? = null, | ||
val observationsByUnit: String? = null, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.