|
1 | 1 | package com.twitter.util
|
2 | 2 |
|
3 |
| -import java.io.{ByteArrayInputStream, ByteArrayOutputStream, ObjectInputStream, ObjectOutputStream} |
4 |
| -import java.util.{Locale, TimeZone} |
| 3 | +import java.io.ByteArrayInputStream |
| 4 | +import java.io.ByteArrayOutputStream |
| 5 | +import java.io.ObjectInputStream |
| 6 | +import java.io.ObjectOutputStream |
| 7 | +import java.util.Locale |
| 8 | +import java.util.TimeZone |
5 | 9 | import java.util.concurrent.TimeUnit
|
6 |
| - |
7 |
| -import org.scalatest.concurrent.{Eventually, IntegrationPatience} |
| 10 | +import org.scalatest.concurrent.Eventually |
| 11 | +import org.scalatest.concurrent.IntegrationPatience |
8 | 12 | import org.scalatestplus.scalacheck.ScalaCheckDrivenPropertyChecks
|
9 |
| - |
10 | 13 | import com.twitter.conversions.DurationOps._
|
| 14 | +import java.time.Instant |
| 15 | +import java.time.OffsetDateTime |
| 16 | +import java.time.ZoneOffset |
| 17 | +import java.time.ZonedDateTime |
11 | 18 | import org.scalatest.wordspec.AnyWordSpec
|
12 | 19 |
|
13 | 20 | trait TimeLikeSpec[T <: TimeLike[T]] extends AnyWordSpec with ScalaCheckDrivenPropertyChecks {
|
@@ -509,7 +516,9 @@ class TimeTest
|
509 | 516 | val t = new Thread(r)
|
510 | 517 | t.start()
|
511 | 518 | assert(t.isAlive == true)
|
512 |
| - eventually { assert(t.getState == Thread.State.TIMED_WAITING) } |
| 519 | + eventually { |
| 520 | + assert(t.getState == Thread.State.TIMED_WAITING) |
| 521 | + } |
513 | 522 | ctl.advance(5.seconds)
|
514 | 523 | t.join()
|
515 | 524 | assert(t.isAlive == false)
|
@@ -712,5 +721,34 @@ class TimeTest
|
712 | 721 | assert(t0.untilNow == 100.hours)
|
713 | 722 | }
|
714 | 723 | }
|
| 724 | + |
| 725 | + "toInstant" in { |
| 726 | + Time.withCurrentTimeFrozen { _ => |
| 727 | + val instant = Instant.ofEpochMilli(Time.now.inMilliseconds) |
| 728 | + assert(instant.toEpochMilli == Time.now.inMillis) |
| 729 | + // java.time.Instant:getNano returns the nanoseconds of the second |
| 730 | + assert(instant.getNano == Time.now.inNanoseconds % Duration.NanosPerSecond) |
| 731 | + } |
| 732 | + } |
| 733 | + |
| 734 | + "toZonedDateTime" in { |
| 735 | + Time.withCurrentTimeFrozen { _ => |
| 736 | + val zonedDateTime = |
| 737 | + ZonedDateTime.ofInstant(Instant.ofEpochMilli(Time.now.inMilliseconds), ZoneOffset.UTC) |
| 738 | + assert(Time.now.toZonedDateTime == zonedDateTime) |
| 739 | + // java.time.Instant:getNano returns the nanoseconds of the second |
| 740 | + assert(zonedDateTime.getNano == Time.now.inNanoseconds % Duration.NanosPerSecond) |
| 741 | + } |
| 742 | + } |
| 743 | + |
| 744 | + "toOffsetDateTime" in { |
| 745 | + Time.withCurrentTimeFrozen { _ => |
| 746 | + val offsetDateTime = |
| 747 | + OffsetDateTime.ofInstant(Instant.ofEpochMilli(Time.now.inMilliseconds), ZoneOffset.UTC) |
| 748 | + assert(Time.now.toOffsetDateTime == offsetDateTime) |
| 749 | + // java.time.Instant:getNano returns the nanoseconds of the second |
| 750 | + assert(offsetDateTime.getNano == Time.now.inNanoseconds % Duration.NanosPerSecond) |
| 751 | + } |
| 752 | + } |
715 | 753 | }
|
716 | 754 | }
|
0 commit comments