Implemented setting time on Date; fixed formatting time tests
This commit is contained in:
parent
095d9c467a
commit
d43d91b6cc
|
@ -23,9 +23,9 @@ expect class Date(millisSinceEpoch: Long) {
|
||||||
|
|
||||||
constructor()
|
constructor()
|
||||||
|
|
||||||
constructor(year: Int, month: Int, day: Int)
|
constructor(year: Int, month: Int, day: Int, hour: Int = 0, minute: Int = 0, second: Int = 0)
|
||||||
|
|
||||||
actual constructor(year: Int, month: Month, day: Int)
|
constructor(year: Int, month: Month, day: Int, hour: Int = 0, minute: Int = 0, second: Int = 0)
|
||||||
|
|
||||||
|
|
||||||
val millisSinceEpoch: Long
|
val millisSinceEpoch: Long
|
||||||
|
|
|
@ -23,13 +23,17 @@ actual class Date(val date: NSDate) { // cannot subclass NSDate as it's a class
|
||||||
|
|
||||||
val DiffBetweenEpochTimeAndReferenceDate = (NSDate.timeIntervalSinceReferenceDate - NSTimeIntervalSince1970).toMillis()
|
val DiffBetweenEpochTimeAndReferenceDate = (NSDate.timeIntervalSinceReferenceDate - NSTimeIntervalSince1970).toMillis()
|
||||||
|
|
||||||
fun from(year: Int, month: Int, day: Int): NSDate {
|
fun from(year: Int, month: Int, day: Int, hour: Int = 0, minute: Int = 0, second: Int = 0): NSDate {
|
||||||
val dateComponents = NSDateComponents()
|
val dateComponents = NSDateComponents()
|
||||||
|
|
||||||
dateComponents.year = year.toLong()
|
dateComponents.year = year.toLong()
|
||||||
dateComponents.month = month.toLong()
|
dateComponents.month = month.toLong()
|
||||||
dateComponents.day = day.toLong()
|
dateComponents.day = day.toLong()
|
||||||
|
|
||||||
|
dateComponents.hour = hour.toLong()
|
||||||
|
dateComponents.minute = minute.toLong()
|
||||||
|
dateComponents.second = second.toLong()
|
||||||
|
|
||||||
val calendar = NSCalendar.currentCalendar
|
val calendar = NSCalendar.currentCalendar
|
||||||
val todayInUtc = calendar.dateFromComponents(dateComponents) !!
|
val todayInUtc = calendar.dateFromComponents(dateComponents) !!
|
||||||
|
|
||||||
|
@ -54,9 +58,9 @@ actual class Date(val date: NSDate) { // cannot subclass NSDate as it's a class
|
||||||
|
|
||||||
actual constructor() : this(NSDate())
|
actual constructor() : this(NSDate())
|
||||||
|
|
||||||
actual constructor(year: Int, month: Int, day: Int) : this(from(year, month, day))
|
actual constructor(year: Int, month: Int, day: Int, hour: Int, minute: Int, second: Int) : this(from(year, month, day, hour, minute, second))
|
||||||
|
|
||||||
actual constructor(year: Int, month: Month, day: Int) : this(year, month.month, day)
|
actual constructor(year: Int, month: Month, day: Int, hour: Int, minute: Int, second: Int) : this(year, month.month, day, hour, minute, second)
|
||||||
|
|
||||||
|
|
||||||
actual val millisSinceEpoch: Long
|
actual val millisSinceEpoch: Long
|
||||||
|
|
|
@ -31,9 +31,9 @@ actual class Date actual constructor(millisSinceEpoch: Long) : java.util.Date(mi
|
||||||
|
|
||||||
actual constructor() : this(System.currentTimeMillis())
|
actual constructor() : this(System.currentTimeMillis())
|
||||||
|
|
||||||
actual constructor(year: Int, month: Int, day: Int) : this(java.util.Date(year - 1900, month - 1, day).time)
|
actual constructor(year: Int, month: Int, day: Int, hour: Int, minute: Int, second: Int) : this(java.util.Date(year - 1900, month - 1, day, hour, minute, second).time)
|
||||||
|
|
||||||
actual constructor(year: Int, month: Month, day: Int) : this(year, month.month, day)
|
actual constructor(year: Int, month: Month, day: Int, hour: Int, minute: Int, second: Int) : this(year, month.month, day, hour, minute, second)
|
||||||
|
|
||||||
|
|
||||||
actual val millisSinceEpoch: Long
|
actual val millisSinceEpoch: Long
|
||||||
|
|
|
@ -41,7 +41,7 @@ class FinTsUtilsTest {
|
||||||
fun formatTime_AM() {
|
fun formatTime_AM() {
|
||||||
|
|
||||||
// given
|
// given
|
||||||
val time = Date(8, 2, 1)
|
val time = Date(0, 0, 0, 8, 2, 1)
|
||||||
|
|
||||||
// when
|
// when
|
||||||
val result = underTest.formatTime(time)
|
val result = underTest.formatTime(time)
|
||||||
|
@ -54,7 +54,7 @@ class FinTsUtilsTest {
|
||||||
fun formatTime_PM() {
|
fun formatTime_PM() {
|
||||||
|
|
||||||
// given
|
// given
|
||||||
val time = Date(18, 22, 51)
|
val time = Date(0, 0, 0, 18, 22, 51)
|
||||||
|
|
||||||
// when
|
// when
|
||||||
val result = underTest.formatTime(time)
|
val result = underTest.formatTime(time)
|
||||||
|
@ -67,7 +67,7 @@ class FinTsUtilsTest {
|
||||||
fun formatTimeAsInt_AM() {
|
fun formatTimeAsInt_AM() {
|
||||||
|
|
||||||
// given
|
// given
|
||||||
val time = Date(8, 2, 1)
|
val time = Date(0, 0, 0, 8, 2, 1)
|
||||||
|
|
||||||
// when
|
// when
|
||||||
val result = underTest.formatTimeAsInt(time)
|
val result = underTest.formatTimeAsInt(time)
|
||||||
|
@ -80,7 +80,7 @@ class FinTsUtilsTest {
|
||||||
fun formatTimeAsInt_PM() {
|
fun formatTimeAsInt_PM() {
|
||||||
|
|
||||||
// given
|
// given
|
||||||
val time = Date(18, 22, 51)
|
val time = Date(0, 0, 0, 18, 22, 51)
|
||||||
|
|
||||||
// when
|
// when
|
||||||
val result = underTest.formatTimeAsInt(time)
|
val result = underTest.formatTimeAsInt(time)
|
||||||
|
|
Loading…
Reference in New Issue