Skip to content

Commit

Permalink
Normalize computed period days
Browse files Browse the repository at this point in the history
  • Loading branch information
pomadchin committed Apr 1, 2021
1 parent dece161 commit 73ba796
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions ogc/src/main/scala/geotrellis/server/ogc/OgcTime.scala
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,16 @@ final case class OgcTimePositions(list: NonEmptyList[ZonedDateTime]) extends Ogc
def sorted: NonEmptyList[ZonedDateTime] = list.sorted

/** Compute (if possible) the period of the [[ZonedDateTime]] lists. */
def computeIntervalPeriod: Option[Duration] = {
def computeIntervalPeriod: Option[PeriodDuration] = {
val periods =
sorted.toList
.sliding(2)
.map { case Seq(l, r, _*) => r.toEpochMilli - l.toEpochMilli }
.toList
.distinct
.map(Duration.ofMillis)
// convert into [[PeriodDuration]] and normalize days, leaving the years and months unchanged
.map(PeriodDuration.of(_).normalizedStandardDays)

if (periods.length < 2) periods.headOption
else None
Expand Down Expand Up @@ -142,7 +144,7 @@ object OgcTimePositions {
* followed by a number of years Y, months M, days D, a time designator T, number
* of hours H, minutes M, and seconds S. Unneeded elements may be omitted. Here are
* a few examples:
* EXAMPLE 1 - P1Y, 1 year
* EXAMPLE 1 - P1Y, 1 year
* EXAMPLE 2 - P1M10D, 1 month plus 10 days
* EXAMPLE 3 - PT2H, 2 hours
*
Expand Down

0 comments on commit 73ba796

Please sign in to comment.