bziobrowski commented on code in PR #14723:
URL: https://github.com/apache/pinot/pull/14723#discussion_r1900881515
##########
pinot-clients/pinot-jdbc-client/src/main/java/org/apache/pinot/client/utils/DateTimeUtils.java:
##########
@@ -32,48 +35,50 @@ private DateTimeUtils() {
private static final String TIMESTAMP_FORMAT_STR = "yyyy-MM-dd HH:mm:ss";
private static final String DATE_FORMAT_STR = "yyyy-MM-dd";
- private static final SimpleDateFormat DATE_FORMAT = new
SimpleDateFormat(DATE_FORMAT_STR);
- private static final SimpleDateFormat TIMESTAMP_FORMAT = new
SimpleDateFormat(TIMESTAMP_FORMAT_STR);
+ private static final DateTimeFormatter DATE_FORMATTER =
DateTimeFormatter.ofPattern(DATE_FORMAT_STR);
+ private static final DateTimeFormatter TIMESTAMP_FORMATTER =
DateTimeFormatter.ofPattern(TIMESTAMP_FORMAT_STR);
- public static Date getDateFromString(String value, Calendar cal)
- throws ParseException {
- DATE_FORMAT.setTimeZone(cal.getTimeZone());
- java.util.Date date = DATE_FORMAT.parse(value);
- Date sqlDate = new Date(date.getTime());
- return sqlDate;
+ public static Date getDateFromString(String value, Calendar cal) {
+ // Parse the input string to a LocalDate
+ LocalDate localDate = LocalDate.parse(value, DATE_FORMATTER);
+
+ // Convert LocalDate to a java.sql.Date, using the Calendar's time zone
+ ZoneId zoneId = cal.getTimeZone().toZoneId();
+ return new Date(localDate.atStartOfDay(zoneId).toInstant().toEpochMilli());
Review Comment:
That'd require using joda-time AFAIK, e.g.
```java
DateTimeFormatter formatter = ..
// or formatter.parseInto(mdt, value, 0) if mdt is thread-local
MutableDateTime mdt = formatter.parseMutableDateTime(value);
mdt.setZone(zone);
mdt.hourOfDay().roundFloor();
return new Date(_dateTime.getMillis());
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]