Skip to content

Commit 508c8eb

Browse files
Merge pull request #174
Date and time
2 parents 8fbebd4 + aafcf3f commit 508c8eb

File tree

22 files changed

+252
-252
lines changed

22 files changed

+252
-252
lines changed

Diff for: 1-js/05-data-types/11-date/1-new-date/solution.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
The `new Date` constructor uses the local time zone. So the only important thing to remember is that months start from zero.
1+
Constructorul `new Date` utilizează fusul orar local. Așadar singurul lucru important de reținut este că lunile încep de la zero.
22

3-
So February has number 1.
3+
Deci Februarie are numărul 1.
44

5-
Here's an example with numbers as date components:
5+
Iată un exemplu cu numere ca și componente ale datei:
66

77
```js run
8-
//new Date(year, month, date, hour, minute, second, millisecond)
8+
//new Date(an, lună, dată, oră, minut, secundă, milisecundă)
99
let d1 = new Date(2012, 1, 20, 3, 12);
1010
alert( d1 );
1111
```
12-
We could also create a date from a string, like this:
12+
Am putea de asemenea să creăm o dată dintr-un șir, în felul următor:
1313

1414
```js run
1515
//new Date(datastring)

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ importance: 5
22

33
---
44

5-
# Create a date
5+
# Creați o dată
66

7-
Create a `Date` object for the date: Feb 20, 2012, 3:12am. The time zone is local.
7+
Creați un obiect `Date` pentru data: Feb 20, 2012, 3:12am. Fusul orar este local.
88

9-
Show it using `alert`.
9+
Afișați-o folosind `alert`.

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

+2-2
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+
Metoda `date.getDay()` returnează numărul zilei săptămânii, începând de duminică.
22

3-
Let's make an array of weekdays, so that we can get the proper day name by its number:
3+
Să creăm o matrice de zile ale săptămânii, astfel încât să putem obține numele zilei corespunzătoare prin numărul ei:
44

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

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ importance: 5
22

33
---
44

5-
# Show a weekday
5+
# Arată o zi a săptămânii
66

7-
Write a function `getWeekDay(date)` to show the weekday in short format: 'MO', 'TU', 'WE', 'TH', 'FR', 'SA', 'SU'.
7+
Scrieți o funcție `getWeekDay(date)` pentru a afișa ziua săptămânii în format scurt: 'MO', 'TU', 'WE', 'TH', 'FR', 'SA', 'SU'.
88

9-
For instance:
9+
De exemplu:
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) ); // ar trebui să iasă "TU"
1414
```

Diff for: 1-js/05-data-types/11-date/3-weekday/_js.view/solution.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ function getLocalDay(date) {
22

33
let day = date.getDay();
44

5-
if (day == 0) { // weekday 0 (sunday) is 7 in european
5+
if (day == 0) { // ziua săptămânii 0 (sunday) este 7 în Europa
66
day = 7;
77
}
88

Diff for: 1-js/05-data-types/11-date/3-weekday/_js.view/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
describe("getLocalDay returns the \"european\" weekday", function() {
1+
describe("getLocalDay returnează ziua \"europeană\"", function() {
22
it("3 January 2014 - friday", function() {
33
assert.equal(getLocalDay(new Date(2014, 0, 3)), 5);
44
});

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ importance: 5
22

33
---
44

5-
# European weekday
5+
# Zi lucrătoare europeană
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+
Țările europene au zile ale săptămânii care încep cu Monday (numărul 1), apoi Tuesday (numărul 2) și până Sunday (numărul 7). Scrieți o funcție `getLocalDay(date)` care returnează ziua săptămânii "Europene" pentru `date`.
88

99
```js no-beautify
1010
let date = new Date(2012, 0, 3); // 3 Jan 2012
11-
alert( getLocalDay(date) ); // tuesday, should show 2
11+
alert( getLocalDay(date) ); // tuesday, ar trebui să arate 2
1212
```

Diff for: 1-js/05-data-types/11-date/4-get-date-ago/_js.view/test.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
describe("getDateAgo", function() {
22

3-
it("1 day before 02.01.2015 -> day 1", function() {
3+
it("1 zi înainte de 02.01.2015 -> day 1", function() {
44
assert.equal(getDateAgo(new Date(2015, 0, 2), 1), 1);
55
});
66

77

8-
it("2 days before 02.01.2015 -> day 31", function() {
8+
it("2 zile înainte de 02.01.2015 -> ziua 31", function() {
99
assert.equal(getDateAgo(new Date(2015, 0, 2), 2), 31);
1010
});
1111

12-
it("100 days before 02.01.2015 -> day 24", function() {
12+
it("100 zile înainte de 02.01.2015 -> ziua 24", function() {
1313
assert.equal(getDateAgo(new Date(2015, 0, 2), 100), 24);
1414
});
1515

16-
it("365 days before 02.01.2015 -> day 2", function() {
16+
it("365 zile înainte de 02.01.2015 -> ziua 2", function() {
1717
assert.equal(getDateAgo(new Date(2015, 0, 2), 365), 2);
1818
});
1919

20-
it("does not modify the given date", function() {
20+
it("nu modifică date-ul dat", function() {
2121
let date = new Date(2015, 0, 2);
2222
let dateCopy = new Date(date);
2323
getDateAgo(dateCopy, 100);

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

+3-3
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+
Ideea este simplă: se scade un anumit număr de zile din `date`:
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+
...Dar funcția nu ar trebui să modifice `date`. Acesta este un lucru important, deoarece codul exterior care ne oferă data nu se așteaptă ca aceasta să se schimbe.
1111

12-
To implement it let's clone the date, like this:
12+
Pentru a implementa acest lucru haideŧi să clonăm data, astfel:
1313

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

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

+5-5
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+
# Ce zi a lunii a fost acum multe zile?
66

7-
Create a function `getDateAgo(date, days)` to return the day of month `days` ago from the `date`.
7+
Creați o funcție `getDateAgo(date, days)` pentru a returna ziua din lună de acum `days` din `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+
De exemplu, dacă astăzi este 20, atunci `getDateAgo(new Date(), 1)` ar trebui să fie 19 și `getDateAgo(new Date(), 2)` ar trebui să fie 18.
1010

11-
Should work reliably for `days=365` or more:
11+
Ar trebui să funcționeze în mod fiabil pentru `days=365` sau mai mult:
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.S. Funcția nu trebuie să modifice `date`-ul dat.
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
describe("getLastDayOfMonth", function() {
2-
it("last day of 01.01.2012 - 31", function() {
2+
it("ultima zi din 01.01.2012 - 31", function() {
33
assert.equal(getLastDayOfMonth(2012, 0), 31);
44
});
55

6-
it("last day of 01.02.2012 - 29 (leap year)", function() {
6+
it("ultima zi din 01.02.2012 - 29 (an bisect)", function() {
77
assert.equal(getLastDayOfMonth(2012, 1), 29);
88
});
99

10-
it("last day of 01.02.2013 - 28", function() {
10+
it("ultima zi din 01.02.2013 - 28", function() {
1111
assert.equal(getLastDayOfMonth(2013, 1), 28);
1212
});
1313
});

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

+2-2
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+
Să creăm o dată folosind luna următoare, dar să trecem zero ca zi:
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+
În mod normal, datele încep de la 1, dar, din punct de vedere tehnic putem trece orice număr, data se va ajusta singură. Deci când trecem 0, atunci înseamnă "cu o zi înainte de prima zi a lunii", cu alte cuvinte: "ultima zi a lunii precedente".

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ importance: 5
22

33
---
44

5-
# Last day of month?
5+
# Ultima zi a lunii?
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+
Scrieți o funcție `getLastDayOfMonth(year, month)` care să returneze ultima zi a lunii. Uneori este 30, 31 sau chiar 28/29 pentru Feb.
88

9-
Parameters:
9+
Parametrii:
1010

11-
- `year` -- four-digits year, for instance 2012.
12-
- `month` -- month, from 0 to 11.
11+
- `year` -- anul din patru cifre, de exemplu 2012.
12+
- `month` -- luna, de la 0 la 11.
1313

14-
For instance, `getLastDayOfMonth(2012, 1) = 29` (leap year, Feb).
14+
De exemplu, `getLastDayOfMonth(2012, 1) = 29` (an bisect, Feb).

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

+6-6
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+
Pentru a obține numărul de secunde, putem genera o dată folosind ziua și ora curentă 00:00:00, apoi să o scădem din "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+
Diferența este numărul de milisecunde de la începutul zilei, pe care trebuie să-l împărțim la 1000 pentru a obține secundele:
44

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

9-
// create an object using the current day/month/year
9+
// creați un obiect folosind ziua/luna/anul curent
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; // diferența de ms
13+
return Math.round(diff / 1000); // face secunde
1414
}
1515

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

19-
An alternative solution would be to get hours/minutes/seconds and convert them to seconds:
19+
O soluție alternativă ar fi să se obțină ore/minute/secunde și să se convertească în secunde:
2020

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

Diff for: 1-js/05-data-types/11-date/6-get-seconds-today/task.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ importance: 5
22

33
---
44

5-
# How many seconds have passed today?
5+
# Câte secunde au trecut astăzi?
66

7-
Write a function `getSecondsToday()` that returns the number of seconds from the beginning of today.
7+
Scrieți o funcție `getSecondsToday()` care returnează numărul de secunde de la începutul zilei de astăzi.
88

9-
For instance, if now were `10:00 am`, and there was no daylight savings shift, then:
9+
De exemplu, dacă acum este `10:00 am`, și nu a fost schimbată ora de vară, atunci:
1010

1111
```js
1212
getSecondsToday() == 36000 // (3600 * 10)
1313
```
1414

15-
The function should work in any day. That is, it should not have a hard-coded value of "today".
15+
Funcția ar trebui să funcționeze în orice zi. Adică, nu ar trebui să aibă o valoare "astăzi" hard-coded.
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
To get the number of milliseconds till tomorrow, we can from "tomorrow 00:00:00" substract the current date.
1+
Pentru a obține numărul de milisecunde până mâine, putem scădea din "mâine 00:00:00" data curentă.
22

3-
First, we generate that "tomorrow", and then do it:
3+
Mai întâi, generăm acel "mâine", și apoi facem acest lucru:
44

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

9-
// tomorrow date
9+
// data de mâine
1010
let tomorrow = new Date(now.getFullYear(), now.getMonth(), *!*now.getDate()+1*/!*);
1111

12-
let diff = tomorrow - now; // difference in ms
13-
return Math.round(diff / 1000); // convert to seconds
12+
let diff = tomorrow - now; // diferența în ms
13+
return Math.round(diff / 1000); // convertește în secunde
1414
}
1515
```
1616

17-
Alternative solution:
17+
Soluție alternativă:
1818

1919
```js run
2020
function getSecondsToTomorrow() {
@@ -29,4 +29,4 @@ function getSecondsToTomorrow() {
2929
}
3030
```
3131

32-
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.
32+
Vă rugăm să rețineți că multe țări au ora de vară (DST), astfel încât pot exista zile cu 23 sau 25 de ore. Este posibil să dorim să tratăm aceste zile separat.

Diff for: 1-js/05-data-types/11-date/7-get-seconds-to-tomorrow/task.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ importance: 5
22

33
---
44

5-
# How many seconds till tomorrow?
5+
# Câte secunde până mâine?
66

7-
Create a function `getSecondsToTomorrow()` that returns the number of seconds till tomorrow.
7+
Creați o funcție `getSecondsToTomorrow()` care returnează numărul de secunde până mâine.
88

9-
For instance, if now is `23:00`, then:
9+
De exemplu, dacă acum este `23:00`, atunci:
1010

1111
```js
1212
getSecondsToTomorrow() == 3600
1313
```
1414

15-
P.S. The function should work at any day, the "today" is not hardcoded.
15+
P.S. Funcția ar trebui să funcționeze în orice zi, "astăzi" nu este hardcoded.
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11

22
function formatDate(date) {
3-
let diff = new Date() - date; // the difference in milliseconds
3+
let diff = new Date() - date; // diferența în milisecunde
44

5-
if (diff < 1000) { // less than 1 second
6-
return 'right now';
5+
if (diff < 1000) { // mai puțin de 1 secundă
6+
return 'chiar acum';
77
}
88

9-
let sec = Math.floor(diff / 1000); // convert diff to seconds
9+
let sec = Math.floor(diff / 1000); // convertește diff în secunde
1010

1111
if (sec < 60) {
12-
return sec + ' sec. ago';
12+
return sec + ' sec. în urmă';
1313
}
1414

15-
let min = Math.floor(diff / 60000); // convert diff to minutes
15+
let min = Math.floor(diff / 60000); // convertește diff în minute
1616
if (min < 60) {
17-
return min + ' min. ago';
17+
return min + ' min. în urmă';
1818
}
1919

20-
// format the date
21-
// add leading zeroes to single-digit day/month/hours/minutes
20+
// formatați data
21+
// adăugați zerouri de început unde este o singură cifră la zi/lună/ore/minute
2222
let d = date;
2323
d = [
2424
'0' + d.getDate(),
2525
'0' + (d.getMonth() + 1),
2626
'' + d.getFullYear(),
2727
'0' + d.getHours(),
2828
'0' + d.getMinutes()
29-
].map(component => component.slice(-2)); // take last 2 digits of every component
29+
].map(component => component.slice(-2)); // se iau ultimele 2 cifre din fiecare component
3030

31-
// join the components into date
31+
// uniți componentele în date
3232
return d.slice(0, 3).join('.') + ' ' + d.slice(3).join(':');
3333
}

Diff for: 1-js/05-data-types/11-date/8-format-date-relative/_js.view/test.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
describe("formatDate", function() {
2-
it("shows 1ms ago as \"right now\"", function() {
3-
assert.equal(formatDate(new Date(new Date - 1)), 'right now');
2+
it("arată 1ms în urmă ca \"chiar acum\"", function() {
3+
assert.equal(formatDate(new Date(new Date - 1)), 'chiar acum');
44
});
55

6-
it('"30 seconds ago"', function() {
7-
assert.equal(formatDate(new Date(new Date - 30 * 1000)), "30 sec. ago");
6+
it('"30 secunde în urmă"', function() {
7+
assert.equal(formatDate(new Date(new Date - 30 * 1000)), "30 sec. în urmă");
88
});
99

10-
it('"5 minutes ago"', function() {
11-
assert.equal(formatDate(new Date(new Date - 5 * 60 * 1000)), "5 min. ago");
10+
it('"5 minute în urmă"', function() {
11+
assert.equal(formatDate(new Date(new Date - 5 * 60 * 1000)), "5 min. în urmă");
1212
});
1313

14-
it("older dates as DD.MM.YY HH:mm", function() {
14+
it("date mai vechi precum DD.MM.YY HH:mm", function() {
1515
assert.equal(formatDate(new Date(2014, 2, 1, 11, 22, 33)), "01.03.14 11:22");
1616
});
1717

0 commit comments

Comments
 (0)