diff options
author | Arthur Rand <arand@ucsc.edu> | 2018-03-28 05:56:21 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-28 05:56:21 -0700 |
commit | fc6ecfe212c84271a3454617054aaf25890e886a (patch) | |
tree | 4d6b85e059e10aa5b461af9e21c32c84bd73250f /src/test/scala/xyz/driver/core/TimeTest.scala | |
parent | 30dba9ebf2abfd06452f46bac2b4c922043f56e6 (diff) | |
download | driver-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/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 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 + } } |