@@ -314,6 +314,44 @@ impl Collection {
314314 self . update_extents ( item) ;
315315 self . maybe_add_item_link ( item)
316316 }
317+
318+ /// Creates a [Hasher](crate::hash::Hasher) from this collection's temporal extent.
319+ ///
320+ /// The `spatial_extent` and `temporal_extent` parameters control the
321+ /// resolution (minimum cell size) of the hasher. The time range is derived
322+ /// from the first interval in this collection's temporal extent.
323+ ///
324+ /// Returns `None` if the collection's first temporal interval does not have
325+ /// both a start and end datetime.
326+ ///
327+ /// # Examples
328+ ///
329+ /// ```
330+ /// use chrono::{TimeDelta, TimeZone, Utc};
331+ /// use stac::Collection;
332+ ///
333+ /// let mut collection = Collection::new("an-id", "a description");
334+ /// collection.extent.temporal.interval =
335+ /// vec![[
336+ /// Some(Utc.with_ymd_and_hms(2020, 1, 1, 0, 0, 0).unwrap()),
337+ /// Some(Utc.with_ymd_and_hms(2025, 1, 1, 0, 0, 0).unwrap()),
338+ /// ]];
339+ ///
340+ /// let hasher = collection.hasher(1.0, TimeDelta::days(1)).unwrap();
341+ /// assert!(hasher.is_some());
342+ /// ```
343+ pub fn hasher (
344+ & self ,
345+ spatial_extent : f64 ,
346+ temporal_extent : chrono:: TimeDelta ,
347+ ) -> std:: result:: Result < Option < crate :: hash:: Hasher > , crate :: hash:: Error > {
348+ let interval = self . extent . temporal . interval . first ( ) ;
349+ let ( start, end) = match interval {
350+ Some ( [ Some ( start) , Some ( end) ] ) => ( * start, * end) ,
351+ _ => return Ok ( None ) ,
352+ } ;
353+ crate :: hash:: Hasher :: new ( spatial_extent, temporal_extent, start..end) . map ( Some )
354+ }
317355}
318356
319357impl Provider {
0 commit comments