From ac7689c313e071e29632f87724b73525e9fc8241 Mon Sep 17 00:00:00 2001 From: satorg Date: Tue, 4 Nov 2025 21:57:35 -0800 Subject: [PATCH 1/3] sync `SyncIO.realTime*` with `Clock` --- .../main/scala/cats/effect/SyncIOCompanionPlatform.scala | 2 +- .../main/scala/cats/effect/SyncIOCompanionPlatform.scala | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/core/js/src/main/scala/cats/effect/SyncIOCompanionPlatform.scala b/core/js/src/main/scala/cats/effect/SyncIOCompanionPlatform.scala index 164ce56862..f46e854a51 100644 --- a/core/js/src/main/scala/cats/effect/SyncIOCompanionPlatform.scala +++ b/core/js/src/main/scala/cats/effect/SyncIOCompanionPlatform.scala @@ -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 } diff --git a/core/jvm-native/src/main/scala/cats/effect/SyncIOCompanionPlatform.scala b/core/jvm-native/src/main/scala/cats/effect/SyncIOCompanionPlatform.scala index 82411ae1b5..5f7c4dd878 100644 --- a/core/jvm-native/src/main/scala/cats/effect/SyncIOCompanionPlatform.scala +++ b/core/jvm-native/src/main/scala/cats/effect/SyncIOCompanionPlatform.scala @@ -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 } From 8fce19ebcae809c217c00fa25daa6b093a8f8c57 Mon Sep 17 00:00:00 2001 From: satorg Date: Tue, 4 Nov 2025 22:54:32 -0800 Subject: [PATCH 2/3] add test for `realTimeZonedDateTime` --- .../cats/effect/SyncIOPlatformSuite.scala | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/jvm-native/src/test/scala/cats/effect/SyncIOPlatformSuite.scala b/tests/jvm-native/src/test/scala/cats/effect/SyncIOPlatformSuite.scala index e01da69943..4e4fb8c9e7 100644 --- a/tests/jvm-native/src/test/scala/cats/effect/SyncIOPlatformSuite.scala +++ b/tests/jvm-native/src/test/scala/cats/effect/SyncIOPlatformSuite.scala @@ -16,6 +16,8 @@ package cats.effect +import java.time.ZoneOffset + trait SyncIOPlatformSuite { self: BaseSuite => def platformTests() = { @@ -30,6 +32,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, ZoneOffset.UTC.getTotalSeconds)) + } + } } From d2e9bbcceeefac2fc6b4add6f685f0c1ef6e828b Mon Sep 17 00:00:00 2001 From: satorg Date: Sun, 9 Nov 2025 16:04:12 -0800 Subject: [PATCH 3/3] simplify `SyncIOPlatformSuite` --- .../src/test/scala/cats/effect/SyncIOPlatformSuite.scala | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/jvm-native/src/test/scala/cats/effect/SyncIOPlatformSuite.scala b/tests/jvm-native/src/test/scala/cats/effect/SyncIOPlatformSuite.scala index 4e4fb8c9e7..6aefda5718 100644 --- a/tests/jvm-native/src/test/scala/cats/effect/SyncIOPlatformSuite.scala +++ b/tests/jvm-native/src/test/scala/cats/effect/SyncIOPlatformSuite.scala @@ -16,8 +16,6 @@ package cats.effect -import java.time.ZoneOffset - trait SyncIOPlatformSuite { self: BaseSuite => def platformTests() = { @@ -45,7 +43,7 @@ trait SyncIOPlatformSuite { self: BaseSuite => now.getOffset.getTotalSeconds ) - assertCompleteAsSync(op, (true, ZoneOffset.UTC.getTotalSeconds)) + assertCompleteAsSync(op, (true, 0)) } }