From 125d2e9fe1383190bf69112c570fed7439c9a757 Mon Sep 17 00:00:00 2001 From: zetashift Date: Fri, 10 Feb 2023 02:22:52 +0100 Subject: [PATCH 1/8] Attempt at adding Native support for core --- build.sbt | 2 +- .../laika/time/PlatformDateTimeImpl.scala | 96 +++++++++++++++++++ .../time/PlatformDateDirectiveSpec.scala | 69 +++++++++++++ .../laika/time/PlatformDateTimeSpec.scala | 50 ++++++++++ project/Dependencies.scala | 23 ++--- 5 files changed, 228 insertions(+), 12 deletions(-) create mode 100644 core/native/src/main/scala/laika/time/PlatformDateTimeImpl.scala create mode 100644 core/native/src/test/scala/laika/time/PlatformDateDirectiveSpec.scala create mode 100644 core/native/src/test/scala/laika/time/PlatformDateTimeSpec.scala diff --git a/build.sbt b/build.sbt index 5e29b5ece..36d761e31 100644 --- a/build.sbt +++ b/build.sbt @@ -104,7 +104,7 @@ lazy val docs = project.in(file("docs")) Laika / target := baseDirectory.value / "target" ) -lazy val core = crossProject(JSPlatform, JVMPlatform) +lazy val core = crossProject(JSPlatform, JVMPlatform, NativePlatform) .withoutSuffixFor(JVMPlatform) .crossType(CrossType.Full) .in(file("core")) diff --git a/core/native/src/main/scala/laika/time/PlatformDateTimeImpl.scala b/core/native/src/main/scala/laika/time/PlatformDateTimeImpl.scala new file mode 100644 index 000000000..452ad198e --- /dev/null +++ b/core/native/src/main/scala/laika/time/PlatformDateTimeImpl.scala @@ -0,0 +1,96 @@ +/* + * Copyright 2012-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + + +import cats.syntax.all._ +import java.time.format.{DateTimeFormatter, DateTimeFormatterBuilder, FormatStyle} +import java.time.{LocalDateTime, OffsetDateTime, ZoneId} +import java.util.Locale +import scala.util.Try + +/** + * @author Jens Halm + */ +object PlatformDateTimeImpl extends PlatformDateTime { + + type Type = OffsetDateTime + + private[laika] def now: Type = OffsetDateTime.now() + + private val offsetDateTime: DateTimeFormatter = new DateTimeFormatterBuilder() + .append(DateTimeFormatter.ISO_LOCAL_DATE_TIME) + .appendPattern("[XXX][X]") + .toFormatter + + def parse (dateString: String): Either[String, Type] = { + + def parseOffsetDateTime(input: String): Either[String, Type] = Try { + OffsetDateTime.from(offsetDateTime.parse(input)) + }.toEither.left.map(_.getMessage) + + def parseLocalDateTime(input: String): Either[String, Type] = Try { + OffsetDateTime.from(LocalDateTime.parse(input).atZone(ZoneId.systemDefault())) + }.toEither.left.map(_.getMessage) + + if (dateString.matches(".*(Z|[+-]\\d\\d[:]?\\d\\d)")) parseOffsetDateTime(dateString) + else if (dateString.contains("T")) parseLocalDateTime(dateString) + else parseLocalDateTime(dateString + "T00:00:00") + } + + private[laika] def format (date: Type, pattern: String, locale: Option[String] = None): Either[String, String] = + getLocale(locale).flatMap { loc => + Try(new DateTimeFormatterBuilder() + .appendPattern(pattern) + .toFormatter + .withLocale(loc) + .format(date) + ).toEither.left.map(_.getMessage) + } + + private lazy val formatterConstants = Map( + "BASIC_ISO_DATE" -> DateTimeFormatter.BASIC_ISO_DATE, + "ISO_LOCAL_DATE" -> DateTimeFormatter.ISO_LOCAL_DATE, + "ISO_OFFSET_DATE" -> DateTimeFormatter.ISO_OFFSET_DATE, + "ISO_DATE" -> DateTimeFormatter.ISO_DATE, + "ISO_LOCAL_TIME" -> DateTimeFormatter.ISO_LOCAL_TIME, + "ISO_OFFSET_TIME" -> DateTimeFormatter.ISO_OFFSET_TIME, + "ISO_TIME" -> DateTimeFormatter.ISO_TIME, + "ISO_LOCAL_DATE_TIME" -> DateTimeFormatter.ISO_LOCAL_DATE_TIME, + "ISO_OFFSET_DATE_TIME" -> DateTimeFormatter.ISO_OFFSET_DATE_TIME, + "ISO_ZONED_DATE_TIME" -> DateTimeFormatter.ISO_ZONED_DATE_TIME, + "ISO_DATE_TIME" -> DateTimeFormatter.ISO_DATE_TIME, + "ISO_ORDINAL_DATE" -> DateTimeFormatter.ISO_ORDINAL_DATE, + "ISO_WEEK_DATE" -> DateTimeFormatter.ISO_WEEK_DATE, + "ISO_INSTANT" -> DateTimeFormatter.ISO_INSTANT, + "RFC_1123_DATE_TIME" -> DateTimeFormatter.RFC_1123_DATE_TIME, + "MEDIUM" -> DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM), + "SHORT" -> DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT) + ) + + private def getLocale (languageTag: Option[String]): Either[String, Locale] = + languageTag.fold[Either[String, Locale]](Right(Locale.getDefault)) { lang => + Try(new Locale.Builder().setLanguageTag(lang).build()).toEither.leftMap(_.getMessage) + } + + private[laika] def formatConstant (date: Type, constant: String, locale: Option[String] = None): Option[Either[String, String]] = + formatterConstants.get(constant.trim.toUpperCase).map { formatter => + getLocale(locale).flatMap { loc => + Try(formatter.withLocale(loc).format(date)).toEither.leftMap(_.getMessage) + } + } + +} diff --git a/core/native/src/test/scala/laika/time/PlatformDateDirectiveSpec.scala b/core/native/src/test/scala/laika/time/PlatformDateDirectiveSpec.scala new file mode 100644 index 000000000..5ef76f911 --- /dev/null +++ b/core/native/src/test/scala/laika/time/PlatformDateDirectiveSpec.scala @@ -0,0 +1,69 @@ +package laika.time + +import laika.ast.sample.{ParagraphCompanionShortcuts, TestSourceBuilders} +import laika.ast.{RootElement, TemplateRoot, TemplateSpan, TemplateString} +import laika.directive.std.{MarkupParserSetup, TemplateParserSetup} +import munit.FunSuite + +import scala.scalajs.js +import scala.util.Try + +class PlatformDateDirectiveSpec extends FunSuite + with ParagraphCompanionShortcuts + with TemplateParserSetup + with MarkupParserSetup + with TestSourceBuilders { + + private val testDate = "2012-01-01T12:30:00+03:00" + + private lazy val longTZ = runTZ("long") + private lazy val fullTZ = runTZ("full") + + private def runTZ(timeStyle: String): String = + PlatformDateTime + .formatConstant(new js.Date(testDate), timeStyle) + .flatMap(_.toOption) + .getOrElse("") + .split(":00 (AM )?") + .last + + def runTemplate (input: String, config: String, expectedContent: TemplateSpan*)(implicit loc: munit.Location): Unit = { + assertEquals(parseTemplateWithConfig(input, config), Right(RootElement(TemplateRoot(expectedContent)))) + } + + private def run(dateStyle: String, expectedFormattedDate: String, language: String = "en", extraDirectiveArg: String = "")(implicit loc: munit.Location): Unit = { + val input = s"""aa @:date(laika.metadata.datePublished, $dateStyle$extraDirectiveArg) bb""" + runTemplate(input, + s"""laika.metadata.datePublished = "$testDate" + |laika.metadata.language = $language""".stripMargin, + TemplateString("aa "), + TemplateString(expectedFormattedDate), + TemplateString(" bb") + ) + } + + test("date directive - SHORT format") { + run("SHORT", "1/1/12, 9:30 AM") + } + + test("date directive - MEDIUM format") { + run("MEDIUM", "Jan 1, 2012, 9:30:00 AM") + } + + test("date directive - LONG format") { + run(s"LONG", s"January 1, 2012 at 9:30:00 AM $longTZ") + } + + test("date directive - LONG format - German - language from document metadata") { + run(s"LONG", s"1. Januar 2012 um 09:30:00 $longTZ", "de") + } + + test("date directive - LONG format - German - language from directive argument") { + run(s"LONG", s"1. Januar 2012 um 09:30:00 $longTZ", extraDirectiveArg = ", de") + } + + test("date directive - FULL format") { + run("FULL", s"Sunday, January 1, 2012 at 9:30:00 AM $fullTZ") + } + +} diff --git a/core/native/src/test/scala/laika/time/PlatformDateTimeSpec.scala b/core/native/src/test/scala/laika/time/PlatformDateTimeSpec.scala new file mode 100644 index 000000000..8bcd3f001 --- /dev/null +++ b/core/native/src/test/scala/laika/time/PlatformDateTimeSpec.scala @@ -0,0 +1,50 @@ +/* + * Copyright 2012-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package laika.time + +import munit.FunSuite + +import scala.scalajs.js + +class PlatformDateTimeSpec extends FunSuite { + + + private def getDate(dateString: String): String = new js.Date(dateString).toISOString() + + + test("parse a date without time") { + assertEquals(PlatformDateTime.parse("2011-10-10").map(_.toISOString), Right(getDate("2011-10-10T00:00:00Z"))) + } + + test("parse a local date time") { + assertEquals(PlatformDateTime.parse("2011-10-10T14:48:00").map(_.toISOString), Right(getDate("2011-10-10T14:48:00"))) + } + + test("parse a UTC date time") { + assertEquals(PlatformDateTime.parse("2011-10-10T14:48:00Z").map(_.toISOString), Right(getDate("2011-10-10T14:48:00Z"))) + } + + test("parse a date time with an offset") { + assertEquals(PlatformDateTime.parse("2011-10-10T14:48:00+0100").map(_.toISOString), Right(getDate("2011-10-10T13:48:00Z"))) + } + + test("fail in case of invalid date format") { + assertEquals(PlatformDateTime.parse("2011-10-10XX14:48:00+0100").isLeft, true) + } + + +} diff --git a/project/Dependencies.scala b/project/Dependencies.scala index 45bd5db4d..5c0be4455 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -3,19 +3,20 @@ object Dependencies { object versions { - val scala2_12 = "2.12.17" - val scala2_13 = "2.13.10" - val scala3 = "3.2.1" + val scala2_12 = "2.12.17" + val scala2_13 = "2.13.10" + val scala3 = "3.2.1" - val catsCore = "2.9.0" - val catsEffect = "3.4.5" - val fs2 = "3.5.0" - val http4s = "0.23.18" + val catsCore = "2.9.0" + val catsEffect = "3.4.5" + val fs2 = "3.5.0" + val http4s = "0.23.18" - val munit = "0.7.29" - val munitCE3 = "1.0.7" - val jTidy = "r938" - val fop = "2.6" + val munit = "0.7.29" + val munitCE3 = "1.0.7" + val jTidy = "r938" + val fop = "2.6" + val scalaJavaTime = "2.5.0" } } From 012719716d5f7c222314e5206fbc9b5ee3478ee1 Mon Sep 17 00:00:00 2001 From: Arman Bilge Date: Wed, 27 Sep 2023 05:40:14 +0000 Subject: [PATCH 2/8] Regenerate workflow --- .github/workflows/ci.yml | 42 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bd06f7119..239c88ee8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,7 +30,7 @@ jobs: os: [ubuntu-latest] scala: [2.12, 2.13, 3] java: [temurin@8, temurin@17] - project: [rootJS, rootJVM, plugin] + project: [rootJS, rootJVM, rootNative, plugin] exclude: - scala: 2.13 java: temurin@17 @@ -38,6 +38,8 @@ jobs: java: temurin@17 - project: rootJS java: temurin@17 + - project: rootNative + java: temurin@17 - project: plugin java: temurin@17 - project: plugin @@ -89,6 +91,10 @@ jobs: if: matrix.project == 'rootJS' run: sbt 'project ${{ matrix.project }}' '++ ${{ matrix.scala }}' Test/scalaJSLinkerResult + - name: nativeLink + if: matrix.project == 'rootNative' + run: sbt 'project ${{ matrix.project }}' '++ ${{ matrix.scala }}' Test/nativeLink + - name: Test run: sbt 'project ${{ matrix.project }}' '++ ${{ matrix.scala }}' test @@ -110,11 +116,11 @@ jobs: - name: Make target directories if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main') - run: mkdir -p sbt/target pdf/target preview/target core/js/target io/target unidoc/target core/jvm/target project/target + run: mkdir -p sbt/target pdf/target preview/target core/native/target core/js/target io/target unidoc/target core/jvm/target project/target - name: Compress target directories if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main') - run: tar cf targets.tar sbt/target pdf/target preview/target core/js/target io/target unidoc/target core/jvm/target project/target + run: tar cf targets.tar sbt/target pdf/target preview/target core/native/target core/js/target io/target unidoc/target core/jvm/target project/target - name: Upload target directories if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main') @@ -184,6 +190,16 @@ jobs: tar xf targets.tar rm targets.tar + - name: Download target directories (2.12, rootNative) + uses: actions/download-artifact@v3 + with: + name: target-${{ matrix.os }}-${{ matrix.java }}-2.12-rootNative + + - name: Inflate target directories (2.12, rootNative) + run: | + tar xf targets.tar + rm targets.tar + - name: Download target directories (2.12, plugin) uses: actions/download-artifact@v3 with: @@ -214,6 +230,16 @@ jobs: tar xf targets.tar rm targets.tar + - name: Download target directories (2.13, rootNative) + uses: actions/download-artifact@v3 + with: + name: target-${{ matrix.os }}-${{ matrix.java }}-2.13-rootNative + + - name: Inflate target directories (2.13, rootNative) + run: | + tar xf targets.tar + rm targets.tar + - name: Download target directories (3, rootJS) uses: actions/download-artifact@v3 with: @@ -234,6 +260,16 @@ jobs: tar xf targets.tar rm targets.tar + - name: Download target directories (3, rootNative) + uses: actions/download-artifact@v3 + with: + name: target-${{ matrix.os }}-${{ matrix.java }}-3-rootNative + + - name: Inflate target directories (3, rootNative) + run: | + tar xf targets.tar + rm targets.tar + - name: Import signing key if: env.PGP_SECRET != '' && env.PGP_PASSPHRASE == '' env: From 970dd6b579ae3c3b829516d2041ff7f4714ef32d Mon Sep 17 00:00:00 2001 From: Arman Bilge Date: Wed, 27 Sep 2023 05:45:18 +0000 Subject: [PATCH 3/8] Create `jvm-native` source folder --- .../laika/config/PlatformDateTimeImpl.scala | 0 .../time/PlatformDateDirectiveSpec.scala | 0 .../laika/time/PlatformDateTimeSpec.scala | 0 .../laika/time/PlatformDateTimeImpl.scala | 96 ------------------- .../time/PlatformDateDirectiveSpec.scala | 69 ------------- .../laika/time/PlatformDateTimeSpec.scala | 50 ---------- 6 files changed, 215 deletions(-) rename core/{jvm/src => jvm-native}/main/scala/laika/config/PlatformDateTimeImpl.scala (100%) rename core/{jvm/src => jvm-native}/test/scala/laika/time/PlatformDateDirectiveSpec.scala (100%) rename core/{jvm/src => jvm-native}/test/scala/laika/time/PlatformDateTimeSpec.scala (100%) delete mode 100644 core/native/src/main/scala/laika/time/PlatformDateTimeImpl.scala delete mode 100644 core/native/src/test/scala/laika/time/PlatformDateDirectiveSpec.scala delete mode 100644 core/native/src/test/scala/laika/time/PlatformDateTimeSpec.scala diff --git a/core/jvm/src/main/scala/laika/config/PlatformDateTimeImpl.scala b/core/jvm-native/main/scala/laika/config/PlatformDateTimeImpl.scala similarity index 100% rename from core/jvm/src/main/scala/laika/config/PlatformDateTimeImpl.scala rename to core/jvm-native/main/scala/laika/config/PlatformDateTimeImpl.scala diff --git a/core/jvm/src/test/scala/laika/time/PlatformDateDirectiveSpec.scala b/core/jvm-native/test/scala/laika/time/PlatformDateDirectiveSpec.scala similarity index 100% rename from core/jvm/src/test/scala/laika/time/PlatformDateDirectiveSpec.scala rename to core/jvm-native/test/scala/laika/time/PlatformDateDirectiveSpec.scala diff --git a/core/jvm/src/test/scala/laika/time/PlatformDateTimeSpec.scala b/core/jvm-native/test/scala/laika/time/PlatformDateTimeSpec.scala similarity index 100% rename from core/jvm/src/test/scala/laika/time/PlatformDateTimeSpec.scala rename to core/jvm-native/test/scala/laika/time/PlatformDateTimeSpec.scala diff --git a/core/native/src/main/scala/laika/time/PlatformDateTimeImpl.scala b/core/native/src/main/scala/laika/time/PlatformDateTimeImpl.scala deleted file mode 100644 index 452ad198e..000000000 --- a/core/native/src/main/scala/laika/time/PlatformDateTimeImpl.scala +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright 2012-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - - -import cats.syntax.all._ -import java.time.format.{DateTimeFormatter, DateTimeFormatterBuilder, FormatStyle} -import java.time.{LocalDateTime, OffsetDateTime, ZoneId} -import java.util.Locale -import scala.util.Try - -/** - * @author Jens Halm - */ -object PlatformDateTimeImpl extends PlatformDateTime { - - type Type = OffsetDateTime - - private[laika] def now: Type = OffsetDateTime.now() - - private val offsetDateTime: DateTimeFormatter = new DateTimeFormatterBuilder() - .append(DateTimeFormatter.ISO_LOCAL_DATE_TIME) - .appendPattern("[XXX][X]") - .toFormatter - - def parse (dateString: String): Either[String, Type] = { - - def parseOffsetDateTime(input: String): Either[String, Type] = Try { - OffsetDateTime.from(offsetDateTime.parse(input)) - }.toEither.left.map(_.getMessage) - - def parseLocalDateTime(input: String): Either[String, Type] = Try { - OffsetDateTime.from(LocalDateTime.parse(input).atZone(ZoneId.systemDefault())) - }.toEither.left.map(_.getMessage) - - if (dateString.matches(".*(Z|[+-]\\d\\d[:]?\\d\\d)")) parseOffsetDateTime(dateString) - else if (dateString.contains("T")) parseLocalDateTime(dateString) - else parseLocalDateTime(dateString + "T00:00:00") - } - - private[laika] def format (date: Type, pattern: String, locale: Option[String] = None): Either[String, String] = - getLocale(locale).flatMap { loc => - Try(new DateTimeFormatterBuilder() - .appendPattern(pattern) - .toFormatter - .withLocale(loc) - .format(date) - ).toEither.left.map(_.getMessage) - } - - private lazy val formatterConstants = Map( - "BASIC_ISO_DATE" -> DateTimeFormatter.BASIC_ISO_DATE, - "ISO_LOCAL_DATE" -> DateTimeFormatter.ISO_LOCAL_DATE, - "ISO_OFFSET_DATE" -> DateTimeFormatter.ISO_OFFSET_DATE, - "ISO_DATE" -> DateTimeFormatter.ISO_DATE, - "ISO_LOCAL_TIME" -> DateTimeFormatter.ISO_LOCAL_TIME, - "ISO_OFFSET_TIME" -> DateTimeFormatter.ISO_OFFSET_TIME, - "ISO_TIME" -> DateTimeFormatter.ISO_TIME, - "ISO_LOCAL_DATE_TIME" -> DateTimeFormatter.ISO_LOCAL_DATE_TIME, - "ISO_OFFSET_DATE_TIME" -> DateTimeFormatter.ISO_OFFSET_DATE_TIME, - "ISO_ZONED_DATE_TIME" -> DateTimeFormatter.ISO_ZONED_DATE_TIME, - "ISO_DATE_TIME" -> DateTimeFormatter.ISO_DATE_TIME, - "ISO_ORDINAL_DATE" -> DateTimeFormatter.ISO_ORDINAL_DATE, - "ISO_WEEK_DATE" -> DateTimeFormatter.ISO_WEEK_DATE, - "ISO_INSTANT" -> DateTimeFormatter.ISO_INSTANT, - "RFC_1123_DATE_TIME" -> DateTimeFormatter.RFC_1123_DATE_TIME, - "MEDIUM" -> DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM), - "SHORT" -> DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT) - ) - - private def getLocale (languageTag: Option[String]): Either[String, Locale] = - languageTag.fold[Either[String, Locale]](Right(Locale.getDefault)) { lang => - Try(new Locale.Builder().setLanguageTag(lang).build()).toEither.leftMap(_.getMessage) - } - - private[laika] def formatConstant (date: Type, constant: String, locale: Option[String] = None): Option[Either[String, String]] = - formatterConstants.get(constant.trim.toUpperCase).map { formatter => - getLocale(locale).flatMap { loc => - Try(formatter.withLocale(loc).format(date)).toEither.leftMap(_.getMessage) - } - } - -} diff --git a/core/native/src/test/scala/laika/time/PlatformDateDirectiveSpec.scala b/core/native/src/test/scala/laika/time/PlatformDateDirectiveSpec.scala deleted file mode 100644 index 5ef76f911..000000000 --- a/core/native/src/test/scala/laika/time/PlatformDateDirectiveSpec.scala +++ /dev/null @@ -1,69 +0,0 @@ -package laika.time - -import laika.ast.sample.{ParagraphCompanionShortcuts, TestSourceBuilders} -import laika.ast.{RootElement, TemplateRoot, TemplateSpan, TemplateString} -import laika.directive.std.{MarkupParserSetup, TemplateParserSetup} -import munit.FunSuite - -import scala.scalajs.js -import scala.util.Try - -class PlatformDateDirectiveSpec extends FunSuite - with ParagraphCompanionShortcuts - with TemplateParserSetup - with MarkupParserSetup - with TestSourceBuilders { - - private val testDate = "2012-01-01T12:30:00+03:00" - - private lazy val longTZ = runTZ("long") - private lazy val fullTZ = runTZ("full") - - private def runTZ(timeStyle: String): String = - PlatformDateTime - .formatConstant(new js.Date(testDate), timeStyle) - .flatMap(_.toOption) - .getOrElse("") - .split(":00 (AM )?") - .last - - def runTemplate (input: String, config: String, expectedContent: TemplateSpan*)(implicit loc: munit.Location): Unit = { - assertEquals(parseTemplateWithConfig(input, config), Right(RootElement(TemplateRoot(expectedContent)))) - } - - private def run(dateStyle: String, expectedFormattedDate: String, language: String = "en", extraDirectiveArg: String = "")(implicit loc: munit.Location): Unit = { - val input = s"""aa @:date(laika.metadata.datePublished, $dateStyle$extraDirectiveArg) bb""" - runTemplate(input, - s"""laika.metadata.datePublished = "$testDate" - |laika.metadata.language = $language""".stripMargin, - TemplateString("aa "), - TemplateString(expectedFormattedDate), - TemplateString(" bb") - ) - } - - test("date directive - SHORT format") { - run("SHORT", "1/1/12, 9:30 AM") - } - - test("date directive - MEDIUM format") { - run("MEDIUM", "Jan 1, 2012, 9:30:00 AM") - } - - test("date directive - LONG format") { - run(s"LONG", s"January 1, 2012 at 9:30:00 AM $longTZ") - } - - test("date directive - LONG format - German - language from document metadata") { - run(s"LONG", s"1. Januar 2012 um 09:30:00 $longTZ", "de") - } - - test("date directive - LONG format - German - language from directive argument") { - run(s"LONG", s"1. Januar 2012 um 09:30:00 $longTZ", extraDirectiveArg = ", de") - } - - test("date directive - FULL format") { - run("FULL", s"Sunday, January 1, 2012 at 9:30:00 AM $fullTZ") - } - -} diff --git a/core/native/src/test/scala/laika/time/PlatformDateTimeSpec.scala b/core/native/src/test/scala/laika/time/PlatformDateTimeSpec.scala deleted file mode 100644 index 8bcd3f001..000000000 --- a/core/native/src/test/scala/laika/time/PlatformDateTimeSpec.scala +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2012-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package laika.time - -import munit.FunSuite - -import scala.scalajs.js - -class PlatformDateTimeSpec extends FunSuite { - - - private def getDate(dateString: String): String = new js.Date(dateString).toISOString() - - - test("parse a date without time") { - assertEquals(PlatformDateTime.parse("2011-10-10").map(_.toISOString), Right(getDate("2011-10-10T00:00:00Z"))) - } - - test("parse a local date time") { - assertEquals(PlatformDateTime.parse("2011-10-10T14:48:00").map(_.toISOString), Right(getDate("2011-10-10T14:48:00"))) - } - - test("parse a UTC date time") { - assertEquals(PlatformDateTime.parse("2011-10-10T14:48:00Z").map(_.toISOString), Right(getDate("2011-10-10T14:48:00Z"))) - } - - test("parse a date time with an offset") { - assertEquals(PlatformDateTime.parse("2011-10-10T14:48:00+0100").map(_.toISOString), Right(getDate("2011-10-10T13:48:00Z"))) - } - - test("fail in case of invalid date format") { - assertEquals(PlatformDateTime.parse("2011-10-10XX14:48:00+0100").isLeft, true) - } - - -} From 81d264b863b78a261dcd61a1dbb8fba42c8107a3 Mon Sep 17 00:00:00 2001 From: Arman Bilge Date: Wed, 27 Sep 2023 05:48:31 +0000 Subject: [PATCH 4/8] Add scala-java-time to native --- build.sbt | 3 +++ project/Dependencies.scala | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/build.sbt b/build.sbt index 993aa754f..9118e9dd7 100644 --- a/build.sbt +++ b/build.sbt @@ -135,6 +135,9 @@ lazy val core = crossProject(JSPlatform, JVMPlatform, NativePlatform) _.withModuleKind(ModuleKind.CommonJSModule).withESFeatures(_.withESVersion(ESVersion.ES2018)) } ) + .nativeSettings( + libraryDependencies += "io.github.cquiroz" %%% "scala-java-time" % versions.scalaJavaTime + ) lazy val io = project.in(file("io")) .dependsOn(core.jvm % "compile->compile;test->test") diff --git a/project/Dependencies.scala b/project/Dependencies.scala index 6853ffad4..b7a3d3e49 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -15,8 +15,8 @@ object Dependencies { val munitCE3 = "1.0.7" val jTidy = "r938" val fop = "2.9" - val scalaJavaTime = "2.5.0" + val scalaJavaTime = "2.5.0" } } From a835ad50d9ea8fd74b28b8512af1ee8297f43fc3 Mon Sep 17 00:00:00 2001 From: Arman Bilge Date: Wed, 27 Sep 2023 05:50:46 +0000 Subject: [PATCH 5/8] Bump munit --- project/Dependencies.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/project/Dependencies.scala b/project/Dependencies.scala index b7a3d3e49..fe51b5353 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -11,8 +11,8 @@ object Dependencies { val fs2 = "3.9.2" val http4s = "0.23.23" - val munit = "0.7.29" - val munitCE3 = "1.0.7" + val munit = "1.0.0-M10" + val munitCE3 = "2.0.0-M3" val jTidy = "r938" val fop = "2.9" From a96a38b68f3e5eb100651b61aa759d8724bbfee2 Mon Sep 17 00:00:00 2001 From: Arman Bilge Date: Wed, 27 Sep 2023 05:52:20 +0000 Subject: [PATCH 6/8] Fix munit-ce dep --- build.sbt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build.sbt b/build.sbt index 9118e9dd7..27890c0ef 100644 --- a/build.sbt +++ b/build.sbt @@ -54,9 +54,9 @@ def disableUnusedWarningsForMdoc(options: Seq[String]): Seq[String] = val munit = "org.scalameta" %% "munit" % versions.munit % "test" val jTidy = "net.sf.jtidy" % "jtidy" % versions.jTidy % "test" -val catsEffect = "org.typelevel" %% "cats-effect" % versions.catsEffect -val fs2IO = "co.fs2" %% "fs2-io" % versions.fs2 -val munitCE3 = "org.typelevel" %% "munit-cats-effect-3" % versions.munitCE3 % "test" +val catsEffect = "org.typelevel" %% "cats-effect" % versions.catsEffect +val fs2IO = "co.fs2" %% "fs2-io" % versions.fs2 +val munitCE3 = "org.typelevel" %% "munit-cats-effect" % versions.munitCE3 % "test" val fop = "org.apache.xmlgraphics" % "fop" % versions.fop From e98ffa4b4865d05cb4f0e86aae250e82259dbdea Mon Sep 17 00:00:00 2001 From: Arman Bilge Date: Wed, 27 Sep 2023 05:53:30 +0000 Subject: [PATCH 7/8] `munitCE3` -> `munitCE` --- build.sbt | 4 ++-- project/Dependencies.scala | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/build.sbt b/build.sbt index 27890c0ef..46013c69f 100644 --- a/build.sbt +++ b/build.sbt @@ -56,7 +56,7 @@ val jTidy = "net.sf.jtidy" % "jtidy" % versions.jTidy % "test" val catsEffect = "org.typelevel" %% "cats-effect" % versions.catsEffect val fs2IO = "co.fs2" %% "fs2-io" % versions.fs2 -val munitCE3 = "org.typelevel" %% "munit-cats-effect" % versions.munitCE3 % "test" +val munitCE = "org.typelevel" %% "munit-cats-effect" % versions.munitCE % "test" val fop = "org.apache.xmlgraphics" % "fop" % versions.fop @@ -143,7 +143,7 @@ lazy val io = project.in(file("io")) .dependsOn(core.jvm % "compile->compile;test->test") .settings( name := "laika-io", - libraryDependencies ++= Seq(catsEffect, fs2IO, munit, munitCE3), + libraryDependencies ++= Seq(catsEffect, fs2IO, munit, munitCE), Test / scalacOptions ~= disableMissingInterpolatorWarning ) diff --git a/project/Dependencies.scala b/project/Dependencies.scala index fe51b5353..9fbeede60 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -11,10 +11,10 @@ object Dependencies { val fs2 = "3.9.2" val http4s = "0.23.23" - val munit = "1.0.0-M10" - val munitCE3 = "2.0.0-M3" - val jTidy = "r938" - val fop = "2.9" + val munit = "1.0.0-M10" + val munitCE = "2.0.0-M3" + val jTidy = "r938" + val fop = "2.9" val scalaJavaTime = "2.5.0" } From cc3403a07a8c6dfcdfc3f08d248102084f5e5d04 Mon Sep 17 00:00:00 2001 From: Arman Bilge Date: Wed, 27 Sep 2023 05:58:33 +0000 Subject: [PATCH 8/8] Fixing --- .../{ => src}/main/scala/laika/config/PlatformDateTimeImpl.scala | 0 .../test/scala/laika/time/PlatformDateDirectiveSpec.scala | 0 .../{ => src}/test/scala/laika/time/PlatformDateTimeSpec.scala | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename core/jvm-native/{ => src}/main/scala/laika/config/PlatformDateTimeImpl.scala (100%) rename core/jvm-native/{ => src}/test/scala/laika/time/PlatformDateDirectiveSpec.scala (100%) rename core/jvm-native/{ => src}/test/scala/laika/time/PlatformDateTimeSpec.scala (100%) diff --git a/core/jvm-native/main/scala/laika/config/PlatformDateTimeImpl.scala b/core/jvm-native/src/main/scala/laika/config/PlatformDateTimeImpl.scala similarity index 100% rename from core/jvm-native/main/scala/laika/config/PlatformDateTimeImpl.scala rename to core/jvm-native/src/main/scala/laika/config/PlatformDateTimeImpl.scala diff --git a/core/jvm-native/test/scala/laika/time/PlatformDateDirectiveSpec.scala b/core/jvm-native/src/test/scala/laika/time/PlatformDateDirectiveSpec.scala similarity index 100% rename from core/jvm-native/test/scala/laika/time/PlatformDateDirectiveSpec.scala rename to core/jvm-native/src/test/scala/laika/time/PlatformDateDirectiveSpec.scala diff --git a/core/jvm-native/test/scala/laika/time/PlatformDateTimeSpec.scala b/core/jvm-native/src/test/scala/laika/time/PlatformDateTimeSpec.scala similarity index 100% rename from core/jvm-native/test/scala/laika/time/PlatformDateTimeSpec.scala rename to core/jvm-native/src/test/scala/laika/time/PlatformDateTimeSpec.scala