Fix timestamp formats conflict
This commit is contained in:
+23
-9
@@ -689,15 +689,12 @@ impl FormController {
|
||||
},
|
||||
_ => return FormAction::Feedback("Manual addressing requires both IPv4 and IPv6 values.".to_owned()),
|
||||
};
|
||||
let created_utc = match time::OffsetDateTime::now_utc()
|
||||
.format(&time::format_description::well_known::Rfc3339)
|
||||
{
|
||||
Ok(value) => value,
|
||||
Err(_) => {
|
||||
return FormAction::Feedback(
|
||||
"Could not prepare client creation time.".to_owned(),
|
||||
);
|
||||
}
|
||||
let Some(created_utc) =
|
||||
format_creation_timestamp(time::OffsetDateTime::now_utc())
|
||||
else {
|
||||
return FormAction::Feedback(
|
||||
"Could not prepare client creation time.".to_owned(),
|
||||
);
|
||||
};
|
||||
let command = UiCommand::CreateClient {
|
||||
alias: alias.trim().to_owned(),
|
||||
@@ -924,6 +921,13 @@ fn field_value_mut<'a>(
|
||||
}
|
||||
}
|
||||
|
||||
fn format_creation_timestamp(now: time::OffsetDateTime) -> Option<String> {
|
||||
now.replace_nanosecond(0)
|
||||
.ok()?
|
||||
.format(&time::format_description::well_known::Rfc3339)
|
||||
.ok()
|
||||
}
|
||||
|
||||
trait BoundedString {
|
||||
fn push_bounded(&mut self, character: char);
|
||||
}
|
||||
@@ -1054,6 +1058,16 @@ mod tests {
|
||||
assert!(matches!(form.handle_key(KeyCode::Esc), FormAction::Cancel));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn creation_timestamp_discards_fractional_seconds_and_renders_as_valid_metadata() {
|
||||
let instant = time::OffsetDateTime::from_unix_timestamp_nanos(1_700_000_000_123_456_789)
|
||||
.expect("fixed UTC instant is in range");
|
||||
|
||||
let timestamp = format_creation_timestamp(instant).expect("timestamp formats");
|
||||
assert_eq!(timestamp, "2023-11-14T22:13:20Z");
|
||||
assert!(crate::wireguard::metadata::render_block("device", Some(×tamp)).is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rename_requires_full_key_confirmation_and_restart_exposes_exact_draft_choice() {
|
||||
let identity = PublicKey::from_bytes([0x5a; 32]);
|
||||
|
||||
Reference in New Issue
Block a user