Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions crates/pebble/src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,15 @@ impl TaskNode {
Ok(())
}

/// Creates a new task file on disk.
///
/// This method atomically creates a new file at the specified path and writes the task's
/// frontmatter and body.
///
/// # Errors
///
/// Returns an error if the file already exists, if the serialized content fails to generate,
/// or if the file write operation fails.
pub fn create_new_to_disk(&self) -> Result<()> {
let content = self.get_content_for_disk()?;

Expand All @@ -369,6 +378,18 @@ impl TaskNode {
}
}

/// Returns the default UTC datetime used across the application.
///
/// This serves as a standardized timestamp for missing or uninitialized dates.
///
/// # Examples
///
/// ```
/// use chrono::{DateTime, Utc};
/// use pebble::models::default_datetime;
///
/// assert_eq!(default_datetime(), DateTime::<Utc>::UNIX_EPOCH);
/// ```
pub fn default_datetime() -> DateTime<Utc> {
DateTime::<Utc>::UNIX_EPOCH
}
Expand Down
14 changes: 14 additions & 0 deletions crates/pebble/src/task_io.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
use chrono::{DateTime, Utc};

/// Retrieves the current time in UTC for timestamping tasks.
///
/// This function centralizes the acquisition of the current timestamp to ensure
/// all generated dates in the application are consistently recorded in UTC.
///
/// # Examples
///
/// ```
/// use chrono::Utc;
/// use pebble::task_io::current_task_time;
///
/// let now = current_task_time();
/// assert!(now <= Utc::now());
/// ```
pub fn current_task_time() -> DateTime<Utc> {
Utc::now()
}