Skip to content

Commit

Permalink
Sanketika-Obsrv/issue-tracker#107:fix: Setting default timezone value…
Browse files Browse the repository at this point in the history
… in the dynamic router job when there is no timezone is defined
  • Loading branch information
manjudr committed Mar 27, 2024
1 parent cc17970 commit 61e8431
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,8 @@ object TimestampKeyParser {
}

private def addTimeZone(datasetConfig: DatasetConfig, dateTime: DateTime): Long = {
if (datasetConfig.datasetTimezone.isDefined) {
val tz = DateTimeZone.forTimeZone(TimeZone.getTimeZone(datasetConfig.datasetTimezone.get))
val tz = DateTimeZone.forTimeZone(TimeZone.getTimeZone(datasetConfig.datasetTimezone.getOrElse("UTC"))) // TODO - Read from the system setting table for the default timezone
val offsetInMilliseconds = tz.getOffset(dateTime)
dateTime.plusMillis(offsetInMilliseconds).getMillis
} else {
dateTime.getMillis
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class TestTimestampKeyParser extends FlatSpec with Matchers {
DatasetConfig(key = "id", tsKey = "date", entryTopic = "ingest", excludeFields = None, redisDBHost = None, redisDBPort = None, redisDB = None, indexData = None, tsFormat = None, datasetTimezone = None),
JSONUtil.deserialize[mutable.Map[String, AnyRef]]("""{"id":1234, "date":1701373165}"""))
result4.isValid should be(true)
result4.value.asInstanceOf[Long] should be(1701373165000l)
result4.value.asInstanceOf[Long] should be(1701373165000L)

// Validate number date field which is epoch in milli-seconds
val result5 = TimestampKeyParser.parseTimestampKey(
Expand Down Expand Up @@ -97,7 +97,7 @@ class TestTimestampKeyParser extends FlatSpec with Matchers {
DatasetConfig(key = "id", tsKey = "date", entryTopic = "ingest", excludeFields = None, redisDBHost = None, redisDBPort = None, redisDB = None, indexData = None, tsFormat = Some("yyyy-MM-dd"), datasetTimezone = None),
JSONUtil.deserialize[mutable.Map[String, AnyRef]]("""{"id":1234, "date":"2023-03-01"}"""))
result3.isValid should be(true)
result3.value.asInstanceOf[Long] should be(1677609000000l)
result3.value.asInstanceOf[Long] should be(1677609000000L)

// Validate date parser with timezone
val result4 = TimestampKeyParser.parseTimestampKey(
Expand Down

0 comments on commit 61e8431

Please sign in to comment.