Skip to content

Commit

Permalink
feat: add common metadata fields
Browse files Browse the repository at this point in the history
  • Loading branch information
gadomski committed Oct 18, 2023
1 parent d1c2d57 commit bfa9c2c
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
1 change: 1 addition & 0 deletions stac/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
### Added

- `Item.intersects` ([#202](https://github.com/stac-utils/stac-rs/pull/202))
- Common metadata fields ([#203](https://github.com/stac-utils/stac-rs/pull/203))

### Removed

Expand Down
22 changes: 22 additions & 0 deletions stac/src/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,26 @@ pub struct Asset {
#[serde(skip_serializing_if = "Option::is_none")]
pub roles: Option<Vec<String>>,

/// Creation date and time of the corresponding data, in UTC.
///
/// This identifies the creation time of the data.
///
/// This is a [common
/// metadata](https://github.com/radiantearth/stac-spec/blob/master/item-spec/common-metadata.md)
/// field.
#[serde(skip_serializing_if = "Option::is_none")]
pub created: Option<String>,

/// Date and time the metadata was updated last, in UTC.
///
/// This identifies the updated time of the data.
///
/// This is a [common
/// metadata](https://github.com/radiantearth/stac-spec/blob/master/item-spec/common-metadata.md)
/// field.
#[serde(skip_serializing_if = "Option::is_none")]
pub updated: Option<String>,

/// Additional fields on the asset.
#[serde(flatten)]
pub additional_fields: Map<String, Value>,
Expand Down Expand Up @@ -84,6 +104,8 @@ impl Asset {
description: None,
r#type: None,
roles: None,
created: None,
updated: None,
additional_fields: Map::new(),
}
}
Expand Down
64 changes: 64 additions & 0 deletions stac/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,64 @@ pub struct Properties {
/// requires `start_datetime` and `end_datetime` from common metadata to be set.
pub datetime: Option<String>,

/// The first or start date and time for the Item, in UTC.
///
/// It is formatted as date-time according to RFC 3339, section 5.6.
///
/// This is a [common
/// metadata](https://github.com/radiantearth/stac-spec/blob/master/item-spec/common-metadata.md)
/// field.
#[serde(skip_serializing_if = "Option::is_none")]
pub start_datetime: Option<String>,

/// The last or end date and time for the Item, in UTC.
///
/// It is formatted as date-time according to RFC 3339, section 5.6.
///
/// This is a [common
/// metadata](https://github.com/radiantearth/stac-spec/blob/master/item-spec/common-metadata.md)
/// field.
#[serde(skip_serializing_if = "Option::is_none")]
pub end_datetime: Option<String>,

/// A human readable title describing the Item.
///
/// This is a [common
/// metadata](https://github.com/radiantearth/stac-spec/blob/master/item-spec/common-metadata.md)
/// field.
#[serde(skip_serializing_if = "Option::is_none")]
pub title: Option<String>,

/// Detailed multi-line description to fully explain the Item.
///
/// CommonMark 0.29 syntax MAY be used for rich text representation.
///
/// This is a [common
/// metadata](https://github.com/radiantearth/stac-spec/blob/master/item-spec/common-metadata.md)
/// field.
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,

/// Creation date and time of the corresponding data, in UTC.
///
/// This identifies the creation time of the metadata.
///
/// This is a [common
/// metadata](https://github.com/radiantearth/stac-spec/blob/master/item-spec/common-metadata.md)
/// field.
#[serde(skip_serializing_if = "Option::is_none")]
pub created: Option<String>,

/// Date and time the metadata was updated last, in UTC.
///
/// This identifies the updated time of the metadata.
///
/// This is a [common
/// metadata](https://github.com/radiantearth/stac-spec/blob/master/item-spec/common-metadata.md)
/// field.
#[serde(skip_serializing_if = "Option::is_none")]
pub updated: Option<String>,

/// Additional fields on the properties.
#[serde(flatten)]
pub additional_fields: Map<String, Value>,
Expand All @@ -114,6 +172,12 @@ impl Default for Properties {
fn default() -> Properties {
Properties {
datetime: Some(Utc::now().to_rfc3339()),
start_datetime: None,
end_datetime: None,
title: None,
description: None,
created: None,
updated: None,
additional_fields: Map::new(),
}
}
Expand Down

0 comments on commit bfa9c2c

Please sign in to comment.