Skip to content
Merged
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
4 changes: 2 additions & 2 deletions .github/workflows/scala.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ jobs:

steps:
- uses: actions/checkout@v1
- name: Set up JDK 13
- name: Set up JDK 14
uses: olafurpg/setup-scala@v2
with:
java-version: 13
java-version: 14
- name: Cache Coursier
uses: actions/cache@v1
with:
Expand Down
7 changes: 5 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ lazy val scalajavatime = crossProject(JVMPlatform, JSPlatform)
.in(file("core"))
.settings(commonSettings: _*)
.settings(
name := "scala-java-time"
name := "scala-java-time",
libraryDependencies += "org.portable-scala" %%% "portable-scala-reflect" % "1.0.0"
)
.jsSettings(
scalacOptions ++= {
Expand Down Expand Up @@ -172,11 +173,13 @@ lazy val scalajavatimeTZDB = crossProject(JVMPlatform, JSPlatform)
}.taskValue
)
.jvmSettings(
includeTTBP := true,
jsOptimized := false,
skip.in(publish) := scalaJSVersion06
)
.dependsOn(scalajavatime)

lazy val scalajavatimeTZDBJVM = scalajavatimeTZDB.jvm
lazy val scalajavatimeTZDBJVM = scalajavatimeTZDB.jvm.enablePlugins(TzdbPlugin)
lazy val scalajavatimeTZDBJS = scalajavatimeTZDB.js.enablePlugins(TzdbPlugin)

lazy val scalajavatimeTests = crossProject(JVMPlatform, JSPlatform)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.threeten.bp.zone

import org.threeten.bp.ZoneOffset

/**
* Minimal provider for UTC
*/
final class DefaultTzdbZoneRulesProvider extends ZoneRulesProvider {

override protected def provideZoneIds: java.util.Set[String] = {
val zones = new java.util.HashSet[String]()
zones.add("UTC")
zones.add("GMT")
zones
}

override protected def provideRules(regionId: String, forCaching: Boolean): ZoneRules =
ZoneRules.of(ZoneOffset.UTC,
ZoneOffset.UTC,
new java.util.ArrayList(),
new java.util.ArrayList(),
new java.util.ArrayList())

override protected def provideVersions(
zoneId: String
): java.util.NavigableMap[String, ZoneRules] = {
val r = new ZoneMap[String, ZoneRules]
// FIXME the version should be provided by the db
r.put("2017c", provideRules("UTC", true))
r
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,25 @@
*/
package org.threeten.bp.zone

import java.util.ServiceConfigurationError
import java.util.ServiceLoader
import scala.collection.JavaConverters._
import org.portablescala.reflect._

/**
* Try to load time zone rules from implementations provided by {@link ServiceLoader}.
* Try to load time zone rules from implementations via reflefction
*/
class ServiceLoaderZoneRulesInitializer extends ZoneRulesInitializer {

override def initializeProviders(): Unit = {
val loader: ServiceLoader[ZoneRulesProvider] =
ServiceLoader.load(classOf[ZoneRulesProvider], ZoneRulesProvider.getClass.getClassLoader())
loader.iterator.asScala.foreach { provider =>
try {
ZoneRulesProvider.registerProvider(provider)
} catch {
case ex: ServiceConfigurationError =>
if (!(ex.getCause().isInstanceOf[SecurityException])) {
throw ex
}
// Load via reflection the tzdb
// find the package name dynamically to support both org.threeten.bp and java.time packages
val packageName = this.getClass.getName.split("\\.").init.mkString(".")
val optClassData = Reflect.lookupInstantiatableClass(s"$packageName.TzdbZoneRulesProvider")
println(packageName)
println(optClassData)
optClassData
.fold(List[ZoneRulesProvider](new DefaultTzdbZoneRulesProvider())) { c =>
val instance = c.newInstance().asInstanceOf[ZoneRulesProvider]
List[ZoneRulesProvider](instance)
}
}
.foreach(provider => ZoneRulesProvider.registerProvider(provider))
}
}
Loading