Skip to content

Commit

Permalink
fixed datetimes in publication_date and extent.temporal of dataset
Browse files Browse the repository at this point in the history
  • Loading branch information
0x6e66 committed Feb 19, 2024
1 parent 74c2313 commit 4800a4c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
14 changes: 4 additions & 10 deletions src/dataset/datasettype.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::metadata::metadatatype;
use crate::{metadata::metadatatype, utils::string_to_datetime};
use chrono::{DateTime, Utc};
use metadatatype::MetaDataType;
use serde_derive::{Deserialize, Serialize};
Expand Down Expand Up @@ -46,7 +46,7 @@ fn get_publication_date(md: &MetaDataType) -> Option<DateTime<Utc>> {
.citation
.date_time
.clone()
.map(|dt| DateTime::parse_from_rfc3339(&dt).ok().map(|dt| dt.to_utc()))
.map(string_to_datetime)
{
None => None,
Some(v) => v.to_owned(),
Expand Down Expand Up @@ -180,14 +180,8 @@ pub struct Temporal {

impl From<metadatatype::Temporal> for Temporal {
fn from(temp: metadatatype::Temporal) -> Self {
let min_date_time: Option<DateTime<Utc>> =
DateTime::parse_from_rfc3339(&temp.min_date_time)
.ok()
.map(|dt| dt.to_utc());
let max_date_time: Option<DateTime<Utc>> =
DateTime::parse_from_rfc3339(&temp.min_date_time)
.ok()
.map(|dt| dt.to_utc());
let min_date_time: Option<DateTime<Utc>> = string_to_datetime(temp.min_date_time);
let max_date_time: Option<DateTime<Utc>> = string_to_datetime(temp.max_date_time);

Self {
min_date_time,
Expand Down
7 changes: 7 additions & 0 deletions src/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
//! utils module

use crate::prelude::*;
use chrono::{DateTime, Utc};
use elasticsearch::{http::transport::Transport, Elasticsearch};

/// crate a client to the pangaea elasticsearch instance
pub fn get_elastic_client() -> Result<Elasticsearch> {
let transport = Transport::single_node("https://ws.pangaea.de/es/pangaea")?;
Ok(Elasticsearch::new(transport))
}

pub fn string_to_datetime(dt: String) -> Option<DateTime<Utc>> {
DateTime::parse_from_rfc3339(format!("{}+01:00", dt).as_str())
.ok()
.map(|dt| dt.to_utc())
}

0 comments on commit 4800a4c

Please sign in to comment.