hanbings commented on code in PR #302:
URL: https://github.com/apache/hudi-rs/pull/302#discussion_r2051447821
##########
crates/core/src/table/mod.rs:
##########
@@ -474,6 +481,36 @@ impl Table {
}
}
+/// Formats a timestamp string to `yyyyMMddHHmmSSSSS` format.
+///
+/// The function attempts to parse the input timestamp string (`timestamp`)
into a `DateTime` object.
+/// It first tries parsing the ISO 8601 format, and if that fails, it tries
two other formats: `yyyyMMddHHmmSSSSS`
+/// and `yyyyMMddHHmmSS`. If none of the formats match, it returns the
original input string.
+///
+/// # Arguments
+/// - `timestamp`: The input timestamp string to be formatted.
+///
+/// # Returns
+/// A string formatted as `yyyyMMddHHmmSSSSS`. If the input cannot be parsed,
the original string is returned.
+fn format_timestamp(timestamp: &str) -> String {
+ if let Ok(datetime) = DateTime::parse_from_rfc3339(timestamp) {
+ return datetime.format("%Y%m%d%H%M%S%3f").to_string();
+ }
+
+ let formats = ["yyyyMMddHHmmSSSSS", "yyyyMMddHHmmSS"];
+ for format in formats.iter() {
+ if let Ok(datetime) = DateTime::parse_from_str(timestamp, format) {
+ return datetime.format("%Y%m%d%H%M%S%3f").to_string();
+ }
+ }
+
+ if timestamp.len() == 10 && timestamp.chars().all(|c| c.is_digit(10) || c
== '-') {
Review Comment:
This check is for short time formats like `2019-01-23`. I haven’t come up
with a better way to handle this yet — do you have any suggestions?
--
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]