Recover dateTime parsing with hardcded date

This commit is contained in:
Guntis Smaukstelis
2025-03-03 22:32:39 +02:00
parent b43764b868
commit 17cb0e550a
+4 -3
View File
@@ -7,7 +7,7 @@ import java.nio.ByteBuffer
import java.time.format.DateTimeFormatter
import java.time.temporal.ChronoUnit
import java.time.{ZoneOffset, ZonedDateTime}
import scala.util.Try
import scala.util.{Random, Try}
object GribParser {
def parseFile(path: Path): IO[List[Grib]] = {
@@ -86,9 +86,10 @@ object GribParser {
second = bytes(18)
referenceTime = Try(ZonedDateTime.of(
year, month, day,
hour, minute, second, 0, // last 0 is nanos
hour, minute, second, 0,
ZoneOffset.UTC // This is what 'Z' represents - UTC/Zero offset
)).recover { case _ => extractDateTime(path) }.get
)).recoverWith { case _ => Try(extractDateTime(path))
}.getOrElse(ZonedDateTime.of(2000, 1, 1, Random.nextInt(24), 0, 0, 0, ZoneOffset.UTC))
} yield (referenceTime, length)
}