alamb commented on code in PR #12345:
URL: https://github.com/apache/arrow-rs/pull/12345#discussion_r4635697176


##########
parquet/src/record/api.rs:
##########
@@ -922,32 +921,60 @@ impl fmt::Display for Field {
 
 /// Helper method to convert Parquet date into a string.
 /// Input `value` is a number of days since the epoch in UTC.
-/// Date is displayed in local timezone.
+/// Date is displayed in UTC timezone.
 #[inline]
 fn convert_date_to_string(value: i32) -> String {
-    static NUM_SECONDS_IN_DAY: i64 = 60 * 60 * 24;
-    let dt = Utc
-        .timestamp_opt(value as i64 * NUM_SECONDS_IN_DAY, 0)
-        .unwrap();
-    format!("{}", dt.format("%Y-%m-%d"))
+    format_date(value as i64)
 }
 
 /// Helper method to convert Parquet timestamp into a string.
 /// Input `value` is a number of milliseconds since the epoch in UTC.
 /// Datetime is displayed in UTC timezone.
 #[inline]
 fn convert_timestamp_millis_to_string(value: i64) -> String {
-    let dt = Utc.timestamp_millis_opt(value).unwrap();
-    format!("{}", dt.format("%Y-%m-%d %H:%M:%S%.3f %:z"))
+    let (secs, millis) = (value.div_euclid(1_000), value.rem_euclid(1_000));
+    format!("{}.{millis:03} +00:00", format_datetime(secs))
 }
 
 /// Helper method to convert Parquet timestamp into a string.
 /// Input `value` is a number of microseconds since the epoch in UTC.
 /// Datetime is displayed in UTC timezone.
 #[inline]
 fn convert_timestamp_micros_to_string(value: i64) -> String {
-    let dt = Utc.timestamp_micros(value).unwrap();
-    format!("{}", dt.format("%Y-%m-%d %H:%M:%S%.6f %:z"))
+    let (secs, micros) = (value.div_euclid(1_000_000), 
value.rem_euclid(1_000_000));
+    format!("{}.{micros:06} +00:00", format_datetime(secs))
+}
+
+/// Formats seconds since the epoch as `YYYY-MM-DD hh:mm:ss` in UTC.
+fn format_datetime(secs: i64) -> String {
+    let time = secs.rem_euclid(86_400);
+    format!(
+        "{} {:02}:{:02}:{:02}",
+        format_date(secs.div_euclid(86_400)),
+        time / 3_600,
+        time / 60 % 60,
+        time % 60
+    )
+}
+
+/// Formats days since the epoch as a proleptic Gregorian `YYYY-MM-DD` date. 
Years
+/// outside 0..=9999 are signed, as in ISO 8601 and chrono's `%Y`.
+fn format_date(days: i64) -> String {

Review Comment:
   I am a little worried about having custom date formatting code in the 
parquet crate if we can avoid it
   
   Is there precident for doing this elsewhere in this repo? Can you link to 
the corresponding code in chrono to show it is equivalent to this?
   
   



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