Skip to content

Commit

Permalink
use UTC timezone for sqlite
Browse files Browse the repository at this point in the history
  • Loading branch information
saral committed Oct 3, 2023
1 parent b579d93 commit b39ca68
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ internal val DEFAULT_DATE_STRING_FORMATTER by lazy {
DateTimeFormatter.ISO_LOCAL_DATE.withLocale(Locale.ROOT).withZone(ZoneId.systemDefault())
}
internal val DEFAULT_DATE_TIME_STRING_FORMATTER by lazy {
DateTimeFormatter.ISO_LOCAL_DATE_TIME.withLocale(Locale.ROOT).withZone(ZoneId.systemDefault())
DateTimeFormatter.ISO_LOCAL_DATE_TIME.withLocale(Locale.ROOT).withZone(ZoneOffset.UTC)
}
internal val SQLITE_AND_ORACLE_DATE_TIME_STRING_FORMATTER by lazy {
DateTimeFormatter.ofPattern(
"yyyy-MM-dd HH:mm:ss.SSS",
Locale.ROOT
).withZone(ZoneId.systemDefault())
).withZone(ZoneOffset.UTC)
}

internal val ORACLE_TIME_STRING_FORMATTER by lazy {
Expand Down Expand Up @@ -241,7 +241,9 @@ class JavaInstantColumnType : ColumnType(), IDateColumnType {
}

return when {
currentDialect is OracleDialect || currentDialect.h2Mode == H2Dialect.H2CompatibilityMode.Oracle ->
currentDialect is OracleDialect || currentDialect.h2Mode == H2Dialect.H2CompatibilityMode.Oracle
|| currentDialect is SQLiteDialect
->
"'${SQLITE_AND_ORACLE_DATE_TIME_STRING_FORMATTER.format(instant)}'"
else -> "'${DEFAULT_DATE_TIME_STRING_FORMATTER.format(instant)}'"
}
Expand All @@ -254,7 +256,7 @@ class JavaInstantColumnType : ColumnType(), IDateColumnType {
}

override fun readObject(rs: ResultSet, index: Int): Any? {
return rs.getTimestamp(index)
return rs.getTimestamp(index, Calendar.getInstance(TimeZone.getTimeZone(ZoneOffset.UTC)))
}

override fun notNullValueToDB(value: Any): Any = when {
Expand Down

0 comments on commit b39ca68

Please sign in to comment.