refactor(core): Centralize timestamp parsing in core::time
Duplicate ISO 8601 timestamp parsing functions existed in both discussion.rs and merge_request.rs transformers. This extracts iso_to_ms_strict() and iso_to_ms_opt_strict() into core::time as the single source of truth, and updates both transformer modules to use the shared implementations. Also removes the private now_ms() from merge_request.rs in favor of the existing core::time::now_ms(), and replaces the local parse_timestamp_opt() in discussion.rs with the public iso_to_ms() from core::time. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -59,6 +59,22 @@ pub fn parse_since(input: &str) -> Option<i64> {
|
||||
iso_to_ms(input)
|
||||
}
|
||||
|
||||
/// Convert ISO 8601 timestamp to milliseconds with strict error handling.
|
||||
/// Returns Err with a descriptive message if the timestamp is invalid.
|
||||
pub fn iso_to_ms_strict(iso_string: &str) -> Result<i64, String> {
|
||||
DateTime::parse_from_rfc3339(iso_string)
|
||||
.map(|dt| dt.timestamp_millis())
|
||||
.map_err(|_| format!("Invalid timestamp: {}", iso_string))
|
||||
}
|
||||
|
||||
/// Convert optional ISO 8601 timestamp to optional milliseconds (strict).
|
||||
pub fn iso_to_ms_opt_strict(iso_string: &Option<String>) -> Result<Option<i64>, String> {
|
||||
match iso_string {
|
||||
Some(s) => iso_to_ms_strict(s).map(Some),
|
||||
None => Ok(None),
|
||||
}
|
||||
}
|
||||
|
||||
/// Format milliseconds epoch to human-readable full datetime.
|
||||
pub fn format_full_datetime(ms: i64) -> String {
|
||||
DateTime::from_timestamp_millis(ms)
|
||||
|
||||
Reference in New Issue
Block a user