forked from aneonex/BitcoinChecker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimeUtils.kt
More file actions
24 lines (20 loc) · 899 Bytes
/
TimeUtils.kt
File metadata and controls
24 lines (20 loc) · 899 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package com.aneonex.bitcoinchecker.datamodule.util
import java.time.ZonedDateTime
import java.time.format.DateTimeFormatter
object TimeUtils {
// const val NANOS_IN_MILLIS: Long = 1000
const val MILLIS_IN_SECOND: Long = 1000
const val MILLIS_IN_MINUTE = 60 * MILLIS_IN_SECOND
const val MILLIS_IN_HOUR = 60 * MILLIS_IN_MINUTE
const val MILLIS_IN_DAY = 24 * MILLIS_IN_HOUR
const val MILLIS_IN_YEAR = 365 * MILLIS_IN_DAY
fun parseTimeToMillis(time: Long): Long {
if (time < MILLIS_IN_YEAR) return time * MILLIS_IN_SECOND else if (time > 5000 * MILLIS_IN_YEAR) return time / 1000
return time
}
// Parsing string and converting to timestamp.
// Returns 0 if parsing failed
fun convertISODateToTimestamp(isoDateString: String): Long {
return ZonedDateTime.parse(isoDateString, DateTimeFormatter.ISO_DATE_TIME).toEpochSecond()
}
}