#[cfg(any(feature = "admin-osm", feature = "tz-ned", feature = "tz-osm"))]
use serde::{Deserialize, Serialize};
#[cfg(feature = "web")]
use utoipa::ToSchema;
#[cfg(feature = "admin-osm")]
use rtz_core::geo::admin::osm::OsmAdmin;
#[cfg(feature = "tz-ned")]
use rtz_core::geo::tz::ned::NedTimezone;
#[cfg(feature = "tz-osm")]
use rtz_core::geo::tz::osm::OsmTimezone;
#[cfg(feature = "tz-ned")]
#[derive(Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "web", derive(ToSchema))]
#[serde(rename_all = "camelCase")]
pub struct NedTimezoneResponse1 {
pub id: usize,
pub identifier: Option<&'static str>,
pub description: &'static str,
pub dst_description: Option<&'static str>,
pub offset: &'static str,
pub zone: f32,
pub raw_offset: i32,
}
#[cfg(feature = "tz-ned")]
impl From<&'static NedTimezone> for NedTimezoneResponse1 {
fn from(value: &'static NedTimezone) -> NedTimezoneResponse1 {
NedTimezoneResponse1 {
id: value.id,
identifier: value.identifier.as_deref(),
description: value.description.as_ref(),
dst_description: value.dst_description.as_deref(),
offset: value.offset.as_ref(),
zone: value.zone,
raw_offset: value.raw_offset,
}
}
}
#[cfg(feature = "tz-osm")]
#[derive(Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "web", derive(ToSchema))]
#[serde(rename_all = "camelCase")]
pub struct OsmTimezoneResponse1 {
pub id: usize,
pub identifier: &'static str,
pub short_identifier: String,
pub offset: String,
pub raw_offset: i32,
pub raw_base_offset: i32,
pub raw_dst_offset: i32,
pub zone: f32,
pub current_time: String,
}
#[cfg(feature = "tz-osm")]
impl From<&'static OsmTimezone> for OsmTimezoneResponse1 {
fn from(value: &'static OsmTimezone) -> OsmTimezoneResponse1 {
use chrono::{Offset, Utc};
use chrono_tz::{OffsetComponents, Tz};
let tz: Tz = value.identifier.parse().unwrap();
let time = Utc::now().with_timezone(&tz);
let tz_offset = time.offset();
let fixed_offset = tz_offset.fix();
let short_identifier = tz_offset.to_string();
let offset = format!("UTC{}", fixed_offset);
let raw_offset = fixed_offset.local_minus_utc();
let raw_base_offset = tz_offset.base_utc_offset().num_seconds() as i32;
let raw_dst_offset = tz_offset.dst_offset().num_seconds() as i32;
let zone = raw_offset as f32 / 3600.0;
let current_time = time.to_rfc3339();
OsmTimezoneResponse1 {
id: value.id,
identifier: value.identifier.as_ref(),
short_identifier,
offset,
raw_offset,
raw_base_offset,
raw_dst_offset,
zone,
current_time,
}
}
}
#[cfg(feature = "admin-osm")]
#[derive(Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "web", derive(ToSchema))]
#[serde(rename_all = "camelCase")]
pub struct OsmAdminResponse1 {
pub id: usize,
pub name: &'static str,
pub level: usize,
}
#[cfg(feature = "admin-osm")]
impl From<&'static OsmAdmin> for OsmAdminResponse1 {
fn from(value: &'static OsmAdmin) -> OsmAdminResponse1 {
OsmAdminResponse1 {
id: value.id,
name: value.name.as_ref(),
level: value.level,
}
}
}