Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/uu/date/locales/en-US.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,31 @@ date-usage =
Show the time on the west coast of the US (use tzselect(1) to find TZ)

TZ='America/Los_Angeles' date

date-help-date = display time described by STRING, not 'now'
date-help-file = like --date; once for each line of DATEFILE
date-help-iso-8601 = output date/time in ISO 8601 format.
FMT='date' for date only (the default),
'hours', 'minutes', 'seconds', or 'ns'
for date and time to the indicated precision.
Example: 2006-08-14T02:34:56-06:00
date-help-rfc-email = output date and time in RFC 5322 format.
Example: Mon, 14 Aug 2006 02:34:56 -0600
date-help-rfc-3339 = output date/time in RFC 3339 format.
FMT='date', 'seconds', or 'ns'
for date and time to the indicated precision.
Example: 2006-08-14 02:34:56-06:00
date-help-debug = annotate the parsed date, and warn about questionable usage to stderr
date-help-reference = display the last modification time of FILE
date-help-set = set time described by STRING
date-help-set-macos = set time described by STRING (not available on mac yet)
date-help-set-redox = set time described by STRING (not available on redox yet)
date-help-universal = print or set Coordinated Universal Time (UTC)

date-error-invalid-date = invalid date '{$date}'
date-error-invalid-format = invalid format '{$format}' ({$error})
date-error-expected-file-got-directory = expected file, got directory '{$path}'
date-error-date-overflow = date overflow '{$date}'
date-error-setting-date-not-supported-macos = setting the date is not supported by macOS
date-error-setting-date-not-supported-redox = setting the date is not supported by Redox
date-error-cannot-set-date = cannot set date
101 changes: 101 additions & 0 deletions src/uu/date/locales/fr-FR.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
date-about = afficher ou définir la date système
date-usage = [OPTION]... [+FORMAT]
date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]

FORMAT contrôle la sortie. Les séquences interprétées sont :
{ "| Séquence | Description | Exemple |" }
{ "| -------- | -------------------------------------------------------------- | ---------------------- |" }
{ "| %% | un % littéral | % |" }
{ "| %a | nom abrégé du jour de la semaine selon la locale | dim |" }
{ "| %A | nom complet du jour de la semaine selon la locale | dimanche |" }
{ "| %b | nom abrégé du mois selon la locale | jan |" }
{ "| %B | nom complet du mois selon la locale | janvier |" }
{ "| %c | date et heure selon la locale | jeu 3 mar 23:05:25 2005|" }
{ "| %C | siècle ; comme %Y, sauf qu'on omet les deux derniers chiffres | 20 |" }
{ "| %d | jour du mois | 01 |" }
{ "| %D | date ; identique à %m/%d/%y | 12/31/99 |" }
{ "| %e | jour du mois, rempli avec des espaces ; identique à %_d | 3 |" }
{ "| %F | date complète ; identique à %Y-%m-%d | 2005-03-03 |" }
{ "| %g | deux derniers chiffres de l'année du numéro de semaine ISO (voir %G) | 05 |" }
{ "| %G | année du numéro de semaine ISO (voir %V) ; normalement utile seulement avec %V | 2005 |" }
{ "| %h | identique à %b | jan |" }
{ "| %H | heure (00..23) | 23 |" }
{ "| %I | heure (01..12) | 11 |" }
{ "| %j | jour de l'année (001..366) | 062 |" }
{ "| %k | heure, remplie avec des espaces ( 0..23) ; identique à %_H | 3 |" }
{ "| %l | heure, remplie avec des espaces ( 1..12) ; identique à %_I | 9 |" }
{ "| %m | mois (01..12) | 03 |" }
{ "| %M | minute (00..59) | 30 |" }
{ "| %n | une nouvelle ligne | \\n |" }
{ "| %N | nanosecondes (000000000..999999999) | 123456789 |" }
{ "| %p | équivalent locale de AM ou PM ; vide si inconnu | PM |" }
{ "| %P | comme %p, mais en minuscules | pm |" }
{ "| %q | trimestre de l'année (1..4) | 1 |" }
{ "| %r | heure sur 12 heures selon la locale | 11:11:04 PM |" }
{ "| %R | heure sur 24 heures et minute ; identique à %H:%M | 23:30 |" }
{ "| %s | secondes depuis 1970-01-01 00:00:00 UTC | 1615432800 |" }
{ "| %S | seconde (00..60) | 30 |" }
{ "| %t | une tabulation | \\t |" }
{ "| %T | heure ; identique à %H:%M:%S | 23:30:30 |" }
{ "| %u | jour de la semaine (1..7) ; 1 est lundi | 4 |" }
{ "| %U | numéro de semaine de l'année, avec dimanche comme premier jour de la semaine (00..53) | 10 |" }
{ "| %V | numéro de semaine ISO, avec lundi comme premier jour de la semaine (01..53) | 12 |" }
{ "| %w | jour de la semaine (0..6) ; 0 est dimanche | 4 |" }
{ "| %W | numéro de semaine de l'année, avec lundi comme premier jour de la semaine (00..53) | 11 |" }
{ "| %x | représentation de la date selon la locale | 03/03/2005 |" }
{ "| %X | représentation de l'heure selon la locale | 23:30:30 |" }
{ "| %y | deux derniers chiffres de l'année (00..99) | 05 |" }
{ "| %Y | année | 2005 |" }
{ "| %z | fuseau horaire numérique +hhmm | -0400 |" }
{ "| %:z | fuseau horaire numérique +hh:mm | -04:00 |" }
{ "| %::z | fuseau horaire numérique +hh:mm:ss | -04:00:00 |" }
{ "| %:::z | fuseau horaire numérique avec : à la précision nécessaire | -04, +05:30 |" }
{ "| %Z | abréviation alphabétique du fuseau horaire | EDT |" }

Par défaut, date remplit les champs numériques avec des zéros.
Les indicateurs optionnels suivants peuvent suivre '%' :
{ "* `-` (tiret) ne pas remplir le champ" }
{ "* `_` (soulignement) remplir avec des espaces" }
{ "* `0` (zéro) remplir avec des zéros" }
{ "* `^` utiliser des majuscules si possible" }
{ "* `#` utiliser l'inverse si possible" }
Après tout indicateur vient une largeur de champ optionnelle, comme nombre décimal ;
puis un modificateur optionnel, qui est soit
{ "* `E` pour utiliser les représentations alternatives de la locale si disponibles, ou" }
{ "* `O` pour utiliser les symboles numériques alternatifs de la locale si disponibles." }
Exemples :
Convertir les secondes depuis l'époque (1970-01-01 UTC) en date

date --date='@2147483647'

Montrer l'heure sur la côte ouest des États-Unis (utiliser tzselect(1) pour trouver TZ)

TZ='America/Los_Angeles' date

date-help-date = afficher l'heure décrite par CHAÎNE, pas 'maintenant'
date-help-file = comme --date ; une fois pour chaque ligne de FICHIER_DATE
date-help-iso-8601 = afficher la date/heure au format ISO 8601.
FMT='date' pour la date seulement (par défaut),
'hours', 'minutes', 'seconds', ou 'ns'
pour la date et l'heure à la précision indiquée.
Exemple : 2006-08-14T02:34:56-06:00
date-help-rfc-email = afficher la date et l'heure au format RFC 5322.
Exemple : Mon, 14 Aug 2006 02:34:56 -0600
date-help-rfc-3339 = afficher la date/heure au format RFC 3339.
FMT='date', 'seconds', ou 'ns'
pour la date et l'heure à la précision indiquée.
Exemple : 2006-08-14 02:34:56-06:00
date-help-debug = annoter la date analysée et avertir des usages douteux sur stderr
date-help-reference = afficher l'heure de dernière modification du FICHIER
date-help-set = définir l'heure décrite par CHAÎNE
date-help-set-macos = définir l'heure décrite par CHAÎNE (pas encore disponible sur mac)
date-help-set-redox = définir l'heure décrite par CHAÎNE (pas encore disponible sur redox)
date-help-universal = afficher ou définir le Temps Universel Coordonné (UTC)

date-error-invalid-date = date invalide '{$date}'
date-error-invalid-format = format invalide '{$format}' ({$error})
date-error-expected-file-got-directory = fichier attendu, répertoire obtenu '{$path}'
date-error-date-overflow = débordement de date '{$date}'
date-error-setting-date-not-supported-macos = la définition de la date n'est pas prise en charge par macOS
date-error-setting-date-not-supported-redox = la définition de la date n'est pas prise en charge par Redox
date-error-cannot-set-date = impossible de définir la date
101 changes: 57 additions & 44 deletions src/uu/date/src/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
use std::fs::File;
use std::io::{BufRead, BufReader};
use std::path::PathBuf;
use uucore::display::Quotable;
use uucore::error::FromIo;
use uucore::error::{UResult, USimpleError};
use uucore::{format_usage, show};
#[cfg(windows)]
use windows_sys::Win32::{Foundation::SYSTEMTIME, System::SystemInformation::SetSystemTime};

use uucore::locale::get_message;
use std::collections::HashMap;
use uucore::locale::{get_message, get_message_with_args};
use uucore::parser::shortcut_value_parser::ShortcutValueParser;

// Options
Expand All @@ -43,29 +43,6 @@
const OPT_UNIVERSAL: &str = "universal";
const OPT_UNIVERSAL_2: &str = "utc";

// Help strings

static ISO_8601_HELP_STRING: &str = "output date/time in ISO 8601 format.
FMT='date' for date only (the default),
'hours', 'minutes', 'seconds', or 'ns'
for date and time to the indicated precision.
Example: 2006-08-14T02:34:56-06:00";

static RFC_5322_HELP_STRING: &str = "output date and time in RFC 5322 format.
Example: Mon, 14 Aug 2006 02:34:56 -0600";

static RFC_3339_HELP_STRING: &str = "output date/time in RFC 3339 format.
FMT='date', 'seconds', or 'ns'
for date and time to the indicated precision.
Example: 2006-08-14 02:34:56-06:00";

#[cfg(not(any(target_os = "macos", target_os = "redox")))]
static OPT_SET_HELP_STRING: &str = "set time described by STRING";
#[cfg(target_os = "macos")]
static OPT_SET_HELP_STRING: &str = "set time described by STRING (not available on mac yet)";
#[cfg(target_os = "redox")]
static OPT_SET_HELP_STRING: &str = "set time described by STRING (not available on redox yet)";

/// Settings for this program, parsed from the command line
struct Settings {
utc: bool,
Expand Down Expand Up @@ -141,7 +118,10 @@
if !form.starts_with('+') {
return Err(USimpleError::new(
1,
format!("invalid date {}", form.quote()),
get_message_with_args(
"date-error-invalid-date",
HashMap::from([("date".to_string(), form.to_string())]),
),
));
}
let form = form[1..].to_string();
Expand Down Expand Up @@ -182,7 +162,10 @@
Some(Err((input, _err))) => {
return Err(USimpleError::new(
1,
format!("invalid date {}", input.quote()),
get_message_with_args(
"date-error-invalid-date",
HashMap::from([("date".to_string(), input.to_string())]),
),
));
}
Some(Ok(date)) => Some(date),
Expand Down Expand Up @@ -231,7 +214,10 @@
Err(_) => {
return Err(USimpleError::new(
1,
format!("invalid date {relative_time}"),
get_message_with_args(
"date-error-date-overflow",
HashMap::from([("date".to_string(), relative_time.to_string())]),
),

Check warning on line 220 in src/uu/date/src/date.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/date/src/date.rs#L217-L220

Added lines #L217 - L220 were not covered by tests
));
}
}
Expand All @@ -245,7 +231,10 @@
if path.is_dir() {
return Err(USimpleError::new(
2,
format!("expected file, got directory {}", path.quote()),
get_message_with_args(
"date-error-expected-file-got-directory",
HashMap::from([("path".to_string(), path.to_string_lossy().to_string())]),
),
));
}
let file = File::open(path)
Expand All @@ -271,13 +260,22 @@
Err(e) => {
return Err(USimpleError::new(
1,
format!("invalid format {format_string} ({e})"),
get_message_with_args(
"date-error-invalid-format",
HashMap::from([
("format".to_string(), format_string.to_string()),
("error".to_string(), e.to_string()),
]),
),
));
}
},
Err((input, _err)) => show!(USimpleError::new(
1,
format!("invalid date {}", input.quote())
get_message_with_args(
"date-error-invalid-date",
HashMap::from([("date".to_string(), input.to_string())])
)
)),
}
}
Expand All @@ -297,15 +295,15 @@
.long(OPT_DATE)
.value_name("STRING")
.allow_hyphen_values(true)
.help("display time described by STRING, not 'now'"),
.help(get_message("date-help-date")),
)
.arg(
Arg::new(OPT_FILE)
.short('f')
.long(OPT_FILE)
.value_name("DATEFILE")
.value_hint(clap::ValueHint::FilePath)
.help("like --date; once for each line of DATEFILE"),
.help(get_message("date-help-file")),
)
.arg(
Arg::new(OPT_ISO_8601)
Expand All @@ -317,26 +315,26 @@
]))
.num_args(0..=1)
.default_missing_value(OPT_DATE)
.help(ISO_8601_HELP_STRING),
.help(get_message("date-help-iso-8601")),
)
.arg(
Arg::new(OPT_RFC_EMAIL)
.short('R')
.long(OPT_RFC_EMAIL)
.help(RFC_5322_HELP_STRING)
.help(get_message("date-help-rfc-email"))
.action(ArgAction::SetTrue),
)
.arg(
Arg::new(OPT_RFC_3339)
.long(OPT_RFC_3339)
.value_name("FMT")
.value_parser(ShortcutValueParser::new([DATE, SECONDS, NS]))
.help(RFC_3339_HELP_STRING),
.help(get_message("date-help-rfc-3339")),
)
.arg(
Arg::new(OPT_DEBUG)
.long(OPT_DEBUG)
.help("annotate the parsed date, and warn about questionable usage to stderr")
.help(get_message("date-help-debug"))
.action(ArgAction::SetTrue),
)
.arg(
Expand All @@ -345,21 +343,34 @@
.long(OPT_REFERENCE)
.value_name("FILE")
.value_hint(clap::ValueHint::AnyPath)
.help("display the last modification time of FILE"),
.help(get_message("date-help-reference")),
)
.arg(
Arg::new(OPT_SET)
.short('s')
.long(OPT_SET)
.value_name("STRING")
.help(OPT_SET_HELP_STRING),
.help({
#[cfg(not(any(target_os = "macos", target_os = "redox")))]
{
get_message("date-help-set")
}
#[cfg(target_os = "macos")]
{
get_message("date-help-set-macos")
}
#[cfg(target_os = "redox")]
{
get_message("date-help-set-redox")
}
}),
)
.arg(
Arg::new(OPT_UNIVERSAL)
.short('u')
.long(OPT_UNIVERSAL)
.alias(OPT_UNIVERSAL_2)
.help("print or set Coordinated Universal Time (UTC)")
.help(get_message("date-help-universal"))
.action(ArgAction::SetTrue),
)
.arg(Arg::new(OPT_FORMAT))
Expand Down Expand Up @@ -427,15 +438,15 @@
fn set_system_datetime(_date: Zoned) -> UResult<()> {
Err(USimpleError::new(
1,
"setting the date is not supported by macOS".to_string(),
get_message("date-error-setting-date-not-supported-macos"),
))
}

#[cfg(target_os = "redox")]
fn set_system_datetime(_date: Zoned) -> UResult<()> {
Err(USimpleError::new(
1,
"setting the date is not supported by Redox".to_string(),
get_message("date-error-setting-date-not-supported-redox"),
))
}

Expand All @@ -457,7 +468,8 @@
if result == 0 {
Ok(())
} else {
Err(std::io::Error::last_os_error().map_err_context(|| "cannot set date".to_string()))
Err(std::io::Error::last_os_error()
.map_err_context(|| get_message("date-error-cannot-set-date")))
}
}

Expand All @@ -483,7 +495,8 @@
let result = unsafe { SetSystemTime(&system_time) };

if result == 0 {
Err(std::io::Error::last_os_error().map_err_context(|| "cannot set date".to_string()))
Err(std::io::Error::last_os_error()
.map_err_context(|| get_message("date-error-cannot-set-date")))
} else {
Ok(())
}
Expand Down
Loading