Skip to content

Commit

Permalink
Fixed issue with dateutils return seconds instead of milliseconds epoch
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt B Krystof committed Sep 5, 2024
1 parent 432ef6a commit a68f9a8
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,22 @@ object DateUtils {

private const val DATE_FORMAT = "yyyyMMdd'T'HHmmss'Z'"

private val dateFormat = FastDateFormat.getInstance(DATE_FORMAT)

/**
* Get the epoch time from a string provided.
*
* @param dateStr String
* @param fieldName String
* @return Long
* @return Long - Epoch time in milliseconds
* @throws BadRequestException
*/
@Throws(BadRequestException::class)
fun getEpochFromDateString(dateStr: String, fieldName: String): Long {
try {
var dateFormat = FastDateFormat.getInstance(DATE_FORMAT)
// Parse the date string to a Date object
val date = dateFormat.parse(dateStr)
return date.time // time with millisecs
return date.time
} catch (e: ParseException) {
throw BadRequestException("Failed to parse $fieldName: $dateStr. Format should be: ${DATE_FORMAT}.")
}
Expand Down

0 comments on commit a68f9a8

Please sign in to comment.