Skip to content

Commit c541a5e

Browse files
authored
feat: TimeRange: deserialize time as long (#769)
| Q | A | ----------------- | ---------- | Bug fix? | no | New feature? | no <!-- please update the /CHANGELOG.md file --> | BC breaks? | no | Related Issue | | Need Doc update | no ## Describe your change Homogenize JSON deserialization of TimeRange with serialization, using `long` for timestamps. ## What problem is this fixing? Some customers build rules with an end date very far away in the future, which cannot be captured as number of seconds from epoch with an int.
1 parent f7432af commit c541a5e

File tree

1 file changed

+2
-2
lines changed
  • algoliasearch-core/src/main/java/com/algolia/search/models/rules

1 file changed

+2
-2
lines changed

algoliasearch-core/src/main/java/com/algolia/search/models/rules/TimeRange.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ class TimeRangeDeserializer extends JsonDeserializer<TimeRange> {
6767
public TimeRange deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
6868
JsonNode node = p.getCodec().readTree(p);
6969
// 'from' unix timestamp
70-
int fromTimestamp = (Integer) node.get("from").numberValue();
70+
long fromTimestamp = node.get("from").asLong();
7171
Instant fromInstant = Instant.ofEpochSecond(fromTimestamp);
7272
OffsetDateTime from = OffsetDateTime.ofInstant(fromInstant, ZoneOffset.UTC);
7373
// 'until' unix timestamp
74-
int untilTimestamp = (Integer) node.get("until").numberValue();
74+
long untilTimestamp = node.get("until").asLong();
7575
Instant untilInstant = Instant.ofEpochSecond(untilTimestamp);
7676
OffsetDateTime until = OffsetDateTime.ofInstant(untilInstant, ZoneOffset.UTC);
7777
return new TimeRange(from, until);

0 commit comments

Comments
 (0)