package com.vgmlr.shim
import java.time.LocalDate
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import java.time.temporal.ChronoUnit
import java.util.Locale
object OTCClock {
fun getOTCTime(dateTime: LocalDateTime): String {
val now = dateTime
val currentYear = now.year
val march20Current = LocalDate.of(currentYear, 3, 20)
val newYearDate = if (now.toLocalDate().isBefore(march20Current)) {
LocalDate.of(currentYear - 1, 3, 20)
} else {
march20Current
}
val daysSince = ChronoUnit.DAYS.between(newYearDate, now.toLocalDate()) + 1
val otcYear = "0" + newYearDate.format(DateTimeFormatter.ofPattern("yy"))
val timePart = now.format(DateTimeFormatter.ofPattern("HH:mm"))
val ddMonPart = now.format(DateTimeFormatter.ofPattern("dd MMM", Locale.ENGLISH))
return "$timePart $daysSince $otcYear ($ddMonPart)"
}
fun getCurrentOTCTime(): String {
return getOTCTime(LocalDateTime.now())
}
fun getFileNameTimestamp(): String {
val now = LocalDateTime.now()
val currentYear = now.year
val march20Current = LocalDate.of(currentYear, 3, 20)
val newYearDate = if (now.toLocalDate().isBefore(march20Current)) {
LocalDate.of(currentYear - 1, 3, 20)
} else {
march20Current
}
val daysSince = ChronoUnit.DAYS.between(newYearDate, now.toLocalDate()) + 1
val otcYear = "0" + newYearDate.format(DateTimeFormatter.ofPattern("yy"))
val hhmmss = now.format(DateTimeFormatter.ofPattern("HHmmss"))
return "$otcYear$daysSince$hhmmss"
}
}