aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorArthur Rand <arand@ucsc.edu>2018-03-28 05:56:21 -0700
committerGitHub <noreply@github.com>2018-03-28 05:56:21 -0700
commitfc6ecfe212c84271a3454617054aaf25890e886a (patch)
tree4d6b85e059e10aa5b461af9e21c32c84bd73250f /src/test
parent30dba9ebf2abfd06452f46bac2b4c922043f56e6 (diff)
downloaddriver-core-fc6ecfe212c84271a3454617054aaf25890e886a.tar.gz
driver-core-fc6ecfe212c84271a3454617054aaf25890e886a.tar.bz2
driver-core-fc6ecfe212c84271a3454617054aaf25890e886a.zip
[API-1468] add TimeOfDay (#141)v1.8.11
* add TimeOfDay * add formatter * . * Revert "." This reverts commit 89576de98092dd75d3af7d82d244d5eaa24d31d9. * scalafmt * add before and after to ToD, and tests * rearrage, make fromStrings * add generator * address comments * use explicit string for TimeZoneId * renaming * revert Converters changes * change name of private method * change apply method * use month
Diffstat (limited to 'src/test')
-rw-r--r--src/test/scala/xyz/driver/core/JsonTest.scala10
-rw-r--r--src/test/scala/xyz/driver/core/TimeTest.scala36
-rw-r--r--src/test/scala/xyz/driver/core/database/DatabaseTest.scala1
3 files changed, 46 insertions, 1 deletions
diff --git a/src/test/scala/xyz/driver/core/JsonTest.scala b/src/test/scala/xyz/driver/core/JsonTest.scala
index a45025a..827624c 100644
--- a/src/test/scala/xyz/driver/core/JsonTest.scala
+++ b/src/test/scala/xyz/driver/core/JsonTest.scala
@@ -11,6 +11,7 @@ import xyz.driver.core.time.provider.SystemTimeProvider
import spray.json._
import xyz.driver.core.TestTypes.CustomGADT
import xyz.driver.core.domain.{Email, PhoneNumber}
+import xyz.driver.core.time.TimeOfDay
class JsonTest extends FlatSpec with Matchers {
import DefaultJsonProtocol._
@@ -61,6 +62,15 @@ class JsonTest extends FlatSpec with Matchers {
parsedTime should be(referenceTime)
}
+ "Json format for TimeOfDay" should "read and write correct JSON" in {
+ val utcTimeZone = java.util.TimeZone.getTimeZone("UTC")
+ val referenceTimeOfDay = TimeOfDay.parseTimeString(utcTimeZone)("08:00:00")
+ val writtenJson = json.timeOfDayFormat.write(referenceTimeOfDay)
+ writtenJson should be("""{"localTime":"08:00:00","timeZone":"UTC"}""".parseJson)
+ val parsed = json.timeOfDayFormat.read(writtenJson)
+ parsed should be(referenceTimeOfDay)
+ }
+
"Json format for Date" should "read and write correct JSON" in {
import date._
diff --git a/src/test/scala/xyz/driver/core/TimeTest.scala b/src/test/scala/xyz/driver/core/TimeTest.scala
index b83137c..b72fde8 100644
--- a/src/test/scala/xyz/driver/core/TimeTest.scala
+++ b/src/test/scala/xyz/driver/core/TimeTest.scala
@@ -7,6 +7,7 @@ import org.scalacheck.Prop.BooleanOperators
import org.scalacheck.{Arbitrary, Gen}
import org.scalatest.prop.Checkers
import org.scalatest.{FlatSpec, Matchers}
+import xyz.driver.core.date.Month
import xyz.driver.core.time.{Time, _}
import scala.concurrent.duration._
@@ -100,4 +101,39 @@ class TimeTest extends FlatSpec with Matchers with Checkers {
textualDate(EST)(timestamp) should not be textualDate(PST)(timestamp)
timestamp.toDate(EST) should not be timestamp.toDate(PST)
}
+
+ "TimeOfDay" should "be created from valid strings and convert to java.sql.Time" in {
+ val s = "07:30:45"
+ val defaultTimeZone = TimeZone.getDefault()
+ val todFactory = TimeOfDay.parseTimeString(defaultTimeZone)(_)
+ val tod = todFactory(s)
+ tod.timeString shouldBe s
+ tod.timeZoneString shouldBe defaultTimeZone.getID
+ val sqlTime = tod.toTime
+ sqlTime.toLocalTime shouldBe tod.localTime
+ a[java.time.format.DateTimeParseException] should be thrownBy {
+ val illegal = "7:15"
+ todFactory(illegal)
+ }
+ }
+
+ "TimeOfDay" should "have correct temporal relationships" in {
+ val s = "07:30:45"
+ val t = "09:30:45"
+ val pst = TimeZone.getTimeZone("America/Los_Angeles")
+ val est = TimeZone.getTimeZone("America/New_York")
+ val pstTodFactory = TimeOfDay.parseTimeString(pst)(_)
+ val estTodFactory = TimeOfDay.parseTimeString(est)(_)
+ val day = 1
+ val month = Month.JANUARY
+ val year = 2018
+ val sTodPst = pstTodFactory(s)
+ val sTodPst2 = pstTodFactory(s)
+ val tTodPst = pstTodFactory(t)
+ val tTodEst = estTodFactory(t)
+ sTodPst.isBefore(tTodPst, day, month, year) shouldBe true
+ tTodPst.isAfter(sTodPst, day, month, year) shouldBe true
+ tTodEst.isBefore(sTodPst, day, month, year) shouldBe true
+ sTodPst.sameTimeAs(sTodPst2, day, month, year) shouldBe true
+ }
}
diff --git a/src/test/scala/xyz/driver/core/database/DatabaseTest.scala b/src/test/scala/xyz/driver/core/database/DatabaseTest.scala
index f85dcad..8d2a4ac 100644
--- a/src/test/scala/xyz/driver/core/database/DatabaseTest.scala
+++ b/src/test/scala/xyz/driver/core/database/DatabaseTest.scala
@@ -39,5 +39,4 @@ class DatabaseTest extends FlatSpec with Matchers with Checkers {
an[DatabaseException] should be thrownBy TestConverter.expectValidOrEmpty(mapper, invalidOp)
}
-
}