mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Convert Timestamp to data class
This commit is contained in:
@@ -18,8 +18,6 @@
|
|||||||
*/
|
*/
|
||||||
package org.isoron.uhabits.core.models
|
package org.isoron.uhabits.core.models
|
||||||
|
|
||||||
import org.apache.commons.lang3.builder.EqualsBuilder
|
|
||||||
import org.apache.commons.lang3.builder.HashCodeBuilder
|
|
||||||
import org.isoron.platform.time.LocalDate
|
import org.isoron.platform.time.LocalDate
|
||||||
import org.isoron.uhabits.core.utils.DateFormats.Companion.getCSVDateFormat
|
import org.isoron.uhabits.core.utils.DateFormats.Companion.getCSVDateFormat
|
||||||
import org.isoron.uhabits.core.utils.DateUtils
|
import org.isoron.uhabits.core.utils.DateUtils
|
||||||
@@ -30,8 +28,7 @@ import java.util.Date
|
|||||||
import java.util.GregorianCalendar
|
import java.util.GregorianCalendar
|
||||||
import java.util.TimeZone
|
import java.util.TimeZone
|
||||||
|
|
||||||
class Timestamp(unixTime: Long) : Comparable<Timestamp> {
|
data class Timestamp(var unixTime: Long) : Comparable<Timestamp> {
|
||||||
val unixTime: Long
|
|
||||||
|
|
||||||
constructor(cal: GregorianCalendar) : this(cal.timeInMillis)
|
constructor(cal: GregorianCalendar) : this(cal.timeInMillis)
|
||||||
|
|
||||||
@@ -49,19 +46,6 @@ class Timestamp(unixTime: Long) : Comparable<Timestamp> {
|
|||||||
return java.lang.Long.signum(unixTime - other.unixTime)
|
return java.lang.Long.signum(unixTime - other.unixTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
|
||||||
if (this === other) return true
|
|
||||||
if (other == null || javaClass != other.javaClass) return false
|
|
||||||
val timestamp = other as Timestamp
|
|
||||||
return EqualsBuilder()
|
|
||||||
.append(unixTime, timestamp.unixTime)
|
|
||||||
.isEquals
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
|
||||||
return HashCodeBuilder(17, 37).append(unixTime).toHashCode()
|
|
||||||
}
|
|
||||||
|
|
||||||
operator fun minus(days: Int): Timestamp {
|
operator fun minus(days: Int): Timestamp {
|
||||||
return plus(-days)
|
return plus(-days)
|
||||||
}
|
}
|
||||||
@@ -140,9 +124,7 @@ class Timestamp(unixTime: Long) : Comparable<Timestamp> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
var unixTime = unixTime
|
|
||||||
require(unixTime >= 0) { "Invalid unix time: $unixTime" }
|
require(unixTime >= 0) { "Invalid unix time: $unixTime" }
|
||||||
if (unixTime % DAY_LENGTH != 0L) unixTime = unixTime / DAY_LENGTH * DAY_LENGTH
|
if (unixTime % DAY_LENGTH != 0L) unixTime = unixTime / DAY_LENGTH * DAY_LENGTH
|
||||||
this.unixTime = unixTime
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user