From e8115aef59119e40d0ec187f102481bedd688feb Mon Sep 17 00:00:00 2001 From: Nico Mandery Date: Wed, 12 Feb 2020 19:31:59 +0100 Subject: [PATCH] feature gate for datetime support --- src/vector/feature.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/vector/feature.rs b/src/vector/feature.rs index c41fb6bd..798fb3c1 100644 --- a/src/vector/feature.rs +++ b/src/vector/feature.rs @@ -5,6 +5,8 @@ use utils::{_string, _last_null_pointer_err}; use gdal_sys::{self, OGRErr, OGRFeatureH, OGRFieldType}; use vector::geometry::Geometry; use vector::layer::Layer; + +#[cfg(feature = "datetime")] use chrono::{Date, FixedOffset, DateTime, TimeZone, Datelike, Timelike}; use errors::*; @@ -66,9 +68,11 @@ impl<'a> Feature<'a> { let rv = unsafe { gdal_sys::OGR_F_GetFieldAsInteger(self.c_feature, field_id) }; Ok(FieldValue::IntegerValue(rv as i32)) }, + #[cfg(feature = "datetime")] OGRFieldType::OFTDateTime => { Ok(FieldValue::DateTimeValue(self.get_field_datetime(field_id)?)) }, + #[cfg(feature = "datetime")] OGRFieldType::OFTDate => { Ok(FieldValue::DateValue(self.get_field_datetime(field_id)?.date())) }, @@ -76,6 +80,7 @@ impl<'a> Feature<'a> { } } + #[cfg(feature = "datetime")] fn get_field_datetime(&self, field_id: c_int) -> Result> { let mut year: c_int = 0; let mut month: c_int = 0; @@ -179,6 +184,7 @@ impl<'a> Feature<'a> { Ok(()) } + #[cfg(feature = "datetime")] pub fn set_field_datetime(&self, field_name: &str, value: DateTime) -> Result<()> { let c_str_field_name = CString::new(field_name)?; let idx = unsafe { gdal_sys::OGR_F_GetFieldIndex(self.c_feature, c_str_field_name.as_ptr())}; @@ -207,7 +213,11 @@ impl<'a> Feature<'a> { FieldValue::RealValue(value) => self.set_field_double(field_name, value), FieldValue::StringValue(ref value) => self.set_field_string(field_name, value.as_str()), FieldValue::IntegerValue(value) => self.set_field_integer(field_name, value), + + #[cfg(feature = "datetime")] FieldValue::DateTimeValue(value) => self.set_field_datetime(field_name, value), + + #[cfg(feature = "datetime")] FieldValue::DateValue(value) => self.set_field_datetime(field_name, value.and_hms(0, 0, 0)), } } @@ -233,7 +243,12 @@ pub enum FieldValue { IntegerValue(i32), StringValue(String), RealValue(f64), + + #[cfg(feature = "datetime")] DateValue(Date), + + + #[cfg(feature = "datetime")] DateTimeValue(DateTime), } @@ -264,6 +279,7 @@ impl FieldValue { } /// Interpret the value as `Date`. + #[cfg(feature = "datetime")] pub fn into_date(self) -> Option> { match self { FieldValue::DateValue(rv) => Some(rv), @@ -273,6 +289,7 @@ impl FieldValue { } /// Interpret the value as `DateTime`. + #[cfg(feature = "datetime")] pub fn into_datetime(self) -> Option> { match self { FieldValue::DateTimeValue(rv) => Some(rv),