Skip to content

Commit

Permalink
Merge pull request #7 from MrGunflame/document-epoch
Browse files Browse the repository at this point in the history
Document `Builder::epoch`
  • Loading branch information
MrGunflame authored Apr 3, 2024
2 parents 38e2cd3 + 009787d commit fe4d8e2
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,25 @@ impl Builder {
self
}

/// Sets the `epoch` value of the `Builder`.
///
/// The `epoch` is the instant at which the `timestamp` of the Snowflake is zero. In other
/// words `epoch` is the earliest time a Snowflake can be constructed.
///
/// The default value is [`UNIX_EPOCH`].
///
/// # Examples
///
/// ```
/// # use std::time::{Duration, SystemTime};
/// # use snowflaked::{Builder, Generator, Snowflake};
/// #
/// let now = SystemTime::now();
/// let mut generator: Generator = Builder::new().epoch(now).build();
///
/// let id: u64 = generator.generate();
/// assert!(now + Duration::from_millis(id.timestamp()) >= now);
/// ```
#[inline]
pub const fn epoch(mut self, epoch: SystemTime) -> Self {
self.epoch = epoch;
Expand Down

0 comments on commit fe4d8e2

Please sign in to comment.