├── .envrc ├── .git-blame-ignore-revs ├── .gitattributes ├── .github ├── dependabot.yml ├── release-drafter.yml └── workflows │ ├── ci.yml │ ├── clean.yml │ └── release-drafter.yml ├── .gitignore ├── .jvmopts ├── .scalafmt.conf ├── CHANGELOG.md ├── LICENSE.txt ├── README.md ├── build.sbt ├── changes.xml ├── core ├── js │ └── src │ │ └── main │ │ └── scala │ │ ├── java │ │ └── util │ │ │ ├── SimpleTimeZone.scala │ │ │ └── TimeZone.scala │ │ └── org │ │ └── threeten │ │ └── bp │ │ ├── chrono │ │ ├── ChronologyPlatformHelper.scala │ │ └── HijrahDateConfigurator.scala │ │ ├── format │ │ └── CasePlatformHelper.scala │ │ └── zone │ │ ├── DefaultTzdbZoneRulesProvider.scala │ │ └── ServiceLoaderZoneRulesInitializer.scala ├── jvm │ └── src │ │ └── main │ │ ├── resources │ │ ├── META-INF │ │ │ └── services │ │ │ │ └── org.threeten.bp.zone.ZoneRulesProvider │ │ └── org │ │ │ └── threeten │ │ │ └── bp │ │ │ ├── TZDB.dat │ │ │ └── format │ │ │ └── ChronologyText.properties │ │ ├── scala-2 │ │ └── org │ │ │ └── threeten │ │ │ └── bp │ │ │ └── zone │ │ │ └── ServiceLoaderZoneRulesInitializer.scala │ │ ├── scala-3 │ │ └── org │ │ │ └── threeten │ │ │ └── bp │ │ │ └── zone │ │ │ └── ServiceLoaderZoneRulesInitializer.scala │ │ └── scala │ │ └── org │ │ └── threeten │ │ └── bp │ │ ├── chrono │ │ ├── ChronologyPlatformHelper.scala │ │ ├── HijrahDateConfigurator.scala │ │ ├── JapaneseChronology.scala │ │ ├── JapaneseDate.scala │ │ ├── JapaneseEra.scala │ │ └── internal │ │ │ └── TTBPJapaneseEra.scala │ │ ├── format │ │ └── CasePlatformHelper.scala │ │ └── zone │ │ └── DefaultTzdbZoneRulesProvider.scala ├── native │ └── src │ │ └── main │ │ └── scala │ │ ├── java │ │ └── util │ │ │ ├── SimpleTimeZone.scala │ │ │ └── TimeZone.scala │ │ └── org │ │ └── threeten │ │ └── bp │ │ ├── chrono │ │ ├── ChronologyPlatformHelper.scala │ │ └── HijrahDateConfigurator.scala │ │ ├── format │ │ └── CasePlatformHelper.scala │ │ └── zone │ │ ├── DefaultTzdbZoneRulesProvider.scala │ │ └── ServiceLoaderZoneRulesInitializer.scala └── shared │ └── src │ ├── main │ ├── scala-2 │ │ └── org │ │ │ └── threeten │ │ │ └── bp │ │ │ ├── DayOfWeek.scala │ │ │ ├── Month.scala │ │ │ ├── chrono │ │ │ ├── HijrahEra.scala │ │ │ ├── IsoEra.scala │ │ │ ├── MinguoEra.scala │ │ │ └── ThaiBuddhistEra.scala │ │ │ ├── format │ │ │ ├── FormatStyle.scala │ │ │ ├── ResolverStyle.scala │ │ │ ├── SignStyle.scala │ │ │ ├── TextStyle.scala │ │ │ └── internal │ │ │ │ └── TTBPDateTimeFormatterBuilder.scala │ │ │ ├── temporal │ │ │ ├── ChronoField.scala │ │ │ ├── ChronoUnit.scala │ │ │ ├── IsoFields.scala │ │ │ └── JulianFields.scala │ │ │ └── zone │ │ │ ├── ZoneMap.scala │ │ │ └── ZoneOffsetTransitionRule.scala │ ├── scala-3 │ │ └── org │ │ │ └── threeten │ │ │ └── bp │ │ │ ├── DayOfWeek.scala │ │ │ ├── Month.scala │ │ │ ├── chrono │ │ │ ├── HijrahEra.scala │ │ │ ├── IsoEra.scala │ │ │ ├── MinguoEra.scala │ │ │ └── ThaiBuddhistEra.scala │ │ │ ├── format │ │ │ ├── FormatStyle.scala │ │ │ ├── ResolverStyle.scala │ │ │ ├── SignStyle.scala │ │ │ ├── TextStyle.scala │ │ │ └── internal │ │ │ │ └── TTBPDateTimeFormatterBuilder.scala │ │ │ ├── temporal │ │ │ ├── ChronoField.scala │ │ │ ├── ChronoUnit.scala │ │ │ ├── IsoFields.scala │ │ │ └── JulianFields.scala │ │ │ └── zone │ │ │ ├── ZoneMap.scala │ │ │ └── ZoneOffsetTransitionRule.scala │ └── scala │ │ └── org │ │ └── threeten │ │ └── bp │ │ ├── Clock.scala │ │ ├── DateTimeException.scala │ │ ├── Duration.scala │ │ ├── Instant.scala │ │ ├── LocalDate.scala │ │ ├── LocalDateTime.scala │ │ ├── LocalTime.scala │ │ ├── MonthDay.scala │ │ ├── OffsetDateTime.scala │ │ ├── OffsetTime.scala │ │ ├── Period.scala │ │ ├── Year.scala │ │ ├── YearMonth.scala │ │ ├── ZoneId.scala │ │ ├── ZoneOffset.scala │ │ ├── ZoneRegion.scala │ │ ├── ZonedDateTime.scala │ │ ├── chrono │ │ ├── AbstractChronology.scala │ │ ├── ChronoLocalDate.scala │ │ ├── ChronoLocalDateImpl.scala │ │ ├── ChronoLocalDateTime.scala │ │ ├── ChronoLocalDateTimeImpl.scala │ │ ├── ChronoPeriod.scala │ │ ├── ChronoPeriodImpl.scala │ │ ├── ChronoZonedDateTime.scala │ │ ├── ChronoZonedDateTimeImpl.scala │ │ ├── Chronology.scala │ │ ├── Era.scala │ │ ├── HijrahChronology.scala │ │ ├── HijrahDate.scala │ │ ├── IsoChronology.scala │ │ ├── MinguoChronology.scala │ │ ├── MinguoDate.scala │ │ ├── ThaiBuddhistChronology.scala │ │ ├── ThaiBuddhistDate.scala │ │ └── package.scala │ │ ├── format │ │ ├── DateTimeBuilder.scala │ │ ├── DateTimeFormatStyleProvider.scala │ │ ├── DateTimeFormatter.scala │ │ ├── DateTimeFormatterBuilder.scala │ │ ├── DateTimeParseException.scala │ │ ├── DecimalStyle.scala │ │ ├── SimpleDateTimeFormatStyleProvider.scala │ │ ├── internal │ │ │ ├── DateTimePrinterParser.scala │ │ │ ├── TTBPDateTimeParseContext.scala │ │ │ ├── TTBPDateTimePrintContext.scala │ │ │ ├── TTBPDateTimeTextProvider.scala │ │ │ └── TTBPSimpleDateTimeTextProvider.scala │ │ └── package.scala │ │ ├── package.scala │ │ ├── temporal │ │ ├── Temporal.scala │ │ ├── TemporalAccessor.scala │ │ ├── TemporalAdjuster.scala │ │ ├── TemporalAdjusters.scala │ │ ├── TemporalAmount.scala │ │ ├── TemporalField.scala │ │ ├── TemporalQueries.scala │ │ ├── TemporalQuery.scala │ │ ├── TemporalUnit.scala │ │ ├── UnsupportedTemporalTypeException.scala │ │ ├── ValueRange.scala │ │ ├── WeekFields.scala │ │ └── package.scala │ │ └── zone │ │ ├── StandardZoneRules.scala │ │ ├── ZoneOffsetTransition.scala │ │ ├── ZoneRules.scala │ │ ├── ZoneRulesBuilder.scala │ │ ├── ZoneRulesException.scala │ │ ├── ZoneRulesInitializer.scala │ │ ├── ZoneRulesProvider.scala │ │ └── package.scala │ └── site │ ├── markdown │ ├── index.md │ └── update-tzdb.md │ ├── resources │ └── css │ │ └── site.css │ └── site.xml ├── demo ├── shared │ └── src │ │ └── main │ │ └── scala │ │ └── demo │ │ └── DemoApp.scala └── sizes.md ├── docs └── src │ └── main │ └── tut │ └── index.md ├── flake.lock ├── flake.nix ├── project ├── build.properties └── plugins.sbt ├── sbt └── tests ├── js └── src │ └── test │ └── scala │ ├── java │ └── util │ │ └── TestTimeZone.scala │ └── org │ └── threeten │ └── bp │ ├── Platform.scala │ └── zone │ └── TestStandardZoneRulesNegativeTZDB.scala ├── jvm └── src │ └── test │ └── scala │ └── org │ └── threeten │ └── bp │ ├── ClassLoaderChecker.scala │ ├── Platform.scala │ ├── UsabilityChrono.scala │ └── chrono │ └── TestJapaneseChronology.scala ├── native └── src │ └── test │ └── scala │ ├── java │ └── util │ │ └── TestTimeZone.scala │ └── org │ └── threeten │ └── bp │ ├── Platform.scala │ └── zone │ └── TestStandardZoneRulesNegativeTZDB.scala └── shared └── src └── test ├── scala-2 └── org │ └── threeten │ └── bp │ └── temporal │ └── MockFieldNoValue.scala ├── scala-3 └── org │ └── threeten │ └── bp │ └── temporal │ └── MockFieldNoValue.scala └── scala ├── java └── util │ └── TestZoneMap.scala └── org └── threeten └── bp ├── AssertionsHelper.scala ├── Examples.scala ├── FluentAPIChecker.scala ├── GenDateTimeTest.scala ├── MockSimplePeriod.scala ├── Performance.scala ├── PerformanceZone.scala ├── TestClock.scala ├── TestClock_Fixed.scala ├── TestClock_Offset.scala ├── TestClock_System.scala ├── TestClock_Tick.scala ├── TestDayOfWeek.scala ├── TestDuration.scala ├── TestExamples.scala ├── TestInstant.scala ├── TestLocalDate.scala ├── TestLocalDateTime.scala ├── TestLocalTime.scala ├── TestMonth.scala ├── TestOffsetDateTime.scala ├── TestOffsetDateTime_instants.scala ├── TestOffsetTime.scala ├── TestPeriod.scala ├── TestZoneId.scala ├── TestZoneOffset.scala ├── TestZonedDateTime.scala ├── UsabilityBasic.scala ├── chrono ├── TestChronoLocalDate.scala ├── TestChronoLocalDateTime.scala ├── TestChronoZonedDateTime.scala ├── TestChronology.scala ├── TestHijrahChronology.scala ├── TestIsoChronology.scala ├── TestMinguoChronology.scala └── TestThaiBuddhistChronology.scala ├── format ├── GenTestPrinterParser.scala ├── MockIOExceptionAppendable.scala ├── TestCharLiteralParser.scala ├── TestCharLiteralPrinter.scala ├── TestDateTimeBuilderCombinations.scala ├── TestDateTimeFormatter.scala ├── TestDateTimeFormatterBuilder.scala ├── TestDateTimeFormatters.scala ├── TestDateTimeParsing.scala ├── TestDateTimeTextPrinting.scala ├── TestDecimalStyle.scala ├── TestFractionPrinterParser.scala ├── TestNumberParser.scala ├── TestNumberPrinter.scala ├── TestPadParserDecorator.scala ├── TestPadPrinterDecorator.scala ├── TestReducedParser.scala ├── TestReducedPrinter.scala ├── TestSettingsParser.scala ├── TestSimpleDateTimeTextProvider.scala ├── TestStringLiteralParser.scala ├── TestStringLiteralPrinter.scala ├── TestTextParser.scala ├── TestTextPrinter.scala ├── TestZoneIdParser.scala ├── TestZoneOffsetParser.scala └── TestZoneOffsetPrinter.scala ├── temporal ├── MockFieldValue.scala ├── TestChronoField.scala ├── TestChronoUnit.scala ├── TestIsoFields.scala ├── TestJulianFields.scala ├── TestMonthDay.scala ├── TestTemporalAdjusters.scala ├── TestValueRange.scala ├── TestYear.scala └── TestYearMonth.scala └── zone ├── TestFixedZoneRules.scala ├── TestStandardZoneRules.scala ├── TestZoneOffsetTransition.scala ├── TestZoneOffsetTransitionRule.scala ├── TestZoneRulesBuilder.scala └── TestZoneRulesProvider.scala /.envrc: -------------------------------------------------------------------------------- 1 | use flake 2 | layout node 3 | eval "$shellHook" 4 | -------------------------------------------------------------------------------- /.git-blame-ignore-revs: -------------------------------------------------------------------------------- 1 | # Scala Steward: Reformat with scalafmt 3.6.1 2 | aa7db3a42121f78a5b3bed3658786c1cef83efe8 3 | 4 | # Enable scalafmt for Scala 3 5 | 64df4ae51873593a789af5848bd225c14d0baf8a 6 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Manage line endings, info from GitHub 2 | # Set default behaviour, in case users don't have core.autocrlf set. 3 | * text=auto 4 | 5 | # Denote all files that are truly binary and should not be modified. 6 | *.png binary 7 | *.jpg binary 8 | *.jar binary 9 | *.dat binary 10 | *.zip binary 11 | *.tar binary 12 | *.gz binary 13 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | 4 | - package-ecosystem: "github-actions" 5 | directory: "/" 6 | schedule: 7 | interval: "monthly" 8 | -------------------------------------------------------------------------------- /.github/release-drafter.yml: -------------------------------------------------------------------------------- 1 | name-template: 'v$NEXT_PATCH_VERSION' 2 | tag-template: 'v$NEXT_PATCH_VERSION' 3 | template: | 4 | # What's Changed 5 | $CHANGES 6 | categories: 7 | - title: 'New' 8 | label: 'type: feature' 9 | - title: 'Bug Fixes' 10 | label: 'type: bug' 11 | - title: 'Maintenance' 12 | label: 'type: maintenance' 13 | - title: 'Documentation' 14 | label: 'type: docs' 15 | - title: 'Dependency Updates' 16 | label: 'type: dependencies' 17 | -------------------------------------------------------------------------------- /.github/workflows/clean.yml: -------------------------------------------------------------------------------- 1 | # This file was automatically generated by sbt-github-actions using the 2 | # githubWorkflowGenerate task. You should add and commit this file to 3 | # your git repository. It goes without saying that you shouldn't edit 4 | # this file by hand! Instead, if you wish to make changes, you should 5 | # change your sbt build configuration to revise the workflow description 6 | # to meet your needs, then regenerate this file. 7 | 8 | name: Clean 9 | 10 | on: push 11 | 12 | jobs: 13 | delete-artifacts: 14 | name: Delete Artifacts 15 | runs-on: ubuntu-latest 16 | env: 17 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 18 | steps: 19 | - name: Delete artifacts 20 | run: | 21 | # Customize those three lines with your repository and credentials: 22 | REPO=${GITHUB_API_URL}/repos/${{ github.repository }} 23 | 24 | # A shortcut to call GitHub API. 25 | ghapi() { curl --silent --location --user _:$GITHUB_TOKEN "$@"; } 26 | 27 | # A temporary file which receives HTTP response headers. 28 | TMPFILE=/tmp/tmp.$$ 29 | 30 | # An associative array, key: artifact name, value: number of artifacts of that name. 31 | declare -A ARTCOUNT 32 | 33 | # Process all artifacts on this repository, loop on returned "pages". 34 | URL=$REPO/actions/artifacts 35 | while [[ -n "$URL" ]]; do 36 | 37 | # Get current page, get response headers in a temporary file. 38 | JSON=$(ghapi --dump-header $TMPFILE "$URL") 39 | 40 | # Get URL of next page. Will be empty if we are at the last page. 41 | URL=$(grep '^Link:' "$TMPFILE" | tr ',' '\n' | grep 'rel="next"' | head -1 | sed -e 's/.*.*//') 42 | rm -f $TMPFILE 43 | 44 | # Number of artifacts on this page: 45 | COUNT=$(( $(jq <<<$JSON -r '.artifacts | length') )) 46 | 47 | # Loop on all artifacts on this page. 48 | for ((i=0; $i < $COUNT; i++)); do 49 | 50 | # Get name of artifact and count instances of this name. 51 | name=$(jq <<<$JSON -r ".artifacts[$i].name?") 52 | ARTCOUNT[$name]=$(( $(( ${ARTCOUNT[$name]} )) + 1)) 53 | 54 | id=$(jq <<<$JSON -r ".artifacts[$i].id?") 55 | size=$(( $(jq <<<$JSON -r ".artifacts[$i].size_in_bytes?") )) 56 | printf "Deleting '%s' #%d, %'d bytes\n" $name ${ARTCOUNT[$name]} $size 57 | ghapi -X DELETE $REPO/actions/artifacts/$id 58 | done 59 | done 60 | -------------------------------------------------------------------------------- /.github/workflows/release-drafter.yml: -------------------------------------------------------------------------------- 1 | name: Release Drafter 2 | 3 | on: 4 | push: 5 | # branches to consider in the event; optional, defaults to all 6 | branches: 7 | - master 8 | 9 | jobs: 10 | update_release_draft: 11 | runs-on: ubuntu-latest 12 | steps: 13 | # Drafts your next Release notes as Pull Requests are merged into "master" 14 | - uses: release-drafter/release-drafter@v5 15 | env: 16 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 17 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | /bin/ 3 | /lib/ 4 | /dist/ 5 | /test-output/ 6 | /jvm/test-output/ 7 | /temp* 8 | *.settings/ 9 | /nbproject/private/ 10 | *target/ 11 | .classpath 12 | .project 13 | .checkstyle 14 | *.class 15 | *.jar 16 | *.war 17 | *.ear 18 | /*.launch 19 | /*.dic 20 | /.idea 21 | *.iml 22 | .ensime 23 | .ensime_cache/ 24 | /project/project/ 25 | /project/target/ 26 | shared/js/src/main/resources/ 27 | tzdb/js/src/main/resources/ 28 | 29 | /src/*/ 30 | !/src/changes/ 31 | !/src/main/ 32 | !/src/site/ 33 | !/src/test/ 34 | 35 | **/TempTest.java 36 | /.idea/ 37 | /threetenbp.iml 38 | .metaserver/ 39 | .bloop/ 40 | .metals/ 41 | project/metals.sbt 42 | .direnv/ 43 | .bsp/ 44 | 45 | .DS_Store 46 | -------------------------------------------------------------------------------- /.jvmopts: -------------------------------------------------------------------------------- 1 | -Xmx4g 2 | -Xss4m 3 | -Dfile.encoding=UTF8 4 | -XX:+PrintCommandLineFlags 5 | -------------------------------------------------------------------------------- /.scalafmt.conf: -------------------------------------------------------------------------------- 1 | version = "3.6.1" 2 | style = default 3 | 4 | maxColumn = 100 5 | 6 | // Vertical alignment is pretty, but leads to bigger diffs 7 | align.preset = most 8 | 9 | rewrite.rules = [ 10 | AvoidInfix 11 | RedundantBraces 12 | RedundantParens 13 | AsciiSortImports 14 | PreferCurlyFors 15 | ] 16 | 17 | align.tokens.add = [{code = "=>", owner = "Case"}] 18 | align.tokens.add = [{code = ":", owner = "Term.Param"}, "=", "shouldBe", "<-", "^"] 19 | align.openParenCallSite = true 20 | spaces.inImportCurlyBraces = true 21 | 22 | continuationIndent.defnSite = 2 23 | 24 | docstrings.style = Asterisk 25 | 26 | rewrite.neverInfix.excludeFilters = [until 27 | to 28 | by 29 | eq 30 | ne 31 | "should.*" 32 | "contain.*" 33 | "must.*" 34 | in 35 | be 36 | taggedAs 37 | thrownBy 38 | synchronized 39 | have 40 | when 41 | size 42 | theSameElementsAs] 43 | 44 | runner.dialect = scala213 45 | fileOverride { 46 | "glob:**/scala-3/**" { 47 | runner.dialect = scala3 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # 2.1.0 2 | 3 | * Drop scala.js 0.6 support 4 | * Support scala 3.0.0-M2/M3 5 | 6 | # 2.0.0 7 | 8 | * First fully featured release 9 | 10 | # 2.0.0-RC4 11 | 12 | * Support sbt-locales 13 | * Size reduction optimizations 14 | * Support scala.js 1.0.1 15 | * Switch to scalafmt 16 | * Drop support for scala 2.10 17 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * * Neither the name of JSR-310 nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | ## Scala Java-Time 3 | 4 | ![build](https://github.com/cquiroz/scala-java-time/workflows/build/badge.svg) 5 | [![Maven Central](https://img.shields.io/maven-central/v/io.github.cquiroz/scala-java-time_2.11.svg)](https://maven-badges.herokuapp.com/maven-central/io.github.cquiroz/scala-java-time_2.11) 6 | [![Scala.js](https://www.scala-js.org/assets/badges/scalajs-1.0.0.svg)](https://www.scala-js.org/) 7 | 8 | This project provides an implementation of the `java.time` package, a date and time library that was added in Java 8. 9 | The implementation is based on the original BSD-licensed reference implementation (before it was contributed to OpenJDK). 10 | 11 | #### Usage 12 | 13 | The *scala-java-time* library is currently available for Scala (JVM, version 8 and later), Scala.js (JavaScript) and Scala Native (LLVM). 14 | Scala 2.11, Scala 2.12, Scala 2.13 and Scala 3.0.0 are supported. 15 | 16 | To get started with SBT, add one (or both) of these dependencies: 17 | 18 | - `libraryDependencies += "io.github.cquiroz" %%% "scala-java-time" % "2.5.0"` 19 | 20 | 21 | #### Documentation 22 | 23 | See the [documentation](http://cquiroz.github.io/scala-java-time/) 24 | -------------------------------------------------------------------------------- /core/js/src/main/scala/java/util/SimpleTimeZone.scala: -------------------------------------------------------------------------------- 1 | package java.util 2 | 3 | class SimpleTimeZone(rawOffset: Int, var ID: String) extends TimeZone { 4 | override def getRawOffset = rawOffset 5 | /* concrete methods */ 6 | override def getID: String = ID 7 | override def setID(id: String): Unit = ID = id 8 | 9 | } 10 | -------------------------------------------------------------------------------- /core/js/src/main/scala/java/util/TimeZone.scala: -------------------------------------------------------------------------------- 1 | package java.util 2 | 3 | import java.text.DateFormatSymbols 4 | 5 | import java.time.{ Instant, ZoneId } 6 | import java.time.zone.ZoneRulesProvider 7 | 8 | import scala.collection.JavaConverters._ 9 | import scala.util.Try 10 | import scala.scalajs.js 11 | import js.annotation._ 12 | 13 | @js.native 14 | trait DateTimeFormatOptions extends js.Object { 15 | val timeZone: js.UndefOr[String] 16 | } 17 | 18 | @js.native 19 | @JSGlobal("Intl.DateTimeFormat") 20 | class DateTimeFormat() extends js.Object { 21 | def resolvedOptions(): DateTimeFormatOptions = js.native 22 | } 23 | 24 | object TimeZone { 25 | final val SHORT = 0 26 | final val LONG = 1 27 | 28 | private var default: TimeZone = { 29 | // This is supported since EcmaScript 1 30 | def offsetInMillis: Int = { 31 | val browserDate = new scalajs.js.Date() 32 | browserDate.getTimezoneOffset().toInt * 60 * 1000 33 | } 34 | 35 | def timeZone: String = { 36 | def browserTZ: Try[String] = 37 | Try { 38 | val browserDate = new scalajs.js.Date() 39 | browserDate.toTimeString().split(' ')(1).takeWhile(e => e != ' ') 40 | } 41 | 42 | Try { 43 | // First try with the intl API 44 | new DateTimeFormat().resolvedOptions().timeZone.getOrElse(browserTZ.getOrElse("UTC")) 45 | }.orElse { 46 | // If it fails try to parse it from the date string 47 | browserTZ 48 | }.getOrElse("UTC") // Fallback to UTC 49 | } 50 | 51 | new SimpleTimeZone(offsetInMillis, timeZone) 52 | } 53 | 54 | def getDefault: TimeZone = default 55 | def setDefault(timeZone: TimeZone): Unit = default = timeZone 56 | 57 | def getTimeZone(timeZone: String): TimeZone = getTimeZone(ZoneId.of(timeZone)) 58 | def getTimeZone(zoneId: ZoneId): TimeZone = { 59 | val rules = zoneId.getRules 60 | val offsetInMillis = rules.getStandardOffset(Instant.now).getTotalSeconds * 1000 61 | new SimpleTimeZone(offsetInMillis, zoneId.getId) 62 | } 63 | 64 | def getAvailableIDs: Array[String] = ZoneRulesProvider.getAvailableZoneIds.asScala.toArray 65 | def getAvailableIDs(offsetMillis: Int): Array[String] = 66 | getAvailableIDs.filter(getTimeZone(_).getRawOffset == offsetMillis) 67 | 68 | } 69 | 70 | @SerialVersionUID(3581463369166924961L) 71 | abstract class TimeZone extends Serializable with Cloneable { 72 | /* values */ 73 | private var ID: String = null 74 | 75 | /* abstract methods */ 76 | // def getOffset(era: Int, year: Int, month: Int, day: Int, dayOfWeek: Int, milliseconds: Int): Int 77 | def getRawOffset: Int 78 | // def inDaylightTime(date: Date): Boolean 79 | // def setRawOffset(offsetMillis: Int): Unit 80 | // def useDaylightTime: Boolean 81 | 82 | /* concrete methods */ 83 | def getID: String = ID 84 | def setID(id: String): Unit = ID = id 85 | 86 | def getDisplayName(daylight: Boolean, style: Int, locale: Locale): String = { 87 | if (style != TimeZone.SHORT && style != TimeZone.LONG) 88 | throw new IllegalArgumentException(s"Illegal timezone style: $style") 89 | 90 | // Safely looks up given index in the array 91 | def atIndex(strs: Array[String], idx: Int): Option[String] = 92 | if (idx >= 0 && idx < strs.length) Option(strs(idx)) 93 | else None 94 | 95 | val id = getID 96 | def currentIdStrings(strs: Array[String]): Boolean = 97 | atIndex(strs, 0).contains(id) 98 | 99 | val zoneStrings = DateFormatSymbols.getInstance(locale).getZoneStrings 100 | val zoneName = zoneStrings.find(currentIdStrings).flatMap { strs => 101 | (daylight, style) match { 102 | case (false, TimeZone.LONG) => atIndex(strs, 1) 103 | case (false, TimeZone.SHORT) => atIndex(strs, 2) 104 | case (true, TimeZone.LONG) => atIndex(strs, 3) 105 | case (true, TimeZone.SHORT) => atIndex(strs, 4) 106 | case _ => None 107 | } 108 | } 109 | 110 | zoneName.orElse { 111 | if (id.startsWith("GMT+") || id.startsWith("GMT-")) Some(id) 112 | else None 113 | }.orNull 114 | } 115 | 116 | def getDisplayName(daylight: Boolean, style: Int): String = 117 | getDisplayName(daylight, style, Locale.getDefault(Locale.Category.DISPLAY)) 118 | 119 | def getDisplayName(locale: Locale): String = 120 | getDisplayName(daylight = false, TimeZone.LONG, locale) 121 | 122 | def getDisplayName: String = 123 | getDisplayName(daylight = false, TimeZone.LONG, Locale.getDefault(Locale.Category.DISPLAY)) 124 | 125 | def toZoneId: ZoneId = ZoneId.of(getID) 126 | 127 | override def clone: AnyRef = { 128 | val cloned = super.clone.asInstanceOf[TimeZone] 129 | cloned.ID = this.ID 130 | cloned 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /core/js/src/main/scala/org/threeten/bp/chrono/ChronologyPlatformHelper.scala: -------------------------------------------------------------------------------- 1 | package org.threeten.bp.chrono 2 | 3 | import java.util.Iterator 4 | import java.util.Collections 5 | 6 | private[chrono] object ChronologyPlatformHelper { 7 | def loadAdditionalChronologies: Iterator[Chronology] = Collections.emptyIterator[Chronology] 8 | } 9 | -------------------------------------------------------------------------------- /core/js/src/main/scala/org/threeten/bp/chrono/HijrahDateConfigurator.scala: -------------------------------------------------------------------------------- 1 | package org.threeten.bp.chrono 2 | 3 | import java.io.IOException 4 | import java.text.ParseException 5 | 6 | object HijrahDateConfigurator { 7 | @throws[IOException] 8 | @throws[ParseException] 9 | private[chrono] def readDeviationConfig(): Unit = { 10 | // The Javascript side doesn't support the deviation configuration 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /core/js/src/main/scala/org/threeten/bp/format/CasePlatformHelper.scala: -------------------------------------------------------------------------------- 1 | package org.threeten.bp.format 2 | 3 | private[format] object CasePlatformHelper { 4 | // Scala.js forwards the call to the native JavaScript API in which toLowerCase is locale-independent. 5 | def toLocaleIndependentLowerCase(string: String): String = string.toLowerCase 6 | } 7 | -------------------------------------------------------------------------------- /core/js/src/main/scala/org/threeten/bp/zone/DefaultTzdbZoneRulesProvider.scala: -------------------------------------------------------------------------------- 1 | package org.threeten.bp.zone 2 | 3 | import org.threeten.bp.ZoneOffset 4 | 5 | /** 6 | * Minimal provider for UTC 7 | */ 8 | final class DefaultTzdbZoneRulesProvider extends ZoneRulesProvider { 9 | 10 | override protected def provideZoneIds: java.util.Set[String] = { 11 | val zones = new java.util.HashSet[String]() 12 | zones.add("UTC") 13 | zones.add("GMT") 14 | zones 15 | } 16 | 17 | override protected def provideRules(regionId: String, forCaching: Boolean): ZoneRules = 18 | ZoneRules.of(ZoneOffset.UTC, 19 | ZoneOffset.UTC, 20 | new java.util.ArrayList(), 21 | new java.util.ArrayList(), 22 | new java.util.ArrayList() 23 | ) 24 | 25 | override protected def provideVersions( 26 | zoneId: String 27 | ): java.util.NavigableMap[String, ZoneRules] = { 28 | val r = new ZoneMap[String, ZoneRules] 29 | // FIXME the version should be provided by the db 30 | r.put("2017c", provideRules("UTC", true)) 31 | r 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /core/js/src/main/scala/org/threeten/bp/zone/ServiceLoaderZoneRulesInitializer.scala: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos 2 | * 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * * Neither the name of JSR-310 nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | package org.threeten.bp.zone 32 | 33 | import org.portablescala.reflect._ 34 | 35 | /** 36 | * Try to load time zone rules from implementations via reflefction 37 | */ 38 | class ServiceLoaderZoneRulesInitializer extends ZoneRulesInitializer { 39 | 40 | override def initializeProviders(): Unit = { 41 | // Load via reflection the tzdb 42 | // find the package name dynamically to support both org.threeten.bp and java.time packages 43 | val packageName = this.getClass.getName.split("\\.").init.mkString(".") 44 | val optClassData = Reflect.lookupInstantiatableClass(s"$packageName.TzdbZoneRulesProvider") 45 | optClassData 46 | .fold(List[ZoneRulesProvider](new DefaultTzdbZoneRulesProvider())) { c => 47 | val instance = c.newInstance().asInstanceOf[ZoneRulesProvider] 48 | List[ZoneRulesProvider](instance) 49 | } 50 | .foreach(provider => ZoneRulesProvider.registerProvider(provider)) 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /core/jvm/src/main/resources/META-INF/services/org.threeten.bp.zone.ZoneRulesProvider: -------------------------------------------------------------------------------- 1 | org.threeten.bp.zone.TzdbZoneRulesProvider 2 | -------------------------------------------------------------------------------- /core/jvm/src/main/resources/org/threeten/bp/TZDB.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cquiroz/scala-java-time/86b8686cf0162a4f4fb1fc07d96d979df01499b6/core/jvm/src/main/resources/org/threeten/bp/TZDB.dat -------------------------------------------------------------------------------- /core/jvm/src/main/resources/org/threeten/bp/format/ChronologyText.properties: -------------------------------------------------------------------------------- 1 | ISO = ISO 2 | ThaiBuddhist = Buddhist Calendar 3 | Minguo = Minguo Calendar 4 | Japanese = Japanese Calendar 5 | Hijrah-umalqura = Islamic Umm al-Qura Calendar 6 | -------------------------------------------------------------------------------- /core/jvm/src/main/scala-2/org/threeten/bp/zone/ServiceLoaderZoneRulesInitializer.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * * Neither the name of JSR-310 nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.threeten.bp.zone 33 | 34 | import org.portablescala.reflect._ 35 | 36 | /** 37 | * Try to load time zone rules from implementations via reflefction 38 | */ 39 | class ServiceLoaderZoneRulesInitializer extends ZoneRulesInitializer { 40 | 41 | override def initializeProviders(): Unit = { 42 | // Load via reflection the tzdb 43 | // find the package name dynamically to support both org.threeten.bp and java.time packages 44 | val packageName = this.getClass.getName.split("\\.").init.mkString(".") 45 | val optClassData = Reflect.lookupInstantiatableClass(s"$packageName.TzdbZoneRulesProvider") 46 | optClassData 47 | .fold(List[ZoneRulesProvider](new DefaultTzdbZoneRulesProvider())) { c => 48 | val instance = c.newInstance().asInstanceOf[ZoneRulesProvider] 49 | List[ZoneRulesProvider](instance) 50 | } 51 | .foreach(provider => ZoneRulesProvider.registerProvider(provider)) 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /core/jvm/src/main/scala-3/org/threeten/bp/zone/ServiceLoaderZoneRulesInitializer.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * * Neither the name of JSR-310 nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.threeten.bp.zone 33 | 34 | /** 35 | * Try to load time zone rules from implementations via reflefction 36 | */ 37 | class ServiceLoaderZoneRulesInitializer extends ZoneRulesInitializer { 38 | 39 | override def initializeProviders(): Unit = {} 40 | } 41 | -------------------------------------------------------------------------------- /core/jvm/src/main/scala/org/threeten/bp/chrono/ChronologyPlatformHelper.scala: -------------------------------------------------------------------------------- 1 | package org.threeten.bp.chrono 2 | 3 | import java.util.Iterator 4 | import java.util.ServiceLoader 5 | 6 | private[chrono] object ChronologyPlatformHelper { 7 | def loadAdditionalChronologies: Iterator[Chronology] = 8 | ServiceLoader.load(classOf[Chronology], classOf[Chronology].getClassLoader).iterator 9 | } 10 | -------------------------------------------------------------------------------- /core/jvm/src/main/scala/org/threeten/bp/chrono/internal/TTBPJapaneseEra.scala: -------------------------------------------------------------------------------- 1 | package org.threeten.bp.chrono.internal 2 | 3 | import org.threeten.bp.chrono.JapaneseEra 4 | import org.threeten.bp.LocalDate 5 | import org.threeten.bp.DateTimeException 6 | import java.util.Arrays 7 | 8 | object TTBPJapaneseEra { 9 | 10 | /** 11 | * Registers an additional instance of {@code JapaneseEra}.

A new Japanese era can begin at 12 | * any time. This method allows one new era to be registered without the need for a new library 13 | * version. If needed, callers should assign the result to a static variable accessible across the 14 | * application. This must be done once, in early startup code.

NOTE: This method does not 15 | * exist in Java SE 8. 16 | * 17 | * @param since 18 | * the date representing the first date of the era, validated not null 19 | * @param name 20 | * the name 21 | * @return 22 | * the { @code JapaneseEra} singleton, not null 23 | * @throws DateTimeException 24 | * if an additional era has already been registered 25 | */ 26 | def registerEra(since: LocalDate, name: String): JapaneseEra = { 27 | val known = JapaneseEra.KNOWN_ERAS.get 28 | if (known.length > 5) 29 | throw new DateTimeException("Only one additional Japanese era can be added") 30 | require(since != null) 31 | require(name != null) 32 | if (!since.isAfter(JapaneseEra.REIWA.since)) 33 | throw new DateTimeException( 34 | "Invalid since date for additional Japanese era, must be after Reiwa" 35 | ) 36 | val era = new JapaneseEra(JapaneseEra.ADDITIONAL_VALUE, since, name) 37 | val newArray = Arrays.copyOf(known, 6) 38 | newArray(5) = era 39 | if (!JapaneseEra.KNOWN_ERAS.compareAndSet(known, newArray)) 40 | throw new DateTimeException("Only one additional Japanese era can be added") 41 | era 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /core/jvm/src/main/scala/org/threeten/bp/format/CasePlatformHelper.scala: -------------------------------------------------------------------------------- 1 | package org.threeten.bp.format 2 | 3 | import java.util.Locale 4 | 5 | private[format] object CasePlatformHelper { 6 | def toLocaleIndependentLowerCase(string: String): String = string.toLowerCase(Locale.ENGLISH) 7 | } 8 | -------------------------------------------------------------------------------- /core/jvm/src/main/scala/org/threeten/bp/zone/DefaultTzdbZoneRulesProvider.scala: -------------------------------------------------------------------------------- 1 | package org.threeten.bp.zone 2 | 3 | import org.threeten.bp.ZoneOffset 4 | 5 | /** 6 | * Minimal provider for UTC 7 | */ 8 | final class DefaultTzdbZoneRulesProvider extends ZoneRulesProvider { 9 | 10 | override protected def provideZoneIds: java.util.Set[String] = { 11 | val zones = new java.util.HashSet[String]() 12 | zones.add("UTC") 13 | zones.add("GMT") 14 | zones 15 | } 16 | 17 | override protected def provideRules(regionId: String, forCaching: Boolean): ZoneRules = 18 | ZoneRules.of(ZoneOffset.UTC, 19 | ZoneOffset.UTC, 20 | new java.util.ArrayList(), 21 | new java.util.ArrayList(), 22 | new java.util.ArrayList() 23 | ) 24 | 25 | override protected def provideVersions( 26 | zoneId: String 27 | ): java.util.NavigableMap[String, ZoneRules] = { 28 | val r = new ZoneMap[String, ZoneRules] 29 | // FIXME the version should be provided by the db 30 | r.put("2017c", provideRules("UTC", true)) 31 | r 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /core/native/src/main/scala/java/util/SimpleTimeZone.scala: -------------------------------------------------------------------------------- 1 | package java.util 2 | 3 | class SimpleTimeZone(rawOffset: Int, var ID: String) extends TimeZone { 4 | override def getRawOffset = rawOffset 5 | /* concrete methods */ 6 | override def getID: String = ID 7 | override def setID(id: String): Unit = ID = id 8 | 9 | } 10 | -------------------------------------------------------------------------------- /core/native/src/main/scala/java/util/TimeZone.scala: -------------------------------------------------------------------------------- 1 | package java.util 2 | 3 | import java.text.DateFormatSymbols 4 | import java.time.{ Instant, ZoneId } 5 | import java.time.zone.ZoneRulesProvider 6 | import scala.collection.JavaConverters._ 7 | 8 | object TimeZone { 9 | final val SHORT = 0 10 | final val LONG = 1 11 | 12 | private var default: TimeZone = 13 | // TODO: implement this functionality, perhaps using https://github.com/scala-native/scala-native/blob/master/posixlib/src/main/scala/scala/scalanative/posix/time.scala 14 | new SimpleTimeZone(0, "UTC") 15 | 16 | def getDefault: TimeZone = default 17 | def setDefault(timeZone: TimeZone): Unit = default = timeZone 18 | 19 | def getTimeZone(timeZone: String): TimeZone = getTimeZone(ZoneId.of(timeZone)) 20 | def getTimeZone(zoneId: ZoneId): TimeZone = { 21 | val rules = zoneId.getRules 22 | val offsetInMillis = rules.getStandardOffset(Instant.now).getTotalSeconds * 1000 23 | new SimpleTimeZone(offsetInMillis, zoneId.getId) 24 | } 25 | 26 | def getAvailableIDs: Array[String] = ZoneRulesProvider.getAvailableZoneIds.asScala.toArray 27 | def getAvailableIDs(offsetMillis: Int): Array[String] = 28 | getAvailableIDs.filter(getTimeZone(_).getRawOffset == offsetMillis) 29 | 30 | } 31 | 32 | @SerialVersionUID(3581463369166924961L) 33 | abstract class TimeZone extends Serializable with Cloneable { 34 | /* values */ 35 | private var ID: String = null 36 | 37 | /* abstract methods */ 38 | // def getOffset(era: Int, year: Int, month: Int, day: Int, dayOfWeek: Int, milliseconds: Int): Int 39 | def getRawOffset: Int 40 | // def inDaylightTime(date: Date): Boolean 41 | // def setRawOffset(offsetMillis: Int): Unit 42 | // def useDaylightTime: Boolean 43 | 44 | /* concrete methods */ 45 | def getID: String = ID 46 | def setID(id: String): Unit = ID = id 47 | 48 | def getDisplayName(daylight: Boolean, style: Int, locale: Locale): String = { 49 | if (style != TimeZone.SHORT && style != TimeZone.LONG) 50 | throw new IllegalArgumentException(s"Illegal timezone style: $style") 51 | 52 | // Safely looks up given index in the array 53 | def atIndex(strs: Array[String], idx: Int): Option[String] = 54 | if (idx >= 0 && idx < strs.length) Option(strs(idx)) 55 | else None 56 | 57 | val id = getID 58 | def currentIdStrings(strs: Array[String]): Boolean = 59 | atIndex(strs, 0).contains(id) 60 | 61 | val zoneStrings = DateFormatSymbols.getInstance(locale).getZoneStrings 62 | val zoneName = zoneStrings.find(currentIdStrings).flatMap { strs => 63 | (daylight, style) match { 64 | case (false, TimeZone.LONG) => atIndex(strs, 1) 65 | case (false, TimeZone.SHORT) => atIndex(strs, 2) 66 | case (true, TimeZone.LONG) => atIndex(strs, 3) 67 | case (true, TimeZone.SHORT) => atIndex(strs, 4) 68 | case _ => None 69 | } 70 | } 71 | 72 | zoneName.orElse { 73 | if (id.startsWith("GMT+") || id.startsWith("GMT-")) Some(id) 74 | else None 75 | }.orNull 76 | } 77 | 78 | def getDisplayName(daylight: Boolean, style: Int): String = 79 | getDisplayName(daylight, style, Locale.getDefault(Locale.Category.DISPLAY)) 80 | 81 | def getDisplayName(locale: Locale): String = 82 | getDisplayName(daylight = false, TimeZone.LONG, locale) 83 | 84 | def getDisplayName: String = 85 | getDisplayName(daylight = false, TimeZone.LONG, Locale.getDefault(Locale.Category.DISPLAY)) 86 | 87 | def toZoneId: ZoneId = ZoneId.of(getID) 88 | 89 | override def clone: AnyRef = { 90 | val cloned = super.clone.asInstanceOf[TimeZone] 91 | cloned.ID = this.ID 92 | cloned 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /core/native/src/main/scala/org/threeten/bp/chrono/ChronologyPlatformHelper.scala: -------------------------------------------------------------------------------- 1 | package org.threeten.bp.chrono 2 | 3 | import java.util.Iterator 4 | import java.util.Collections 5 | 6 | private[chrono] object ChronologyPlatformHelper { 7 | def loadAdditionalChronologies: Iterator[Chronology] = Collections.emptyIterator[Chronology] 8 | } 9 | -------------------------------------------------------------------------------- /core/native/src/main/scala/org/threeten/bp/chrono/HijrahDateConfigurator.scala: -------------------------------------------------------------------------------- 1 | package org.threeten.bp.chrono 2 | 3 | import java.io.IOException 4 | import java.text.ParseException 5 | 6 | object HijrahDateConfigurator { 7 | @throws[IOException] 8 | @throws[ParseException] 9 | private[chrono] def readDeviationConfig(): Unit = { 10 | // The Native side doesn't support the deviation configuration 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /core/native/src/main/scala/org/threeten/bp/format/CasePlatformHelper.scala: -------------------------------------------------------------------------------- 1 | package org.threeten.bp.format 2 | 3 | private[format] object CasePlatformHelper { 4 | // Scala Native forwards the call to the native API in which toLowerCase is locale-independent. 5 | def toLocaleIndependentLowerCase(string: String): String = string.toLowerCase 6 | } 7 | -------------------------------------------------------------------------------- /core/native/src/main/scala/org/threeten/bp/zone/DefaultTzdbZoneRulesProvider.scala: -------------------------------------------------------------------------------- 1 | package org.threeten.bp.zone 2 | 3 | import org.threeten.bp.ZoneOffset 4 | 5 | /** 6 | * Minimal provider for UTC 7 | */ 8 | final class DefaultTzdbZoneRulesProvider extends ZoneRulesProvider { 9 | 10 | override protected def provideZoneIds: java.util.Set[String] = { 11 | val zones = new java.util.HashSet[String]() 12 | zones.add("UTC") 13 | zones.add("GMT") 14 | zones 15 | } 16 | 17 | override protected def provideRules(regionId: String, forCaching: Boolean): ZoneRules = 18 | ZoneRules.of(ZoneOffset.UTC, 19 | ZoneOffset.UTC, 20 | new java.util.ArrayList(), 21 | new java.util.ArrayList(), 22 | new java.util.ArrayList() 23 | ) 24 | 25 | override protected def provideVersions( 26 | zoneId: String 27 | ): java.util.NavigableMap[String, ZoneRules] = { 28 | val r = new ZoneMap[String, ZoneRules] 29 | // FIXME the version should be provided by the db 30 | r.put("2017c", provideRules("UTC", true)) 31 | r 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /core/native/src/main/scala/org/threeten/bp/zone/ServiceLoaderZoneRulesInitializer.scala: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos 2 | * 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * * Neither the name of JSR-310 nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | package org.threeten.bp.zone 32 | 33 | import org.portablescala.reflect._ 34 | 35 | /** 36 | * Try to load time zone rules from implementations via reflefction 37 | */ 38 | class ServiceLoaderZoneRulesInitializer extends ZoneRulesInitializer { 39 | 40 | override def initializeProviders(): Unit = { 41 | // Load via reflection the tzdb 42 | // find the package name dynamically to support both org.threeten.bp and java.time packages 43 | val packageName = this.getClass.getName.split("\\.").init.mkString(".") 44 | val optClassData = Reflect.lookupInstantiatableClass(s"$packageName.TzdbZoneRulesProvider") 45 | optClassData 46 | .fold(List[ZoneRulesProvider](new DefaultTzdbZoneRulesProvider())) { c => 47 | val instance = c.newInstance().asInstanceOf[ZoneRulesProvider] 48 | List[ZoneRulesProvider](instance) 49 | } 50 | .foreach(provider => ZoneRulesProvider.registerProvider(provider)) 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /core/shared/src/main/scala-2/org/threeten/bp/chrono/HijrahEra.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * * Neither the name of JSR-310 nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.threeten.bp.chrono 33 | 34 | import org.threeten.bp.DateTimeException 35 | import org.threeten.bp.temporal.ChronoField 36 | import org.threeten.bp.temporal.ChronoField.ERA 37 | import org.threeten.bp.temporal.TemporalField 38 | import org.threeten.bp.temporal.UnsupportedTemporalTypeException 39 | import org.threeten.bp.temporal.ValueRange 40 | 41 | object HijrahEra { 42 | 43 | /** 44 | * The singleton instance for the era before the current one, 'Before Anno Hegirae', which has the 45 | * value 0. 46 | */ 47 | lazy val BEFORE_AH = new HijrahEra("BEFORE_AH", 0) 48 | 49 | /** The singleton instance for the current era, 'Anno Hegirae', which has the value 1. */ 50 | lazy val AH = new HijrahEra("AH", 1) 51 | 52 | lazy val values: Array[HijrahEra] = Array(BEFORE_AH, AH) 53 | 54 | /** 55 | * Obtains an instance of {@code HijrahEra} from a value. 56 | * 57 | * The current era (from ISO date 622-06-19 onwards) has the value 1 The previous era has the 58 | * value 0. 59 | * 60 | * @param hijrahEra 61 | * the era to represent, from 0 to 1 62 | * @return 63 | * the HijrahEra singleton, never null 64 | * @throws DateTimeException 65 | * if the era is invalid 66 | */ 67 | def of(hijrahEra: Int): HijrahEra = 68 | hijrahEra match { 69 | case 0 => BEFORE_AH 70 | case 1 => AH 71 | case _ => throw new DateTimeException("HijrahEra not valid") 72 | } 73 | 74 | } 75 | 76 | /** 77 | * An era in the Hijrah calendar system. 78 | * 79 | * The Hijrah calendar system has two eras. The date {@code 0001-01-01 (Hijrah)} is {@code 622-06-19 80 | * (ISO)}. 81 | * 82 | * Do not use {@code ordinal()} to obtain the numeric representation of {@code HijrahEra}. Use 83 | * {@code getValue()} instead. 84 | * 85 | *

Specification for implementors

This is an immutable and thread-safe enum. 86 | */ 87 | final class HijrahEra(name: String, ordinal: Int) extends Enum[HijrahEra](name, ordinal) with Era { 88 | 89 | /** 90 | * Gets the era numeric value. 91 | * 92 | * The current era (from ISO date 622-06-19 onwards) has the value 1. The previous era has the 93 | * value 0. 94 | * 95 | * @return 96 | * the era value, from 0 (BEFORE_AH) to 1 (AH) 97 | */ 98 | def getValue: Int = ordinal 99 | 100 | override def range(field: TemporalField): ValueRange = 101 | if (field eq ERA) ValueRange.of(1, 1) 102 | else if (field.isInstanceOf[ChronoField]) 103 | throw new UnsupportedTemporalTypeException(s"Unsupported field: $field") 104 | else field.rangeRefinedBy(this) 105 | 106 | /** 107 | * Returns the proleptic year from this era and year of era. 108 | * 109 | * @param yearOfEra 110 | * the year of Era 111 | * @return 112 | * the computed prolepticYear 113 | */ 114 | private[chrono] def prolepticYear(yearOfEra: Int): Int = 115 | if (this eq HijrahEra.AH) yearOfEra else 1 - yearOfEra 116 | } 117 | -------------------------------------------------------------------------------- /core/shared/src/main/scala-2/org/threeten/bp/chrono/IsoEra.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * * Neither the name of JSR-310 nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.threeten.bp.chrono 33 | 34 | import org.threeten.bp.DateTimeException 35 | 36 | object IsoEra { 37 | 38 | /** 39 | * The singleton instance for the era BCE, 'Before Current Era'. The 'ISO' part of the name 40 | * emphasizes that this differs from the BCE era in the Gregorian calendar system. This has the 41 | * numeric value of {@code 0}. 42 | */ 43 | lazy val BCE = new IsoEra("BCE", 0) 44 | 45 | /** 46 | * The singleton instance for the era CE, 'Current Era'. The 'ISO' part of the name emphasizes 47 | * that this differs from the CE era in the Gregorian calendar system. This has the numeric value 48 | * of {@code 1}. 49 | */ 50 | lazy val CE = new IsoEra("CE", 1) 51 | 52 | lazy val values: Array[IsoEra] = Array(BCE, CE) 53 | 54 | /** 55 | * Obtains an instance of {@code IsoEra} from an {@code int} value. 56 | * 57 | * {@code IsoEra} is an enum representing the ISO eras of BCE/CE. This factory allows the enum to 58 | * be obtained from the {@code int} value. 59 | * 60 | * @param era 61 | * the BCE/CE value to represent, from 0 (BCE) to 1 (CE) 62 | * @return 63 | * the era singleton, not null 64 | * @throws DateTimeException 65 | * if the value is invalid 66 | */ 67 | def of(era: Int): IsoEra = 68 | era match { 69 | case 0 => BCE 70 | case 1 => CE 71 | case _ => throw new DateTimeException(s"Invalid era: $era") 72 | } 73 | } 74 | 75 | /** 76 | * An era in the ISO calendar system. 77 | * 78 | * The ISO-8601 standard does not define eras. A definition has therefore been created with two eras 79 | * - 'Current era' (CE) for years from 0001-01-01 (ISO) and 'Before current era' (BCE) for years 80 | * before that. 81 | * 82 | * Do not use {@code ordinal()} to obtain the numeric representation of {@code IsoEra}. Use 83 | * {@code getValue()} instead. 84 | * 85 | *

Specification for implementors

This is an immutable and thread-safe enum. 86 | */ 87 | final class IsoEra(name: String, ordinal: Int) extends Enum[IsoEra](name, ordinal) with Era { 88 | 89 | /** 90 | * Gets the numeric era {@code int} value. 91 | * 92 | * The era BCE has the value 0, while the era CE has the value 1. 93 | * 94 | * @return 95 | * the era value, from 0 (BCE) to 1 (CE) 96 | */ 97 | def getValue: Int = ordinal 98 | } 99 | -------------------------------------------------------------------------------- /core/shared/src/main/scala-2/org/threeten/bp/chrono/MinguoEra.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * * Neither the name of JSR-310 nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.threeten.bp.chrono 33 | 34 | import org.threeten.bp.DateTimeException 35 | 36 | object MinguoEra { 37 | 38 | /** 39 | * The singleton instance for the era BEFORE_ROC, 'Before Republic of China'. This has the numeric 40 | * value of {@code 0}. 41 | */ 42 | lazy val BEFORE_ROC = new MinguoEra("BEFORE_ROC", 0) 43 | 44 | /** 45 | * The singleton instance for the era ROC, 'Republic of China'. This has the numeric value of 46 | * {@code 1}. 47 | */ 48 | lazy val ROC = new MinguoEra("ROC", 1) 49 | 50 | lazy val values: Array[MinguoEra] = Array(BEFORE_ROC, ROC) 51 | 52 | /** 53 | * Obtains an instance of {@code MinguoEra} from an {@code int} value. 54 | * 55 | * {@code MinguoEra} is an enum representing the Minguo eras of BEFORE_ROC/ROC. This factory 56 | * allows the enum to be obtained from the {@code int} value. 57 | * 58 | * @param era 59 | * the BEFORE_ROC/ROC value to represent, from 0 (BEFORE_ROC) to 1 (ROC) 60 | * @return 61 | * the era singleton, not null 62 | * @throws DateTimeException 63 | * if the value is invalid 64 | */ 65 | def of(era: Int): MinguoEra = 66 | era match { 67 | case 0 => BEFORE_ROC 68 | case 1 => ROC 69 | case _ => throw new DateTimeException(s"Invalid era: $era") 70 | } 71 | 72 | } 73 | 74 | /** 75 | * An era in the Minguo calendar system. 76 | * 77 | * The Minguo calendar system has two eras. The date {@code 0001-01-01 (Minguo)} is equal to {@code 78 | * 1912-01-01 (ISO)}. 79 | * 80 | * Do not use {@code ordinal()} to obtain the numeric representation of {@code MinguoEra}. Use 81 | * {@code getValue()} instead. 82 | * 83 | *

Specification for implementors

This is an immutable and thread-safe enum. 84 | */ 85 | final class MinguoEra(name: String, ordinal: Int) extends Enum[MinguoEra](name, ordinal) with Era { 86 | 87 | /** 88 | * Gets the numeric era {@code int} value. 89 | * 90 | * The era BEFORE_ROC has the value 0, while the era ROC has the value 1. 91 | * 92 | * @return 93 | * the era value, from 0 (BEFORE_ROC) to 1 (ROC) 94 | */ 95 | def getValue: Int = ordinal 96 | 97 | } 98 | -------------------------------------------------------------------------------- /core/shared/src/main/scala-2/org/threeten/bp/chrono/ThaiBuddhistEra.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * * Neither the name of JSR-310 nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.threeten.bp.chrono 33 | 34 | import org.threeten.bp.DateTimeException 35 | 36 | object ThaiBuddhistEra { 37 | 38 | /** 39 | * The singleton instance for the era before the current one, 'Before Buddhist Era', which has the 40 | * value 0. 41 | */ 42 | lazy val BEFORE_BE = new ThaiBuddhistEra("BEFORE_BE", 0) 43 | 44 | /** The singleton instance for the current era, 'Buddhist Era', which has the value 1. */ 45 | lazy val BE = new ThaiBuddhistEra("BE", 1) 46 | 47 | lazy val values: Array[ThaiBuddhistEra] = Array(BEFORE_BE, BE) 48 | 49 | /** 50 | * Obtains an instance of {@code ThaiBuddhistEra} from a value. 51 | * 52 | * The current era (from ISO year -543 onwards) has the value 1 The previous era has the value 0. 53 | * 54 | * @param thaiBuddhistEra 55 | * the era to represent, from 0 to 1 56 | * @return 57 | * the BuddhistEra singleton, never null 58 | * @throws DateTimeException 59 | * if the era is invalid 60 | */ 61 | def of(thaiBuddhistEra: Int): ThaiBuddhistEra = 62 | thaiBuddhistEra match { 63 | case 0 => BEFORE_BE 64 | case 1 => BE 65 | case _ => throw new DateTimeException("Era is not valid for ThaiBuddhistEra") 66 | } 67 | 68 | } 69 | 70 | /** 71 | * An era in the Thai Buddhist calendar system. 72 | * 73 | * The Thai Buddhist calendar system has two eras. 74 | * 75 | * Do not use ordinal() to obtain the numeric representation of a ThaiBuddhistEra instance. Use 76 | * getValue() instead. 77 | * 78 | *

Specification for implementors

This is an immutable and thread-safe enum. 79 | */ 80 | final class ThaiBuddhistEra(name: String, ordinal: Int) 81 | extends Enum[ThaiBuddhistEra](name, ordinal) 82 | with Era { 83 | 84 | /** 85 | * Gets the era numeric value. 86 | * 87 | * The current era (from ISO year -543 onwards) has the value 1 The previous era has the value 0. 88 | * 89 | * @return 90 | * the era value, from 0 (BEFORE_BE) to 1 (BE) 91 | */ 92 | def getValue: Int = ordinal 93 | 94 | } 95 | -------------------------------------------------------------------------------- /core/shared/src/main/scala-2/org/threeten/bp/format/FormatStyle.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * * Neither the name of JSR-310 nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.threeten.bp.format 33 | 34 | /** 35 | * Enumeration of the style of a localized date, time or date-time formatter. 36 | * 37 | * These styles are used when obtaining a date-time style from configuration. See {@link 38 | * DateTimeFormatter} and {@link DateTimeFormatterBuilder} for usage. 39 | * 40 | *

Specification for implementors

This is an immutable and thread-safe enum. 41 | */ 42 | object FormatStyle { 43 | 44 | /** 45 | * Full text style, with the most detail. For example, the format might be 'Tuesday, April 12, 46 | * 1952 AD' or '3:30:42pm PST'. 47 | */ 48 | lazy val FULL = new FormatStyle("FULL", 0) 49 | 50 | /** 51 | * Long text style, with lots of detail. For example, the format might be 'January 12, 1952'. 52 | */ 53 | lazy val LONG = new FormatStyle("LONG", 1) 54 | 55 | /** 56 | * Medium text style, with some detail. For example, the format might be 'Jan 12, 1952'. 57 | */ 58 | lazy val MEDIUM = new FormatStyle("MEDIUM", 2) 59 | 60 | /** 61 | * Short text style, typically numeric. For example, the format might be '12.13.52' or '3:30pm'. 62 | */ 63 | lazy val SHORT = new FormatStyle("SHORT", 3) 64 | } 65 | 66 | final class FormatStyle private (name: String, ordinal: Int) 67 | extends Enum[FormatStyle](name, ordinal) 68 | -------------------------------------------------------------------------------- /core/shared/src/main/scala-2/org/threeten/bp/format/ResolverStyle.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * * Neither the name of JSR-310 nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.threeten.bp.format 33 | 34 | /** 35 | * Enumeration of different ways to resolve dates and times. 36 | * 37 | * Parsing a text string occurs in two phases. Phase 1 is a basic text parse according to the fields 38 | * added to the builder. Phase 2 resolves the parsed field-value pairs into date and/or time 39 | * objects. This style is used to control how phase 2, resolving, happens. 40 | * 41 | *

Specification for implementors

This is an immutable and thread-safe enum. 42 | */ 43 | object ResolverStyle { 44 | 45 | /** 46 | * Style to resolve dates and times strictly. 47 | * 48 | * Using strict resolution will ensure that all parsed values are within the outer range of valid 49 | * values for the field. Individual fields may be further processed for strictness. 50 | * 51 | * For example, resolving year-month and day-of-month in the ISO calendar system using strict mode 52 | * will ensure that the day-of-month is valid for the year-month, rejecting invalid values. 53 | */ 54 | lazy val STRICT = new ResolverStyle("STRICT", 0) 55 | 56 | /** 57 | * Style to resolve dates and times in a smart, or intelligent, manner. 58 | * 59 | * Using smart resolution will perform the sensible default for each field, which may be the same 60 | * as strict, the same as lenient, or a third behavior. Individual fields will interpret this 61 | * differently. 62 | * 63 | * For example, resolving year-month and day-of-month in the ISO calendar system using smart mode 64 | * will ensure that the day-of-month is from 1 to 31, converting any value beyond the last valid 65 | * day-of-month to be the last valid day-of-month. 66 | */ 67 | lazy val SMART = new ResolverStyle("SMART", 1) 68 | 69 | /** 70 | * Style to resolve dates and times leniently. 71 | * 72 | * Using lenient resolution will resolve the values in an appropriate lenient manner. Individual 73 | * fields will interpret this differently. 74 | * 75 | * For example, lenient mode allows the month in the ISO calendar system to be outside the range 1 76 | * to 12. For example, month 15 is treated as being 3 months after month 12. 77 | */ 78 | lazy val LENIENT = new ResolverStyle("LENIENT", 2) 79 | } 80 | 81 | final class ResolverStyle(name: String, ordinal: Int) extends Enum[ResolverStyle](name, ordinal) 82 | -------------------------------------------------------------------------------- /core/shared/src/main/scala-2/org/threeten/bp/format/SignStyle.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * * Neither the name of JSR-310 nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.threeten.bp.format 33 | 34 | /** 35 | * Enumeration of ways to handle the positive/negative sign. 36 | * 37 | * The formatting engine allows the positive and negative signs of numbers to be controlled using 38 | * this enum. See {@link DateTimeFormatterBuilder} for usage. 39 | * 40 | *

Specification for implementors

This is an immutable and thread-safe enum. 41 | */ 42 | object SignStyle { 43 | 44 | /** 45 | * Style to output the sign only if the value is negative. 46 | * 47 | * In strict parsing, the negative sign will be accepted and the positive sign rejected. In 48 | * lenient parsing, any sign will be accepted. 49 | */ 50 | lazy val NORMAL = new SignStyle("NORMAL", 0) 51 | 52 | /** 53 | * Style to always output the sign, where zero will output '+'. 54 | * 55 | * In strict parsing, the absence of a sign will be rejected. In lenient parsing, any sign will be 56 | * accepted, with the absence of a sign treated as a positive number. 57 | */ 58 | lazy val ALWAYS = new SignStyle("ALWAYS", 1) 59 | 60 | /** 61 | * Style to never output sign, only outputting the absolute value. 62 | * 63 | * In strict parsing, any sign will be rejected. In lenient parsing, any sign will be accepted 64 | * unless the width is fixed. 65 | */ 66 | lazy val NEVER = new SignStyle("NEVER", 2) 67 | 68 | /** 69 | * Style to block negative values, throwing an exception on printing. 70 | * 71 | * In strict parsing, any sign will be rejected. In lenient parsing, any sign will be accepted 72 | * unless the width is fixed. 73 | */ 74 | lazy val NOT_NEGATIVE = new SignStyle("NOT_NEGATIVE", 3) 75 | 76 | /** 77 | * Style to always output the sign if the value exceeds the pad width. A negative value will 78 | * always output the '-' sign. 79 | * 80 | * In strict parsing, the sign will be rejected unless the pad width is exceeded. In lenient 81 | * parsing, any sign will be accepted, with the absence of a sign treated as a positive number. 82 | */ 83 | lazy val EXCEEDS_PAD = new SignStyle("EXCEEDS_PAD", 4) 84 | } 85 | 86 | final class SignStyle(name: String, ordinal: Int) extends Enum[SignStyle](name, ordinal) { 87 | 88 | /** 89 | * Parse helper. 90 | * 91 | * @param positive 92 | * true if positive sign parsed, false for negative sign 93 | * @param strict 94 | * true if strict, false if lenient 95 | * @param fixedWidth 96 | * true if fixed width, false if not 97 | * @return 98 | * true if valid 99 | */ 100 | private[format] def parse(positive: Boolean, strict: Boolean, fixedWidth: Boolean): Boolean = 101 | ordinal match { 102 | case 0 => 103 | !positive || !strict 104 | case 1 | 4 => 105 | true 106 | case _ => 107 | !strict && !fixedWidth 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /core/shared/src/main/scala-2/org/threeten/bp/format/TextStyle.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * * Neither the name of JSR-310 nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.threeten.bp.format 33 | 34 | /** 35 | * Enumeration of the style of text formatting and parsing. 36 | * 37 | * Text styles define three sizes for the formatted text - 'full', 'short' and 'narrow'. Each of 38 | * these three sizes is available in both 'standard' and 'stand-alone' variations. 39 | * 40 | * The difference between the three sizes is obvious in most languages. For example, in English the 41 | * 'full' month is 'January', the 'short' month is 'Jan' and the 'narrow' month is 'J'. Note that 42 | * the narrow size is often not unique. For example, 'January', 'June' and 'July' all have the 43 | * 'narrow' text 'J'. 44 | * 45 | * The difference between the 'standard' and 'stand-alone' forms is trickier to describe as there is 46 | * no difference in English. However, in other languages there is a difference in the word used when 47 | * the text is used alone, as opposed to in a complete date. For example, the word used for a month 48 | * when used alone in a date picker is different to the word used for month in association with a 49 | * day and year in a date. 50 | * 51 | *

Specification for implementors

This is immutable and thread-safe enum. 52 | */ 53 | object TextStyle { 54 | lazy val FULL = new TextStyle("FULL", 0) 55 | lazy val FULL_STANDALONE = new TextStyle("FULL_STANDALONE", 1) 56 | lazy val SHORT = new TextStyle("SHORT", 2) 57 | lazy val SHORT_STANDALONE = new TextStyle("SHORT_STANDALONE", 3) 58 | lazy val NARROW = new TextStyle("NARROW", 4) 59 | lazy val NARROW_STANDALONE = new TextStyle("NARROW_STANDALONE", 5) 60 | 61 | lazy val values: Array[TextStyle] = 62 | Array(FULL, FULL_STANDALONE, SHORT, SHORT_STANDALONE, NARROW, NARROW_STANDALONE) 63 | } 64 | 65 | final class TextStyle(name: String, ordinal: Int) extends Enum[TextStyle](name, ordinal) { 66 | 67 | /** 68 | * Checks if the style is stand-alone. 69 | * 70 | * @return 71 | * true if the style is stand-alone 72 | */ 73 | def isStandalone: Boolean = (ordinal & 1) == 1 74 | 75 | /** 76 | * Converts the style to the equivalent stand-alone style. 77 | * 78 | * @return 79 | * the matching stand-alone style 80 | */ 81 | def asStandalone: TextStyle = TextStyle.values(ordinal | 1) 82 | 83 | /** 84 | * Converts the style to the equivalent normal style. 85 | * 86 | * @return 87 | * the matching normal style 88 | */ 89 | def asNormal: TextStyle = TextStyle.values(ordinal & ~1) 90 | } 91 | -------------------------------------------------------------------------------- /core/shared/src/main/scala-3/org/threeten/bp/chrono/HijrahEra.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * * Neither the name of JSR-310 nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.threeten.bp.chrono 33 | 34 | import org.threeten.bp.DateTimeException 35 | import org.threeten.bp.temporal.ChronoField 36 | import org.threeten.bp.temporal.ChronoField.ERA 37 | import org.threeten.bp.temporal.TemporalField 38 | import org.threeten.bp.temporal.UnsupportedTemporalTypeException 39 | import org.threeten.bp.temporal.ValueRange 40 | 41 | object HijrahEra { 42 | 43 | /** 44 | * Obtains an instance of {@code HijrahEra} from a value. 45 | * 46 | * The current era (from ISO date 622-06-19 onwards) has the value 1 The previous era has the 47 | * value 0. 48 | * 49 | * @param hijrahEra 50 | * the era to represent, from 0 to 1 51 | * @return 52 | * the HijrahEra singleton, never null 53 | * @throws DateTimeException 54 | * if the era is invalid 55 | */ 56 | def of(hijrahEra: Int): HijrahEra = 57 | hijrahEra match { 58 | case 0 => BEFORE_AH 59 | case 1 => AH 60 | case _ => throw new DateTimeException("HijrahEra not valid") 61 | } 62 | 63 | } 64 | 65 | /** 66 | * An era in the Hijrah calendar system. 67 | * 68 | * The Hijrah calendar system has two eras. The date {@code 0001-01-01 (Hijrah)} is {@code 622-06-19 69 | * (ISO)}. 70 | * 71 | * Do not use {@code ordinal()} to obtain the numeric representation of {@code HijrahEra}. Use 72 | * {@code getValue()} instead. 73 | * 74 | *

Specification for implementors

This is an immutable and thread-safe enum. 75 | */ 76 | enum HijrahEra(name: String, ordinal: Int) extends java.lang.Enum[HijrahEra] with Era { 77 | 78 | /** 79 | * The singleton instance for the era before the current one, 'Before Anno Hegirae', which has the 80 | * value 0. 81 | */ 82 | case BEFORE_AH extends HijrahEra("BEFORE_AH", 0) 83 | 84 | /** The singleton instance for the current era, 'Anno Hegirae', which has the value 1. */ 85 | case AH extends HijrahEra("AH", 1) 86 | 87 | /** 88 | * Gets the era numeric value. 89 | * 90 | * The current era (from ISO date 622-06-19 onwards) has the value 1. The previous era has the 91 | * value 0. 92 | * 93 | * @return 94 | * the era value, from 0 (BEFORE_AH) to 1 (AH) 95 | */ 96 | def getValue: Int = ordinal 97 | 98 | override def range(field: TemporalField): ValueRange = 99 | if (field eq ERA) ValueRange.of(1, 1) 100 | else if (field.isInstanceOf[ChronoField]) 101 | throw new UnsupportedTemporalTypeException(s"Unsupported field: $field") 102 | else field.rangeRefinedBy(this) 103 | 104 | /** 105 | * Returns the proleptic year from this era and year of era. 106 | * 107 | * @param yearOfEra 108 | * the year of Era 109 | * @return 110 | * the computed prolepticYear 111 | */ 112 | private[chrono] def prolepticYear(yearOfEra: Int): Int = 113 | if (this eq HijrahEra.AH) yearOfEra else 1 - yearOfEra 114 | } 115 | -------------------------------------------------------------------------------- /core/shared/src/main/scala-3/org/threeten/bp/chrono/IsoEra.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * * Neither the name of JSR-310 nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.threeten.bp.chrono 33 | 34 | import org.threeten.bp.DateTimeException 35 | 36 | object IsoEra { 37 | 38 | /** 39 | * Obtains an instance of {@code IsoEra} from an {@code int} value. 40 | * 41 | * {@code IsoEra} is an enum representing the ISO eras of BCE/CE. This factory allows the enum to 42 | * be obtained from the {@code int} value. 43 | * 44 | * @param era 45 | * the BCE/CE value to represent, from 0 (BCE) to 1 (CE) 46 | * @return 47 | * the era singleton, not null 48 | * @throws DateTimeException 49 | * if the value is invalid 50 | */ 51 | def of(era: Int): IsoEra = 52 | era match { 53 | case 0 => BCE 54 | case 1 => CE 55 | case _ => throw new DateTimeException(s"Invalid era: $era") 56 | } 57 | } 58 | 59 | /** 60 | * An era in the ISO calendar system. 61 | * 62 | * The ISO-8601 standard does not define eras. A definition has therefore been created with two eras 63 | * \- 'Current era' (CE) for years from 0001-01-01 (ISO) and 'Before current era' (BCE) for years 64 | * before that. 65 | * 66 | * Do not use {@code ordinal()} to obtain the numeric representation of {@code IsoEra}. Use 67 | * {@code getValue()} instead. 68 | * 69 | *

Specification for implementors

This is an immutable and thread-safe enum. 70 | */ 71 | enum IsoEra(name: String, ordinal: Int) extends java.lang.Enum[IsoEra] with Era { 72 | 73 | /** 74 | * The singleton instance for the era BCE, 'Before Current Era'. The 'ISO' part of the name 75 | * emphasizes that this differs from the BCE era in the Gregorian calendar system. This has the 76 | * numeric value of {@code 0}. 77 | */ 78 | case BCE extends IsoEra("BCE", 0) 79 | 80 | /** 81 | * The singleton instance for the era CE, 'Current Era'. The 'ISO' part of the name emphasizes 82 | * that this differs from the CE era in the Gregorian calendar system. This has the numeric value 83 | * of {@code 1}. 84 | */ 85 | case CE extends IsoEra("CE", 1) 86 | 87 | /** 88 | * Gets the numeric era {@code int} value. 89 | * 90 | * The era BCE has the value 0, while the era CE has the value 1. 91 | * 92 | * @return 93 | * the era value, from 0 (BCE) to 1 (CE) 94 | */ 95 | def getValue: Int = ordinal 96 | } 97 | -------------------------------------------------------------------------------- /core/shared/src/main/scala-3/org/threeten/bp/chrono/MinguoEra.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * * Neither the name of JSR-310 nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.threeten.bp.chrono 33 | 34 | import org.threeten.bp.DateTimeException 35 | 36 | object MinguoEra { 37 | 38 | /** 39 | * Obtains an instance of {@code MinguoEra} from an {@code int} value. 40 | * 41 | * {@code MinguoEra} is an enum representing the Minguo eras of BEFORE_ROC/ROC. This factory 42 | * allows the enum to be obtained from the {@code int} value. 43 | * 44 | * @param era 45 | * the BEFORE_ROC/ROC value to represent, from 0 (BEFORE_ROC) to 1 (ROC) 46 | * @return 47 | * the era singleton, not null 48 | * @throws DateTimeException 49 | * if the value is invalid 50 | */ 51 | def of(era: Int): MinguoEra = 52 | era match { 53 | case 0 => BEFORE_ROC 54 | case 1 => ROC 55 | case _ => throw new DateTimeException(s"Invalid era: $era") 56 | } 57 | 58 | } 59 | 60 | /** 61 | * An era in the Minguo calendar system. 62 | * 63 | * The Minguo calendar system has two eras. The date {@code 0001-01-01 (Minguo)} is equal to {@code 64 | * 1912-01-01 (ISO)}. 65 | * 66 | * Do not use {@code ordinal()} to obtain the numeric representation of {@code MinguoEra}. Use 67 | * {@code getValue()} instead. 68 | * 69 | *

Specification for implementors

This is an immutable and thread-safe enum. 70 | */ 71 | enum MinguoEra(name: String, ordinal: Int) extends java.lang.Enum[MinguoEra] with Era { 72 | 73 | /** 74 | * The singleton instance for the era BEFORE_ROC, 'Before Republic of China'. This has the numeric 75 | * value of {@code 0}. 76 | */ 77 | case BEFORE_ROC extends MinguoEra("BEFORE_ROC", 0) 78 | 79 | /** 80 | * The singleton instance for the era ROC, 'Republic of China'. This has the numeric value of 81 | * {@code 1}. 82 | */ 83 | case ROC extends MinguoEra("ROC", 1) 84 | 85 | /** 86 | * Gets the numeric era {@code int} value. 87 | * 88 | * The era BEFORE_ROC has the value 0, while the era ROC has the value 1. 89 | * 90 | * @return 91 | * the era value, from 0 (BEFORE_ROC) to 1 (ROC) 92 | */ 93 | def getValue: Int = ordinal 94 | 95 | } 96 | -------------------------------------------------------------------------------- /core/shared/src/main/scala-3/org/threeten/bp/chrono/ThaiBuddhistEra.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * * Neither the name of JSR-310 nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.threeten.bp.chrono 33 | 34 | import org.threeten.bp.DateTimeException 35 | 36 | object ThaiBuddhistEra { 37 | 38 | /** 39 | * Obtains an instance of {@code ThaiBuddhistEra} from a value. 40 | * 41 | * The current era (from ISO year -543 onwards) has the value 1 The previous era has the value 0. 42 | * 43 | * @param thaiBuddhistEra 44 | * the era to represent, from 0 to 1 45 | * @return 46 | * the BuddhistEra singleton, never null 47 | * @throws DateTimeException 48 | * if the era is invalid 49 | */ 50 | def of(thaiBuddhistEra: Int): ThaiBuddhistEra = 51 | thaiBuddhistEra match { 52 | case 0 => BEFORE_BE 53 | case 1 => BE 54 | case _ => throw new DateTimeException("Era is not valid for ThaiBuddhistEra") 55 | } 56 | 57 | } 58 | 59 | /** 60 | * An era in the Thai Buddhist calendar system. 61 | * 62 | * The Thai Buddhist calendar system has two eras. 63 | * 64 | * Do not use ordinal() to obtain the numeric representation of a ThaiBuddhistEra instance. Use 65 | * getValue() instead. 66 | * 67 | *

Specification for implementors

This is an immutable and thread-safe enum. 68 | */ 69 | enum ThaiBuddhistEra(name: String, ordinal: Int) extends java.lang.Enum[ThaiBuddhistEra] with Era { 70 | 71 | /** 72 | * The singleton instance for the era before the current one, 'Before Buddhist Era', which has the 73 | * value 0. 74 | */ 75 | case BEFORE_BE extends ThaiBuddhistEra("BEFORE_BE", 0) 76 | 77 | /** The singleton instance for the current era, 'Buddhist Era', which has the value 1. */ 78 | case BE extends ThaiBuddhistEra("BE", 1) 79 | 80 | /** 81 | * Gets the era numeric value. 82 | * 83 | * The current era (from ISO year -543 onwards) has the value 1 The previous era has the value 0. 84 | * 85 | * @return 86 | * the era value, from 0 (BEFORE_BE) to 1 (BE) 87 | */ 88 | def getValue: Int = ordinal 89 | 90 | } 91 | -------------------------------------------------------------------------------- /core/shared/src/main/scala-3/org/threeten/bp/format/FormatStyle.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * * Neither the name of JSR-310 nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.threeten.bp.format 33 | 34 | /** 35 | * Enumeration of the style of a localized date, time or date-time formatter. 36 | * 37 | * These styles are used when obtaining a date-time style from configuration. See {@link 38 | * DateTimeFormatter} and {@link DateTimeFormatterBuilder} for usage. 39 | * 40 | *

Specification for implementors

This is an immutable and thread-safe enum. 41 | */ 42 | enum FormatStyle private (name: String, ordinal: Int) extends java.lang.Enum[FormatStyle] { 43 | 44 | /** 45 | * Full text style, with the most detail. For example, the format might be 'Tuesday, April 12, 46 | * 1952 AD' or '3:30:42pm PST'. 47 | */ 48 | case FULL extends FormatStyle("FULL", 0) 49 | 50 | /** 51 | * Long text style, with lots of detail. For example, the format might be 'January 12, 1952'. 52 | */ 53 | case LONG extends FormatStyle("LONG", 1) 54 | 55 | /** 56 | * Medium text style, with some detail. For example, the format might be 'Jan 12, 1952'. 57 | */ 58 | case MEDIUM extends FormatStyle("MEDIUM", 2) 59 | 60 | /** 61 | * Short text style, typically numeric. For example, the format might be '12.13.52' or '3:30pm'. 62 | */ 63 | case SHORT extends FormatStyle("SHORT", 3) 64 | } 65 | -------------------------------------------------------------------------------- /core/shared/src/main/scala-3/org/threeten/bp/format/ResolverStyle.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * * Neither the name of JSR-310 nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.threeten.bp.format 33 | 34 | /** 35 | * Enumeration of different ways to resolve dates and times. 36 | * 37 | * Parsing a text string occurs in two phases. Phase 1 is a basic text parse according to the fields 38 | * added to the builder. Phase 2 resolves the parsed field-value pairs into date and/or time 39 | * objects. This style is used to control how phase 2, resolving, happens. 40 | * 41 | *

Specification for implementors

This is an immutable and thread-safe enum. 42 | */ 43 | enum ResolverStyle(name: String, ordinal: Int) extends java.lang.Enum[ResolverStyle] { 44 | 45 | /** 46 | * Style to resolve dates and times strictly. 47 | * 48 | * Using strict resolution will ensure that all parsed values are within the outer range of valid 49 | * values for the field. Individual fields may be further processed for strictness. 50 | * 51 | * For example, resolving year-month and day-of-month in the ISO calendar system using strict mode 52 | * will ensure that the day-of-month is valid for the year-month, rejecting invalid values. 53 | */ 54 | case STRICT extends ResolverStyle("STRICT", 0) 55 | 56 | /** 57 | * Style to resolve dates and times in a smart, or intelligent, manner. 58 | * 59 | * Using smart resolution will perform the sensible default for each field, which may be the same 60 | * as strict, the same as lenient, or a third behavior. Individual fields will interpret this 61 | * differently. 62 | * 63 | * For example, resolving year-month and day-of-month in the ISO calendar system using smart mode 64 | * will ensure that the day-of-month is from 1 to 31, converting any value beyond the last valid 65 | * day-of-month to be the last valid day-of-month. 66 | */ 67 | case SMART extends ResolverStyle("SMART", 1) 68 | 69 | /** 70 | * Style to resolve dates and times leniently. 71 | * 72 | * Using lenient resolution will resolve the values in an appropriate lenient manner. Individual 73 | * fields will interpret this differently. 74 | * 75 | * For example, lenient mode allows the month in the ISO calendar system to be outside the range 1 76 | * to 12. For example, month 15 is treated as being 3 months after month 12. 77 | */ 78 | case LENIENT extends ResolverStyle("LENIENT", 2) 79 | } 80 | -------------------------------------------------------------------------------- /core/shared/src/main/scala-3/org/threeten/bp/format/SignStyle.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * * Neither the name of JSR-310 nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.threeten.bp.format 33 | 34 | /** 35 | * Enumeration of ways to handle the positive/negative sign. 36 | * 37 | * The formatting engine allows the positive and negative signs of numbers to be controlled using 38 | * this enum. See {@link DateTimeFormatterBuilder} for usage. 39 | * 40 | *

Specification for implementors

This is an immutable and thread-safe enum. 41 | */ 42 | enum SignStyle(name: String, ordinal: Int) extends java.lang.Enum[SignStyle] { 43 | 44 | /** 45 | * Style to output the sign only if the value is negative. 46 | * 47 | * In strict parsing, the negative sign will be accepted and the positive sign rejected. In 48 | * lenient parsing, any sign will be accepted. 49 | */ 50 | case NORMAL extends SignStyle("NORMAL", 0) 51 | 52 | /** 53 | * Style to always output the sign, where zero will output '+'. 54 | * 55 | * In strict parsing, the absence of a sign will be rejected. In lenient parsing, any sign will be 56 | * accepted, with the absence of a sign treated as a positive number. 57 | */ 58 | case ALWAYS extends SignStyle("ALWAYS", 1) 59 | 60 | /** 61 | * Style to never output sign, only outputting the absolute value. 62 | * 63 | * In strict parsing, any sign will be rejected. In lenient parsing, any sign will be accepted 64 | * unless the width is fixed. 65 | */ 66 | case NEVER extends SignStyle("NEVER", 2) 67 | 68 | /** 69 | * Style to block negative values, throwing an exception on printing. 70 | * 71 | * In strict parsing, any sign will be rejected. In lenient parsing, any sign will be accepted 72 | * unless the width is fixed. 73 | */ 74 | case NOT_NEGATIVE extends SignStyle("NOT_NEGATIVE", 3) 75 | 76 | /** 77 | * Style to always output the sign if the value exceeds the pad width. A negative value will 78 | * always output the '-' sign. 79 | * 80 | * In strict parsing, the sign will be rejected unless the pad width is exceeded. In lenient 81 | * parsing, any sign will be accepted, with the absence of a sign treated as a positive number. 82 | */ 83 | case EXCEEDS_PAD extends SignStyle("EXCEEDS_PAD", 4) 84 | 85 | /** 86 | * Parse helper. 87 | * 88 | * @param positive 89 | * true if positive sign parsed, false for negative sign 90 | * @param strict 91 | * true if strict, false if lenient 92 | * @param fixedWidth 93 | * true if fixed width, false if not 94 | * @return 95 | * true if valid 96 | */ 97 | private[format] def parse(positive: Boolean, strict: Boolean, fixedWidth: Boolean): Boolean = 98 | ordinal match { 99 | case 0 => 100 | !positive || !strict 101 | case 1 | 4 => 102 | true 103 | case _ => 104 | !strict && !fixedWidth 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /core/shared/src/main/scala-3/org/threeten/bp/format/TextStyle.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * * Neither the name of JSR-310 nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.threeten.bp.format 33 | 34 | /** 35 | * Enumeration of the style of text formatting and parsing. 36 | * 37 | * Text styles define three sizes for the formatted text - 'full', 'short' and 'narrow'. Each of 38 | * these three sizes is available in both 'standard' and 'stand-alone' variations. 39 | * 40 | * The difference between the three sizes is obvious in most languages. For example, in English the 41 | * 'full' month is 'January', the 'short' month is 'Jan' and the 'narrow' month is 'J'. Note that 42 | * the narrow size is often not unique. For example, 'January', 'June' and 'July' all have the 43 | * 'narrow' text 'J'. 44 | * 45 | * The difference between the 'standard' and 'stand-alone' forms is trickier to describe as there is 46 | * no difference in English. However, in other languages there is a difference in the word used when 47 | * the text is used alone, as opposed to in a complete date. For example, the word used for a month 48 | * when used alone in a date picker is different to the word used for month in association with a 49 | * day and year in a date. 50 | * 51 | *

Specification for implementors

This is immutable and thread-safe enum. 52 | */ 53 | 54 | enum TextStyle(name: String, ordinal: Int) extends java.lang.Enum[TextStyle] { 55 | case FULL extends TextStyle("FULL", 0) 56 | case FULL_STANDALONE extends TextStyle("FULL_STANDALONE", 1) 57 | case SHORT extends TextStyle("SHORT", 2) 58 | case SHORT_STANDALONE extends TextStyle("SHORT_STANDALONE", 3) 59 | case NARROW extends TextStyle("NARROW", 4) 60 | case NARROW_STANDALONE extends TextStyle("NARROW_STANDALONE", 5) 61 | 62 | /** 63 | * Checks if the style is stand-alone. 64 | * 65 | * @return 66 | * true if the style is stand-alone 67 | */ 68 | def isStandalone: Boolean = (ordinal & 1) == 1 69 | 70 | /** 71 | * Converts the style to the equivalent stand-alone style. 72 | * 73 | * @return 74 | * the matching stand-alone style 75 | */ 76 | def asStandalone: TextStyle = TextStyle.values(ordinal | 1) 77 | 78 | /** 79 | * Converts the style to the equivalent normal style. 80 | * 81 | * @return 82 | * the matching normal style 83 | */ 84 | def asNormal: TextStyle = TextStyle.values(ordinal & ~1) 85 | } 86 | -------------------------------------------------------------------------------- /core/shared/src/main/scala/org/threeten/bp/DateTimeException.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * * Neither the name of JSR-310 nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.threeten.bp 33 | 34 | /** 35 | * Exception used to indicate a problem while calculating a date-time. 36 | * 37 | * This exception is used to indicate problems with creating, querying and manipulating date-time 38 | * objects. 39 | * 40 | *

Specification for implementors

This class is intended for use in a single thread. 41 | * 42 | * Constructs a new date-time exception with the specified message and cause. 43 | * 44 | * @param message 45 | * the message to use for this exception, may be null 46 | * @param cause 47 | * the cause of the exception, may be null 48 | */ 49 | @SerialVersionUID(-1632418723876261839L) 50 | class DateTimeException(message: String, cause: Throwable) 51 | extends RuntimeException(message, cause) { 52 | 53 | /** 54 | * Constructs a new date-time exception with the specified message. 55 | * 56 | * @param message 57 | * the message to use for this exception, may be null 58 | */ 59 | def this(message: String) = this(message, null) 60 | 61 | } 62 | -------------------------------------------------------------------------------- /core/shared/src/main/scala/org/threeten/bp/ZoneRegion.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * * Neither the name of JSR-310 nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.threeten.bp 33 | 34 | import java.io.Serializable 35 | import java.util.Objects 36 | import java.util.regex.Pattern 37 | import org.threeten.bp.zone.ZoneRules 38 | import org.threeten.bp.zone.ZoneRulesException 39 | import org.threeten.bp.zone.ZoneRulesProvider 40 | import scala.annotation.meta.field 41 | 42 | private object ZoneRegion { 43 | 44 | /** The regex pattern for region IDs. */ 45 | private lazy val PATTERN: Pattern = Pattern.compile("[A-Za-z][A-Za-z0-9~/._+-]+") 46 | 47 | /** 48 | * Obtains an instance of {@code ZoneId} from an identifier. 49 | * 50 | * @param zoneId 51 | * the time-zone ID, not null 52 | * @param checkAvailable 53 | * whether to check if the zone ID is available 54 | * @return 55 | * the zone ID, not null 56 | * @throws DateTimeException 57 | * if the ID format is invalid 58 | * @throws DateTimeException 59 | * if checking availability and the ID cannot be found 60 | */ 61 | private[bp] def ofId(zoneId: String, checkAvailable: Boolean): ZoneRegion = { 62 | Objects.requireNonNull(zoneId, "zoneId") 63 | if (zoneId.length < 2 || !PATTERN.matcher(zoneId).matches) 64 | throw new DateTimeException(s"Invalid ID for region-based ZoneId, invalid format: $zoneId") 65 | var rules: ZoneRules = null 66 | try rules = ZoneRulesProvider.getRules(zoneId, forCaching = true) 67 | catch { 68 | case ex: ZoneRulesException => 69 | if (zoneId == "GMT0") 70 | rules = ZoneOffset.UTC.getRules 71 | else if (checkAvailable) 72 | throw ex 73 | } 74 | new ZoneRegion(zoneId, rules) 75 | } 76 | 77 | } 78 | 79 | /** 80 | * A geographical region where the same time-zone rules apply. 81 | * 82 | * Time-zone information is categorized as a set of rules defining when and how the offset from 83 | * UTC/Greenwich changes. These rules are accessed using identifiers based on geographical regions, 84 | * such as countries or states. The most common region classification is the Time Zone Database 85 | * (TZDB), which defines regions such as 'Europe/Paris' and 'Asia/Tokyo'. 86 | * 87 | * The region identifier, modeled by this class, is distinct from the underlying rules, modeled by 88 | * {@link ZoneRules}. The rules are defined by governments and change frequently. By contrast, the 89 | * region identifier is well-defined and long-lived. This separation also allows rules to be shared 90 | * between regions if appropriate. 91 | * 92 | *

Specification for implementors

This class is immutable and thread-safe. 93 | * 94 | * @constructor 95 | * @param id 96 | * the time-zone ID, not null 97 | * @param rules 98 | * the rules, null for lazy lookup 99 | */ 100 | final class ZoneRegion private[bp] ( 101 | private val id: String, 102 | @(transient @field) private val rules: ZoneRules 103 | ) extends ZoneId 104 | with Serializable { 105 | 106 | def getId: String = id 107 | 108 | def getRules: ZoneRules = 109 | if (rules != null) rules else ZoneRulesProvider.getRules(id, forCaching = false) 110 | 111 | } 112 | -------------------------------------------------------------------------------- /core/shared/src/main/scala/org/threeten/bp/chrono/AbstractChronology.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * * Neither the name of JSR-310 nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.threeten.bp.chrono 33 | 34 | /** 35 | * An abstract implementation of {@code Chronology}. 36 | * 37 | *

Specification for implementors

This class must be implemented with care to ensure other 38 | * classes operate correctly. All implementations that can be instantiated must be final, immutable 39 | * and thread-safe. Subclasses should be Serializable wherever possible. 40 | */ 41 | abstract class AbstractChronology extends Chronology 42 | -------------------------------------------------------------------------------- /core/shared/src/main/scala/org/threeten/bp/chrono/package.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * * Neither the name of JSR-310 nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.threeten.bp 33 | 34 | /** 35 | * Support for calendar systems other than the default ISO. 36 | * 37 | * The main API is based around the calendar system defined in ISO-8601. This package provides 38 | * support for alternate systems. 39 | * 40 | * The supported calendar systems includes: 41 | * 42 | * -{@linkplain org.threeten.bp.chrono.HijrahChronology Hijrah calendar} 43 | * -{@linkplain org.threeten.bp.chrono.JapaneseChronology Japanese calendar} 44 | * -{@linkplain org.threeten.bp.chrono.MinguoChronology Minguo calendar} 45 | * -{@linkplain org.threeten.bp.chrono.ThaiBuddhistChronology Thai Buddhist calendar} 46 | * 47 | * It is intended that applications use the main API whenever possible, including code to read and 48 | * write from a persistent data store, such as a database, and to send dates and times across a 49 | * network. This package is then used at the user interface level to deal with localized 50 | * input/output. See {@link org.threeten.bp.chrono.ChronoLocalDate ChronoLocalDate} for a full 51 | * discussion of the issues. 52 | * 53 | * ==Example== 54 | * 55 | * This example creates and uses a date in a non-ISO calendar system. 56 | * 57 | *
 // Print the Thai Buddhist date ChronoLocalDate now1 =
58 |  * ThaiBuddhistChronology.INSTANCE.now(); int day = now1.get(ChronoField.DAY_OF_MONTH); int dow =
59 |  * now1.get(ChronoField.DAY_OF_WEEK); int month = now1.get(ChronoField.MONTH_OF_YEAR); int year =
60 |  * now1.get(ChronoField.YEAR); System.out.printf(" Today is %s %s %d-%s-%d%n",
61 |  * now1.getChronology().getId(), dow, day, month, year);
62 |  *
63 |  * // Enumerate the list of available calendars and print today for each Set<String> names =
64 |  * Chronology.getAvailableIds(); for (String name : names) { Chronology<?> chrono =
65 |  * Chronology.of(name); ChronoLocalDate<?> date = chrono.now(); System.out.printf(" %20s:
66 |  * %s%n", chrono.getId(), date.toString()); }
67 |  *
68 |  * // Print today's date and the last day of the year for the Thai Buddhist Calendar.
69 |  * ChronoLocalDate first = now1 .with(ChronoField.DAY_OF_MONTH, 1) .with(ChronoField.MONTH_OF_YEAR,
70 |  * 1); ChronoLocalDate last = first .plus(1, ChronoUnit.YEARS) .minus(1, ChronoUnit.DAYS);
71 |  * System.out.printf(" %s: 1st of year: %s; end of year: %s%n", last.getChronology().getId(), first,
72 |  * last); 
73 | */ 74 | package object chrono 75 | -------------------------------------------------------------------------------- /core/shared/src/main/scala/org/threeten/bp/format/DateTimeFormatStyleProvider.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * * Neither the name of JSR-310 nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.threeten.bp.format 33 | 34 | import java.util.Locale 35 | import org.threeten.bp.chrono.Chronology 36 | 37 | private[format] object DateTimeFormatStyleProvider { 38 | 39 | /** 40 | * Gets the provider. 41 | * 42 | * @return 43 | * the provider, not null 44 | */ 45 | private[format] def getInstance: DateTimeFormatStyleProvider = 46 | new SimpleDateTimeFormatStyleProvider 47 | } 48 | 49 | /** 50 | * The Service Provider Interface (SPI) to be implemented by classes providing date-time formatting 51 | * information. 52 | * 53 | *

Specification for implementors

This interface is a service provider that can be called 54 | * by multiple threads. Implementations must be thread-safe. Implementations should cache the 55 | * returned formatters. 56 | */ 57 | abstract class DateTimeFormatStyleProvider { 58 | 59 | /** 60 | * Gets the available locales. 61 | * 62 | * @return 63 | * the locales 64 | */ 65 | def getAvailableLocales: Array[Locale] = throw new UnsupportedOperationException 66 | 67 | /** 68 | * Gets a localized date, time or date-time formatter. 69 | * 70 | * The formatter will be the most appropriate to use for the date and time style in the locale. 71 | * For example, some locales will use the month name while others will use the number. 72 | * 73 | * @param dateStyle 74 | * the date formatter style to obtain, null to obtain a time formatter 75 | * @param timeStyle 76 | * the time formatter style to obtain, null to obtain a date formatter 77 | * @param chrono 78 | * the chronology to use, not null 79 | * @param locale 80 | * the locale to use, not null 81 | * @return 82 | * the date-time formatter, not null 83 | * @throws IllegalArgumentException 84 | * if both format styles are null 85 | * @throws IllegalArgumentException 86 | * if the locale is not a recognized locale 87 | */ 88 | def getFormatter( 89 | dateStyle: FormatStyle, 90 | timeStyle: FormatStyle, 91 | chrono: Chronology, 92 | locale: Locale 93 | ): DateTimeFormatter 94 | } 95 | -------------------------------------------------------------------------------- /core/shared/src/main/scala/org/threeten/bp/format/DateTimeParseException.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * * Neither the name of JSR-310 nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.threeten.bp.format 33 | 34 | import org.threeten.bp.DateTimeException 35 | 36 | /** 37 | * An exception thrown when an error occurs during parsing. 38 | * 39 | * This exception includes the text being parsed and the error index. 40 | * 41 | *

Specification for implementors

This class is intended for use in a single thread. 42 | * 43 | * Constructs a new exception with the specified message and cause. 44 | * 45 | * @param message 46 | * the message to use for this exception, may be null 47 | * @param parsedData 48 | * the parsed text, should not be null 49 | * @param errorIndex 50 | * the index in the parsed string that was invalid, should be a valid index 51 | * @param cause 52 | * the cause exception, may be null 53 | */ 54 | @SerialVersionUID(4304633501674722597L) 55 | class DateTimeParseException( 56 | message: String, 57 | parsedData: CharSequence, 58 | private val errorIndex: Int, 59 | cause: Throwable 60 | ) extends DateTimeException(message, cause) { 61 | 62 | def this(message: String, parsedData: CharSequence, errorIndex: Int) = 63 | this(message, parsedData, errorIndex, null) 64 | 65 | /** 66 | * The text that was being parsed. 67 | */ 68 | private final val parsedString: String = parsedData.toString 69 | 70 | /** 71 | * Returns the string that was being parsed. 72 | * 73 | * @return 74 | * the string that was being parsed, should not be null. 75 | */ 76 | def getParsedString: String = parsedString 77 | 78 | /** 79 | * Returns the index where the error was found. 80 | * 81 | * @return 82 | * the index in the parsed string that was invalid, should be a valid index 83 | */ 84 | def getErrorIndex: Int = errorIndex 85 | } 86 | -------------------------------------------------------------------------------- /core/shared/src/main/scala/org/threeten/bp/format/SimpleDateTimeFormatStyleProvider.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * * Neither the name of JSR-310 nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.threeten.bp.format 33 | 34 | import java.text.DateFormat 35 | import java.text.SimpleDateFormat 36 | import java.util.Locale 37 | import java.util.HashMap 38 | import java.util.Map 39 | import org.threeten.bp.chrono.Chronology 40 | 41 | private object SimpleDateTimeFormatStyleProvider { 42 | 43 | /** Cache of formatters. */ 44 | private lazy val FORMATTER_CACHE: Map[String, AnyRef] = 45 | new HashMap[String, AnyRef]() 46 | } 47 | 48 | /** 49 | * The Service Provider Implementation to obtain date-time formatters for a style. 50 | * 51 | * This implementation is based on extraction of data from a {@link SimpleDateFormat}. 52 | * 53 | *

Specification for implementors

This class is immutable and thread-safe. 54 | */ 55 | final class SimpleDateTimeFormatStyleProvider extends DateTimeFormatStyleProvider { 56 | override def getAvailableLocales: Array[Locale] = DateFormat.getAvailableLocales 57 | 58 | def getFormatter( 59 | dateStyle: FormatStyle, 60 | timeStyle: FormatStyle, 61 | chrono: Chronology, 62 | locale: Locale 63 | ): DateTimeFormatter = { 64 | if (dateStyle == null && timeStyle == null) 65 | throw new IllegalArgumentException("Date and Time style must not both be null") 66 | val key: String = chrono.getId + '|' + locale.toString + '|' + dateStyle + timeStyle 67 | val cached: AnyRef = SimpleDateTimeFormatStyleProvider.FORMATTER_CACHE.get(key) 68 | if (cached != null) { 69 | if (cached == "") 70 | throw new IllegalArgumentException("Unable to convert DateFormat to DateTimeFormatter") 71 | cached.asInstanceOf[DateTimeFormatter] 72 | } else 73 | (if (dateStyle != null) 74 | if (timeStyle != null) 75 | DateFormat.getDateTimeInstance(convertStyle(dateStyle), convertStyle(timeStyle), locale) 76 | else 77 | DateFormat.getDateInstance(convertStyle(dateStyle), locale) 78 | else 79 | DateFormat.getTimeInstance(convertStyle(timeStyle), locale)) match { 80 | case format: SimpleDateFormat => 81 | val pattern: String = format.toPattern 82 | val formatter: DateTimeFormatter = 83 | new DateTimeFormatterBuilder().appendPattern(pattern).toFormatter(locale) 84 | SimpleDateTimeFormatStyleProvider.FORMATTER_CACHE.put(key, formatter) 85 | formatter 86 | case _ => 87 | SimpleDateTimeFormatStyleProvider.FORMATTER_CACHE.put(key, "") 88 | throw new IllegalArgumentException("Unable to convert DateFormat to DateTimeFormatter") 89 | } 90 | } 91 | 92 | /** 93 | * Converts the enum style to the old format style. 94 | * @param style 95 | * the enum style, not null 96 | * @return 97 | * the int style 98 | */ 99 | private def convertStyle(style: FormatStyle): Int = style.ordinal 100 | } 101 | -------------------------------------------------------------------------------- /core/shared/src/main/scala/org/threeten/bp/format/internal/DateTimePrinterParser.scala: -------------------------------------------------------------------------------- 1 | package org.threeten.bp.format.internal 2 | 3 | import java.lang.StringBuilder 4 | 5 | /** 6 | * Strategy for printing/parsing date-time information. 7 | * 8 | * The printer may print any part, or the whole, of the input date-time object. Typically, a 9 | * complete print is constructed from a number of smaller units, each outputting a single field. 10 | * 11 | * The parser may parse any piece of text from the input, storing the result in the context. 12 | * Typically, each individual parser will just parse one field, such as the day-of-month, storing 13 | * the value in the context. Once the parse is complete, the caller will then convert the context to 14 | * a {@link DateTimeBuilder} to merge the parsed values to create the desired object, such as a 15 | * {@code LocalDate}. 16 | * 17 | * The parse position will be updated during the parse. Parsing will start at the specified index 18 | * and the return value specifies the new parse position for the next parser. If an error occurs, 19 | * the returned index will be negative and will have the error position encoded using the complement 20 | * operator. 21 | * 22 | *

Specification for implementors

This interface must be implemented with care to ensure 23 | * other classes operate correctly. All implementations that can be instantiated must be final, 24 | * immutable and thread-safe. 25 | * 26 | * The context is not a thread-safe object and a new instance will be created for each print that 27 | * occurs. The context must not be stored in an instance variable or shared with any other threads. 28 | */ 29 | private[format] trait DateTimePrinterParser { 30 | 31 | /** 32 | * Prints the date-time object to the buffer. 33 | * 34 | * The context holds information to use during the print. It also contains the date-time 35 | * information to be printed. 36 | * 37 | * The buffer must not be mutated beyond the content controlled by the implementation. 38 | * 39 | * @param context 40 | * the context to print using, not null 41 | * @param buf 42 | * the buffer to append to, not null 43 | * @return 44 | * false if unable to query the value from the date-time, true otherwise 45 | * @throws DateTimeException 46 | * if the date-time cannot be printed successfully 47 | */ 48 | def print(context: TTBPDateTimePrintContext, buf: StringBuilder): Boolean 49 | 50 | /** 51 | * Parses text into date-time information. 52 | * 53 | * The context holds information to use during the parse. It is also used to store the parsed 54 | * date-time information. 55 | * 56 | * @param context 57 | * the context to use and parse into, not null 58 | * @param text 59 | * the input text to parse, not null 60 | * @param position 61 | * the position to start parsing at, from 0 to the text length 62 | * @return 63 | * the new parse position, where negative means an error with the error position encoded using 64 | * the complement ~ operator 65 | * @throws NullPointerException 66 | * if the context or text is null 67 | * @throws IndexOutOfBoundsException 68 | * if the position is invalid 69 | */ 70 | def parse(context: TTBPDateTimeParseContext, text: CharSequence, position: Int): Int 71 | } 72 | -------------------------------------------------------------------------------- /core/shared/src/main/scala/org/threeten/bp/format/internal/TTBPDateTimeTextProvider.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * * Neither the name of JSR-310 nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.threeten.bp.format.internal 33 | 34 | import java.util.Locale 35 | import org.threeten.bp.temporal.TemporalField 36 | import org.threeten.bp.format.TextStyle 37 | 38 | private[format] object TTBPDateTimeTextProvider { 39 | lazy val Provider: TTBPDateTimeTextProvider = new TTBPSimpleDateTimeTextProvider() 40 | } 41 | 42 | /** 43 | * The Service Provider Interface (SPI) to be implemented by classes providing the textual form of a 44 | * date-time field. 45 | * 46 | *

Specification for implementors

This interface is a service provider that can be called 47 | * by multiple threads. Implementations must be thread-safe. Implementations should cache the 48 | * textual information.

This class has been made pubilc primarily for the benefit of Android. 49 | */ 50 | abstract class TTBPDateTimeTextProvider { 51 | 52 | /** 53 | * Gets the text for the specified field, locale and style for the purpose of printing. 54 | * 55 | * The text associated with the value is returned. The null return value should be used if there 56 | * is no applicable text, or if the text would be a numeric representation of the value. 57 | * 58 | * @param field 59 | * the field to get text for, not null 60 | * @param value 61 | * the field value to get text for, not null 62 | * @param style 63 | * the style to get text for, not null 64 | * @param locale 65 | * the locale to get text for, not null 66 | * @return 67 | * the text for the field value, null if no text found 68 | */ 69 | def getText(field: TemporalField, value: Long, style: TextStyle, locale: Locale): String 70 | 71 | /** 72 | * Gets an iterator of text to field for the specified field, locale and style for the purpose of 73 | * parsing. 74 | * 75 | * The iterator must be returned in order from the longest text to the shortest. 76 | * 77 | * The null return value should be used if there is no applicable parsable text, or if the text 78 | * would be a numeric representation of the value. Text can only be parsed if all the values for 79 | * that field-style-locale combination are unique. 80 | * 81 | * @param field 82 | * the field to get text for, not null 83 | * @param style 84 | * the style to get text for, null for all parsable text 85 | * @param locale 86 | * the locale to get text for, not null 87 | * @return 88 | * the iterator of text to field pairs, in order from longest text to shortest text, null if the 89 | * field or style is not parsable 90 | */ 91 | def getTextIterator( 92 | field: TemporalField, 93 | style: TextStyle, 94 | locale: Locale 95 | ): Iterator[(String, Long)] 96 | } 97 | -------------------------------------------------------------------------------- /core/shared/src/main/scala/org/threeten/bp/format/package.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * * Neither the name of JSR-310 nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.threeten.bp 33 | 34 | /** 35 | * Provides classes to print and parse dates and times. 36 | * 37 | * Printing and parsing is based around the {@link org.threeten.bp.format.DateTimeFormatter 38 | * DateTimeFormatter} class. That class contains common formatters and factory methods. The {@link 39 | * org.threeten.bp.format.DateTimeFormatterBuilder DateTimeFormatterBuilder} class is available for 40 | * advanced and complex use cases. 41 | * 42 | * Localization occurs by calling {@link 43 | * org.threeten.bp.format.DateTimeFormatter#withLocale(java.util.Locale) withLocale(Locale)} on the 44 | * formatter. Further customization is possible using {@link org.threeten.bp.format.DecimalStyle 45 | * DecimalStyle}. 46 | */ 47 | package object format 48 | -------------------------------------------------------------------------------- /core/shared/src/main/scala/org/threeten/bp/temporal/UnsupportedTemporalTypeException.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * * Neither the name of JSR-310 nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.threeten.bp.temporal 33 | 34 | import org.threeten.bp.DateTimeException 35 | 36 | /** 37 | * An exception that indicates a type is unsupported. 38 | * 39 | *

Specification for implementors

This class is intended for use in a single thread. 40 | * 41 | * Constructs a new date-time exception with the specified message and cause. 42 | * 43 | * @param message 44 | * the message to use for this exception, may be null 45 | * @param cause 46 | * the cause of the exception, may be null 47 | */ 48 | class UnsupportedTemporalTypeException(message: String, cause: Throwable) 49 | extends DateTimeException(message, cause) { 50 | 51 | /** 52 | * Constructs a new date-time exception with the specified message. 53 | * 54 | * @param message 55 | * the message to use for this exception, may be null 56 | */ 57 | def this(message: String) = this(message, null) 58 | 59 | } 60 | -------------------------------------------------------------------------------- /core/shared/src/main/scala/org/threeten/bp/zone/ZoneRulesException.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * * Neither the name of JSR-310 nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.threeten.bp.zone 33 | 34 | import org.threeten.bp.DateTimeException 35 | 36 | /** 37 | * Thrown to indicate a problem with time-zone configuration. 38 | * 39 | * This exception is used to indicate a problems with the configured time-zone rules. 40 | * 41 | *

Specification for implementors

This class is intended for use in a single thread. 42 | * 43 | * Constructs a new date-time exception with the specified message and cause. 44 | * 45 | * @param message 46 | * the message to use for this exception, may be null 47 | * @param cause 48 | * the cause of the exception, may be null 49 | */ 50 | @SerialVersionUID(-1632418723876261839L) 51 | class ZoneRulesException(message: String, cause: Throwable) 52 | extends DateTimeException(message, cause) { 53 | 54 | /** 55 | * Constructs a new date-time exception with the specified message. 56 | * 57 | * @param message 58 | * the message to use for this exception, may be null 59 | */ 60 | def this(message: String) = this(message, null) 61 | } 62 | -------------------------------------------------------------------------------- /core/shared/src/main/scala/org/threeten/bp/zone/package.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * * Neither the name of JSR-310 nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.threeten.bp 33 | 34 | /** 35 | * Support for time-zones and their rules. 36 | * 37 | * Daylight Saving Time and Time-Zones are concepts used by Governments to alter local time. This 38 | * package provides support for time-zones, their rules and the resulting gaps and overlaps in the 39 | * local time-line typically caused by Daylight Saving Time. 40 | */ 41 | package object zone 42 | -------------------------------------------------------------------------------- /core/shared/src/site/markdown/index.md: -------------------------------------------------------------------------------- 1 | ## About 2 | 3 | **ThreeTen-Backport** provides a backport of the 4 | [Java SE 8](https://docs.oracle.com/javase/8/docs/api/java/time/package-summary.html) date-time classes to Java SE 6 and 7. 5 | 6 | The backport is NOT an implementation of JSR-310, as that would require 7 | jumping through lots of unnecessary hoops. 8 | Instead, this is a simple backport intended to allow users to quickly 9 | use the JSR-310 API on Java SE 6 and 7. 10 | The backport should be referred to using the "ThreeTen" name. 11 | The backport is curated by the primary author of the Java 8 date and time library, [Stephen Colebourne](http://www.joda.org/). 12 | 13 | ThreeTen-Backport is licensed under the business-friendly [BSD 3-clause license](license.html). 14 | 15 | 16 | ## Features 17 | 18 | The features of the backport match those of Java SE 8: 19 | 20 | * Date and time value types 21 | * Formatting 22 | * Alternate calendar systems 23 | * Utilities 24 | 25 | The API of ThreeTen-Extra matches that of Java SE 8 as far as practicable. 26 | Default and static methods on interfaces are simulated in the backport 27 | by using an abstract class rather than an interface. 28 | In addition, static query constants are used to simulate method references, for example 29 | use LocalDate.FROM rather than LocalDate::from. 30 | 31 | 32 | ## Documentation 33 | 34 | Various documentation is available: 35 | 36 | * The [Javadoc](apidocs/index.html) 37 | * The [change notes](changes-report.html) for each release 38 | * The [GitHub](https://github.com/ThreeTen/threetenbp) source repository 39 | * The mechanism to [update](update-tzdb.html) the time-zone information 40 | 41 | --- 42 | 43 | ## Releases 44 | 45 | Release 1.3.1 is the latest release. 46 | It is considered to be stable and usable in production. 47 | 48 | The project runs on Java SE 6 (or later) and has no [dependencies](dependencies.html). 49 | 50 | There are some known issues. 51 | The Hijrah calendar system does not work. 52 | Formatting and parsing often depends on data only available in Java SE 8. 53 | Zone id and text parsing is significantly less powerful. 54 | 55 | Available in [Maven Central](http://search.maven.org/#artifactdetails%7Corg.threeten%7Cthreetenbp%7C1.3.1%7Cjar). 56 | 57 | ```xml 58 | 59 | org.threeten 60 | threetenbp 61 | 1.3.1 62 | 63 | ``` 64 | 65 | --- 66 | 67 | ### Support 68 | 69 | Support on bugs, library usage or enhancement requests is available on a best efforts basis. 70 | 71 | To suggest enhancements or contribute, please [fork the source code](https://github.com/ThreeTen/threetenbp) 72 | on GitHub and send a Pull Request. 73 | 74 | Alternatively, use GitHub [issues](https://github.com/ThreeTen/threetenbp/issues). 75 | 76 | Note that pull requests and issues will only be considered so far as matching the behaviour of Java SE 8. 77 | Additional requested features will be rejected. 78 | -------------------------------------------------------------------------------- /core/shared/src/site/markdown/update-tzdb.md: -------------------------------------------------------------------------------- 1 | ## Update tzdb 2 | 3 | ThreeTen-Backport contains a set of time-zone information independent of the JDK. 4 | This can be updated when time-zone rules change. 5 | There are two ways to update the data. 6 | 7 | 8 | ## Build separate tzdb.jar 9 | 10 | The first option is to build a standalone tzdb file. 11 | The generated jar file is added to the classpath in addition to the standard threetenbp.jar file. 12 | 13 | 1. Clone the [source repository](https://github.com/ThreeTen/threetenbp) from GitHub 14 | 2. [Download](http://www.iana.org/time-zones) the latest tzdb from IANA 15 | 3. Unpack the files in the tar.gz to the folder `src/tzdb/{tzdb-version}` inside the cloned source 16 | 4. Run the maven command `mvn clean package -Dtzdb-jar` 17 | 5. Add the resulting tzdb-{version}.jar file in the `target` folder to your classpath 18 | (ignore the tadb-all.jar file) 19 | 20 | This is the preferred approach as it separates the tzdb data from released code. 21 | 22 | 23 | ## Rebuild threetenbp.jar 24 | 25 | The second option is to rebuild the main threetenbp.jar file. 26 | The generated jar file will replace the standard threetenbp.jar file. 27 | 28 | 1. Clone the [source repository](https://github.com/ThreeTen/threetenbp) from GitHub 29 | 2. [Download](http://www.iana.org/time-zones) the latest tzdb from IANA 30 | 3. Unpack the files in the tar.gz to the folder `src/tzdb/{tzdb-version}` inside the cloned source 31 | 4. Change the version number in the maven pom to indicate it is your unoffical build 32 | 5. Run the maven command `mvn clean compile` 33 | 6. Run the maven command `mvn package -Dtzdb-update` 34 | 7. Use the resulting threetenbp.jar file in the `target` folder 35 | -------------------------------------------------------------------------------- /core/shared/src/site/resources/css/site.css: -------------------------------------------------------------------------------- 1 | /* Fix broken definition that causes hyperlinks to break */ 2 | h1[id]:before, 3 | h2[id]:before, 4 | h3[id]:before, 5 | h4[id]:before, 6 | h5[id]:before, 7 | h6[id]:before, 8 | a[name]:before { 9 | height:0px; 10 | margin:0px; 11 | } 12 | /* Blacker text */ 13 | body { 14 | color: #222; 15 | } 16 | code, pre { 17 | color: #444; 18 | } 19 | .dropdown-menu>li>a { 20 | color: #666; 21 | } 22 | /* Sidebar had too much padding at the top */ 23 | .well { 24 | padding-top: 6px; 25 | padding-bottom: 36px; 26 | } 27 | /* Font Awesome icons by CSS as markdown class is stripped */ 28 | h2 i { 29 | display: inline-block; 30 | font: normal normal normal 14px/1 FontAwesome; 31 | font-size: inherit; 32 | text-rendering: auto; 33 | -webkit-font-smoothing: antialiased; 34 | -moz-osx-font-smoothing: grayscale; 35 | } 36 | h2#About i:before { 37 | content: "\f015"; 38 | } 39 | h2#Features i:before { 40 | content: "\f0d0"; 41 | } 42 | h2#Documentation i:before { 43 | content: "\f02d"; 44 | } 45 | h2#Releases i:before { 46 | content: "\f02c"; 47 | } 48 | -------------------------------------------------------------------------------- /core/shared/src/site/site.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | UA-1425975-2 6 | 7 | 8 | lt.velykis.maven.skins 9 | reflow-maven-skin 10 | 1.1.1 11 | 12 | 13 | 14 | 15 | false 16 | true 17 | github 18 | false 19 | bootswatch-cosmo 20 | 21 | ThreeTen Backport 22 | index.html 23 | 24 | Documentation|Releases|Development|ThreeTen 25 | 26 | Documentation 27 | Releases 28 | Development 29 | Reports 30 | 31 | 34 | false 35 | false 36 | false 37 | 38 | 39 | 40 | 3 41 | 42 | 43 | 44 | Home 45 | false 46 | 47 | 48 | false 49 | 50 | 51 | false 52 | 53 | 54 | false 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /demo/shared/src/main/scala/demo/DemoApp.scala: -------------------------------------------------------------------------------- 1 | package demo 2 | 3 | import java.time._ 4 | import java.time.zone.ZoneRulesProvider 5 | import java.time.format._ 6 | // import scala.scalajs.js.annotation.JSExportTopLevel 7 | // import java.util.Locale 8 | 9 | // @JSExportTopLevel("DemoApp") 10 | object DemoApp { 11 | def main(args: Array[String]): Unit = { 12 | val fixedClock = Clock.fixed(Instant.ofEpochSecond(1234567890L), ZoneOffset.ofHours(0)) 13 | 14 | val dateClock = LocalDateTime.now(fixedClock) 15 | 16 | val tomorrow = dateClock.plusDays(1) 17 | 18 | val duration = Duration.between(dateClock, tomorrow) 19 | 20 | Instant.now(fixedClock) 21 | Instant.parse("2007-12-03T10:15:30.00Z") 22 | 23 | val period = Period.between(dateClock.toLocalDate, tomorrow.toLocalDate) 24 | assert(period.get(temporal.ChronoUnit.DAYS) == 1L) 25 | 26 | val date1 = LocalDate.of(2001, 1, 31) 27 | val date2 = LocalDate.of(2001, 2, 28) 28 | assert(date1.plusMonths(1) == date2) 29 | val date3 = date1.`with`(temporal.TemporalAdjusters.next(DayOfWeek.SUNDAY)) 30 | val date4 = LocalDate.of(2001, 2, 4) 31 | assert(date3 == date4) 32 | 33 | val offsetTime = OffsetTime.of(dateClock.toLocalTime, ZoneOffset.ofHours(1)) 34 | 35 | println(LocalDateTime.ofInstant(Instant.now, ZoneId.systemDefault).toString()) 36 | println(ZoneRulesProvider.getAvailableZoneIds) 37 | // Locale.setDefault(Locale.forLanguageTag("fi-FI")) 38 | val instant = Instant.ofEpochMilli(0) 39 | val datetime = LocalDateTime.ofInstant(Instant.now, ZoneId.of("Europe/Helsinki")) 40 | val formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss") 41 | val odt = 42 | OffsetDateTime.parse("2011-12-03T10:15:30+01:00", DateTimeFormatter.ISO_OFFSET_DATE_TIME) 43 | val strRepl = odt.format(formatter) 44 | 45 | println(fixedClock) 46 | println(dateClock) 47 | println(tomorrow) 48 | println(duration) 49 | println(period) 50 | println(offsetTime) 51 | println(instant) 52 | println(datetime) 53 | println(strRepl) 54 | println(odt) 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /demo/sizes.md: -------------------------------------------------------------------------------- 1 | demo is used also to measure the size reductions of PRs 2 | 3 | On sbt: 4 | ; clean; fastOptJS; fullOptJS 5 | Command 6 | ls -l demo/target/scala-2.13/*.js | ag opt | awk '{print $5, $6, $7, $8, $9}' 7 | 8 | Baseline commit 2.0.0-RC5 9 | 2510190 Mar 13 10:30 demo/target/scala-2.13/demo-fastopt.js 10 | 500535 Mar 13 10:30 demo/target/scala-2.13/demo-opt.js 11 | 12 | Commit 0759bf0ea98f1d34be251916290deef0ca3b3a46 (Expanded demo) 13 | 2595791 Mar 13 11:48 demo/target/scala-2.13/demo-fastopt.js 14 | 515115 Mar 13 11:48 demo/target/scala-2.13/demo-opt.js 15 | 16 | Commit 293f2dab345e2dbfda025b361723a9abd4b0eaf2 17 | 2567763 Mar 15 19:37 demo/target/scala-2.13/demo-fastopt.js 18 | 508845 Mar 15 19:37 demo/target/scala-2.13/demo-opt.js 19 | 20 | Commit 85e334c196242d284408984853d941b305660dec 21 | 2568217 Apr 16 09:51 demo/target/scala-2.13/demo-fastopt.js 22 | 508853 Apr 16 09:52 demo/target/scala-2.13/demo-opt.js 23 | 24 | # Note the increase when going to scala 2.13.4 25 | Commit 3401b787bea943c8999ea606bb2c835ee3217fd0 26 | 2924794 Dec 16 00:38 demo/target/scala-2.13/demo-fastopt.js 27 | 574642 Dec 16 00:37 demo/target/scala-2.13/demo-opt.js 28 | 29 | -------------------------------------------------------------------------------- /flake.lock: -------------------------------------------------------------------------------- 1 | { 2 | "nodes": { 3 | "devshell": { 4 | "inputs": { 5 | "flake-utils": "flake-utils", 6 | "nixpkgs": "nixpkgs" 7 | }, 8 | "locked": { 9 | "lastModified": 1667210711, 10 | "narHash": "sha256-IoErjXZAkzYWHEpQqwu/DeRNJGFdR7X2OGbkhMqMrpw=", 11 | "owner": "numtide", 12 | "repo": "devshell", 13 | "rev": "96a9dd12b8a447840cc246e17a47b81a4268bba7", 14 | "type": "github" 15 | }, 16 | "original": { 17 | "owner": "numtide", 18 | "repo": "devshell", 19 | "type": "github" 20 | } 21 | }, 22 | "flake-utils": { 23 | "locked": { 24 | "lastModified": 1642700792, 25 | "narHash": "sha256-XqHrk7hFb+zBvRg6Ghl+AZDq03ov6OshJLiSWOoX5es=", 26 | "owner": "numtide", 27 | "repo": "flake-utils", 28 | "rev": "846b2ae0fc4cc943637d3d1def4454213e203cba", 29 | "type": "github" 30 | }, 31 | "original": { 32 | "owner": "numtide", 33 | "repo": "flake-utils", 34 | "type": "github" 35 | } 36 | }, 37 | "flake-utils_2": { 38 | "locked": { 39 | "lastModified": 1667395993, 40 | "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", 41 | "owner": "numtide", 42 | "repo": "flake-utils", 43 | "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", 44 | "type": "github" 45 | }, 46 | "original": { 47 | "owner": "numtide", 48 | "repo": "flake-utils", 49 | "type": "github" 50 | } 51 | }, 52 | "nixpkgs": { 53 | "locked": { 54 | "lastModified": 1643381941, 55 | "narHash": "sha256-pHTwvnN4tTsEKkWlXQ8JMY423epos8wUOhthpwJjtpc=", 56 | "owner": "NixOS", 57 | "repo": "nixpkgs", 58 | "rev": "5efc8ca954272c4376ac929f4c5ffefcc20551d5", 59 | "type": "github" 60 | }, 61 | "original": { 62 | "owner": "NixOS", 63 | "ref": "nixpkgs-unstable", 64 | "repo": "nixpkgs", 65 | "type": "github" 66 | } 67 | }, 68 | "nixpkgs_2": { 69 | "locked": { 70 | "lastModified": 1667639549, 71 | "narHash": "sha256-frqZKSG/933Ctwl9voSZnXDwo8CqddXcjQhnCzwNqaM=", 72 | "owner": "nixos", 73 | "repo": "nixpkgs", 74 | "rev": "cae3751e9f74eea29c573d6c2f14523f41c2821a", 75 | "type": "github" 76 | }, 77 | "original": { 78 | "owner": "nixos", 79 | "ref": "nixpkgs-unstable", 80 | "repo": "nixpkgs", 81 | "type": "github" 82 | } 83 | }, 84 | "root": { 85 | "inputs": { 86 | "flake-utils": [ 87 | "typelevel-nix", 88 | "flake-utils" 89 | ], 90 | "nixpkgs": [ 91 | "typelevel-nix", 92 | "nixpkgs" 93 | ], 94 | "typelevel-nix": "typelevel-nix" 95 | } 96 | }, 97 | "typelevel-nix": { 98 | "inputs": { 99 | "devshell": "devshell", 100 | "flake-utils": "flake-utils_2", 101 | "nixpkgs": "nixpkgs_2" 102 | }, 103 | "locked": { 104 | "lastModified": 1667839487, 105 | "narHash": "sha256-pSf4jrLeGmoeSTDi55T7w3C+DbVJhAmfoFJiWJ6VNcs=", 106 | "owner": "typelevel", 107 | "repo": "typelevel-nix", 108 | "rev": "322901710808b2703bd972a4ac6d11444b28a5c4", 109 | "type": "github" 110 | }, 111 | "original": { 112 | "owner": "typelevel", 113 | "repo": "typelevel-nix", 114 | "type": "github" 115 | } 116 | } 117 | }, 118 | "root": "root", 119 | "version": 7 120 | } 121 | -------------------------------------------------------------------------------- /flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | inputs = { 3 | typelevel-nix.url = "github:typelevel/typelevel-nix"; 4 | nixpkgs.follows = "typelevel-nix/nixpkgs"; 5 | flake-utils.follows = "typelevel-nix/flake-utils"; 6 | }; 7 | 8 | outputs = { self, nixpkgs, flake-utils, typelevel-nix }: 9 | flake-utils.lib.eachDefaultSystem (system: 10 | let 11 | pkgs-x86_64 = import nixpkgs { system = "x86_64-darwin"; }; 12 | scala-cli-overlay = final: prev: { scala-cli = pkgs-x86_64.scala-cli; }; 13 | pkgs = import nixpkgs { 14 | inherit system; 15 | overlays = [ typelevel-nix.overlay scala-cli-overlay ]; 16 | }; 17 | in { 18 | devShell = pkgs.devshell.mkShell { 19 | imports = [ typelevel-nix.typelevelShell ]; 20 | packages = [ 21 | pkgs.nodePackages.vscode-langservers-extracted 22 | ]; 23 | typelevelShell = { 24 | nodejs.enable = true; 25 | jdk.package = pkgs.jdk17; 26 | }; 27 | }; 28 | } 29 | 30 | ); 31 | } 32 | -------------------------------------------------------------------------------- /project/build.properties: -------------------------------------------------------------------------------- 1 | sbt.version=1.10.0 2 | -------------------------------------------------------------------------------- /project/plugins.sbt: -------------------------------------------------------------------------------- 1 | addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.3.2") 2 | 3 | addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.16.0") 4 | 5 | addSbtPlugin("io.github.cquiroz" % "sbt-tzdb" % "4.2.0") 6 | 7 | addSbtPlugin("org.typelevel" % "sbt-typelevel-ci-release" % "0.7.1") 8 | 9 | addSbtPlugin("org.portable-scala" % "sbt-scala-native-crossproject" % "1.3.2") 10 | 11 | addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.5.3") 12 | -------------------------------------------------------------------------------- /tests/js/src/test/scala/java/util/TestTimeZone.scala: -------------------------------------------------------------------------------- 1 | package java.util 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | import org.threeten.bp.ZoneId 5 | 6 | class TestTimeZone extends AnyFunSuite { 7 | 8 | val sampleTimeZones = Seq("UTC", "GMT", "Europe/Madrid", "Australia/Sydney") 9 | val sampleOffsets = Seq(0, 0, 3600000, 36000000) 10 | val sampleDisplayNames = Seq( 11 | "Coordinated Universal Time", 12 | "Greenwich Mean Time", 13 | "Central European Time", 14 | "Australian Eastern Standard Time (New South Wales)" 15 | ) 16 | 17 | test("default") { 18 | TimeZone.getDefault.getID === "GMT" 19 | } 20 | 21 | test("getTimeZone") { 22 | val zonesWithOffsets = sampleTimeZones.zip(sampleOffsets) 23 | 24 | for ((tzId, offset) <- zonesWithOffsets) { 25 | ZoneId.of(tzId) 26 | val tz = TimeZone.getTimeZone(tzId) 27 | 28 | assert(tz.getID === tzId) 29 | assert(tz.getRawOffset === offset) 30 | // assert(tz.toZoneId === zoneId) 31 | } 32 | } 33 | 34 | test("availableIDs") { 35 | val availableIds = TimeZone.getAvailableIDs 36 | for (tzId <- sampleTimeZones) 37 | assert(availableIds.contains(tzId)) 38 | } 39 | 40 | test("availableIDs by offset") { 41 | val zonesByOffsets = sampleOffsets.zip(sampleTimeZones).groupBy(_._1).mapValues(_.map(_._2)) 42 | for ((offset, ids) <- zonesByOffsets) { 43 | val tzs = TimeZone.getAvailableIDs(offset) 44 | assert(ids.forall(tzs.contains)) 45 | } 46 | } 47 | 48 | ignore("getDisplayName") { 49 | val zonesWithNames = sampleTimeZones.zip(sampleDisplayNames) 50 | for ((id, name) <- zonesWithNames) { 51 | val tz = TimeZone.getTimeZone(id) 52 | assert(tz.getDisplayName(Locale.ENGLISH) === name) 53 | } 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /tests/js/src/test/scala/org/threeten/bp/Platform.scala: -------------------------------------------------------------------------------- 1 | package org.threeten.bp 2 | 3 | import java.util.NavigableMap 4 | import org.threeten.bp.zone.ZoneMap 5 | 6 | object Platform { 7 | type NPE = Throwable 8 | type DFE = Throwable 9 | type CCE = Throwable 10 | 11 | /** 12 | * Returns `true` if and only if the code is executing on a JVM. Note: Returns `false` when 13 | * executing on any JS VM. 14 | */ 15 | final val executingInJVM = true 16 | 17 | def setupLocales(): Unit = {} 18 | 19 | def zoneMap(m: scala.collection.immutable.TreeMap[Int, String]): NavigableMap[Int, String] = 20 | ZoneMap(m) 21 | } 22 | -------------------------------------------------------------------------------- /tests/js/src/test/scala/org/threeten/bp/zone/TestStandardZoneRulesNegativeTZDB.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * * Neither the name of JSR-310 nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.threeten.bp.zone 33 | 34 | import org.scalatest.funsuite.AnyFunSuite 35 | import org.threeten.bp._ 36 | 37 | class TestStandardZoneRulesNegative extends AnyFunSuite with AssertionsHelper { 38 | private def createZDT(year: Int, month: Int, day: Int, zone: ZoneId): ZonedDateTime = 39 | LocalDateTime.of(year, month, day, 0, 0).atZone(zone) 40 | 41 | private def europeDublin: ZoneRules = 42 | ZoneId.of("Europe/Dublin").getRules 43 | 44 | test("Dublin_getStandardOffset") { 45 | val test: ZoneRules = europeDublin 46 | var zdt: ZonedDateTime = createZDT(1840, 1, 1, ZoneOffset.UTC) 47 | while (zdt.getYear < 2010) { 48 | val instant: Instant = zdt.toInstant 49 | if (zdt.getYear < 1881) 50 | assertEquals(test.getStandardOffset(instant), ZoneOffset.ofHoursMinutes(0, -25)) 51 | else if (zdt.getYear >= 1881 && zdt.getYear < 1917) 52 | assertEquals(test.getStandardOffset(instant), ZoneOffset.ofHoursMinutesSeconds(0, -25, -21)) 53 | else if (zdt.getYear >= 1917 && zdt.getYear < 1969) 54 | assertEquals(test.getStandardOffset(instant), 55 | TestStandardZoneRules.OFFSET_ZERO, 56 | zdt.toString() 57 | ) 58 | else 59 | assertEquals(test.getStandardOffset(instant), 60 | TestStandardZoneRules.OFFSET_PONE 61 | ) // negative DST 62 | zdt = zdt.plusMonths(6) 63 | } 64 | } 65 | 66 | test("Dublin_dst") { 67 | val test = europeDublin 68 | assertEquals(test.isDaylightSavings(createZDT(1960, 1, 1, ZoneOffset.UTC).toInstant), false) 69 | assertEquals(test.getDaylightSavings(createZDT(1960, 1, 1, ZoneOffset.UTC).toInstant), 70 | Duration.ofHours(0) 71 | ) 72 | assertEquals(test.isDaylightSavings(createZDT(1960, 7, 1, ZoneOffset.UTC).toInstant), true) 73 | assertEquals(test.getDaylightSavings(createZDT(1960, 7, 1, ZoneOffset.UTC).toInstant), 74 | Duration.ofHours(1) 75 | ) 76 | // negative DST causes isDaylightSavings() to reverse 77 | assertEquals(test.isDaylightSavings(createZDT(2016, 1, 1, ZoneOffset.UTC).toInstant), true) 78 | assertEquals(test.getDaylightSavings(createZDT(2016, 1, 1, ZoneOffset.UTC).toInstant), 79 | Duration.ofHours(-1) 80 | ) 81 | assertEquals(test.isDaylightSavings(createZDT(2016, 7, 1, ZoneOffset.UTC).toInstant), false) 82 | assertEquals(test.getDaylightSavings(createZDT(2016, 7, 1, ZoneOffset.UTC).toInstant), 83 | Duration.ofHours(0) 84 | ) 85 | 86 | // TZDB data is messed up, comment out tests until better fix available 87 | // val formatter1 = new DateTimeFormatterBuilder().appendZoneText(TextStyle.FULL).toFormatter() 88 | // assertEquals(formatter1.format(createZDT(2016, 1, 1, ZoneId.of("Europe/Dublin"))), "Greenwich Mean Time") 89 | // assertEquals(formatter1.format(createZDT(2016, 7, 1, ZoneId.of("Europe/Dublin"))), "Irish Standard Time") 90 | // 91 | // val formatter2 = new DateTimeFormatterBuilder().appendZoneText(TextStyle.SHORT).toFormatter() 92 | // assertEquals(formatter2.format(createZDT(2016, 1, 1, ZoneId.of("Europe/Dublin"))), "GMT") 93 | // assertEquals(formatter2.format(createZDT(2016, 7, 1, ZoneId.of("Europe/Dublin"))), "IST") 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /tests/jvm/src/test/scala/org/threeten/bp/Platform.scala: -------------------------------------------------------------------------------- 1 | package org.threeten.bp 2 | 3 | import java.util.NavigableMap 4 | import java.util.TreeMap 5 | import scala.collection.JavaConverters._ 6 | 7 | object Platform { 8 | type NPE = NullPointerException 9 | type DFE = IndexOutOfBoundsException 10 | type CCE = ClassCastException 11 | 12 | /** 13 | * Returns `true` if and only if the code is executing on a JVM. Note: Returns `false` when 14 | * executing on any JS VM. 15 | */ 16 | final val executingInJVM = false 17 | 18 | def setupLocales(): Unit = () 19 | 20 | def zoneMap(m: scala.collection.immutable.TreeMap[Int, String]): NavigableMap[Int, String] = 21 | new TreeMap(m.asJava) 22 | } 23 | -------------------------------------------------------------------------------- /tests/native/src/test/scala/java/util/TestTimeZone.scala: -------------------------------------------------------------------------------- 1 | package java.util 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | import org.threeten.bp.ZoneId 5 | 6 | class TestTimeZone extends AnyFunSuite { 7 | 8 | val sampleTimeZones = Seq("UTC", "GMT", "Europe/Madrid", "Australia/Sydney") 9 | val sampleOffsets = Seq(0, 0, 3600000, 36000000) 10 | val sampleDisplayNames = Seq( 11 | "Coordinated Universal Time", 12 | "Greenwich Mean Time", 13 | "Central European Time", 14 | "Australian Eastern Standard Time (New South Wales)" 15 | ) 16 | 17 | test("default") { 18 | TimeZone.getDefault.getID === "GMT" 19 | } 20 | 21 | test("getTimeZone") { 22 | val zonesWithOffsets = sampleTimeZones.zip(sampleOffsets) 23 | 24 | for ((tzId, offset) <- zonesWithOffsets) { 25 | ZoneId.of(tzId) 26 | val tz = TimeZone.getTimeZone(tzId) 27 | 28 | assert(tz.getID === tzId) 29 | assert(tz.getRawOffset === offset) 30 | // assert(tz.toZoneId === zoneId) 31 | } 32 | } 33 | 34 | test("availableIDs") { 35 | val availableIds = TimeZone.getAvailableIDs 36 | for (tzId <- sampleTimeZones) 37 | assert(availableIds.contains(tzId)) 38 | } 39 | 40 | test("availableIDs by offset") { 41 | val zonesByOffsets = sampleOffsets.zip(sampleTimeZones).groupBy(_._1).mapValues(_.map(_._2)) 42 | for ((offset, ids) <- zonesByOffsets) { 43 | val tzs = TimeZone.getAvailableIDs(offset) 44 | assert(ids.forall(tzs.contains)) 45 | } 46 | } 47 | 48 | ignore("getDisplayName") { 49 | val zonesWithNames = sampleTimeZones.zip(sampleDisplayNames) 50 | for ((id, name) <- zonesWithNames) { 51 | val tz = TimeZone.getTimeZone(id) 52 | assert(tz.getDisplayName(Locale.ENGLISH) === name) 53 | } 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /tests/native/src/test/scala/org/threeten/bp/Platform.scala: -------------------------------------------------------------------------------- 1 | package org.threeten.bp 2 | 3 | import java.util.NavigableMap 4 | import org.threeten.bp.zone.ZoneMap 5 | 6 | object Platform { 7 | type NPE = NullPointerException 8 | type DFE = IndexOutOfBoundsException 9 | type CCE = ClassCastException 10 | 11 | /** 12 | * Returns `true` if and only if the code is executing on a JVM. Note: Returns `false` when 13 | * executing on any JS VM. 14 | */ 15 | final val executingInJVM = true 16 | 17 | def setupLocales(): Unit = {} 18 | 19 | def zoneMap(m: scala.collection.immutable.TreeMap[Int, String]): NavigableMap[Int, String] = 20 | ZoneMap(m) 21 | } 22 | -------------------------------------------------------------------------------- /tests/native/src/test/scala/org/threeten/bp/zone/TestStandardZoneRulesNegativeTZDB.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * * Neither the name of JSR-310 nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.threeten.bp.zone 33 | 34 | import org.scalatest.funsuite.AnyFunSuite 35 | import org.threeten.bp._ 36 | 37 | class TestStandardZoneRulesNegative extends AnyFunSuite with AssertionsHelper { 38 | private def createZDT(year: Int, month: Int, day: Int, zone: ZoneId): ZonedDateTime = 39 | LocalDateTime.of(year, month, day, 0, 0).atZone(zone) 40 | 41 | private def europeDublin: ZoneRules = 42 | ZoneId.of("Europe/Dublin").getRules 43 | 44 | test("Dublin_getStandardOffset") { 45 | val test: ZoneRules = europeDublin 46 | var zdt: ZonedDateTime = createZDT(1840, 1, 1, ZoneOffset.UTC) 47 | while (zdt.getYear < 2010) { 48 | val instant: Instant = zdt.toInstant 49 | if (zdt.getYear < 1881) 50 | assertEquals(test.getStandardOffset(instant), ZoneOffset.ofHoursMinutes(0, -25)) 51 | else if (zdt.getYear >= 1881 && zdt.getYear < 1917) 52 | assertEquals(test.getStandardOffset(instant), ZoneOffset.ofHoursMinutesSeconds(0, -25, -21)) 53 | else if (zdt.getYear >= 1917 && zdt.getYear < 1969) 54 | assertEquals(test.getStandardOffset(instant), 55 | TestStandardZoneRules.OFFSET_ZERO, 56 | zdt.toString() 57 | ) 58 | else 59 | assertEquals(test.getStandardOffset(instant), 60 | TestStandardZoneRules.OFFSET_PONE 61 | ) // negative DST 62 | zdt = zdt.plusMonths(6) 63 | } 64 | } 65 | 66 | test("Dublin_dst") { 67 | val test = europeDublin 68 | assertEquals(test.isDaylightSavings(createZDT(1960, 1, 1, ZoneOffset.UTC).toInstant), false) 69 | assertEquals(test.getDaylightSavings(createZDT(1960, 1, 1, ZoneOffset.UTC).toInstant), 70 | Duration.ofHours(0) 71 | ) 72 | assertEquals(test.isDaylightSavings(createZDT(1960, 7, 1, ZoneOffset.UTC).toInstant), true) 73 | assertEquals(test.getDaylightSavings(createZDT(1960, 7, 1, ZoneOffset.UTC).toInstant), 74 | Duration.ofHours(1) 75 | ) 76 | // negative DST causes isDaylightSavings() to reverse 77 | assertEquals(test.isDaylightSavings(createZDT(2016, 1, 1, ZoneOffset.UTC).toInstant), true) 78 | assertEquals(test.getDaylightSavings(createZDT(2016, 1, 1, ZoneOffset.UTC).toInstant), 79 | Duration.ofHours(-1) 80 | ) 81 | assertEquals(test.isDaylightSavings(createZDT(2016, 7, 1, ZoneOffset.UTC).toInstant), false) 82 | assertEquals(test.getDaylightSavings(createZDT(2016, 7, 1, ZoneOffset.UTC).toInstant), 83 | Duration.ofHours(0) 84 | ) 85 | 86 | // TZDB data is messed up, comment out tests until better fix available 87 | // val formatter1 = new DateTimeFormatterBuilder().appendZoneText(TextStyle.FULL).toFormatter() 88 | // assertEquals(formatter1.format(createZDT(2016, 1, 1, ZoneId.of("Europe/Dublin"))), "Greenwich Mean Time") 89 | // assertEquals(formatter1.format(createZDT(2016, 7, 1, ZoneId.of("Europe/Dublin"))), "Irish Standard Time") 90 | // 91 | // val formatter2 = new DateTimeFormatterBuilder().appendZoneText(TextStyle.SHORT).toFormatter() 92 | // assertEquals(formatter2.format(createZDT(2016, 1, 1, ZoneId.of("Europe/Dublin"))), "GMT") 93 | // assertEquals(formatter2.format(createZDT(2016, 7, 1, ZoneId.of("Europe/Dublin"))), "IST") 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /tests/shared/src/test/scala-2/org/threeten/bp/temporal/MockFieldNoValue.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * * Neither the name of JSR-310 nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.threeten.bp.temporal 33 | 34 | import java.util.Locale 35 | 36 | import org.threeten.bp.DateTimeException 37 | import org.threeten.bp.format.ResolverStyle 38 | import org.threeten.bp.temporal.ChronoUnit.{ MONTHS, WEEKS } 39 | 40 | /** Mock DateTimeField that returns null. */ 41 | object MockFieldNoValue { 42 | val INSTANCE = new MockFieldNoValue("INSTANCE", 0) 43 | } 44 | 45 | final class MockFieldNoValue(name: String, ordinal: Int) 46 | extends Enum[MockFieldNoValue](name, ordinal) 47 | with TemporalField { 48 | override def toString: String = null 49 | def getBaseUnit: TemporalUnit = WEEKS 50 | def getRangeUnit: TemporalUnit = MONTHS 51 | def range: ValueRange = ValueRange.of(1, 20) 52 | def isDateBased: Boolean = true 53 | def isTimeBased: Boolean = false 54 | def isSupportedBy(dateTime: TemporalAccessor): Boolean = true 55 | def rangeRefinedBy(dateTime: TemporalAccessor): ValueRange = ValueRange.of(1, 20) 56 | def getFrom(dateTime: TemporalAccessor): Long = throw new DateTimeException("Mock") 57 | def adjustInto[R <: Temporal](dateTime: R, newValue: Long): R = 58 | throw new DateTimeException("Mock") 59 | override def getDisplayName(locale: Locale): String = "Mock" 60 | override def resolve( 61 | fieldValues: java.util.Map[TemporalField, java.lang.Long], 62 | partialTemporal: TemporalAccessor, 63 | resolverStyle: ResolverStyle 64 | ): TemporalAccessor = 65 | null 66 | } 67 | -------------------------------------------------------------------------------- /tests/shared/src/test/scala-3/org/threeten/bp/temporal/MockFieldNoValue.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * * Neither the name of JSR-310 nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.threeten.bp.temporal 33 | 34 | import java.util.Locale 35 | 36 | import org.threeten.bp.DateTimeException 37 | import org.threeten.bp.format.ResolverStyle 38 | import org.threeten.bp.temporal.ChronoUnit.{ MONTHS, WEEKS } 39 | 40 | /** Mock DateTimeField that returns null. */ 41 | enum MockFieldNoValue private (name: String, ordinal: Int) 42 | extends Enum[MockFieldNoValue] 43 | with TemporalField { 44 | case INSTANCE extends MockFieldNoValue("INSTANCE", 0) 45 | override def toString: String = null 46 | def getBaseUnit: TemporalUnit = WEEKS 47 | def getRangeUnit: TemporalUnit = MONTHS 48 | def range: ValueRange = ValueRange.of(1, 20) 49 | def isDateBased: Boolean = true 50 | def isTimeBased: Boolean = false 51 | def isSupportedBy(dateTime: TemporalAccessor): Boolean = true 52 | def rangeRefinedBy(dateTime: TemporalAccessor): ValueRange = ValueRange.of(1, 20) 53 | def getFrom(dateTime: TemporalAccessor): Long = throw new DateTimeException("Mock") 54 | def adjustInto[R <: Temporal](dateTime: R, newValue: Long): R = 55 | throw new DateTimeException("Mock") 56 | override def getDisplayName(locale: Locale): String = "Mock" 57 | override def resolve( 58 | fieldValues: java.util.Map[TemporalField, java.lang.Long], 59 | partialTemporal: TemporalAccessor, 60 | resolverStyle: ResolverStyle 61 | ): TemporalAccessor = 62 | null 63 | } 64 | -------------------------------------------------------------------------------- /tests/shared/src/test/scala/org/threeten/bp/AssertionsHelper.scala: -------------------------------------------------------------------------------- 1 | package org.threeten.bp 2 | 3 | import org.scalactic.{ Prettifier, source } 4 | import org.scalatest.Assertion 5 | import org.scalatest.funsuite.AnyFunSuite 6 | 7 | /** 8 | * Helper methods to avoid rewriting much of the TestNG tests 9 | */ 10 | trait AssertionsHelper { this: AnyFunSuite => 11 | def isIsoLeap(year: Long): Boolean = 12 | if (year % 4 != 0) 13 | false 14 | else if (year % 100 == 0 && year % 400 != 0) 15 | false 16 | else 17 | true 18 | 19 | def assertEquals[A, B]( 20 | o1: A, 21 | o2: B, 22 | msg: String 23 | )(implicit prettifier: Prettifier, pos: source.Position): Assertion = 24 | assert(o1 == o2, msg) 25 | 26 | def assertEquals[A, B]( 27 | o1: A, 28 | o2: B 29 | )(implicit prettifier: Prettifier, pos: source.Position): Assertion = 30 | assert(o1 == o2) 31 | 32 | def assertSame[A <: AnyRef, B <: AnyRef]( 33 | o1: A, 34 | o2: B 35 | )(implicit prettifier: Prettifier, pos: source.Position): Assertion = 36 | assert(o1 eq o2) 37 | 38 | def assertNotEquals[A, B]( 39 | o1: A, 40 | o2: B 41 | )(implicit prettifier: Prettifier, pos: source.Position): Assertion = 42 | assert(o1 != o2) 43 | 44 | def assertFalse(b: Boolean)(implicit prettifier: Prettifier, pos: source.Position): Assertion = 45 | assert(!b) 46 | 47 | def assertTrue(b: Boolean)(implicit prettifier: Prettifier, pos: source.Position): Assertion = 48 | assert(b) 49 | 50 | def assertNull[A](a: A)(implicit prettifier: Prettifier, pos: source.Position): Assertion = 51 | assert(a == null) 52 | 53 | def assertNotNull[A]( 54 | a: A, 55 | msg: String 56 | )(implicit prettifier: Prettifier, pos: source.Position): Assertion = 57 | assert(a != null, msg) 58 | 59 | def assertNotNull[A](a: A)(implicit prettifier: Prettifier, pos: source.Position): Assertion = 60 | assert(a != null) 61 | 62 | } 63 | -------------------------------------------------------------------------------- /tests/shared/src/test/scala/org/threeten/bp/MockSimplePeriod.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * * Neither the name of JSR-310 nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.threeten.bp 33 | 34 | import java.util.{ Collections, Objects } 35 | 36 | import org.threeten.bp.temporal.ChronoUnit.{ DAYS, FOREVER, SECONDS } 37 | import org.threeten.bp.temporal.{ Temporal, TemporalAmount, TemporalUnit } 38 | 39 | /** Mock period of time measured using a single unit, such as {@code 3 Days}. */ 40 | object MockSimplePeriod { 41 | 42 | /** A constant for a period of zero, measured in days. */ 43 | val ZERO_DAYS: MockSimplePeriod = new MockSimplePeriod(0, DAYS) 44 | 45 | /** A constant for a period of zero, measured in seconds. */ 46 | val ZERO_SECONDS: MockSimplePeriod = new MockSimplePeriod(0, SECONDS) 47 | 48 | /** 49 | * Obtains a {@code MockSimplePeriod} from an amount and unit.

The parameters represent the 50 | * two parts of a phrase like '6 Days'. 51 | * 52 | * @param amount 53 | * the amount of the period, measured in terms of the unit, positive or negative 54 | * @param unit 55 | * the unit that the period is measured in, must not be the 'Forever' unit, not null 56 | * @return 57 | * the { @code MockSimplePeriod} instance, not null 58 | * @throws DateTimeException 59 | * if the period unit is { @link org.threeten.bp.temporal.ChronoUnit#FOREVER}. 60 | */ 61 | def of(amount: Long, unit: TemporalUnit): MockSimplePeriod = new MockSimplePeriod(amount, unit) 62 | } 63 | 64 | /** 65 | * @param amount 66 | * the amount of the period 67 | * @param unit 68 | * the unit the period is measured in 69 | */ 70 | final class MockSimplePeriod private (private val amount: Long, private val unit: TemporalUnit) 71 | extends TemporalAmount 72 | with Comparable[MockSimplePeriod] { 73 | Objects.requireNonNull(unit, "unit") 74 | if (unit eq FOREVER) 75 | throw new DateTimeException("Cannot create a period of the Forever unit") 76 | 77 | def getUnits: java.util.List[TemporalUnit] = Collections.singletonList(unit) 78 | 79 | def get(unit: TemporalUnit): Long = 80 | if (this.unit == unit) 81 | amount 82 | else 83 | throw new DateTimeException("Unsupported unit: " + unit) 84 | 85 | def getAmount: Long = amount 86 | 87 | def getUnit: TemporalUnit = unit 88 | 89 | def addTo(dateTime: Temporal): Temporal = dateTime.plus(amount, unit) 90 | 91 | def subtractFrom(dateTime: Temporal): Temporal = dateTime.minus(amount, unit) 92 | 93 | def compareTo(otherPeriod: MockSimplePeriod): Int = 94 | if (unit != otherPeriod.getUnit) 95 | throw new IllegalArgumentException( 96 | "Units cannot be compared: " + unit + " and " + otherPeriod.getUnit 97 | ) 98 | else 99 | java.lang.Long.compare(amount, otherPeriod.amount) 100 | 101 | override def equals(obj: Any): Boolean = 102 | obj match { 103 | case other: MockSimplePeriod => 104 | (this eq other) || (this.amount == other.amount && (this.unit == other.unit)) 105 | case _ => false 106 | } 107 | 108 | override def hashCode: Int = unit.hashCode ^ (amount ^ (amount >>> 32)).toInt 109 | 110 | override def toString: String = amount + " " + unit 111 | } 112 | -------------------------------------------------------------------------------- /tests/shared/src/test/scala/org/threeten/bp/TestClock.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-present Stephen Colebourne & Michael Nascimento Santos 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * * Neither the name of JSR-310 nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.threeten.bp 33 | 34 | import org.scalatest.funsuite.AnyFunSuite 35 | 36 | /** Test Clock. */ 37 | object TestClock { 38 | 39 | private[bp] class MockInstantClock private[bp] ( 40 | override val millis: Long, 41 | private[bp] val zone: ZoneId 42 | ) extends Clock { 43 | 44 | def instant: Instant = Instant.ofEpochMilli(millis) 45 | 46 | def getZone: ZoneId = zone 47 | 48 | override def withZone(timeZone: ZoneId): Clock = 49 | new TestClock.MockInstantClock(millis, timeZone) 50 | 51 | override def equals(obj: Any): Boolean = false 52 | 53 | override def hashCode: Int = 0 54 | 55 | override def toString: String = "Mock" 56 | } 57 | 58 | private val INSTANT: Instant = Instant.ofEpochSecond(1873687, 357000000) 59 | private val ZONE: ZoneId = ZoneId.of("Europe/Paris") 60 | private val MOCK_INSTANT: Clock = new TestClock.MockInstantClock(INSTANT.toEpochMilli, ZONE) 61 | } 62 | 63 | class TestClock extends AnyFunSuite with AssertionsHelper { 64 | test("mockInstantClock_get") { 65 | assertEquals(TestClock.MOCK_INSTANT.instant, TestClock.INSTANT) 66 | assertEquals(TestClock.MOCK_INSTANT.millis, TestClock.INSTANT.toEpochMilli) 67 | assertEquals(TestClock.MOCK_INSTANT.getZone, TestClock.ZONE) 68 | } 69 | 70 | test("mockInstantClock_withZone") { 71 | val london: ZoneId = ZoneId.of("Europe/London") 72 | val changed: Clock = TestClock.MOCK_INSTANT.withZone(london) 73 | assertEquals(TestClock.MOCK_INSTANT.instant, TestClock.INSTANT) 74 | assertEquals(TestClock.MOCK_INSTANT.millis, TestClock.INSTANT.toEpochMilli) 75 | assertEquals(changed.getZone, london) 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /tests/shared/src/test/scala/org/threeten/bp/TestExamples.scala: -------------------------------------------------------------------------------- 1 | package org.threeten.bp 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class TestExamples extends AnyFunSuite with AssertionsHelper { 6 | 7 | test("testExamples") { 8 | 9 | // always returns 2009-02-13T23:31:30 10 | val fixedClock = Clock.fixed(Instant.ofEpochSecond(1234567890L), ZoneOffset.ofHours(0)) 11 | 12 | val date = LocalDateTime.now(fixedClock) 13 | 14 | assertEquals(date.getYear, 2009) 15 | assertEquals(date.getMonth, Month.FEBRUARY) 16 | assertEquals(date.getMonthValue, 2) 17 | assertEquals(date.getDayOfWeek, DayOfWeek.FRIDAY) 18 | assertEquals(date.getDayOfMonth, 13) 19 | assertEquals(date.getDayOfYear, 44) 20 | assertEquals(date.getHour, 23) 21 | assertEquals(date.getMinute, 31) 22 | assertEquals(date.getSecond, 30) 23 | 24 | val tomorrow = date.plusDays(1) 25 | 26 | val duration = Duration.between(date, tomorrow) 27 | assertEquals(duration.toMinutes, 1440L) 28 | 29 | Instant.now(fixedClock) 30 | Instant.parse("2007-12-03T10:15:30.00Z") 31 | 32 | val period = Period.between(date.toLocalDate, tomorrow.toLocalDate) 33 | assertEquals(period.get(temporal.ChronoUnit.DAYS), 1L) 34 | 35 | val date1 = LocalDate.of(2001, 1, 31) 36 | val date2 = LocalDate.of(2001, 2, 28) 37 | assertEquals(date1.plusMonths(1), date2) 38 | val date3 = date1.`with`(temporal.TemporalAdjusters.next(DayOfWeek.SUNDAY)) 39 | val date4 = LocalDate.of(2001, 2, 4) 40 | assertEquals(date3, date4) 41 | 42 | val offsetTime = OffsetTime.of(date.toLocalTime, ZoneOffset.ofHours(1)) 43 | assertEquals(offsetTime.getHour, 23) 44 | assertEquals(offsetTime.isBefore(OffsetTime.of(date.toLocalTime, ZoneOffset.ofHours(0))), true) 45 | 46 | val localeUS = java.util.Locale.US 47 | assertEquals(localeUS.getLanguage, "en") 48 | 49 | assertEquals(date.format(format.DateTimeFormatter.BASIC_ISO_DATE), "20090213") 50 | val format1 = format.DateTimeFormatter.ofPattern("MMMM MM d HH mm ss EE EEEE yyyy G[ VV z Z]", 51 | java.util.Locale.GERMAN 52 | ) 53 | assertEquals(date.format(format1), "Februar 02 13 23 31 30 Fr. Freitag 2009 n. Chr.") 54 | 55 | // failes due to non-existent method String#toLowerCase(String, Locale): String 56 | LocalDate.parse("12.11.2010", format.DateTimeFormatter.ofPattern("dd.MM.yyyy")) 57 | 58 | // val japDate = chrono.JapaneseDate.now(fixedClock) 59 | // assertEquals(japDate.toString, "Japanese Heisei 21-02-13") 60 | // 61 | // This tries to read property files from disk 62 | val hijDate = chrono.HijrahDate.now(fixedClock) 63 | assertEquals(hijDate.toString, "Hijrah-umalqura AH 1430-02-17") 64 | 65 | val thaiDate = chrono.ThaiBuddhistDate.now(fixedClock) 66 | assertEquals(thaiDate.toString, "ThaiBuddhist BE 2552-02-13") 67 | 68 | val mingDate = chrono.MinguoDate.now(fixedClock) 69 | assertEquals(mingDate.toString, "Minguo ROC 98-02-13") 70 | 71 | // val format2 = format.DateTimeFormatter.ofPattern("GGGG") 72 | // assertEquals(mingDate.format(format2), "Anno Domini") // WTF? 73 | 74 | ZonedDateTime.now(fixedClock) 75 | // ZonedDateTime.now(ZoneRegion.ofId("Europe/Berlin", true)) 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /tests/shared/src/test/scala/org/threeten/bp/format/GenTestPrinterParser.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * * Neither the name of JSR-310 nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.threeten.bp.format 33 | 34 | import java.util.Locale 35 | import java.lang.StringBuilder 36 | 37 | import org.scalatest.funsuite.AnyFunSuite 38 | import org.scalatest.BeforeAndAfterEach 39 | import org.threeten.bp.LocalDateTime 40 | import org.threeten.bp.ZoneId 41 | import org.threeten.bp.ZonedDateTime 42 | import org.threeten.bp.DateTimeException 43 | import org.threeten.bp.chrono.IsoChronology 44 | import org.threeten.bp.temporal.{ TemporalAccessor, TemporalField, TemporalQuery, ValueRange } 45 | import org.threeten.bp.format.internal.TTBPDateTimeParseContext 46 | import org.threeten.bp.format.internal.TTBPDateTimePrintContext 47 | 48 | /** Abstract PrinterParser test. */ 49 | object GenTestPrinterParser { 50 | private val EMPTY: TemporalAccessor = new TemporalAccessor() { 51 | def isSupported(field: TemporalField): Boolean = true 52 | def getLong(field: TemporalField): Long = throw new DateTimeException("Mock") 53 | override def get(field: TemporalField): Int = 54 | range(field).checkValidIntValue(getLong(field), field) 55 | override def query[R](query: TemporalQuery[R]): R = query.queryFrom(this) 56 | override def range(field: TemporalField): ValueRange = field.range 57 | } 58 | } 59 | 60 | trait GenTestPrinterParser extends BeforeAndAfterEach { this: AnyFunSuite => 61 | protected var printEmptyContext: TTBPDateTimePrintContext = null 62 | protected var printContext: TTBPDateTimePrintContext = null 63 | protected var parseContext: TTBPDateTimeParseContext = null 64 | protected var buf: StringBuilder = null 65 | 66 | override def beforeEach() = { 67 | printEmptyContext = new TTBPDateTimePrintContext(GenTestPrinterParser.EMPTY, 68 | Locale.ENGLISH, 69 | DecimalStyle.STANDARD 70 | ) 71 | val zdt: ZonedDateTime = 72 | LocalDateTime.of(2011, 6, 30, 12, 30, 40, 0).atZone(ZoneId.of("Europe/Paris")) 73 | printContext = new TTBPDateTimePrintContext(zdt, Locale.ENGLISH, DecimalStyle.STANDARD) 74 | parseContext = 75 | new TTBPDateTimeParseContext(Locale.ENGLISH, DecimalStyle.STANDARD, IsoChronology.INSTANCE) 76 | buf = new StringBuilder 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /tests/shared/src/test/scala/org/threeten/bp/format/MockIOExceptionAppendable.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * * Neither the name of JSR-310 nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.threeten.bp.format 33 | 34 | import java.io.IOException 35 | 36 | /** Mock Appendable that throws IOException. */ 37 | class MockIOExceptionAppendable extends Appendable { 38 | def append(csq: CharSequence): Appendable = 39 | throw new IOException 40 | 41 | def append(c: Char): Appendable = 42 | throw new IOException 43 | 44 | def append(csq: CharSequence, start: Int, end: Int): Appendable = 45 | throw new IOException 46 | } 47 | -------------------------------------------------------------------------------- /tests/shared/src/test/scala/org/threeten/bp/format/TestCharLiteralParser.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * * Neither the name of JSR-310 nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.threeten.bp.format 33 | 34 | import org.scalatest.funsuite.AnyFunSuite 35 | import org.threeten.bp.AssertionsHelper 36 | import org.threeten.bp.format.internal.TTBPDateTimeFormatterBuilder._ 37 | import org.threeten.bp.format.internal.DateTimePrinterParser 38 | import org.threeten.bp.temporal.TemporalQueries 39 | 40 | /** Test CharLiteralPrinterParser. */ 41 | class TestCharLiteralParser extends AnyFunSuite with GenTestPrinterParser with AssertionsHelper { 42 | val data_success: List[List[Any]] = 43 | List( 44 | List(new CharLiteralPrinterParser('a'), true, "a", 0, 1), 45 | List(new CharLiteralPrinterParser('a'), true, "aOTHER", 0, 1), 46 | List(new CharLiteralPrinterParser('a'), true, "OTHERaOTHER", 5, 6), 47 | List(new CharLiteralPrinterParser('a'), true, "OTHERa", 5, 6), 48 | List(new CharLiteralPrinterParser('a'), true, "", 0, ~0), 49 | List(new CharLiteralPrinterParser('a'), true, "a", 1, ~1), 50 | List(new CharLiteralPrinterParser('a'), true, "A", 0, ~0), 51 | List(new CharLiteralPrinterParser('a'), true, "b", 0, ~0), 52 | List(new CharLiteralPrinterParser('a'), true, "OTHERbOTHER", 5, ~5), 53 | List(new CharLiteralPrinterParser('a'), true, "OTHERb", 5, ~5), 54 | List(new CharLiteralPrinterParser('a'), false, "a", 0, 1), 55 | List(new CharLiteralPrinterParser('a'), false, "A", 0, 1) 56 | ) 57 | 58 | test("parse_success") { 59 | data_success.foreach { 60 | case (pp: DateTimePrinterParser) :: (caseSensitive: Boolean) :: (text: String) :: (pos: Int) :: (expectedPos: Int) :: Nil => 61 | parseContext.setCaseSensitive(caseSensitive) 62 | val result: Int = pp.parse(parseContext, text, pos) 63 | assertEquals(result, expectedPos) 64 | assertEquals(parseContext.toParsed.query(TemporalQueries.chronology), null) 65 | assertEquals(parseContext.toParsed.query(TemporalQueries.zoneId), null) 66 | case _ => 67 | fail() 68 | } 69 | } 70 | 71 | val data_error: List[List[Any]] = 72 | List[List[Any]]( 73 | List(new CharLiteralPrinterParser('a'), "a", -1, classOf[IndexOutOfBoundsException]), 74 | List(new CharLiteralPrinterParser('a'), "a", 2, classOf[IndexOutOfBoundsException]) 75 | ) 76 | 77 | test("parse_error") { 78 | data_error.foreach { 79 | case (pp: CharLiteralPrinterParser) :: (text: String) :: (pos: Int) :: (expected: Class[ 80 | _ 81 | ]) :: Nil => 82 | try pp.parse(parseContext, text, pos) 83 | catch { 84 | case ex: RuntimeException => 85 | assertTrue(expected.isInstance(ex)) 86 | assertEquals(parseContext.toParsed.query(TemporalQueries.chronology), null) 87 | assertEquals(parseContext.toParsed.query(TemporalQueries.zoneId), null) 88 | } 89 | case _ => 90 | fail() 91 | } 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /tests/shared/src/test/scala/org/threeten/bp/format/TestCharLiteralPrinter.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * * Neither the name of JSR-310 nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.threeten.bp.format 33 | 34 | import org.scalatest.funsuite.AnyFunSuite 35 | import org.threeten.bp.AssertionsHelper 36 | import org.threeten.bp.format.internal.TTBPDateTimeFormatterBuilder 37 | 38 | /** Test CharLiteralPrinterParser. */ 39 | class TestCharLiteralPrinter extends AnyFunSuite with GenTestPrinterParser with AssertionsHelper { 40 | test("print_emptyCalendrical") { 41 | buf.append("EXISTING") 42 | val pp: TTBPDateTimeFormatterBuilder.CharLiteralPrinterParser = 43 | new TTBPDateTimeFormatterBuilder.CharLiteralPrinterParser('a') 44 | pp.print(printEmptyContext, buf) 45 | assertEquals(buf.toString, "EXISTINGa") 46 | } 47 | 48 | test("print_dateTime") { 49 | buf.append("EXISTING") 50 | val pp: TTBPDateTimeFormatterBuilder.CharLiteralPrinterParser = 51 | new TTBPDateTimeFormatterBuilder.CharLiteralPrinterParser('a') 52 | pp.print(printContext, buf) 53 | assertEquals(buf.toString, "EXISTINGa") 54 | } 55 | 56 | test("print_emptyAppendable") { 57 | val pp: TTBPDateTimeFormatterBuilder.CharLiteralPrinterParser = 58 | new TTBPDateTimeFormatterBuilder.CharLiteralPrinterParser('a') 59 | pp.print(printContext, buf) 60 | assertEquals(buf.toString, "a") 61 | } 62 | 63 | test("toString") { 64 | val pp: TTBPDateTimeFormatterBuilder.CharLiteralPrinterParser = 65 | new TTBPDateTimeFormatterBuilder.CharLiteralPrinterParser('a') 66 | assertEquals(pp.toString, "'a'") 67 | } 68 | 69 | test("toString_apos") { 70 | val pp: TTBPDateTimeFormatterBuilder.CharLiteralPrinterParser = 71 | new TTBPDateTimeFormatterBuilder.CharLiteralPrinterParser('\'') 72 | assertEquals(pp.toString, "''") 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /tests/shared/src/test/scala/org/threeten/bp/format/TestStringLiteralPrinter.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * * Neither the name of JSR-310 nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.threeten.bp.format 33 | 34 | import org.scalatest.funsuite.AnyFunSuite 35 | import org.threeten.bp.AssertionsHelper 36 | import org.threeten.bp.format.internal.TTBPDateTimeFormatterBuilder 37 | 38 | /** Test StringLiteralPrinterParser. */ 39 | class TestStringLiteralPrinter extends AnyFunSuite with GenTestPrinterParser with AssertionsHelper { 40 | test("test_print_emptyCalendrical") { 41 | buf.append("EXISTING") 42 | val pp: TTBPDateTimeFormatterBuilder.StringLiteralPrinterParser = 43 | new TTBPDateTimeFormatterBuilder.StringLiteralPrinterParser("hello") 44 | pp.print(printEmptyContext, buf) 45 | assertEquals(buf.toString, "EXISTINGhello") 46 | } 47 | 48 | test("test_print_dateTime") { 49 | buf.append("EXISTING") 50 | val pp: TTBPDateTimeFormatterBuilder.StringLiteralPrinterParser = 51 | new TTBPDateTimeFormatterBuilder.StringLiteralPrinterParser("hello") 52 | pp.print(printContext, buf) 53 | assertEquals(buf.toString, "EXISTINGhello") 54 | } 55 | 56 | test("test_print_emptyAppendable") { 57 | val pp: TTBPDateTimeFormatterBuilder.StringLiteralPrinterParser = 58 | new TTBPDateTimeFormatterBuilder.StringLiteralPrinterParser("hello") 59 | pp.print(printContext, buf) 60 | assertEquals(buf.toString, "hello") 61 | } 62 | 63 | test("test_toString") { 64 | val pp: TTBPDateTimeFormatterBuilder.StringLiteralPrinterParser = 65 | new TTBPDateTimeFormatterBuilder.StringLiteralPrinterParser("hello") 66 | assertEquals(pp.toString, "'hello'") 67 | } 68 | 69 | test("test_toString_apos") { 70 | val pp: TTBPDateTimeFormatterBuilder.StringLiteralPrinterParser = 71 | new TTBPDateTimeFormatterBuilder.StringLiteralPrinterParser("o'clock") 72 | assertEquals(pp.toString, "'o''clock'") 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /tests/shared/src/test/scala/org/threeten/bp/temporal/MockFieldValue.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * * Neither the name of JSR-310 nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.threeten.bp.temporal 33 | 34 | import org.threeten.bp.DateTimeException 35 | 36 | /** Mock simple date-time with one field-value. */ 37 | final class MockFieldValue(private val field: TemporalField, private val value: Long) 38 | extends TemporalAccessor { 39 | 40 | def isSupported(field: TemporalField): Boolean = field != null && (field == this.field) 41 | 42 | override def range(field: TemporalField): ValueRange = 43 | if (field.isInstanceOf[ChronoField]) 44 | if (isSupported(field)) 45 | field.range 46 | else 47 | throw new DateTimeException("Unsupported field: " + field) 48 | else 49 | field.rangeRefinedBy(this) 50 | 51 | def getLong(field: TemporalField): Long = 52 | if (this.field == field) 53 | value 54 | else 55 | throw new DateTimeException("Unsupported field: " + field) 56 | 57 | override def get(field: TemporalField): Int = 58 | range(field).checkValidIntValue(getLong(field), field) 59 | 60 | override def query[R](query: TemporalQuery[R]) = 61 | query.queryFrom(this) 62 | } 63 | -------------------------------------------------------------------------------- /tests/shared/src/test/scala/org/threeten/bp/temporal/TestChronoField.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * * Neither the name of JSR-310 nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package org.threeten.bp.temporal 33 | 34 | import org.scalatest.funsuite.AnyFunSuite 35 | import org.threeten.bp.AssertionsHelper 36 | 37 | /** Test. */ 38 | class TestChronoField extends AnyFunSuite with AssertionsHelper { 39 | test("isDateBased") { 40 | for (field <- ChronoField.values) 41 | if ((field eq ChronoField.INSTANT_SECONDS) || (field eq ChronoField.OFFSET_SECONDS)) 42 | assertEquals(field.isTimeBased, false) 43 | else 44 | assertEquals(field.isDateBased, field.getBaseUnit.isDateBased) 45 | } 46 | 47 | test("isTimeBased") { 48 | for (field <- ChronoField.values) 49 | if ((field eq ChronoField.INSTANT_SECONDS) || (field eq ChronoField.OFFSET_SECONDS)) 50 | assertEquals(field.isTimeBased, false) 51 | else 52 | assertEquals(field.isTimeBased, field.getBaseUnit.isTimeBased) 53 | } 54 | } 55 | --------------------------------------------------------------------------------