Skip to content

Commit cf48f33

Browse files
committed
date: fix l10n duplicate and apply rustfmt
1 parent 64af5bc commit cf48f33

3 files changed

Lines changed: 26 additions & 24 deletions

File tree

src/uu/date/locales/fr-FR.ftl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,3 @@ date-error-format-missing-plus = l'argument {$arg} ne commence pas par un signe
105105
lorsqu'une option est utilisée pour spécifier une ou plusieurs dates, tout argument autre
106106
qu'une option doit être une chaîne de format commençant par un signe '+'.
107107
date-error-format-modifier-width-too-large = la largeur du modificateur de format '{$width}' est trop grande pour le spécificateur '%{$specifier}'
108-
date-error-format-modifier-width-too-large = la largeur du modificateur de format '{$width}' est trop grande pour le spécificateur '%{$specifier}'

src/uu/date/src/format_modifiers.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,12 @@ fn format_with_modifiers(
160160
let width = if width_str.is_empty() {
161161
0
162162
} else {
163-
width_str.parse().map_err(|_| FormatError::FieldWidthTooLarge {
164-
width: width_str.to_string(),
165-
specifier: spec.to_string(),
166-
})?
163+
width_str
164+
.parse()
165+
.map_err(|_| FormatError::FieldWidthTooLarge {
166+
width: width_str.to_string(),
167+
specifier: spec.to_string(),
168+
})?
167169
};
168170
let modified = apply_modifiers(&formatted, flags, width, spec)?;
169171
result.push_str(&modified);
@@ -325,40 +327,38 @@ fn apply_modifiers(
325327
// Zero padding: sign first, then zeros (e.g., "-0022")
326328
let sign = result.chars().next().unwrap();
327329
let rest = &result[1..];
328-
let target_len = result
329-
.len()
330-
.checked_add(padding)
331-
.ok_or_else(|| FormatError::FieldWidthTooLarge {
332-
width: width.to_string(),
333-
specifier: specifier.to_string(),
334-
})?;
335-
let mut padded = String::new();
336-
padded.try_reserve(target_len).map_err(|_| {
330+
let target_len = result.len().checked_add(padding).ok_or_else(|| {
337331
FormatError::FieldWidthTooLarge {
338332
width: width.to_string(),
339333
specifier: specifier.to_string(),
340334
}
341335
})?;
336+
let mut padded = String::new();
337+
padded
338+
.try_reserve(target_len)
339+
.map_err(|_| FormatError::FieldWidthTooLarge {
340+
width: width.to_string(),
341+
specifier: specifier.to_string(),
342+
})?;
342343
padded.push(sign);
343344
padded.extend(std::iter::repeat_n('0', padding));
344345
padded.push_str(rest);
345346
result = padded;
346347
} else {
347348
// Default: pad on the left (e.g., " -22" or " 1999")
348-
let target_len = result
349-
.len()
350-
.checked_add(padding)
351-
.ok_or_else(|| FormatError::FieldWidthTooLarge {
352-
width: width.to_string(),
353-
specifier: specifier.to_string(),
354-
})?;
355-
let mut padded = String::new();
356-
padded.try_reserve(target_len).map_err(|_| {
349+
let target_len = result.len().checked_add(padding).ok_or_else(|| {
357350
FormatError::FieldWidthTooLarge {
358351
width: width.to_string(),
359352
specifier: specifier.to_string(),
360353
}
361354
})?;
355+
let mut padded = String::new();
356+
padded
357+
.try_reserve(target_len)
358+
.map_err(|_| FormatError::FieldWidthTooLarge {
359+
width: width.to_string(),
360+
specifier: specifier.to_string(),
361+
})?;
362362
padded.extend(std::iter::repeat_n(pad_char, padding));
363363
padded.push_str(&result);
364364
result = padded;

tests/by-util/test_date.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2417,7 +2417,10 @@ fn test_date_format_modifier_percent_escape() {
24172417
#[test]
24182418
fn test_date_format_modifier_huge_width_fails_without_abort() {
24192419
// GNU date also exits with failure for extreme width values.
2420-
let formats = [format!("+%{}c", usize::MAX), "+%184467440737095516160c".to_string()];
2420+
let formats = [
2421+
format!("+%{}c", usize::MAX),
2422+
"+%184467440737095516160c".to_string(),
2423+
];
24212424

24222425
for format in formats {
24232426
new_ucmd!()

0 commit comments

Comments
 (0)