Skip to content

Commit

Permalink
Add example to documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
TypicalHog authored Feb 20, 2024
1 parent c87245c commit e6b5337
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
//! The official Rust implementation of the RANDEVU algorithm
//! The official Rust implementation of the [RANDEVU](https://github.com/TypicalHog/randevu) algorithm
//!
//! # Example
//! ```rust
//! use randevu::{rdv, utc_date_with_offset};
//!
//! fn main() {
//! let object = "THE_SIMPSONS";
//! let date = utc_date_with_offset(0);
//! let rdv = rdv(object, &date);
//!
//! println!("Object {} has RDV{} today", object, rdv);
//! }
//! ```
use blake3;
use chrono::{Duration, Utc};

/// Returns current UTC date (String) in ISO 8601 format, with an offset (i64) in days
/// Returns current UTC DATE `String` in ISO 8601 format (YYYY-MM-DD), with an OFFSET `i64` in days
pub fn utc_date_with_offset(offset: i64) -> String {
(Utc::now() + Duration::days(offset))
.format("%Y-%m-%d")
.to_string()
}

/// Returns RDV level (u32) for an object (&str) on a specific date (&str)
/// Returns RDV level `u32` for an OBJECT `&str` on a specific DATE `&str`
///
/// RDV = number of leading zero bits in blake3(blake3(OBJECT) || blake3(DATE))
/// **RDV = number of leading zero bits in blake3(blake3(OBJECT) || blake3(DATE))**
pub fn rdv(object: &str, date: &str) -> u32 {
let mut hasher = blake3::Hasher::new();
hasher.update(blake3::hash(object.as_bytes()).as_bytes());
Expand Down

0 comments on commit e6b5337

Please sign in to comment.