-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathTimeUtils.kt
63 lines (53 loc) · 2.4 KB
/
TimeUtils.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package me.iru.timedisplay
import net.minecraft.client.MinecraftClient
import java.text.SimpleDateFormat
import java.time.temporal.ChronoUnit
import java.util.*
import java.util.concurrent.TimeUnit
object TimeUtils {
val getPlayTime: () -> String = {
val playtime = TimeDisplay.playtimeTickCache
val playtimeInSecons = playtime / 20
val hour = (playtimeInSecons / 60 / 60)
val min = (playtimeInSecons / 60) % 60
val sec = (playtimeInSecons) % 60
val formatted = "${String.format("%02d", hour)}:${String.format("%02d", min)}:${String.format("%02d", sec)}"
"Play Time: ($formatted)"
}
val getRealTime: () -> String = {
val format = if (TimeDisplay.config.twelveClockMode) "h:mm:ss a" else "HH:mm:ss"
val sdf = SimpleDateFormat(format)
sdf.format(System.currentTimeMillis())
}
val getRealDate: () -> String = {
val sdf = SimpleDateFormat("yyyy/MM/dd")
sdf.format(System.currentTimeMillis())
}
val getMinecraftHour: () -> String = {
val timeDay: Long = MinecraftClient.getInstance().world!!.timeOfDay
val dayTicks = (timeDay % 24000).toInt()
val hour = (dayTicks / 1000 + 6) % 24
val min = (dayTicks / 16.666666).toInt() % 60
val sec = (dayTicks / 0.277777).toInt() % 60
if(TimeDisplay.config.twelveClockMode) {
"Ingame Time (${String.format("%02d", hour % 12)}:${String.format("%02d", min)}:${String.format("%02d", sec)} ${if(hour > 12) "PM" else "AM"})"
} else {
"Ingame Time (${String.format("%02d", hour)}:${String.format("%02d", min)}:${String.format("%02d", sec)} )"
}
}
val getMinecraftDate: () -> String = {
val timeDay: Long = MinecraftClient.getInstance().world!!.timeOfDay
val days = (timeDay / 24000L)
val start = Date(31530000000).toInstant()
val now = Date(TimeUnit.DAYS.toMillis(days)).toInstant()
val sdf = SimpleDateFormat("dd MMMM '(Year' yyyy')'", Locale.ENGLISH)
val formatted = sdf.format(ChronoUnit.MILLIS.between(start, now))
val pieces = formatted.split("(Year ")
val year = pieces[1].removeSuffix(")").toInt() - 1968
"${pieces[0]}(Year ${year})"
}
val getMinecraftTotalDays: () -> String = {
val timeDay: Long = MinecraftClient.getInstance().world!!.timeOfDay
"Total Ingame Days (${timeDay / 24000L})"
}
}