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 |
25 |
|
override def toString: String = underlying.toUTCString() |
22 |
26 |
|
|
23 |
|
- |
def dayOfMonth: Int = underlying.getUTCDate().toInt |
24 |
|
- |
def month: Int = (underlying.getUTCMonth() + 1).toInt |
25 |
|
- |
def year: Int = underlying.getUTCFullYear().toInt |
26 |
|
- |
def hour: Int = underlying.getUTCHours().toInt |
27 |
|
- |
def minute: Int = underlying.getUTCMinutes().toInt |
28 |
|
- |
def second: Int = underlying.getUTCSeconds().toInt |
29 |
|
- |
def millisecond: Int = underlying.getUTCMilliseconds().toInt |
|
27 |
+ |
def dayOfMonth: Int = underlying.getUTCDate() |
|
28 |
+ |
def month: Int = underlying.getUTCMonth() + 1 |
|
29 |
+ |
def year: Int = underlying.getUTCFullYear() |
|
30 |
+ |
def hour: Int = underlying.getUTCHours() |
|
31 |
+ |
def minute: Int = underlying.getUTCMinutes() |
|
32 |
+ |
def second: Int = underlying.getUTCSeconds() |
|
33 |
+ |
def millisecond: Int = underlying.getUTCMilliseconds() |
30 |
34 |
|
|
31 |
|
- |
def dayOfWeek: DayOfWeek = DayOfWeek.of(dayOfWeekJSToJVM(underlying.getUTCDay().toInt)) |
|
35 |
+ |
def dayOfWeek: DayOfWeek = DayOfWeek.of(dayOfWeekJSToJVM(underlying.getUTCDay())) |
32 |
36 |
|
def toLocalDate: LocalDate = LocalDate.of(year, month, dayOfMonth) |
33 |
37 |
|
def toLocalTime: LocalTime = LocalTime.of(hour, minute, second, millisToNanos(millisecond)) |
34 |
38 |
|
|
35 |
39 |
|
def jsGetTime: Double = underlying.getTime() |
36 |
40 |
|
|
37 |
|
- |
def withYear(year: Int): JSDate = updated(_.setUTCFullYear(yearD, monthD - 1, |
38 |
|
- |
limitToLastDayOfMonth(dayOfMonth, year).toDouble)) |
|
41 |
+ |
def withYear(year: Int): JSDate = updated(_.setUTCFullYear(year, month - 1, limitToLastDayOfMonth(dayOfMonth, year))) |
39 |
42 |
|
|
40 |
43 |
|
def withMonth(month: Int): JSDate = |
41 |
|
- |
updated(_.setUTCMonth(monthD - 1, limitToLastDayOfMonth(dayOfMonth, forMonth = month).toDouble)) |
42 |
|
- |
def withDayOfMonth(dayOfMonth: Int): JSDate = updated(_.setUTCDate(dayOfMonthD)) |
43 |
|
- |
def withHour(hour: Int): JSDate = updated(_.setUTCHours(hourD, minuteD, secondD, millisecondD)) |
44 |
|
- |
def withMinute(minute: Int): JSDate = updated(_.setUTCMinutes(minuteD, secondD, millisecondD)) |
45 |
|
- |
def withSecond(second: Int): JSDate = updated(_.setUTCSeconds(secondD, millisecondD)) |
46 |
|
- |
def withMillisecond(millisecond: Int): JSDate = updated(_.setUTCMilliseconds(millisecondD)) |
|
44 |
+ |
updated(_.setUTCMonth(month - 1, limitToLastDayOfMonth(dayOfMonth, forMonth = month))) |
|
45 |
+ |
def withDayOfMonth(dayOfMonth: Int): JSDate = updated(_.setUTCDate(dayOfMonth)) |
|
46 |
+ |
def withHour(hour: Int): JSDate = updated(_.setUTCHours(hour, minute, second, millisecond)) |
|
47 |
+ |
def withMinute(minute: Int): JSDate = updated(_.setUTCMinutes(minute, second, millisecond)) |
|
48 |
+ |
def withSecond(second: Int): JSDate = updated(_.setUTCSeconds(second, millisecond)) |
|
49 |
+ |
def withMillisecond(millisecond: Int): JSDate = updated(_.setUTCMilliseconds(millisecond)) |
47 |
50 |
|
|
48 |
51 |
|
def millisecondsUntil(other: JSDate): Long = (other.jsGetTime - jsGetTime).toLong |
49 |
52 |
|
def secondsUntil(other: JSDate): Long = millisecondsUntil(other) / MillisInSecond |