Skip to content

Commit

Permalink
fix: datatime millis (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengjiachun authored Jan 31, 2024
1 parent b47085f commit 158d378
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 4 additions & 6 deletions ingester-protocol/src/main/java/io/greptime/models/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,17 @@ static int getDateValue(Object value) {
return (int) getLongValue(value);
}

static int getDateTimeValue(Object value) {
static long getDateTimeValue(Object value) {
if (value instanceof Instant) {
long epochSecond = ((Instant) value).getEpochSecond();
return (int) epochSecond;
return ((Instant) value).toEpochMilli();
}

if (value instanceof Date) {
Instant instant = ((Date) value).toInstant();
long epochSecond = instant.getEpochSecond();
return (int) epochSecond;
return instant.toEpochMilli();
}

return (int) getLongValue(value);
return getLongValue(value);
}

static Common.IntervalMonthDayNano getIntervalMonthDayNanoValue(Object value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ public void testGetDateTimeValue() {
TimeZone gmtTimeZone = TimeZone.getTimeZone("GMT");
cal.setTimeZone(gmtTimeZone);
cal.set(1970, Calendar.JANUARY, 2, 0, 0, 0);
Assert.assertEquals(86400, Util.getDateTimeValue(cal.getTime()));
Assert.assertEquals(86400, Util.getDateTimeValue(Instant.ofEpochSecond(86400)));
cal.set(Calendar.MILLISECOND, 111);
Assert.assertEquals(86400111, Util.getDateTimeValue(cal.getTime()));
Assert.assertEquals(86400111, Util.getDateTimeValue(cal.getTime().toInstant()));
Assert.assertEquals(86400000, Util.getDateTimeValue(Instant.ofEpochSecond(86400)));
Assert.assertEquals(86400, Util.getDateTimeValue(86400));
}

Expand Down

0 comments on commit 158d378

Please sign in to comment.