-
Notifications
You must be signed in to change notification settings - Fork 446
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add utils time related functions
- Loading branch information
1 parent
2780a65
commit e6f2f71
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |