vpavkin / dtc

Compare 78eabb6 ... +2 ... 9618b00

Coverage Reach
laws/shared/src/main/scala/dtc/laws/GeneralLocalDateTimeLaws.scala laws/shared/src/main/scala/dtc/laws/DateTimeLaws.scala laws/shared/src/main/scala/dtc/laws/LocalDateTimeTests.scala laws/shared/src/main/scala/dtc/laws/ZonedDateTimeTests.scala laws/shared/src/main/scala/dtc/laws/DateTimeTests.scala laws/shared/src/main/scala/dtc/laws/ZonedDateTimeLaws.scala laws/shared/src/main/scala/dtc/laws/package.scala laws/shared/src/main/scala/dtc/laws/LocalDateTimeLaws.scala laws/shared/src/main/scala/dtc/laws/ProviderTests.scala laws/shared/src/main/scala/dtc/laws/ProviderLaws.scala core/js/src/main/scala/dtc/js/JSDate.scala core/js/src/main/scala/dtc/js/package.scala core/js/src/main/scala/dtc/instances/jsDate.scala core/jvm/src/main/scala/dtc/instances/ZonedDateTimeInstanceWithoutOrder.scala core/jvm/src/main/scala/dtc/instances/localDateTime.scala core/jvm/src/main/scala/dtc/instances/zonedDateTime.scala core/jvm/src/main/scala/dtc/syntax/timeZone.scala core/shared/src/main/scala/dtc/package.scala core/shared/src/main/scala/dtc/TimePoint.scala core/shared/src/main/scala/dtc/ControlledTimeProvider.scala core/shared/src/main/scala/dtc/syntax/provider.scala core/shared/src/main/scala/dtc/Local.scala core/shared/src/main/scala/dtc/TimeZoneId.scala core/shared/src/main/scala/dtc/Capture.scala core/shared/src/main/scala/dtc/Zoned.scala core/shared/src/main/scala/dtc/Provider.scala core/shared/src/main/scala/dtc/Offset.scala moment/src/main/scala/dtc/js/MomentDateTime.scala moment/src/main/scala/dtc/js/MomentZonedDateTime.scala moment/src/main/scala/dtc/js/MomentLocalDateTime.scala moment/src/main/scala/dtc/instances/moment/package.scala moment/src/main/scala/dtc/instances/moment/MomentZonedDateTimeInstanceWithoutOrder.scala moment/src/main/scala/dtc/instances/moment/providers.scala cats/shared/src/main/scala/dtc/cats/instances/zoned.scala cats/shared/src/main/scala/dtc/cats/instances/local.scala cats/shared/src/main/scala/dtc/cats/instances/capture.scala cats/shared/src/main/scala/dtc/cats/syntax/package.scala examples/shared/src/main/scala/dtc/examples/Period.scala examples/shared/src/main/scala/dtc/examples/Calendar.scala

No flags found

Use flags to group coverage reports by test type, project and/or folders.
Then setup custom commit statuses and notifications for each flag.

e.g., #unittest #integration

#production #enterprise

#frontend #backend

Learn more about Codecov Flags here.

Showing 1 of 4 files from the diff.
Other files ignored by Codecov
.travis.yml has changed.
build.sbt has changed.

@@ -5,8 +5,10 @@
Loading
5 5
6 6
import dtc._
7 7
8 +
import scala.language.implicitConversions
8 9
import scala.scalajs.js.Date
9 10
import scala.util.Try
11 +
import JSDateCompatibility._
10 12
11 13
/**
12 14
  * Mutability safe wrapper around plain JS Date.
@@ -15,20 +17,12 @@
Loading
15 17
  * to fit [[dtc.Local]] typeclass requirements.
16 18
  *
17 19
  * Supports only [[dtc.Local]] typeclass due to weak time-zone capabilities.
20 +
  *
21 +
  * Be aware of [[JSDateCompatibility]] conversions.
18 22
  */
19 23
class JSDate private(private val underlying: Date) {
20 24
21 -
  private def updatedRaw(modifier: Double => Double): JSDate =
22 -
    new JSDate(new Date(modifier(underlying.getTime())))
23 -
24 -
  private def updated(modifier: Date => Unit): JSDate = {
25 -
    val date = new Date(underlying.getTime())
26 -
    modifier(date)
27 -
    new JSDate(date)
28 -
  }
29 -
30 -
  private def limitToLastDayOfMonth(day: Int, forYear: Int = year, forMonth: Int = month) =
31 -
    math.min(day, LocalDate.of(forYear, forMonth, 1).lengthOfMonth())
25 +
  override def toString: String = underlying.toUTCString()
32 26
33 27
  def dayOfMonth: Int = underlying.getUTCDate()
34 28
  def month: Int = underlying.getUTCMonth() + 1
@@ -37,13 +31,15 @@
Loading
37 31
  def minute: Int = underlying.getUTCMinutes()
38 32
  def second: Int = underlying.getUTCSeconds()
39 33
  def millisecond: Int = underlying.getUTCMilliseconds()
34 +
40 35
  def dayOfWeek: DayOfWeek = DayOfWeek.of(dayOfWeekJSToJVM(underlying.getUTCDay()))
41 36
  def toLocalDate: LocalDate = LocalDate.of(year, month, dayOfMonth)
42 37
  def toLocalTime: LocalTime = LocalTime.of(hour, minute, second, millisToNanos(millisecond))
43 38
44 39
  def jsGetTime: Double = underlying.getTime()
45 40
46 41
  def withYear(year: Int): JSDate = updated(_.setUTCFullYear(year, month - 1, limitToLastDayOfMonth(dayOfMonth, year)))
42 +
47 43
  def withMonth(month: Int): JSDate =
48 44
    updated(_.setUTCMonth(month - 1, limitToLastDayOfMonth(dayOfMonth, forMonth = month)))
49 45
  def withDayOfMonth(dayOfMonth: Int): JSDate = updated(_.setUTCDate(dayOfMonth))
@@ -60,17 +56,6 @@
Loading
60 56
  def monthsUntil(other: JSDate): Long = monthsOrYearsUntil(other, ChronoUnit.MONTHS)
61 57
  def yearsUntil(other: JSDate): Long = monthsOrYearsUntil(other, ChronoUnit.YEARS)
62 58
63 -
  private def monthsOrYearsUntil(other: JSDate, units: ChronoUnit): Long = {
64 -
    val thisDate = toLocalDate
65 -
    val thisTime = toLocalTime
66 -
    val otherDate = other.toLocalDate
67 -
    val otherTime = other.toLocalTime
68 -
69 -
    if (otherDate.isAfter(thisDate) && otherTime.isBefore(thisTime)) thisDate.until(otherDate.minusDays(1L), units)
70 -
    else if (otherDate.isBefore(thisDate) && otherTime.isAfter(thisTime)) thisDate.until(otherDate.plusDays(1L), units)
71 -
    else thisDate.until(otherDate, units)
72 -
  }
73 -
74 59
  def plus(d: Duration): JSDate = plusMillis(d.toMillis)
75 60
  def minus(d: Duration): JSDate = plusMillis(-d.toMillis)
76 61
@@ -86,7 +71,31 @@
Loading
86 71
  }
87 72
  def plusMillis(n: Long): JSDate = updatedRaw(_ + n)
88 73
89 -
  override def toString: String = underlying.toUTCString()
74 +
  private def updatedRaw(modifier: Double => Double): JSDate =
75 +
    new JSDate(new Date(modifier(underlying.getTime())))
76 +
77 +
  private def updated(modifier: Date => Unit): JSDate = {
78 +
    val date = new Date(underlying.getTime())
79 +
    modifier(date)
80 +
    new JSDate(date)
81 +
  }
82 +
83 +
  private def limitToLastDayOfMonth(day: Int, forYear: Int = year, forMonth: Int = month): Int =
84 +
    math.min(day, LocalDate.of(forYear, forMonth, 1).lengthOfMonth())
85 +
86 +
  private def monthsOrYearsUntil(other: JSDate, units: ChronoUnit): Long = {
87 +
    val thisDate = toLocalDate
88 +
    val thisTime = toLocalTime
89 +
    val otherDate = other.toLocalDate
90 +
    val otherTime = other.toLocalTime
91 +
92 +
    if (otherDate.isAfter(thisDate) && otherTime.isBefore(thisTime)) thisDate.until(otherDate.minusDays(1L), units)
93 +
    else if (otherDate.isBefore(thisDate) && otherTime.isAfter(thisTime)) thisDate.until(otherDate.plusDays(1L), units)
94 +
    else thisDate.until(otherDate, units)
95 +
  }
96 +
97 +
  private def unusedImportHack: Double = 1.toInt
98 +
90 99
}
91 100
92 101
object JSDate {
@@ -119,3 +128,14 @@
Loading
119 128
    new JSDate(jsDate)
120 129
  }
121 130
}
131 +
132 +
private[js] object JSDateCompatibility {
133 +
134 +
  /**
135 +
    * Since Scala.js 1, JSDate works with Doubles instead io Ints.
136 +
    * See https://github.com/scala-js/scala-js/issues/2751.
137 +
    * This is just to reduce amount of back and forth conversions between Int and Double.
138 +
    */
139 +
  implicit def doubleToInt(x: Double): Int = x.toInt
140 +
141 +
}

Everything is accounted for!

No changes detected that need to be reviewed.
What changes does Codecov check for?
Lines, not adjusted in diff, that have changed coverage data.
Files that introduced coverage data that had none before.
Files that have missing coverage data that once were tracked.
Files Coverage
cats/shared/src/main/scala/dtc/cats 0.00%
core -0.72% 83.69%
examples/shared/src/main/scala/dtc/examples 0.00%
laws/shared/src/main/scala/dtc/laws 98.36%
moment/src/main/scala/dtc 81.50%
Project Totals (39 files) 77.73%
Loading