Skip to content

Commit

Permalink
removed DateTimeFromatter
Browse files Browse the repository at this point in the history
Signed-off-by: Ronnak Saxena <ronsax@amazon.com>
  • Loading branch information
ronnaksaxena committed Aug 31, 2023
1 parent 22edaa5 commit 9ad89c6
Showing 1 changed file with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ import org.opensearch.search.builder.SearchSourceBuilder
import java.time.LocalDateTime
import java.time.ZoneOffset
import java.time.ZonedDateTime
import java.time.format.DateTimeFormatter

const val DATE_FIELD_STRICT_DATE_OPTIONAL_TIME_FORMAT = "strict_date_optional_time"
const val DATE_FIELD_EPOCH_MILLIS_FORMAT = "epoch_millis"
Expand Down Expand Up @@ -504,11 +503,21 @@ fun SearchSourceBuilder.changeAggregations(aggregationBuilderCollection: Collect
}

fun convertDateStringToEpochMillis(dateString: String): Long {
val pattern = "yyyy-MM-dd HH:mm:ss"
val formatter = DateTimeFormatter.ofPattern(pattern)
val localDateTime = LocalDateTime.parse(dateString, formatter)
val epochMillis = localDateTime.toInstant(ZoneOffset.UTC).toEpochMilli()
return epochMillis
val parts = dateString.split(" ")
val dateParts = parts[0].split("-")
val timeParts = parts[1].split(":")

val year = dateParts[0].toInt()
val month = dateParts[1].toInt()
val day = dateParts[2].toInt()

val hour = timeParts[0].toInt()
val minute = timeParts[1].toInt()
val second = timeParts[2].toInt()

val localDateTime = LocalDateTime.of(year, month, day, hour, minute, second)
val instant = localDateTime.toInstant(ZoneOffset.UTC)
return instant.toEpochMilli()
}
@Suppress("MagicNumber")
fun convertFixedIntervalStringToMs(fixedInterval: String): Long {
Expand Down

0 comments on commit 9ad89c6

Please sign in to comment.