Skip to content
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

Date and Time #352

Merged
merged 30 commits into from
Aug 28, 2020
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
81b3a90
Traducción del artículo Date and Time
Fedebornaz Aug 18, 2020
0230231
Update 1-js/05-data-types/11-date/1-new-date/solution.md
Fedebornaz Aug 19, 2020
5ed3cfa
Update 1-js/05-data-types/11-date/3-weekday/task.md
Fedebornaz Aug 19, 2020
c815759
Update 1-js/05-data-types/11-date/4-get-date-ago/solution.md
Fedebornaz Aug 19, 2020
3d69f63
Update 1-js/05-data-types/11-date/4-get-date-ago/task.md
Fedebornaz Aug 19, 2020
8ed2752
Update 1-js/05-data-types/11-date/4-get-date-ago/task.md
Fedebornaz Aug 19, 2020
b5bf760
Update 1-js/05-data-types/11-date/5-last-day-of-month/task.md
Fedebornaz Aug 19, 2020
d60abda
Update 1-js/05-data-types/11-date/5-last-day-of-month/task.md
Fedebornaz Aug 19, 2020
79c88fb
Update 1-js/05-data-types/11-date/article.md
Fedebornaz Aug 19, 2020
415e063
Update 1-js/05-data-types/11-date/article.md
Fedebornaz Aug 19, 2020
4f5de13
Update 1-js/05-data-types/11-date/article.md
Fedebornaz Aug 19, 2020
f619ed7
Update 1-js/05-data-types/11-date/8-format-date-relative/task.md
Fedebornaz Aug 19, 2020
602a2d1
Update 1-js/05-data-types/11-date/article.md
Fedebornaz Aug 19, 2020
4fce385
Update 1-js/05-data-types/11-date/article.md
Fedebornaz Aug 19, 2020
6c114e2
Update 1-js/05-data-types/11-date/article.md
Fedebornaz Aug 19, 2020
401c423
Update 1-js/05-data-types/11-date/article.md
Fedebornaz Aug 19, 2020
80b74c7
Update 1-js/05-data-types/11-date/article.md
Fedebornaz Aug 19, 2020
6b4af91
Update 1-js/05-data-types/11-date/article.md
Fedebornaz Aug 19, 2020
d53946c
agregados caracteres de cierre de box en línea 97
Fedebornaz Aug 19, 2020
ee2b149
Merge branch 'date-and-time' of https://github.com/Fedebornaz/es.java…
Fedebornaz Aug 19, 2020
48e5264
Update article.md
joaquinelio Aug 19, 2020
b59c98c
Update task.md
joaquinelio Aug 19, 2020
191567f
Update solution.md
joaquinelio Aug 19, 2020
1f4722f
Update article.md
joaquinelio Aug 19, 2020
1147101
Update 1-js/05-data-types/11-date/article.md
Fedebornaz Aug 28, 2020
f3bdfca
Update 1-js/05-data-types/11-date/article.md
Fedebornaz Aug 28, 2020
63681a2
Update 1-js/05-data-types/11-date/article.md
Fedebornaz Aug 28, 2020
450593e
Update 1-js/05-data-types/11-date/2-get-week-day/solution.md
Fedebornaz Aug 28, 2020
046c2fc
Update solution.md
vplentinax Aug 28, 2020
e343aa2
Update solution.md
vplentinax Aug 28, 2020
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
4 changes: 2 additions & 2 deletions 1-js/05-data-types/11-date/1-new-date/solution.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The `new Date` constructor uses the local time zone. So the only important thing to remember is that months start from zero.
El constructor `new Date` utiliza la zona horaria local. Lo único importante por recordar es que los meses se cuentan desde el 0.

So February has number 1.
Por ejemplo, febrero es el mes 1.

```js run
let d = new Date(2012, 1, 20, 3, 12);
Expand Down
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
# Crea una fecha

Create a `Date` object for the date: Feb 20, 2012, 3:12am. The time zone is local.
Crea un objeto `Date` para la fecha: Feb 20, 2012, 3:12am. La zona horaria es local.

Show it using `alert`.
Muéstralo en pantalla utilizando `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.
El método `date.getDay()` devuelve el número del día de la semana, empezando por el domingo.

Let's make an array of weekdays, so that we can get the proper day name by its number:
Hagamos un array de días de la semana, así podemos obtener el nombre del día a través de su número correspondiente.

```js run demo
function getWeekDay(date) {
Expand Down
8 changes: 4 additions & 4 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
# Muestra en pantalla un día de la semana

Write a function `getWeekDay(date)` to show the weekday in short format: 'MO', 'TU', 'WE', 'TH', 'FR', 'SA', 'SU'.
Escribe una función `getWeekDay(date)` para mostrar el día de la semana en formato corto: 'MO', 'TU', 'WE', 'TH', 'FR', 'SA', 'SU'.

For instance:
Por ejemplo:

```js no-beautify
let date = new Date(2012, 0, 3); // 3 Jan 2012
alert( getWeekDay(date) ); // should output "TU"
alert( getWeekDay(date) ); // debería mostrar "TU"
```
4 changes: 2 additions & 2 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,9 +2,9 @@ importance: 5

---

# European weekday
# Día de la semana europeo

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`.
En los países europeos se cuentan los días de la semana a partir del lunes (número 1), seguido del martes (número 2), hasta el domingo (número 7). Escribe una función `getLocalDay(date)` que devuelva el día de la semana "europeo" para la variable `date`.

```js no-beautify
let date = new Date(2012, 0, 3); // 3 Jan 2012
Expand Down
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`:
La idea es simple: restarle a la fecha `date` la cantidad de días especificada.

```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.
...Pero la función no debería modificar la fecha `date`. Esto es importante, ya que no se espera que cambie la variable externa que contiene la fecha.

To implement it let's clone the date, like this:
Para hacerlo, clonemos la fecha de esta manera:

```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?
# ¿Qué día del mes era hace algunos días atrás?

Create a function `getDateAgo(date, days)` to return the day of month `days` ago from the `date`.
Crea una función `getDateAgo(date, days)` que devuelva el día del mes que corresponde, contando la cantidad de días `days` respecto de la fecha `date`.

For instance, if today is 20th, then `getDateAgo(new Date(), 1)` should be 19th and `getDateAgo(new Date(), 2)` should be 18th.
Por ejemplo, si hoy es 20, entonces `getDateAgo(new Date(), 1)` debería ser 19 y `getDateAgo(new Date(), 2)` debería ser 18.

Should work reliably for `days=365` or more:
Debe poder funcionar para `days=365` o más:

```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.D.: La función no debería modificar la fecha `date` pasada como argumento.
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:
Creemos una fecha utilizando el mes próximo, pero pasando 0 como número de día:
```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".
Normalmente, las fechas comienzan a partir del 1, sin embargo podemos pasar como argumento cualquier número, ya que se corregirá automáticamente. De esta manera, si pasamos el número 0 como día, se interpreta como "el día anterior al primer día del mes", o en otras palabras: "el último día del mes anterior".
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?
# ¿Cuál es el último día del mes?

Write a function `getLastDayOfMonth(year, month)` that returns the last day of month. Sometimes it is 30th, 31st or even 28/29th for Feb.
Escribe una función `getLastDayOfMonth(year, month)` que devuelva el último día del mes dado. A veces es 30, 31 o incluso 28/29 para febrero.

Parameters:
Parámetros:

- `year` -- four-digits year, for instance 2012.
- `month` -- month, from 0 to 11.
- `year` -- el año en formato de cuatro dígitos, por ejemplo 2012.
- `month` -- el mes, de 0 a 11.

For instance, `getLastDayOfMonth(2012, 1) = 29` (leap year, Feb).
Por ejemplo, `getLastDayOfMonth(2012, 1) = 29` (febrero, año bisiesto).
12 changes: 6 additions & 6 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".
Para obtener la cantidad de segundos, podemos generar una fecha en la variable "today" utilizando el día de hoy con la hora en 00:00:00, y luego restárselo a la variable "now".

The difference is the number of milliseconds from the beginning of the day, that we should divide by 1000 to get seconds:
El resultado será la cantidad de milisegundos transcurridos desde el comienzo del día, el cual debemos dividir por 1000 para pasarlo a segundos:

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

// create an object using the current day/month/year
// creamos un objeto que contenga el día/mes/año actual
let today = new Date(now.getFullYear(), now.getMonth(), now.getDate());

let diff = now - today; // ms difference
return Math.round(diff / 1000); // make seconds
let diff = now - today; // diferencia entre fechas, representado en ms
return Math.round(diff / 1000); // pasaje a segundos
}

alert( getSecondsToday() );
```

An alternative solution would be to get hours/minutes/seconds and convert them to seconds:
Una solución alternativa sería obtener las horas/minutos/segundos actuales y pasar todo a segundos:

```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 have passed today?
# ¿Cuántos segundos transcurrieron el día de hoy?

Write a function `getSecondsToday()` that returns the number of seconds from the beginning of today.
Escribe una función `getSecondsToday()` que devuelva la cantidad de segundos transcurridos desde el comienzo del día.

For instance, if now were `10:00 am`, and there was no daylight savings shift, then:
Por ejemplo, si en este momento fueran las `10:00 am`, sin horario de verano, entonces:

```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 función debe poder funcionar correctamente cualquier día. Es decir, no debe poseer valores fijos en el código, como por ej. "today".
14 changes: 7 additions & 7 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.
Para obtener la cantidad de milisegundos que faltan para mañana, podemos restarle la fecha actual a "mañana 00:00:00".

First, we generate that "tomorrow", and then do it:
Primero generamos ese "mañana" y luego restamos:

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

// tomorrow date
// el día de mañana
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
let diff = tomorrow - now; // diferencia en ms
return Math.round(diff / 1000); // conversión a segundos
}
```

Alternative solution:
Solución alternativa:

```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.
Ten en cuenta que algunos países tienen horarios de verano (DST), así que es posible que existan días con 23 o 25 horas. Podríamos querer tratar estos días por separado.
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?
# ¿Cuantos segundos faltan para el día de mañana?

Create a function `getSecondsToTomorrow()` that returns the number of seconds till tomorrow.
Crea una funcion `getSecondsToTomorrow()` que devuelva la cantidad de segundos que faltan para el día de mañana.

For instance, if now is `23:00`, then:
Por ejemplo, si ahora son las `23:00`, entonces:

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

P.S. The function should work at any day, the "today" is not hardcoded.
P.D.: La función debe poder funcionar para cualquier día, sin valores fijos en el código como "today".
42 changes: 21 additions & 21 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,50 +1,50 @@
To get the time from `date` till now -- let's substract the dates.
Para obtener el tiempo que transcurrió desde la fecha `date` hasta ahora, restemos ambas fechas entre sí.

```js run demo
function formatDate(date) {
let diff = new Date() - date; // the difference in milliseconds
let diff = new Date() - date; // la diferencia entre ambas, representada en milisegundos

if (diff < 1000) { // less than 1 second
return 'right now';
if (diff < 1000) { // menos de 1 segundo
return 'ahora mismo';
}

let sec = Math.floor(diff / 1000); // convert diff to seconds
let sec = Math.floor(diff / 1000); // convierte el resultado en segundos

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

let min = Math.floor(diff / 60000); // convert diff to minutes
let min = Math.floor(diff / 60000); // convierte el resultado en minutos
if (min < 60) {
return min + ' min. ago';
return 'hace ' + min + ' min.';
}

// format the date
// add leading zeroes to single-digit day/month/hours/minutes
// cambia le formato de la fecha
// se le agrega un dígito 0 al día/mes/horas/minutos que contenga un único digito.
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)); // toma los últimos 2 dígitos de cada componente

// join the components into date
// une los componentes para formar una única fecha
return d.slice(0, 3).join('.') + ' ' + d.slice(3).join(':');
}

alert( formatDate(new Date(new Date - 1)) ); // "right now"
alert( formatDate(new Date(new Date - 1)) ); // "ahora mismo"

alert( formatDate(new Date(new Date - 30 * 1000)) ); // "30 sec. ago"
alert( formatDate(new Date(new Date - 30 * 1000)) ); // "hace 30 seg."

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

// yesterday's date like 31.12.2016 20:00
// la fecha de ayer en formato 31.12.2016 20:00
alert( formatDate(new Date(new Date - 86400 * 1000)) );
```

Alternative solution:
Solución alternativa:

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

// formatting
// dándole formato
year = year.toString().slice(-2);
month = month < 10 ? '0' + month : month;
dayOfMonth = dayOfMonth < 10 ? '0' + dayOfMonth : dayOfMonth;
hour = hour < 10 ? '0' + hour : hour;
minutes = minutes < 10 ? '0' + minutes : minutes;

if (diffSec < 1) {
return 'right now';
return 'ahora mismo';
} else if (diffMin < 1) {
return `${diffSec} sec. ago`
return `hace ${diffSec} seg.`
} else if (diffHour < 1) {
return `${diffMin} min. ago`
return `hace ${diffMin} min.`
} else {
return `${dayOfMonth}.${month}.${year} ${hour}:${minutes}`
}
Expand Down
20 changes: 10 additions & 10 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,24 +2,24 @@ importance: 4

---

# Format the relative date
# Cambia el formato a fecha relativa

Write a function `formatDate(date)` that should format `date` as follows:
Escribe una función `formatDate(date)` que muestre la fecha en el siguiente formato:

- 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 a partir de la fecha `date` pasó menos de 1 segundo, debe devolver `"ahora mismo"`.
- De no ser así, si a partir de la fecha `date` pasó menos de 1 minuto, debe retornar `"hace n seg,"`.
- De no ser así, si pasó menos de una hora, debe retornar `"hace n min."`.
- De no ser así, debe retornar la fecha completa en el formato `"DD.MM.AA HH:mm"`. Es decir: `"día.mes.año horas:minutos"`, cada uno de ellos en formato de 2 digitos, por ej. `31.12.16 10:00`.

For instance:

```js
alert( formatDate(new Date(new Date - 1)) ); // "right now"
alert( formatDate(new Date(new Date - 1)) ); // "ahora mismo"

alert( formatDate(new Date(new Date - 30 * 1000)) ); // "30 sec. ago"
alert( formatDate(new Date(new Date - 30 * 1000)) ); // "hace 30 seg."

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

// yesterday's date like 31.12.16 20:00
// la fecha de ayer en formato 31.12.16 20:00
alert( formatDate(new Date(new Date - 86400 * 1000)) );
```
Loading