Skip to content

Commit

Permalink
Adds functions for creating and parsing clone cell name
Browse files Browse the repository at this point in the history
  • Loading branch information
zippy committed Jul 11, 2024
1 parent 71adfcd commit c03d603
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions crates/hpos_connect_hc/src/sl_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<SlCloneSpec> {
let mut parts = name.split(".");
let days_in_bucket = parts.next().ok_or(anyhow!("no days in clone name"))?.parse::<u32>()?;
let time_bucket = parts.next().ok_or(anyhow!("no bucket in clone name"))?.parse::<u32>()?;
Ok(SlCloneSpec{days_in_bucket, time_bucket})
}

0 comments on commit c03d603

Please sign in to comment.