Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ package cats.effect
import scala.scalajs.js

private[effect] trait SyncIOCompanionPlatform { this: SyncIO.type =>
final def realTimeDate: SyncIO[js.Date] = realTime.map(d => new js.Date(d.toMillis.toDouble))
final def realTimeDate: SyncIO[js.Date] = syncForSyncIO.realTimeDate
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@

package cats.effect

import java.time.Instant
import java.time.{Instant, ZonedDateTime}

private[effect] trait SyncIOCompanionPlatform { this: SyncIO.type =>
final def realTimeInstant: SyncIO[Instant] =
realTime.map(d => Instant.ofEpochMilli(d.toMillis))

final def realTimeInstant: SyncIO[Instant] = syncForSyncIO.realTimeInstant

final def realTimeZonedDateTime: SyncIO[ZonedDateTime] = syncForSyncIO.realTimeZonedDateTime
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,22 @@ trait SyncIOPlatformSuite { self: BaseSuite =>
assertCompleteAsSync(op, true)
}

testUnit(
"realTimeZonedDateTime should return a ZonedDateTime constructed from realTime with UTC offset") {

// Unfortunately since SyncIO doesn't use on a controllable
// clock source, so a diff best we can do
val op = for {
realTime <- SyncIO.realTime
now <- SyncIO.realTimeZonedDateTime
} yield (
(now.toInstant.toEpochMilli - realTime.toMillis) <= 10000,
now.getOffset.getTotalSeconds
)

assertCompleteAsSync(op, (true, 0))
}

}

}
Loading