Skip to content

Commit e6239c5

Browse files
committed
Merge pull request scala-js#1 from nicolasstucki/add-config
Initial PR with configurations and ported code.
2 parents f771e51 + e53b5b6 commit e6239c5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+7271
-0
lines changed

.travis.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
sudo: false
2+
language: scala
3+
install:
4+
- git clone https://github.com/scala-js/scala-js.git
5+
- cd scala-js
6+
- sbt ++$TRAVIS_SCALA_VERSION compiler/publishLocal library/publishLocal javalibEx/publishLocal testInterface/publishLocal stubs/publishLocal jasmineTestFramework/publishLocal jUnitRuntime/publishLocal jUnitPlugin/publishLocal
7+
- sbt ++2.10.6 ir/publishLocal tools/publishLocal jsEnvs/publishLocal testAdapter/publishLocal sbtPlugin/publishLocal
8+
- cd ..
9+
script:
10+
- sbt ++$TRAVIS_SCALA_VERSION root/scalastyle testSuiteJVM/scalastyle testSuiteJVM/test:scalastyle testSuite/scalastyle testSuite/test:scalastyle
11+
- sbt ++$TRAVIS_SCALA_VERSION testSuiteJVM/test
12+
- sbt ++$TRAVIS_SCALA_VERSION testSuite/test
13+
- sbt ++$TRAVIS_SCALA_VERSION 'set scalaJSUseRhino in Global := false' testSuite/test
14+
- sbt ++$TRAVIS_SCALA_VERSION 'set scalaJSStage in Global := FullOptStage' testSuite/test
15+
scala:
16+
- 2.10.6
17+
- 2.11.7
18+
- 2.12.0-M3
19+
jdk:
20+
- oraclejdk8

build.sbt

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import sbt.Keys._
2+
import org.scalajs.sbtplugin.cross.CrossProject
3+
4+
lazy val root: Project = project.in(file(".")).
5+
enablePlugins(ScalaJSPlugin)
6+
7+
lazy val testSuite = CrossProject(
8+
jvmId = "testSuiteJVM",
9+
jsId = "testSuite",
10+
base = file("testSuite"),
11+
crossType = CrossType.Full
12+
).
13+
jsConfigure(_ .enablePlugins(ScalaJSJUnitPlugin)).
14+
settings(
15+
testOptions +=
16+
Tests.Argument(TestFramework("com.novocode.junit.JUnitFramework"), "-v", "-a")
17+
).
18+
jsSettings(
19+
name := "java.time testSuite on JS"
20+
).
21+
jvmSettings(
22+
name := "java.time testSuite on JVM",
23+
libraryDependencies +=
24+
"com.novocode" % "junit-interface" % "0.9" % "test"
25+
)
26+
27+
lazy val testSuiteJS = testSuite.js.dependsOn(root)
28+
lazy val testSuiteJVM = testSuite.jvm.dependsOn(root)
29+
30+
name := "scalajs-java-time"
31+
32+
version := "0.0.1-SNAPSHOT"
33+
34+
organization := "org.scala-js"
35+
36+
scalaVersion := "2.11.7"
37+
38+
scalacOptions ++= Seq("-deprecation", "-feature", "-Xfatal-warnings")
39+
40+
homepage := Some(url(http://github.com/%3Cspan%20class=%22pl-s%22%3E%3Cspan%20class=%22pl-pds%22%3E"%3C/span%3Ehttp://scala-js.org/%3Cspan%20class=%22pl-pds%22%3E"%3C/span%3E%3C/span%3E))
41+
42+
licenses += ("MIT", url(http://github.com/%3Cspan%20class=%22pl-s%22%3E%3Cspan%20class=%22pl-pds%22%3E"%3C/span%3Ehttp://opensource.org/licenses/mit-license.php%3Cspan%20class=%22pl-pds%22%3E"%3C/span%3E%3C/span%3E))

project/build.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sbt.version=0.13.9

project/build.sbt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.6-SNAPSHOT")
2+
3+
addSbtPlugin("org.scalastyle" % "scalastyle-sbt-plugin" % "0.8.0")

scalastyle-config.xml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<scalastyle>
2+
<name>Scalastyle configuration for Scala.js</name>
3+
4+
<check level="error" enabled="true" class="org.scalastyle.file.FileTabChecker"/>
5+
<check level="error" enabled="true" class="org.scalastyle.file.WhitespaceEndOfLineChecker"/>
6+
<check level="error" enabled="true" class="org.scalastyle.file.NewLineAtEofChecker"/>
7+
8+
<!--Indentation checker, whilst useful gives false positives on the file headers, so disabled for now-->
9+
<check level="error" enabled="false" class="org.scalastyle.file.IndentationChecker"/>
10+
11+
<!--
12+
Enforce the hard limit on line length, which is 120 characters.
13+
Most of the time the soft limit of 80 characters should be observed, but
14+
we can hardly tell an automated style checker about a soft limit.
15+
-->
16+
<check level="error" enabled="true" class="org.scalastyle.file.FileLineLengthChecker">
17+
<parameters>
18+
<parameter name="maxLineLength"><![CDATA[120]]></parameter>
19+
</parameters>
20+
</check>
21+
22+
<check level="error" enabled="true" class="org.scalastyle.scalariform.RedundantIfChecker"/>
23+
<check level="error" enabled="true" class="org.scalastyle.scalariform.SimplifyBooleanExpressionChecker"/>
24+
25+
<check level="error" enabled="true" class="org.scalastyle.scalariform.UppercaseLChecker"/>
26+
27+
<check level="error" enabled="true" class="org.scalastyle.scalariform.ProcedureDeclarationChecker"/>
28+
29+
<check level="error" enabled="true" class="org.scalastyle.scalariform.ClassNamesChecker">
30+
<parameters>
31+
<parameter name="regex"><![CDATA[^[A-Z][A-Za-z0-9]*$]]></parameter>
32+
</parameters>
33+
</check>
34+
<check level="error" enabled="true" class="org.scalastyle.scalariform.ObjectNamesChecker">
35+
<parameters>
36+
<parameter name="regex"><![CDATA[^[A-Z][A-Za-z0-9]*$]]></parameter>
37+
</parameters>
38+
</check>
39+
<check level="error" enabled="true" class="org.scalastyle.scalariform.PackageObjectNamesChecker">
40+
<parameters>
41+
<parameter name="regex"><![CDATA[^[a-z][A-Za-z]*$]]></parameter>
42+
</parameters>
43+
</check>
44+
45+
<check level="error" enabled="true" class="org.scalastyle.scalariform.EqualsHashCodeChecker"/>
46+
<check level="error" enabled="true" class="org.scalastyle.scalariform.CovariantEqualsChecker"/>
47+
48+
<check level="error" enabled="true" class="org.scalastyle.scalariform.IllegalImportsChecker">
49+
<parameters>
50+
<parameter name="illegalImports"><![CDATA[sun._,java.awt._]]></parameter>
51+
</parameters>
52+
</check>
53+
54+
<check level="error" enabled="true" class="org.scalastyle.scalariform.ReturnChecker"/>
55+
56+
<check level="error" enabled="true" class="org.scalastyle.scalariform.EmptyClassChecker"/>
57+
58+
<!-- Currently too strict, see https://github.com/scalastyle/scalastyle/issues/142 -->
59+
<check level="error" enabled="false" class="org.scalastyle.scalariform.ForBraceChecker"/>
60+
61+
<check level="error" enabled="true" class="org.scalastyle.scalariform.PublicMethodsHaveTypeChecker"/>
62+
63+
<check level="error" enabled="true" class="org.scalastyle.scalariform.NoWhitespaceBeforeLeftBracketChecker"/>
64+
<check level="error" enabled="true" class="org.scalastyle.scalariform.NoWhitespaceAfterLeftBracketChecker"/>
65+
66+
<check level="error" enabled="true" class="org.scalastyle.scalariform.DisallowSpaceBeforeTokenChecker">
67+
<parameters>
68+
<parameter name="tokens">COLON, COMMA, RPAREN</parameter>
69+
</parameters>
70+
</check>
71+
<check level="error" enabled="true" class="org.scalastyle.scalariform.DisallowSpaceAfterTokenChecker">
72+
<parameters>
73+
<parameter name="tokens">LPAREN</parameter>
74+
</parameters>
75+
</check>
76+
<check level="error" enabled="true" class="org.scalastyle.scalariform.EnsureSingleSpaceAfterTokenChecker">
77+
<parameters>
78+
<parameter name="tokens">IF, FOR, WHILE, DO, TRY</parameter>
79+
</parameters>
80+
</check>
81+
</scalastyle>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package java.time
2+
3+
private[time] object Constants {
4+
final val NANOS_IN_MICRO = 1000
5+
6+
final val MICROS_IN_MILLI = 1000
7+
8+
final val NANOS_IN_MILLI = MICROS_IN_MILLI * NANOS_IN_MICRO
9+
10+
final val MILLIS_IN_SECOND = 1000
11+
12+
final val MICROS_IN_SECOND = MILLIS_IN_SECOND * MICROS_IN_MILLI
13+
14+
final val NANOS_IN_SECOND = MILLIS_IN_SECOND * NANOS_IN_MILLI
15+
16+
final val SECONDS_IN_MINUTE = 60
17+
18+
final val MILLIS_IN_MINUTE = SECONDS_IN_MINUTE * MILLIS_IN_SECOND
19+
20+
final val MICROS_IN_MINUTE = SECONDS_IN_MINUTE * MICROS_IN_SECOND
21+
22+
final val NANOS_IN_MINUTE = SECONDS_IN_MINUTE * NANOS_IN_SECOND.toLong
23+
24+
final val MINUTES_IN_HOUR = 60
25+
26+
final val SECONDS_IN_HOUR = MINUTES_IN_HOUR * SECONDS_IN_MINUTE
27+
28+
final val MILLIS_IN_HOUR = MINUTES_IN_HOUR * MILLIS_IN_MINUTE
29+
30+
final val MICROS_IN_HOUR = MINUTES_IN_HOUR * MICROS_IN_MINUTE.toLong
31+
32+
final val NANOS_IN_HOUR = MINUTES_IN_HOUR * NANOS_IN_MINUTE
33+
34+
final val HOURS_IN_DAY = 24
35+
36+
final val MINUTES_IN_DAY = HOURS_IN_DAY * MINUTES_IN_HOUR
37+
38+
final val SECONDS_IN_DAY = HOURS_IN_DAY * SECONDS_IN_HOUR
39+
40+
final val MILLIS_IN_DAY = HOURS_IN_DAY * MILLIS_IN_HOUR
41+
42+
final val MICROS_IN_DAY = HOURS_IN_DAY * MICROS_IN_HOUR
43+
44+
final val NANOS_IN_DAY = HOURS_IN_DAY * NANOS_IN_HOUR
45+
46+
final val SECONDS_IN_WEEK = SECONDS_IN_DAY * 7
47+
48+
final val SECONDS_IN_MONTH = 2629746
49+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package java.time
2+
3+
class DateTimeException(message: String, cause: Throwable)
4+
extends RuntimeException(message, cause) {
5+
def this(message: String) = this(message, null)
6+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package java.time
2+
3+
import java.time.temporal._
4+
5+
final class DayOfWeek private (name: String, value: Int)
6+
extends Enum[DayOfWeek](name, value - 1) with TemporalAccessor
7+
with TemporalAdjuster {
8+
9+
def getValue(): Int = value
10+
11+
// Not implemented
12+
// def getDisplayName(style: TextStyle, locale: ju.Locale): String
13+
14+
def isSupported(field: TemporalField): Boolean = field match {
15+
case _: ChronoField => field == ChronoField.DAY_OF_WEEK
16+
case null => false
17+
case _ => field.isSupportedBy(this)
18+
}
19+
20+
// Implemented by TemporalAccessor
21+
// def range(field: TemporalField): ValueRange
22+
23+
// Implemented by TemporalAccessor
24+
// def get(field: TemporalField): Int
25+
26+
def getLong(field: TemporalField): Long = field match {
27+
case ChronoField.DAY_OF_WEEK => ordinal + 1
28+
29+
case _: ChronoField =>
30+
throw new UnsupportedTemporalTypeException(s"Field not supported: $field")
31+
32+
case _ => field.getFrom(this)
33+
}
34+
35+
def plus(days: Long): DayOfWeek = {
36+
val offset = (days % 7 + 7) % 7
37+
DayOfWeek.of((ordinal + offset.toInt) % 7 + 1)
38+
}
39+
40+
def minus(days: Long): DayOfWeek = plus(-(days % 7))
41+
42+
// Not implemented
43+
// def query[R](query: TemporalQuery[R]): R
44+
45+
def adjustInto(temporal: Temporal): Temporal =
46+
temporal.`with`(ChronoField.DAY_OF_WEEK, ordinal + 1)
47+
}
48+
49+
object DayOfWeek {
50+
final val MONDAY = new DayOfWeek("MONDAY", 1)
51+
52+
final val TUESDAY = new DayOfWeek("TUESDAY", 2)
53+
54+
final val WEDNESDAY = new DayOfWeek("WEDNESDAY", 3)
55+
56+
final val THURSDAY = new DayOfWeek("THURSDAY", 4)
57+
58+
final val FRIDAY = new DayOfWeek("FRIDAY", 5)
59+
60+
final val SATURDAY = new DayOfWeek("SATURDAY", 6)
61+
62+
final val SUNDAY = new DayOfWeek("SUNDAY", 7)
63+
64+
private val days =
65+
Seq(MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY)
66+
67+
def values(): Array[DayOfWeek] = days.toArray
68+
69+
def valueOf(name: String): DayOfWeek = days.find(_.name == name).getOrElse {
70+
throw new IllegalArgumentException(s"No such weekday: $name")
71+
}
72+
73+
def of(dayOfWeek: Int): DayOfWeek = days.lift(dayOfWeek - 1).getOrElse {
74+
throw new DateTimeException(s"Invalid value for weekday: $dayOfWeek")
75+
}
76+
77+
def from(temporal: TemporalAccessor): DayOfWeek =
78+
DayOfWeek.of(temporal.get(ChronoField.DAY_OF_WEEK))
79+
}

0 commit comments

Comments
 (0)