Skip to content

Commit

Permalink
feat: Add utils time related functions
Browse files Browse the repository at this point in the history
  • Loading branch information
IshanGrover2004 committed Jul 16, 2024
1 parent 2780a65 commit e6f2f71
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/rust/lib_ccxr/src/util/time.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//! Provides Rust equivalent code for functions in `utility.c` involves time operations. Uses Rust-native types as input and output.
use crate::time::units::{Timestamp, TimestampError, TimestampFormat};

/// Rust equivalent for `timestamp_to_srttime` function in C.
/// Uses Rust-native types as input and output.
pub fn timestamp_to_srttime(
timestamp: Timestamp,
buffer: &mut String,
) -> Result<(), TimestampError> {
timestamp.write_srt_time(buffer)
}

/// Rust equivalent for `timestamp_to_vtttime` function in C.
/// Uses Rust-native types as input and output.
pub fn timestamp_to_vtttime(
timestamp: Timestamp,
buffer: &mut String,
) -> Result<(), TimestampError> {
timestamp.write_vtt_time(buffer)
}

/// Rust equivalent for `millis_to_date` function in C. Uses Rust-native types as input and output.
pub fn millis_to_date(
timestamp: Timestamp,
buffer: &mut String,
date_format: TimestampFormat,
) -> Result<(), TimestampError> {
timestamp.write_formatted_time(buffer, date_format)
}

/// Rust equivalent for `stringztoms` function in C. Uses Rust-native types as input and output.
pub fn stringztoms(s: &str) -> Option<Timestamp> {
Timestamp::parse_optional_hhmmss_from_str(s).ok()
}

0 comments on commit e6f2f71

Please sign in to comment.