-
Notifications
You must be signed in to change notification settings - Fork 1
/
Utils.kt
28 lines (24 loc) · 941 Bytes
/
Utils.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package kaist.iclab.abclogger.common
import com.google.protobuf.GeneratedMessageV3
import org.bson.conversions.Bson
import org.litote.kmongo.coroutine.CoroutineAggregatePublisher
import org.litote.kmongo.coroutine.CoroutineCollection
import java.security.MessageDigest
import java.time.LocalDateTime
import java.time.OffsetDateTime
import java.time.ZoneOffset
fun toOffsetDateTime(timeMillis: Long, offsetSec: Int? = null): OffsetDateTime {
val zoneOffset = if (offsetSec != null) {
ZoneOffset.ofTotalSeconds(offsetSec)
} else {
OffsetDateTime.now().offset
}
val localDateTime = LocalDateTime.ofEpochSecond(timeMillis / 1000, 0, zoneOffset)
return OffsetDateTime.of(
localDateTime, zoneOffset
)
}
fun toMd5Hash(value: String): String =
MessageDigest.getInstance("MD5").digest(value.toByteArray()).joinToString("") {
it.toInt().and(0xFF).toString(16).padStart(2, '0')
}