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
10 changes: 5 additions & 5 deletions 1-js/05-data-types/11-date/1-new-date/solution.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
The `new Date` constructor uses the local time zone. So the only important thing to remember is that months start from zero.
Constructorul `new Date` utilizează fusul orar local. Așadar singurul lucru important de reținut este că lunile încep de la zero.

So February has number 1.
Deci Februarie are numărul 1.

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

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

```js run
//new Date(datastring)
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ți o dată

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

Show it using `alert`.
Afișați-o folosind `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.
Metoda `date.getDay()` returnează numărul zilei săptămânii, începând de duminică.

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

```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
# Arată o zi a săptămânii

Write a function `getWeekDay(date)` to show the weekday in short format: 'MO', 'TU', 'WE', 'TH', 'FR', 'SA', 'SU'.
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'.

For instance:
De exemplu:

```js no-beautify
let date = new Date(2012, 0, 3); // 3 Jan 2012
alert( getWeekDay(date) ); // should output "TU"
alert( getWeekDay(date) ); // ar trebui să iasă "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) { // ziua săptămânii 0 (sunday) este 7 în Europa
day = 7;
}

Expand Down
2 changes: 1 addition & 1 deletion 1-js/05-data-types/11-date/3-weekday/_js.view/test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
describe("getLocalDay returns the \"european\" weekday", function() {
describe("getLocalDay returnează ziua \"europeană\"", function() {
it("3 January 2014 - friday", function() {
assert.equal(getLocalDay(new Date(2014, 0, 3)), 5);
});
Expand Down
6 changes: 3 additions & 3 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
# Zi lucrătoare europeană

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`.
Ță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`.

```js no-beautify
let date = new Date(2012, 0, 3); // 3 Jan 2012
alert( getLocalDay(date) ); // tuesday, should show 2
alert( getLocalDay(date) ); // tuesday, ar trebui să arate 2
```
10 changes: 5 additions & 5 deletions 1-js/05-data-types/11-date/4-get-date-ago/_js.view/test.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
describe("getDateAgo", function() {

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


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

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

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

it("does not modify the given date", function() {
it("nu modifică date-ul dat", function() {
let date = new Date(2015, 0, 2);
let dateCopy = new Date(date);
getDateAgo(dateCopy, 100);
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`:
Ideea este simplă: se scade un anumit număr de zile din `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.
...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.

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

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

Create a function `getDateAgo(date, days)` to return the day of month `days` ago from the `date`.
Creați o funcție `getDateAgo(date, days)` pentru a returna ziua din lună de acum `days` din `date`.

For instance, if today is 20th, then `getDateAgo(new Date(), 1)` should be 19th and `getDateAgo(new Date(), 2)` should be 18th.
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.

Should work reliably for `days=365` or more:
Ar trebui să funcționeze în mod fiabil pentru `days=365` sau mai mult:

```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. Funcția nu trebuie să modifice `date`-ul dat.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
describe("getLastDayOfMonth", function() {
it("last day of 01.01.2012 - 31", function() {
it("ultima zi din 01.01.2012 - 31", function() {
assert.equal(getLastDayOfMonth(2012, 0), 31);
});

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

it("last day of 01.02.2013 - 28", function() {
it("ultima zi din 01.02.2013 - 28", function() {
assert.equal(getLastDayOfMonth(2013, 1), 28);
});
});
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:
Să creăm o dată folosind luna următoare, dar să trecem zero ca zi:
```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".
Î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".
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?
# Ultima zi a lunii?

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

Parameters:
Parametrii:

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

For instance, `getLastDayOfMonth(2012, 1) = 29` (leap year, Feb).
De exemplu, `getLastDayOfMonth(2012, 1) = 29` (an bisect, Feb).
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".
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".

The difference is the number of milliseconds from the beginning of the day, that we should divide by 1000 to get seconds:
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:

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

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

alert( getSecondsToday() );
```

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

```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?
# Câte secunde au trecut astăzi?

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

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

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

The function should work in any day. That is, it should not have a hard-coded value of "today".
Funcția ar trebui să funcționeze în orice zi. Adică, nu ar trebui să aibă o valoare "astăzi" hard-coded.
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.
Pentru a obține numărul de milisecunde până mâine, putem scădea din "mâine 00:00:00" data curentă.

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

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

// tomorrow date
// data de mâine
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; // diferența în ms
return Math.round(diff / 1000); // convertește în secunde
}
```

Alternative solution:
Soluție alternativă:

```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.
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.
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?
# Câte secunde până mâine?

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

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

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

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

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

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

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

if (sec < 60) {
return sec + ' sec. ago';
return sec + ' sec. în urmă';
}

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

// format the date
// add leading zeroes to single-digit day/month/hours/minutes
// formatați data
// adăugați zerouri de început unde este o singură cifră la zi/lună/ore/minute
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)); // se iau ultimele 2 cifre din fiecare component

// join the components into date
// uniți componentele în date
return d.slice(0, 3).join('.') + ' ' + d.slice(3).join(':');
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
describe("formatDate", function() {
it("shows 1ms ago as \"right now\"", function() {
assert.equal(formatDate(new Date(new Date - 1)), 'right now');
it("arată 1ms în urmă ca \"chiar acum\"", function() {
assert.equal(formatDate(new Date(new Date - 1)), 'chiar acum');
});

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

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

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

Expand Down
Loading