Skip to content

Translate Date and Time into French #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 27, 2019
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
6 changes: 3 additions & 3 deletions 1-js/05-data-types/11-date/1-new-date/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ importance: 5

---

# Create a date
# Créer une date

Create a `Date` object for the date: Feb 20, 2012, 3:12am. The time zone is local.
Créez un objet `Date` pour la date: 20 février 2012, 3h12. Le fuseau horaire est local.

Show it using `alert`.
Montrez-le en utilisant `alert`.
4 changes: 2 additions & 2 deletions 1-js/05-data-types/11-date/2-get-week-day/solution.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The method `date.getDay()` returns the number of the weekday, starting from sunday.
La méthode `date.getDay()` renvoie le numéro du jour de la semaine à partir du dimanche.

Let's make an array of weekdays, so that we can get the proper day name by its number:
Faisons un tableau des jours de la semaine afin d’obtenir le nom du jour par son numéro:

```js run demo
function getWeekDay(date) {
Expand Down
10 changes: 5 additions & 5 deletions 1-js/05-data-types/11-date/2-get-week-day/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ importance: 5

---

# Show a weekday
# Montrer un jour de la semaine

Write a function `getWeekDay(date)` to show the weekday in short format: 'MO', 'TU', 'WE', 'TH', 'FR', 'SA', 'SU'.
Ecrivez une fonction `getWeekDay(date)` pour afficher le jour de la semaine sous forme abrégée: 'MO', 'TU', 'WE', 'TH', 'FR', 'SA', 'SU'.

For instance:
Par exemple:

```js no-beautify
let date = new Date(2012, 0, 3); // 3 Jan 2012
alert( getWeekDay(date) ); // should output "TU"
let date = new Date(2012, 0, 3); // 3 Janvier 2012
alert( getWeekDay(date) ); // devrait afficher "TU"
```
2 changes: 1 addition & 1 deletion 1-js/05-data-types/11-date/3-weekday/_js.view/solution.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ function getLocalDay(date) {

let day = date.getDay();

if (day == 0) { // weekday 0 (sunday) is 7 in european
if (day == 0) { // semaine 0 (dimanche) est 7 en européen
day = 7;
}

Expand Down
8 changes: 4 additions & 4 deletions 1-js/05-data-types/11-date/3-weekday/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ importance: 5

---

# European weekday
# Jour de la semaine européenne

European countries have days of week starting with Monday (number 1), then Tuesday (number 2) and till Sunday (number 7). Write a function `getLocalDay(date)` that returns the "European" day of week for `date`.
Les pays européens ont des jours de la semaine commençant par lundi (numéro 1), puis mardi (numéro 2) et jusqu'au dimanche (numéro 7). Ecrivez une fonction `getLocalDay(date)` qui renvoie le jour de la semaine "européen" pour `date`.

```js no-beautify
let date = new Date(2012, 0, 3); // 3 Jan 2012
alert( getLocalDay(date) ); // tuesday, should show 2
let date = new Date(2012, 0, 3); // 3 Janvier 2012
alert( getLocalDay(date) ); // mardi, devrait afficher 2
```
6 changes: 3 additions & 3 deletions 1-js/05-data-types/11-date/4-get-date-ago/solution.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
The idea is simple: to substract given number of days from `date`:
L'idée est simple: soustraire un nombre donné de jours à partir de la `date`:

```js
function getDateAgo(date, days) {
Expand All @@ -7,9 +7,9 @@ function getDateAgo(date, days) {
}
```

...But the function should not change `date`. That's an important thing, because the outer code which gives us the date does not expect it to change.
...Mais la fonction ne doit pas changer la `date`. C'est une chose importante, car le code externe qui nous donne la date ne s'attend pas à ce qu'il change.

To implement it let's clone the date, like this:
Pour le mettre en oeuvre, clonons la date, comme ceci:

```js run demo
function getDateAgo(date, days) {
Expand Down
10 changes: 5 additions & 5 deletions 1-js/05-data-types/11-date/4-get-date-ago/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ importance: 4

---

# Which day of month was many days ago?
# Quel jour du mois était il y a plusieurs jours ?

Create a function `getDateAgo(date, days)` to return the day of month `days` ago from the `date`.
Créez une fonction `getDateAgo(date, days)` pour renvoyer le `days` précédent la date `date`.

For instance, if today is 20th, then `getDateAgo(new Date(), 1)` should be 19th and `getDateAgo(new Date(), 2)` should be 18th.
Par exemple, si aujourd'hui on est le 20, alors `getDateAgo(new Date(), 1)` doit être le 19 et `getDateAgo(new Date(), 2)` doit être le 18.

Should work reliably for `days=365` or more:
elle doit fonctionner de manière fiable sur plus de 365 jours.

```js
let date = new Date(2015, 0, 2);
Expand All @@ -18,4 +18,4 @@ alert( getDateAgo(date, 2) ); // 31, (31 Dec 2014)
alert( getDateAgo(date, 365) ); // 2, (2 Jan 2014)
```

P.S. The function should not modify the given `date`.
P.S. La fonction ne doit pas modifier la `date` donnée.
4 changes: 2 additions & 2 deletions 1-js/05-data-types/11-date/5-last-day-of-month/solution.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Let's create a date using the next month, but pass zero as the day:
Créons une date en utilisant le mois suivant, mais passons zéro comme jour:
```js run demo
function getLastDayOfMonth(year, month) {
let date = new Date(year, month + 1, 0);
Expand All @@ -10,4 +10,4 @@ alert( getLastDayOfMonth(2012, 1) ); // 29
alert( getLastDayOfMonth(2013, 1) ); // 28
```

Normally, dates start from 1, but technically we can pass any number, the date will autoadjust itself. So when we pass 0, then it means "one day before 1st day of the month", in other words: "the last day of the previous month".
Normalement, les dates commencent à 1, mais techniquement, nous pouvons passer n'importe quel nombre, la date s'ajustera automatiquement. Ainsi, lorsque nous passons 0, cela signifie "un jour avant le 1er jour du mois", autrement dit: "le dernier jour du mois précédent".
12 changes: 6 additions & 6 deletions 1-js/05-data-types/11-date/5-last-day-of-month/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ importance: 5

---

# Last day of month?
# Dernier jour du mois ?

Write a function `getLastDayOfMonth(year, month)` that returns the last day of month. Sometimes it is 30th, 31st or even 28/29th for Feb.
Ecrivez une fonction `getLastDayOfMonth(year, month)` qui renvoie le dernier jour du mois. Parfois, c'est 30, 31 ou même 28/29 février.

Parameters:
Paramètres:

- `year` -- four-digits year, for instance 2012.
- `month` -- month, from 0 to 11.
- `year` -- année à quatre chiffres, par exemple 2012.
- `month` -- mois, de 0 à 11.

For instance, `getLastDayOfMonth(2012, 1) = 29` (leap year, Feb).
Par exemple, `getLastDayOfMonth(2012, 1) = 29` (année bissextile, février).
10 changes: 5 additions & 5 deletions 1-js/05-data-types/11-date/6-get-seconds-today/solution.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
To get the number of seconds, we can generate a date using the current day and time 00:00:00, then substract it from "now".
Pour obtenir le nombre de secondes, nous pouvons générer une date à l'aide du jour et de l'heure en cours 00:00:00, puis la soustraire de "maintenant".

The difference is the number of milliseconds from the beginning of the day, that we should divide by 1000 to get seconds:
La différence est le nombre de millisecondes à partir du début de la journée, qu'il faut diviser par 1000 pour obtenir les secondes:

```js run
function getSecondsToday() {
let now = new Date();

// create an object using the current day/month/year
// crée un objet en utilisant le jour / mois / année en cours
let today = new Date(now.getFullYear(), now.getMonth(), now.getDate());

let diff = now - today; // ms difference
return Math.round(diff / 1000); // make seconds
return Math.round(diff / 1000); // arrondir en secondes
}

alert( getSecondsToday() );
```

An alternative solution would be to get hours/minutes/seconds and convert them to seconds:
Une autre solution serait d’obtenir les heures / minutes / secondes et de les convertir en secondes:

```js run
function getSecondsToday() {
Expand Down
8 changes: 4 additions & 4 deletions 1-js/05-data-types/11-date/6-get-seconds-today/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ importance: 5

---

# How many seconds has passed today?
# Combien de secondes s'est écoulé aujourd'hui ?

Write a function `getSecondsToday()` that returns the number of seconds from the beginning of today.
Ecrivez une fonction `getSecondsToday()` qui renvoie le nombre de secondes depuis le début de la journée.

For instance, if now `10:00 am`, and there was no daylight savings shift, then:
Par exemple, s'il est maintenant `10:00 am`, et qu'il n'y a pas de décalage de l'heure d'été, alors:

```js
getSecondsToday() == 36000 // (3600 * 10)
```

The function should work in any day. That is, it should not have a hard-coded value of "today".
La fonction devrait fonctionner dans n'importe quel jour. Autrement dit, il ne devrait pas avoir de valeur "aujourd'hui" codée en dur.
10 changes: 5 additions & 5 deletions 1-js/05-data-types/11-date/7-get-seconds-to-tomorrow/solution.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
To get the number of milliseconds till tomorrow, we can from "tomorrow 00:00:00" substract the current date.
Pour obtenir le nombre de millisecondes jusqu'à demain, nous pouvons, à partir de "demain 00:00:00", soustraire la date actuelle.

First, we generate that "tomorrow", and then do it:
Tout d'abord, nous générons ce "demain", puis nous le faisons:

```js run
function getSecondsToTomorrow() {
let now = new Date();

// tomorrow date
// date de demain
let tomorrow = new Date(now.getFullYear(), now.getMonth(), *!*now.getDate()+1*/!*);

let diff = tomorrow - now; // difference in ms
return Math.round(diff / 1000); // convert to seconds
}
```

Alternative solution:
solution alternative:

```js run
function getSecondsToTomorrow() {
Expand All @@ -29,4 +29,4 @@ function getSecondsToTomorrow() {
}
```

Please note that many countries have Daylight Savings Time (DST), so there may be days with 23 or 25 hours. We may want to treat such days separately.
Veuillez noter que de nombreux pays ont l'heure d'été (DST), il peut donc y avoir des jours avec 23 ou 25 heures. Nous voudrons peut-être traiter ces jours séparément.
8 changes: 4 additions & 4 deletions 1-js/05-data-types/11-date/7-get-seconds-to-tomorrow/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ importance: 5

---

# How many seconds till tomorrow?
# Combien de secondes jusqu'à demain ?

Create a function `getSecondsToTomorrow()` that returns the number of seconds till tomorrow.
Créez une focntion `getSecondsToTomorrow()` qui renvoie le nombre de secondes jusqu'à demain.

For instance, if now is `23:00`, then:
Par exemple, s'il est maintenant `23:00`, alors:

```js
getSecondsToTomorrow() == 3600
```

P.S. The function should work at any day, the "today" is not hardcoded.
P.S. La fonction devrait fonctionner à tout moment, le «aujourd'hui» n'est pas codé en dur.
24 changes: 12 additions & 12 deletions 1-js/05-data-types/11-date/8-format-date-relative/solution.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
To get the time from `date` till now -- let's substract the dates.
Pour obtenir l'heure à partir de la `date` jusqu'à maintenant -- allons soutraire les dates.

```js run demo
function formatDate(date) {
let diff = new Date() - date; // the difference in milliseconds
let diff = new Date() - date; // la différence en millisecondes

if (diff < 1000) { // less than 1 second
if (diff < 1000) { // moins d'une seconde
return 'right now';
}

let sec = Math.floor(diff / 1000); // convert diff to seconds
let sec = Math.floor(diff / 1000); // convertir la différence en secondes

if (sec < 60) {
return sec + ' sec. ago';
}

let min = Math.floor(diff / 60000); // convert diff to minutes
let min = Math.floor(diff / 60000); // convertir la différence en minutes
if (min < 60) {
return min + ' min. ago';
}

// format the date
// add leading zeroes to single-digit day/month/hours/minutes
// formater la date
// ajoute des zéros au premier jour / mois / heure / minutes
let d = date;
d = [
'0' + d.getDate(),
'0' + (d.getMonth() + 1),
'' + d.getFullYear(),
'0' + d.getHours(),
'0' + d.getMinutes()
].map(component => component.slice(-2)); // take last 2 digits of every component
].map(component => component.slice(-2)); // prend les 2 derniers chiffres de chaque composant

// join the components into date
// joindre les composants en date
return d.slice(0, 3).join('.') + ' ' + d.slice(3).join(':');
}

Expand All @@ -40,11 +40,11 @@ alert( formatDate(new Date(new Date - 30 * 1000)) ); // "30 sec. ago"

alert( formatDate(new Date(new Date - 5 * 60 * 1000)) ); // "5 min. ago"

// yesterday's date like 31.12.2016, 20:00
// date d'hier comme ceci 31.12.2016, 20h00
alert( formatDate(new Date(new Date - 86400 * 1000)) );
```

Alternative solution:
solution alternative:

```js run
function formatDate(date) {
Expand All @@ -58,7 +58,7 @@ function formatDate(date) {
let diffMin = diffSec / 60;
let diffHour = diffMin / 60;

// formatting
// formatage
year = year.toString().slice(-2);
month = month < 10 ? '0' + month : month;
dayOfMonth = dayOfMonth < 10 ? '0' + dayOfMonth : dayOfMonth;
Expand Down
16 changes: 8 additions & 8 deletions 1-js/05-data-types/11-date/8-format-date-relative/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ importance: 4

---

# Format the relative date
# Formater la date relative

Write a function `formatDate(date)` that should format `date` as follows:
Créez une fonction `formatDate(date)` qui devrait formater la `date` comme ceci:

- If since `date` passed less than 1 second, then `"right now"`.
- Otherwise, if since `date` passed less than 1 minute, then `"n sec. ago"`.
- Otherwise, if less than an hour, then `"m min. ago"`.
- Otherwise, the full date in the format `"DD.MM.YY HH:mm"`. That is: `"day.month.year hours:minutes"`, all in 2-digit format, e.g. `31.12.16 10:00`.
- Si depuis la `date` il s'est passé moins de 1 seconde, alors `"right now"`.
- Sinon, si il s'est passé moins d'une minute, alors `"n sec. ago"`.
- Sinon, si c'est moins d'une heure, alors `"m min. ago"`.
- Sinon, la date complète au format `"DD.MM.YY HH:mm"`. C'est à dire: `"day.month.year hours:minutes"`, le tout au format 2 chiffres, par exemple. `31.12.16 10:00`.

For instance:
Par exemple:

```js
alert( formatDate(new Date(new Date - 1)) ); // "right now"
Expand All @@ -20,6 +20,6 @@ alert( formatDate(new Date(new Date - 30 * 1000)) ); // "30 sec. ago"

alert( formatDate(new Date(new Date - 5 * 60 * 1000)) ); // "5 min. ago"

// yesterday's date like 31.12.2016, 20:00
// date d'hier comme ceci 31.12.2016, 20:00
alert( formatDate(new Date(new Date - 86400 * 1000)) );
```
Loading