Skip to content

Commit c944cdf

Browse files
authored
Merge pull request #352 from Fedebornaz/date-and-time
Date and Time
2 parents fa5cee7 + e343aa2 commit c944cdf

File tree

16 files changed

+236
-224
lines changed

16 files changed

+236
-224
lines changed
Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
1-
The `new Date` constructor uses the local time zone. So the only important thing to remember is that months start from zero.
1+
El constructor `new Date` utiliza la zona horaria local. Lo único importante por recordar es que los meses se cuentan desde el 0.
22

3-
So February has number 1.
3+
Por ejemplo, febrero es el mes 1.
4+
5+
Aquí hay un ejemplo con números como componentes de fecha:
6+
7+
```js run
8+
//new Date(año, mes, día, hora, minuto, segundo, milisegundo)
9+
let d1 = new Date(2012, 1, 20, 3, 12);
10+
alert( d1 );
11+
```
12+
13+
También podríamos crear una fecha a partir de un string, así:
414

515
```js run
6-
let d = new Date(2012, 1, 20, 3, 12);
7-
alert( d );
16+
//new Date(datastring)
17+
let d2 = new Date("February 20, 2012 03:12:00");
18+
alert( d2 );
819
```
20+

1-js/05-data-types/11-date/1-new-date/task.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ importance: 5
22

33
---
44

5-
# Create a date
5+
# Crea una fecha
66

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

9-
Show it using `alert`.
9+
Muéstralo en pantalla utilizando `alert`.

1-js/05-data-types/11-date/2-get-week-day/solution.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
The method `date.getDay()` returns the number of the weekday, starting from sunday.
1+
El método `date.getDay()` devuelve el número del día de la semana, empezando por el domingo.
22

3-
Let's make an array of weekdays, so that we can get the proper day name by its number:
3+
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.
44

55
```js run demo
66
function getWeekDay(date) {

1-js/05-data-types/11-date/2-get-week-day/task.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ importance: 5
22

33
---
44

5-
# Show a weekday
5+
# Muestra en pantalla un día de la semana
66

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

9-
For instance:
9+
Por ejemplo:
1010

1111
```js no-beautify
1212
let date = new Date(2012, 0, 3); // 3 Jan 2012
13-
alert( getWeekDay(date) ); // should output "TU"
13+
alert( getWeekDay(date) ); // debería mostrar "TU"
1414
```

1-js/05-data-types/11-date/3-weekday/task.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ importance: 5
22

33
---
44

5-
# European weekday
5+
# Día de la semana europeo
66

7-
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`.
7+
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`.
88

99
```js no-beautify
1010
let date = new Date(2012, 0, 3); // 3 Jan 2012

1-js/05-data-types/11-date/4-get-date-ago/solution.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
The idea is simple: to substract given number of days from `date`:
1+
La idea es simple: restarle a la fecha `date` la cantidad de días especificada.
22

33
```js
44
function getDateAgo(date, days) {
@@ -7,9 +7,9 @@ function getDateAgo(date, days) {
77
}
88
```
99

10-
...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.
10+
...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.
1111

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

1414
```js run demo
1515
function getDateAgo(date, days) {

1-js/05-data-types/11-date/4-get-date-ago/task.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ importance: 4
22

33
---
44

5-
# Which day of month was many days ago?
5+
# ¿Qué día del mes era hace algunos días atrás?
66

7-
Create a function `getDateAgo(date, days)` to return the day of month `days` ago from the `date`.
7+
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`.
88

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

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

1313
```js
1414
let date = new Date(2015, 0, 2);
@@ -18,4 +18,4 @@ alert( getDateAgo(date, 2) ); // 31, (31 Dec 2014)
1818
alert( getDateAgo(date, 365) ); // 2, (2 Jan 2014)
1919
```
2020

21-
P.S. The function should not modify the given `date`.
21+
P.D.: La función no debería modificar la fecha `date` pasada como argumento.

1-js/05-data-types/11-date/5-last-day-of-month/solution.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Let's create a date using the next month, but pass zero as the day:
1+
Creemos una fecha utilizando el mes próximo, pero pasando 0 como número de día:
22
```js run demo
33
function getLastDayOfMonth(year, month) {
44
let date = new Date(year, month + 1, 0);
@@ -10,4 +10,4 @@ alert( getLastDayOfMonth(2012, 1) ); // 29
1010
alert( getLastDayOfMonth(2013, 1) ); // 28
1111
```
1212

13-
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".
13+
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".

1-js/05-data-types/11-date/5-last-day-of-month/task.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ importance: 5
22

33
---
44

5-
# Last day of month?
5+
# ¿Cuál es el último día del mes?
66

7-
Write a function `getLastDayOfMonth(year, month)` that returns the last day of month. Sometimes it is 30th, 31st or even 28/29th for Feb.
7+
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.
88

9-
Parameters:
9+
Parámetros:
1010

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

14-
For instance, `getLastDayOfMonth(2012, 1) = 29` (leap year, Feb).
14+
Por ejemplo, `getLastDayOfMonth(2012, 1) = 29` (febrero, año bisiesto).

1-js/05-data-types/11-date/6-get-seconds-today/solution.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
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".
1+
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".
22

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

55
```js run
66
function getSecondsToday() {
77
let now = new Date();
88

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

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

1616
alert( getSecondsToday() );
1717
```
1818

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

2121
```js run
2222
function getSecondsToday() {

0 commit comments

Comments
 (0)