Skip to content

Commit

Permalink
fixup! feat(services/onedrive): List dir shows metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
erickguan committed Feb 21, 2025
1 parent 99b8767 commit db4c88b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
26 changes: 25 additions & 1 deletion core/src/raw/chrono_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,31 @@ pub fn parse_datetime_from_rfc2822(s: &str) -> Result<DateTime<Utc>> {

/// Parse datetime from rfc3339.
///
/// For example: `2014-11-28T21:00:09+09:00`
/// # Examples
///
/// With a time zone:
///
/// ```
/// use chrono::Datelike;
/// use opendal::Error;
/// use opendal::raw::parse_datetime_from_rfc3339;
///
/// let date_time = parse_datetime_from_rfc3339("2014-11-28T21:00:09+09:00")?;
/// assert_eq!(date_time.date_naive().day(), 28);
/// # Ok::<(), Error>(())
/// ```
///
/// With the UTC offset of 00:00:
///
/// ```
/// use chrono::Timelike;
/// # use opendal::Error;
/// # use opendal::raw::parse_datetime_from_rfc3339;
///
/// let date_time = parse_datetime_from_rfc3339("2014-11-28T21:00:09Z")?;
/// assert_eq!(date_time.hour(), 21);
/// # Ok::<(), Error>(())
/// ```
pub fn parse_datetime_from_rfc3339(s: &str) -> Result<DateTime<Utc>> {
DateTime::parse_from_rfc3339(s)
.map(|v| v.into())
Expand Down
17 changes: 4 additions & 13 deletions core/src/services/onedrive/lister.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

use bytes::Buf;

use chrono::Utc;

use super::backend::OnedriveBackend;
use super::error::parse_error;
use super::graph_model::GraphApiOnedriveListResponse;
Expand Down Expand Up @@ -109,17 +107,10 @@ impl oio::PageList for OnedriveLister {
normalized_path.push('/');
}

let mut meta = Metadata::new(entry_mode)
.with_last_modified(
drive_item
.last_modified_date_time
.parse::<chrono::DateTime<Utc>>()
.map_err(|e| {
Error::new(ErrorKind::Unexpected, "parse last modified time")
.set_source(e)
})?,
)
.with_etag(drive_item.e_tag);
let mut meta = Metadata::new(entry_mode).with_etag(drive_item.e_tag);
let last_modified =
parse_datetime_from_rfc3339(drive_item.last_modified_date_time.as_str())?;
meta.set_last_modified(last_modified);
let content_length = if drive_item.size < 0 {
0
} else {
Expand Down

0 comments on commit db4c88b

Please sign in to comment.