1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
use chrono::{DateTime, Utc};
use crate::client::GoogleMapsClient;
use crate::types::LatLng;
use crate::time_zone::request::Request;
// =============================================================================
impl<'a> Request<'a> {
// -------------------------------------------------------------------------
//
/// Initializes the builder pattern for a Time Zone API query with the
/// required, non-optional parameters.
///
/// ## Arguments:
///
/// * `client` ‧ Your application's Google Maps API client struct.
/// * `location` ‧ Latitude & longitude of the desired time zone location.
/// * `timestamp` ‧ Time is used to determine if Daylight Savings is
/// applicable.
///
/// ## Example:
///
/// ```rust
/// use google_maps::prelude::TimeZoneRequest;
/// use google_maps::{LatLng, NaiveDate};
///
/// let time_zone = TimeZoneRequest::new(
/// &my_settings,
/// // St. Vitus Cathedral in Prague, Czechia
/// LatLng::try_from_dec(50.090_903, 14.400_512)?,
/// // Tuesday February 15, 2022 @ 6:00:00 pm
/// NaiveDate::from_ymd(2022, 2, 15).and_hms(18, 00, 0)
/// ).execute();
/// ```
pub fn new(
client: &GoogleMapsClient,
location: LatLng,
timestamp: DateTime<Utc>,
) -> Request {
// Instantiate struct and return it to caller:
Request {
// Required parameters:
client,
location,
timestamp,
// Optional parameters:
language: None,
// Internal use only:
query: None,
} // struct
} // fn
// -------------------------------------------------------------------------
//
/// Initializes the builder pattern for a Time Zone API query with the
/// required, non-optional parameters.
///
/// This function is the same as `new` but it supports
/// the [geo](https://crates.io/crates/geo) crate's
/// [Coord](https://docs.rs/geo/latest/geo/geometry/struct.Coord.html) type.
///
/// ## Arguments:
///
/// * `client` ‧ Your application's Google Maps API client struct.
/// * `coordinate` - `Coord` of the desired time zone location.
/// * `timestamp` - Time is used to determine if Daylight Savings is
/// applicable.
#[cfg(feature = "geo")]
pub fn try_new_coordinate<'b>(
client: &'a GoogleMapsClient,
coordinate: &'b geo_types::Coord,
timestamp: DateTime<Utc>,
) -> Result<Request<'a>, crate::error::Error> {
// Instantiate struct and return it to caller:
Ok(Request {
// Required parameters:
client,
location: LatLng::try_from(coordinate)?,
timestamp,
// Optional parameters:
language: None,
// Internal use only:
query: None,
}) // struct
} // fn
// -------------------------------------------------------------------------
//
/// Initializes the builder pattern for a Time Zone API query with the
/// required, non-optional parameters.
///
/// This function is the same as `new` but it supports
/// the [geo](https://crates.io/crates/geo) crate's
/// [Point](https://docs.rs/geo/latest/geo/geometry/struct.Point.html) type.
///
/// ## Arguments:
///
/// * `client` ‧ Your application's Google Maps API client struct.
/// * `point` - `Point` of the desired time zone location.
/// * `timestamp` - Time is used to determine if Daylight Savings is
/// applicable.
#[cfg(feature = "geo")]
pub fn try_new_point<'b>(
client: &'a GoogleMapsClient,
point: &'b geo_types::Point,
timestamp: DateTime<Utc>,
) -> Result<Request<'a>, crate::error::Error> {
// Instantiate struct and return it to caller:
Ok(Request {
// Required parameters:
client,
location: LatLng::try_from(point)?,
timestamp,
// Optional parameters:
language: None,
// Internal use only:
query: None,
}) // struct
} // fn
} // impl