Skip to content

Commit

Permalink
[FSTORE-1294] Set Java dateformat to 24h clock in Filter (#1733) (#1510)
Browse files Browse the repository at this point in the history
Co-authored-by: davitbzh <[email protected]>
  • Loading branch information
robzor92 and davitbzh authored Mar 18, 2024
1 parent b053fff commit 283e3d4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.TimeZone;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand All @@ -73,7 +74,7 @@ public class FilterController {
private FeaturegroupController featuregroupController;
private ObjectMapper objectMapper = new ObjectMapper();
private DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
private DateFormat timestampFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
private DateFormat timestampFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

public FilterController() {
}
Expand Down Expand Up @@ -125,6 +126,7 @@ public FilterLogic convertFilterLogic(FilterLogicDTO filterLogicDTO,

public String convertToEventTimeFeatureValue(Feature feature, Date date) throws FeaturestoreException {
String timeType = feature.getType();
timestampFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
if ("date".equals(timeType)) {
return dateFormat.format(date);
} else if ("timestamp".equals(timeType)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,7 @@
import org.junit.Test;
import org.junit.rules.ExpectedException;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;

public class TestFilterController {

Expand Down Expand Up @@ -623,4 +619,19 @@ public void testGetSQLNodeOther() throws Exception {
result = node.toSqlString(new HiveSqlDialect(SqlDialect.EMPTY_CONTEXT)).getSql();
Assert.assertEquals(expected, result);
}

@Test
public void testConvertToEventTimeFeatureValue() throws Exception {
Feature feature = new Feature("fg1_pk", "fg1", "timestamp",true, null,
"prefix2_", fg1);
Date dateWithHandS = new Date(1710442079000L);
String expectedHandS = "2024-03-14 18:47:59";
String resultHandS = filterController.convertToEventTimeFeatureValue(feature, dateWithHandS);
Assert.assertEquals(resultHandS, expectedHandS);

Date date = new Date(1710374400000L);
String expected = "2024-03-14 00:00:00";
String result = filterController.convertToEventTimeFeatureValue(feature, date);
Assert.assertEquals(expected, result);
}
}

0 comments on commit 283e3d4

Please sign in to comment.