Fetching from harmonie servers

This commit is contained in:
Guntis Smaukstelis
2025-02-01 20:19:58 +02:00
parent cb662e5f53
commit 94d0612d80
3 changed files with 128 additions and 0 deletions
+36
View File
@@ -0,0 +1,36 @@
package fetchDMI
import java.time.{ZoneOffset, ZonedDateTime}
object FileName {
def main(args: Array[String]): Unit = {
println("-------- FileName")
val nowUTC = ZonedDateTime.now(ZoneOffset.UTC)
val referenceTime = getClosestReferenceTime(nowUTC)
val timeList = generateTimeList(referenceTime)
timeList.foreach(println)
}
def getClosestReferenceTime(time: ZonedDateTime): ZonedDateTime = {
val referenceHours = Vector(0, 3, 6, 9, 12, 15, 18, 21)
val currentHour = time.getHour
val closestHour = referenceHours
.filter(h => h <= currentHour)
.maxOption
.getOrElse(21) // actually should not be such case
time
.withHour(closestHour)
.withMinute(0)
.withSecond(0)
.withNano(0)
}
// TODO make default count to 62 or 60
def generateTimeList(initialTime: ZonedDateTime, interval: Int = 1, count: Int = 5): List[ZonedDateTime] = {
(0 until count).map(id => initialTime.plusHours(id * interval)).toList
}
}