Skip to content

Commit

Permalink
Preserve type after call to rename
Browse files Browse the repository at this point in the history
See #149
  • Loading branch information
dlindhol committed May 4, 2021
1 parent 2004d17 commit 705a0db
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions core/src/main/scala/latis/time/Time.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import latis.metadata.Metadata
import latis.model.Scalar
import latis.model.StringValueType
import latis.units.UnitConverter
import latis.util.Identifier

/**
* Time is a Scalar that provides special behavior for formated time values.
Expand All @@ -15,6 +16,9 @@ class Time(metadata: Metadata) extends Scalar(metadata) {
//TODO: make sure this has the id or alias "time"
//TODO: validate units eagerly

/** Override to preserve type */
override def rename(id: Identifier): Time = Time(metadata + ("id" -> id.asString))

/**
* Returns the units from the metadata.
*/
Expand Down
9 changes: 9 additions & 0 deletions core/src/test/scala/latis/time/TimeSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import org.scalatest.matchers.should.Matchers._

import latis.data.Data
import latis.metadata.Metadata
import latis.util.Identifier.IdentifierStringContext

class TimeSpec extends AnyFlatSpec {

Expand Down Expand Up @@ -43,4 +44,12 @@ class TimeSpec extends AnyFlatSpec {
formattedTime.ordering.tryCompare("Jan 01, 2000", "Feb 01, 2000") should be (Some(-1))
}

"rename" should "preserve type" in {
val t = Time(Metadata(
"id" -> "foo",
"type" -> "double",
"units" -> "seconds since 2000-01-01"
))
assert(t.rename(id"bar").isInstanceOf[Time])
}
}

0 comments on commit 705a0db

Please sign in to comment.