Russell Sayers created KAFKA-10685:
--------------------------------------

             Summary: --to-datetime passed to kafka-consumer-groups getting 
interpreted as a timezone
                 Key: KAFKA-10685
                 URL: https://issues.apache.org/jira/browse/KAFKA-10685
             Project: Kafka
          Issue Type: Bug
    Affects Versions: 2.7.0
            Reporter: Russell Sayers


If you pass more than 3 decimal places for the fractional seconds of the 
datetime, the microseconds get interpreted as milliseconds.

{{kafka-consumer-groups --bootstrap-server kafka:9092 \}}
{{ --reset-offsets \}}
{{ --group webserver-avro \}}
{{ --topic driver-positions-avro \}}
{{ --to-datetime "2020-11-05T00:46:48.002237400" \}}
{{ --dry-run}}

Relevant code 
[here|https://github.com/apache/kafka/blob/2.7/clients/src/main/java/org/apache/kafka/common/utils/Utils.java#L1304].

Experimenting with getDateTime:
 * getDateTime("2020-11-05T00:46:48.000") -> 1604537208000
 * getDateTime("2020-11-05T00:46:48.000+0800") -> 1604508408000 - correct the 
formatting string allows for ZZZ timezones
 * getDateTime("2020-11-05T00:46:48.000123") -> 1604537208123 - note this ends 
with 123 milliseconds.

The pattern string is "yyyy-MM-dd'T'HH:mm:ss.SSS".  So SimpleDateFormat 
interprets "000123" as 123 milliseconds. See the stackoverflow answer 
[here|https://stackoverflow.com/a/21235602/109102].

The fix?  Remove any digits after more than 3 characters after the decimal 
point, or raise an exception. The code would still need to allow the RFC822 
timezone, i.e Sign TwoDigitHours Minutes.

 



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to