From ad9e15ac16257f7b51b7856b7ba019658533165d Mon Sep 17 00:00:00 2001 From: Yoshimura Yuu Date: Wed, 14 Sep 2022 14:13:47 +0900 Subject: [PATCH 1/6] Add test for `setTimeZone` --- .../tototoshi/slick/JodaSupportSpec.scala | 59 +++++++++++++++++-- 1 file changed, 55 insertions(+), 4 deletions(-) diff --git a/src/test/scala/com/github/tototoshi/slick/JodaSupportSpec.scala b/src/test/scala/com/github/tototoshi/slick/JodaSupportSpec.scala index b22a36c..179d824 100644 --- a/src/test/scala/com/github/tototoshi/slick/JodaSupportSpec.scala +++ b/src/test/scala/com/github/tototoshi/slick/JodaSupportSpec.scala @@ -50,9 +50,11 @@ abstract class JodaSupportSpec extends AnyFunSpec def jdbcDriver: String def jdbcUser: String def jdbcPassword: String + def isWithoutCalender: Boolean import driver.api._ import jodaSupport._ + import slick.sql.SqlProfile.ColumnOption.SqlType case class Jodas( dateTimeZone: DateTimeZone, @@ -72,8 +74,8 @@ abstract class JodaSupportSpec extends AnyFunSpec def dateTimeZone = column[DateTimeZone]("date_time_zone") def localDate = column[LocalDate]("local_date") def dateTime = column[DateTime]("date_time") - def instant = column[Instant]("instant") - def localDateTime = column[LocalDateTime]("local_date_time") + def instant = column[Instant]("instant", SqlType("timestamp not null default CURRENT_TIMESTAMP")) + def localDateTime = column[LocalDateTime]("local_date_time", SqlType("timestamp not null default CURRENT_TIMESTAMP")) def localTime = column[LocalTime]("local_time") def optDateTimeZone = column[Option[DateTimeZone]]("opt_date_time_zone") def optLocalDate = column[Option[LocalDate]]("opt_local_date") @@ -100,7 +102,6 @@ abstract class JodaSupportSpec extends AnyFunSpec val tz = TimeZone.getTimeZone("Asia/Tokyo") TimeZone.setDefault(tz) DateTimeZone.setDefault(DateTimeZone.forID(tz.getID)) - db.run(DBIO.seq(jodaTest.schema.create)).await() } @@ -224,6 +225,41 @@ abstract class JodaSupportSpec extends AnyFunSpec res2.lift(1).map(_.localDate) should not be Some(new LocalDate(2012, 12, 5)) res2.lift(2).map(_.localDate) should not be Some(new LocalDate(2012, 12, 5)) } + + private val systemTimeZone = java.util.TimeZone.getDefault().getID + Seq("Asia/Tokyo", "UTC", "Europe/London", "America/New_York").foreach { tz => + val timeZone = DateTimeZone.forID(tz) + it(s"should be the same in/out joda-time zoned $tz") { + val otherZonedDateTime = new DateTime(2012, 12, 7, 0, 0, 0, 0, timeZone) + val data = Jodas( + DateTimeZone.forID("Asia/Tokyo"), + new LocalDate(2012, 12, 7), + otherZonedDateTime, + new DateTime(2012, 12, 7, 0, 0, 0, 0, DateTimeZone.UTC).toInstant, + new LocalDateTime(2012, 12, 7, 0, 0, 0, 0), + new LocalTime(1000), + Some(DateTimeZone.forID("America/New_York")), + Some(new LocalDate(2012, 12, 6)), + None, + Some(new Instant(1000)), + None, + Some(new LocalTime(1000)) + ) + db.run(jodaTest += data).await() + + val actual = db.run(jodaTest.result).await() + actual should have size 1 + + actual.foreach { d => + if (isWithoutCalender) + d.dateTime.getMillis should be(data.dateTime.getMillis) + else if (systemTimeZone == timeZone.getID) + d.dateTime.getMillis should be(data.dateTime.getMillis) + else + pending + } + } + } } class H2JodaSupportSpec extends JodaSupportSpec { @@ -233,6 +269,7 @@ class H2JodaSupportSpec extends JodaSupportSpec { override def jdbcDriver = "org.h2.Driver" override def jdbcUser = "sa" override def jdbcPassword = null + override val isWithoutCalender = false } abstract class TestContainerSpec extends JodaSupportSpec with ForAllTestContainer { @@ -242,14 +279,27 @@ abstract class TestContainerSpec extends JodaSupportSpec with ForAllTestContaine override def jdbcPassword = container.password } +object MySQLJodaSupportSpec { + val mySQLDockerImageName = "mysql:5.7.41" +} + class MySQLJodaSupportSpec extends TestContainerSpec { override val container = MySQLContainer( configurationOverride = "test-mysql-conf", - mysqlImageVersion = DockerImageName.parse("mysql:5.7.41") + mysqlImageVersion = DockerImageName.parse(MySQLJodaSupportSpec.mySQLDockerImageName) ) override def jdbcDriver = "com.mysql.jdbc.Driver" override val driver = MySQLProfile override val jodaSupport = MySQLJodaSupport + override val isWithoutCalender = false +} + +class MySQLJodaSupportWithoutCalenderSpec extends TestContainerSpec { + override val container = MySQLContainer(mysqlImageVersion = DockerImageName.parse(MySQLJodaSupportSpec.mySQLDockerImageName)) + override def jdbcDriver = "com.mysql.jdbc.Driver" + override val driver = MySQLProfile + override val jodaSupport = new GenericJodaSupport(MySQLProfile, _ => None) + override val isWithoutCalender = true } class PostgresJodaSupportSpec extends TestContainerSpec { @@ -257,4 +307,5 @@ class PostgresJodaSupportSpec extends TestContainerSpec { override def jdbcDriver = "org.postgresql.Driver" override val driver = PostgresProfile override val jodaSupport = PostgresJodaSupport + override val isWithoutCalender = false } From d159b546e3bf180cf75642be87d3149d3d0bfbba Mon Sep 17 00:00:00 2001 From: Scala Steward Date: Tue, 18 Jul 2023 21:59:01 +0000 Subject: [PATCH 2/6] Update mysql-connector-java to 8.1.0 --- build.sbt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sbt b/build.sbt index 15a61a9..0034006 100644 --- a/build.sbt +++ b/build.sbt @@ -45,7 +45,7 @@ lazy val `slick-joda-mapper` = project.in(file(".")) "org.joda" % "joda-convert" % "2.2.3" % "provided", "com.h2database" % "h2" % "2.1.214" % "test", "com.dimafeng" %% "testcontainers-scala" % "0.40.17" % "test", - "mysql" % "mysql-connector-java" % "8.0.33" % "test", + "com.mysql" % "mysql-connector-j" % "8.1.0" % "test", "org.postgresql" % "postgresql" % "42.5.4" % "test", "org.testcontainers" % "mysql" % testContainerVersion % "test", "org.testcontainers" % "postgresql" % testContainerVersion % "test", From 69f8eec670f4ccd32c7c3240a5960d8ba615c8b6 Mon Sep 17 00:00:00 2001 From: Scala Steward Date: Wed, 13 Sep 2023 04:47:19 +0000 Subject: [PATCH 3/6] Update scala-library to 2.13.12 --- build.sbt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.sbt b/build.sbt index 1159073..130f3e9 100644 --- a/build.sbt +++ b/build.sbt @@ -11,8 +11,8 @@ lazy val `slick-joda-mapper` = project.in(file(".")) name := "slick-joda-mapper", organization := "com.github.tototoshi", version := "2.8.0", - crossScalaVersions := Seq("2.12.18", "2.13.11", "3.3.0"), - scalaVersion := "2.13.11", + crossScalaVersions := Seq("2.12.18", "2.13.12", "3.3.0"), + scalaVersion := "2.13.12", scalacOptions ++= Seq( "-deprecation", "-feature", From 74ed8e83e6166075d7cbdbb5990d7d50a08e7563 Mon Sep 17 00:00:00 2001 From: Scala Steward Date: Wed, 13 Sep 2023 04:47:49 +0000 Subject: [PATCH 4/6] Update slf4j-simple to 2.0.9 --- build.sbt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sbt b/build.sbt index 1159073..edd691a 100644 --- a/build.sbt +++ b/build.sbt @@ -49,7 +49,7 @@ lazy val `slick-joda-mapper` = project.in(file(".")) "org.postgresql" % "postgresql" % "42.6.0" % "test", "org.testcontainers" % "mysql" % testContainerVersion % "test", "org.testcontainers" % "postgresql" % testContainerVersion % "test", - "org.slf4j" % "slf4j-simple" % "2.0.7" % "test", + "org.slf4j" % "slf4j-simple" % "2.0.9" % "test", "org.scalatest" %% "scalatest" % "3.2.16" % "test", "com.typesafe.slick" %% "slick" % "3.4.1" % "provided" cross CrossVersion.for3Use2_13 ), From 55026e79b17b09e08804df72c744a4e7002f1e66 Mon Sep 17 00:00:00 2001 From: Scala Steward Date: Mon, 18 Sep 2023 23:28:35 +0000 Subject: [PATCH 5/6] Update h2 to 2.2.224 --- build.sbt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sbt b/build.sbt index 1159073..902e9db 100644 --- a/build.sbt +++ b/build.sbt @@ -43,7 +43,7 @@ lazy val `slick-joda-mapper` = project.in(file(".")) libraryDependencies ++= Seq( "joda-time" % "joda-time" % "2.12.5" % "provided", "org.joda" % "joda-convert" % "2.2.3" % "provided", - "com.h2database" % "h2" % "2.2.220" % "test", + "com.h2database" % "h2" % "2.2.224" % "test", "com.dimafeng" %% "testcontainers-scala" % "0.40.17" % "test", "mysql" % "mysql-connector-java" % "8.0.33" % "test", "org.postgresql" % "postgresql" % "42.6.0" % "test", From 6ff01b04d8cb799ea12f6f17968d50e6bc7330b1 Mon Sep 17 00:00:00 2001 From: Scala Steward Date: Mon, 18 Sep 2023 23:28:42 +0000 Subject: [PATCH 6/6] Update sbt to 1.9.6 --- project/build.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project/build.properties b/project/build.properties index 52413ab..2743082 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.9.3 +sbt.version=1.9.6