tustvold commented on code in PR #5078:
URL: https://github.com/apache/arrow-rs/pull/5078#discussion_r1394272576


##########
arrow-cast/src/parse.rs:
##########
@@ -560,7 +572,32 @@ fn parse_date(string: &str) -> Option<NaiveDate> {
     const HYPHEN: u8 = b'-'.wrapping_sub(b'0');
 
     if digits[4] != HYPHEN {
-        return None;
+        // In this case, the string may be type "yymmdd" or "yyyymmdd", so we 
should check it
+        if string.len() != 6 && string.len() != 8 {
+            return None;
+        }
+        for ch in string.bytes() {
+            if ch < b'0' || ch > b'9' {
+                return None;
+            }
+        }
+        let (year, month, day) = match string.len() {
+            6 => (
+                parse_two_digit_year(digits[0] as i32 * 10 + digits[1] as i32) 
as u16,
+                digits[2] * 10 + digits[3],
+                digits[4] * 10 + digits[5],
+            ),
+            8 => (
+                digits[0] as u16 * 1000
+                    + digits[1] as u16 * 100
+                    + digits[2] as u16 * 10
+                    + digits[3] as u16,
+                digits[4] * 10 + digits[5],
+                digits[6] * 10 + digits[7],
+            ),
+            _ => return None,
+        };

Review Comment:
   ```suggestion
           let (year, month, day) = match (mask, string.len()) {
               (0b111111, 6) => (
                   parse_two_digit_year(digits[0] as i32 * 10 + digits[1] as 
i32) as u16,
                   digits[2] * 10 + digits[3],
                   digits[4] * 10 + digits[5],
               ),
               (0b11111111, 8) => (
                   digits[0] as u16 * 1000
                       + digits[1] as u16 * 100
                       + digits[2] as u16 * 10
                       + digits[3] as u16,
                   digits[4] * 10 + digits[5],
                   digits[6] * 10 + digits[7],
               ),
               _ => return None,
           };
   ```



-- 
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]

Reply via email to