-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ajudst ogr time type to json format #988
Open
michaelmattig
wants to merge
5
commits into
main
Choose a base branch
from
ogr-dataset
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+240
−5
Open
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
74021da
ajudst ogr time type to json format
michaelmattig a7064de
list layers for files in volume
michaelmattig 28a9f22
clean up code
michaelmattig c2418df
add test for listing volume file layers
michaelmattig a5236a9
fix fmt
michaelmattig File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -7,6 +7,7 @@ use ordered_float::NotNan; | |||
use postgres_types::{FromSql, ToSql}; | ||||
use serde::{de::Visitor, Deserialize, Deserializer, Serialize, Serializer}; | ||||
use snafu::ResultExt; | ||||
use std::collections::HashSet; | ||||
use std::{ | ||||
collections::{BTreeMap, HashMap}, | ||||
fmt::{Debug, Formatter}, | ||||
|
@@ -1719,13 +1720,122 @@ impl From<RasterPropertiesEntryType> for geoengine_datatypes::raster::RasterProp | |||
} | ||||
} | ||||
|
||||
#[derive(Serialize, Deserialize, PartialEq, Eq, Clone, Debug, ToSchema)] | ||||
#[derive(PartialEq, Eq, Clone, Debug)] | ||||
pub struct DateTimeParseFormat { | ||||
fmt: String, | ||||
has_tz: bool, | ||||
has_time: bool, | ||||
} | ||||
|
||||
enum FormatStrLoopState { | ||||
Normal, | ||||
Percent(String), | ||||
} | ||||
|
||||
impl DateTimeParseFormat { | ||||
pub fn custom(fmt: String) -> Self { | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks rather complicated. Maybe test it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually I just copied the code from datatypes:
and there it actually is tested. Should I maybe just use that method and then implement From/Into? But then parsing changes in datatypes would reflect in api... so maybe just copy the test as well? |
||||
let (has_tz, has_time) = { | ||||
let mut has_tz = false; | ||||
let mut has_time = false; | ||||
|
||||
let has_tz_values: HashSet<&str> = ["%Z", "%z", "%:z"].into(); | ||||
let has_time_values: HashSet<&str> = | ||||
["%a", "%A", "%M", "%p", "%S", "%X", "%H", "%I"].into(); | ||||
|
||||
let mut state = FormatStrLoopState::Normal; | ||||
|
||||
for c in fmt.chars() { | ||||
match state { | ||||
FormatStrLoopState::Normal => { | ||||
if c == '%' { | ||||
state = FormatStrLoopState::Percent("%".to_string()); | ||||
} | ||||
} | ||||
FormatStrLoopState::Percent(ref mut s) => { | ||||
s.push(c); | ||||
|
||||
if c == '%' { | ||||
// was escaped percentage | ||||
state = FormatStrLoopState::Normal; | ||||
} else if c.is_ascii_alphabetic() { | ||||
if has_tz_values.contains(s.as_str()) { | ||||
has_tz = true; | ||||
} | ||||
if has_time_values.contains(s.as_str()) { | ||||
has_time = true; | ||||
} | ||||
|
||||
state = FormatStrLoopState::Normal; | ||||
} | ||||
} | ||||
} | ||||
} | ||||
|
||||
(has_tz, has_time) | ||||
}; | ||||
|
||||
DateTimeParseFormat { | ||||
fmt, | ||||
has_tz, | ||||
has_time, | ||||
} | ||||
} | ||||
|
||||
pub fn ymd() -> Self { | ||||
let fmt = "%Y-%m-%d".to_owned(); | ||||
Self { | ||||
fmt, | ||||
has_tz: false, | ||||
has_time: false, | ||||
} | ||||
} | ||||
|
||||
pub fn has_tz(&self) -> bool { | ||||
self.has_tz | ||||
} | ||||
|
||||
pub fn has_time(&self) -> bool { | ||||
self.has_time | ||||
} | ||||
|
||||
pub fn is_empty(&self) -> bool { | ||||
self.fmt.is_empty() | ||||
} | ||||
|
||||
pub fn _to_parse_format(&self) -> &str { | ||||
&self.fmt | ||||
} | ||||
} | ||||
|
||||
impl<'a> ToSchema<'a> for DateTimeParseFormat { | ||||
fn schema() -> (&'a str, utoipa::openapi::RefOr<utoipa::openapi::Schema>) { | ||||
use utoipa::openapi::*; | ||||
( | ||||
"DateTimeParseFormat", | ||||
ObjectBuilder::new().schema_type(SchemaType::String).into(), | ||||
) | ||||
} | ||||
} | ||||
|
||||
impl<'de> Deserialize<'de> for DateTimeParseFormat { | ||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> | ||||
where | ||||
D: serde::Deserializer<'de>, | ||||
{ | ||||
let s = String::deserialize(deserializer)?; | ||||
Ok(Self::custom(s)) | ||||
} | ||||
} | ||||
|
||||
impl Serialize for DateTimeParseFormat { | ||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> | ||||
where | ||||
S: serde::Serializer, | ||||
{ | ||||
serializer.serialize_str(&self.fmt) | ||||
} | ||||
} | ||||
|
||||
impl From<geoengine_datatypes::primitives::DateTimeParseFormat> for DateTimeParseFormat { | ||||
fn from(value: geoengine_datatypes::primitives::DateTimeParseFormat) -> Self { | ||||
Self { | ||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add one success case test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
c2418df