From 00b1961e278b2774dab33c7bd3f79ecda7e15870 Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Fri, 23 Jun 2023 16:41:09 -0500 Subject: [PATCH] fix: sourceplusplus/sourceplusplus#1071 --- .../spp/protocol/artifact/metrics/MetricStep.kt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main/kotlin/spp/protocol/artifact/metrics/MetricStep.kt b/src/main/kotlin/spp/protocol/artifact/metrics/MetricStep.kt index 41b48bad..293f2992 100644 --- a/src/main/kotlin/spp/protocol/artifact/metrics/MetricStep.kt +++ b/src/main/kotlin/spp/protocol/artifact/metrics/MetricStep.kt @@ -70,4 +70,17 @@ enum class MetricStep { } return Instant.from(formatter.parse(value)) } + + companion object { + fun fromBucketFormat(value: String): MetricStep { + return values().firstOrNull { + try { + it.bucketFormatter.parse(value) + true + } catch (ignore: Exception) { + false + } + } ?: throw IllegalArgumentException("Invalid date time format: $value") + } + } }