Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: support sub-second durations #1632

Merged
merged 1 commit into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ object Strings {
/**
* Period following conventions of unix `at` command.
*/
private val AtPeriod = """^(\d+)([a-z]+)$""".r
private val AtPeriod = """^(\d+)([a-]+)$""".r

/**
* Period following the ISO8601 conventions.
Expand Down Expand Up @@ -420,10 +420,13 @@ object Strings {
* Convert an `at` command time range into a joda period object.
*/
private def parseAtDuration(amount: String, unit: String): Duration = {
val v = amount.toInt
val v = amount.toLong

// format: off
unit match {
case "ns" => Duration.ofNanos(v)
case "us" | "μs" => Duration.ofNanos(v * 1000L)
case "ms" => Duration.ofMillis(v)
case "seconds" | "second" | "s" => Duration.ofSeconds(v)
case "minutes" | "minute" | "min" | "m" => Duration.ofMinutes(v)
case "hours" | "hour" | "h" => Duration.ofHours(v)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,19 @@ class StringsSuite extends FunSuite {
assertEquals(parseQueryString(query), expected)
}

test("parseDuration, at nanoseconds") {
assertEquals(parseDuration("42ns"), Duration.ofNanos(42L))
}

test("parseDuration, at microseconds") {
assertEquals(parseDuration("42us"), Duration.ofNanos(42_000L))
assertEquals(parseDuration("42μs"), Duration.ofNanos(42_000L))
}

test("parseDuration, at milliseconds") {
assertEquals(parseDuration("42ms"), Duration.ofMillis(42))
}

test("parseDuration, at seconds") {
assertEquals(parseDuration("42seconds"), Duration.ofSeconds(42))
assertEquals(parseDuration("42second"), Duration.ofSeconds(42))
Expand Down
Loading