diff options
author | Aleksandr <ognelisar@gmail.com> | 2018-04-03 10:48:10 +0700 |
---|---|---|
committer | Aleksandr <ognelisar@gmail.com> | 2018-04-03 10:48:10 +0700 |
commit | acf366c1a7f4b7dc7758d8a73b2e497068bb1fe8 (patch) | |
tree | faf601fa831be596fffaeb737a52e508a1473523 /src/test/scala/xyz/driver/core/TimeTest.scala | |
parent | 04a21e9a5ab46f885cb51626d274d570fefe4a29 (diff) | |
parent | 322bbc9010e20195e5b0bb58e703961738ffb89d (diff) | |
download | driver-core-acf366c1a7f4b7dc7758d8a73b2e497068bb1fe8.tar.gz driver-core-acf366c1a7f4b7dc7758d8a73b2e497068bb1fe8.tar.bz2 driver-core-acf366c1a7f4b7dc7758d8a73b2e497068bb1fe8.zip |
Merge branch 'master' into TM-1431
Diffstat (limited to 'src/test/scala/xyz/driver/core/TimeTest.scala')
-rw-r--r-- | src/test/scala/xyz/driver/core/TimeTest.scala | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/test/scala/xyz/driver/core/TimeTest.scala b/src/test/scala/xyz/driver/core/TimeTest.scala index 2aa3edf..75588a2 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._ @@ -102,4 +103,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 + } } |