From c03d60340a3926d0894838e22f0fa2baa060d286 Mon Sep 17 00:00:00 2001 From: Eric Harris-Braun Date: Thu, 11 Jul 2024 10:48:53 -0400 Subject: [PATCH] Adds functions for creating and parsing clone cell name --- crates/hpos_connect_hc/src/sl_utils.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/crates/hpos_connect_hc/src/sl_utils.rs b/crates/hpos_connect_hc/src/sl_utils.rs index 56f4b32..8e7fd3d 100644 --- a/crates/hpos_connect_hc/src/sl_utils.rs +++ b/crates/hpos_connect_hc/src/sl_utils.rs @@ -7,6 +7,7 @@ use chrono::Timelike; use chrono::Utc; use const_env::from_env; use holochain_types::prelude::ClonedCell; +use anyhow::{anyhow, Result}; // General Notes: // These constants are defined here for use by all the other repos @@ -96,3 +97,21 @@ pub fn sl_within_deleting_check_window(window_size: u32) -> bool { let min = now.minute(); now.hour() == 0 && min >= 1 && min <= window_size } + +/// creates the clone name from the bucket and bucket size +pub fn sl_clone_name(spec: SlCloneSpec) -> String { + format!("{}.{}", spec.days_in_bucket, spec.time_bucket) +} + +pub struct SlCloneSpec { + pub days_in_bucket: u32, + pub time_bucket: u32, +} + +/// returns the bucket size and bucket from a clone name +pub fn sl_clone_name_spec(name: &str) -> Result { + let mut parts = name.split("."); + let days_in_bucket = parts.next().ok_or(anyhow!("no days in clone name"))?.parse::()?; + let time_bucket = parts.next().ok_or(anyhow!("no bucket in clone name"))?.parse::()?; + Ok(SlCloneSpec{days_in_bucket, time_bucket}) +} \ No newline at end of file