Skip to content

Commit 1ba5705

Browse files
Date and Time (#168)
* date and time * Update 1-js/05-data-types/11-date/6-get-seconds-today/solution.md * Update 1-js/05-data-types/11-date/2-get-week-day/solution.md * Update 1-js/05-data-types/11-date/8-format-date-relative/solution.md * Update 1-js/05-data-types/11-date/article.md * Update 1-js/05-data-types/11-date/article.md * Update 1-js/05-data-types/11-date/article.md * Update 1-js/05-data-types/11-date/article.md * Update 1-js/05-data-types/11-date/article.md * Update 1-js/05-data-types/11-date/article.md * Update 1-js/05-data-types/11-date/article.md * Update 1-js/05-data-types/11-date/article.md * Update 1-js/05-data-types/11-date/article.md * Update 1-js/05-data-types/11-date/article.md * Update 1-js/05-data-types/11-date/article.md * Update 1-js/05-data-types/11-date/article.md * Update 1-js/05-data-types/11-date/article.md Co-authored-by: Taras <oster.ok@gmail.com>
1 parent a05ff28 commit 1ba5705

File tree

16 files changed

+238
-238
lines changed

16 files changed

+238
-238
lines changed

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

Lines changed: 4 additions & 4 deletions
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+
Конструктор `new Date` використовує місцевий часовий пояс. Отже, єдина важлива річ, яку слід пам’ятати це те, що місяці починаються з нуля.
22

3-
So February has number 1.
3+
Тому лютий має номер 1.
44

5-
Here's an example with numbers as date components:
5+
Ось приклад з номерами як компонентам дати:
66

77
```js run
88
//new Date(year, month, date, hour, minute, second, millisecond)
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+
Ми також можемо створити дату з рядка, як наприклад:
1313

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

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+
# Створити дату
66

7-
Create a `Date` object for the date: Feb 20, 2012, 3:12am. The time zone is local.
7+
Створити об’єкт `Date` на дату: 20 лютого 2012, 3:12 ранку. Часовий пояс є місцевим.
88

9-
Show it using `alert`.
9+
Показати його за допомогою `alert`.
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
The method `date.getDay()` returns the number of the weekday, starting from sunday.
1+
Метод `date.getDay()` повертає номер робочого дня, починаючи з неділі.
22

3-
Let's make an array of weekdays, so that we can get the proper day name by its number:
3+
Зробімо масив буднів, щоб ми могли отримати відповідну назву дня за номером:
44

55
```js run demo
66
function getWeekDay(date) {
7-
let days = ['SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA'];
7+
let days = ['НД', 'ПН', 'ВТ', 'СР', 'ЧТ', 'ПТ', 'СБ'];
88

99
return days[date.getDay()];
1010
}
1111

12-
let date = new Date(2014, 0, 3); // 3 Jan 2014
13-
alert( getWeekDay(date) ); // FR
12+
let date = new Date(2014, 0, 3); // 3 січня 2014
13+
alert( getWeekDay(date) ); // ПТ
1414
```

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

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

33
---
44

5-
# Show a weekday
5+
# Показати робочий день
66

7-
Write a function `getWeekDay(date)` to show the weekday in short format: 'MO', 'TU', 'WE', 'TH', 'FR', 'SA', 'SU'.
7+
Напишіть функцію `getWeekDay(date)`, щоб показати робочий день у короткому форматі: 'ПН', 'ВТ', 'СР', 'ЧТ', 'ПТ', 'СБ', 'НД'.
88

9-
For instance:
9+
Наприклад:
1010

1111
```js no-beautify
12-
let date = new Date(2012, 0, 3); // 3 Jan 2012
13-
alert( getWeekDay(date) ); // should output "TU"
12+
let date = new Date(2012, 0, 3); // 3 січня 2012
13+
alert( getWeekDay(date) ); // повинно виводити "ВТ"
1414
```

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

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

33
---
44

5-
# European weekday
5+
# Європейський робочий день
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+
Європейські країни мають дні тижня, що починаються з понеділка (№ 1), потім вівторок (№ 2) та до неділі (№ 7). Напишіть функцію `getLocalDay(date)`, що повертає "європейський" день тижня для `date`.
88

99
```js no-beautify
10-
let date = new Date(2012, 0, 3); // 3 Jan 2012
11-
alert( getLocalDay(date) ); // tuesday, should show 2
10+
let date = new Date(2012, 0, 3); // 3 січня 2012
11+
alert( getLocalDay(date) ); // вівторок, слід показати 2
1212
```
Lines changed: 6 additions & 6 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+
Ідея проста: відняти від `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+
...Але функція не повинна змінювати `date`. Це важливо, тому що зовнішній код, який дає нам дату, не очікує, що вона зміниться.
1111

12-
To implement it let's clone the date, like this:
12+
Щоб реалізувати це, клонуймо дату, наступним чином:
1313

1414
```js run demo
1515
function getDateAgo(date, days) {
@@ -21,7 +21,7 @@ function getDateAgo(date, days) {
2121

2222
let date = new Date(2015, 0, 2);
2323

24-
alert( getDateAgo(date, 1) ); // 1, (1 Jan 2015)
25-
alert( getDateAgo(date, 2) ); // 31, (31 Dec 2014)
26-
alert( getDateAgo(date, 365) ); // 2, (2 Jan 2014)
24+
alert( getDateAgo(date, 1) ); // 1, (1 січня 2015)
25+
alert( getDateAgo(date, 2) ); // 31, (31 грудня 2014)
26+
alert( getDateAgo(date, 365) ); // 2, (2 січня 2014)
2727
```

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

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

33
---
44

5-
# Which day of month was many days ago?
5+
# Який день місяця був багато днів тому?
66

7-
Create a function `getDateAgo(date, days)` to return the day of month `days` ago from the `date`.
7+
Створіть функцію `getDateAgo(date, days)`, щоб повернути день місяця, який був `days` днів після `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+
Наприклад, якщо сьогодні -- 20-й, то `getDateAgo(new Date(), 1)` має бути 19-го, а `getDateAgo(new Date(), 2)` має бути 18-го.
1010

11-
Should work reliably for `days=365` or more:
11+
Має працювати надійно для `days = 365` або більше:
1212

1313
```js
1414
let date = new Date(2015, 0, 2);
1515

16-
alert( getDateAgo(date, 1) ); // 1, (1 Jan 2015)
17-
alert( getDateAgo(date, 2) ); // 31, (31 Dec 2014)
18-
alert( getDateAgo(date, 365) ); // 2, (2 Jan 2014)
16+
alert( getDateAgo(date, 1) ); // 1, (1 січня 2015)
17+
alert( getDateAgo(date, 2) ); // 31, (31 грудня 2014)
18+
alert( getDateAgo(date, 365) ); // 2, (2 січня 2014)
1919
```
2020

21-
P.S. The function should not modify the given `date`.
21+
P.S. Функція не повинна змінювати `date`.

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+
Створімо дату, використовуючи наступний місяць, але передамо нуль, як день:
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+
Зазвичай дати починаються з 1, але технічно ми можемо передати будь-яке число, дата автоматично відрегулює себе. Отже, коли ми передаємо 0, то це означає "за день до 1-го дня місяця", іншими словами: "останній день попереднього місяця".

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+
# Останній день місяця?
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+
Напишіть функцію `getLastDayOfMonth(year, month)`, що повертає останній день місяця. Іноді це 30-е, 31-ше або навіть 28/29-е для лютого.
88

9-
Parameters:
9+
Параметри:
1010

11-
- `year` -- four-digits year, for instance 2012.
12-
- `month` -- month, from 0 to 11.
11+
- `year` -- чотиризначний рік, наприклад 2012.
12+
- `month` -- місяць, від 0 to 11.
1313

14-
For instance, `getLastDayOfMonth(2012, 1) = 29` (leap year, Feb).
14+
Наприклад, `getLastDayOfMonth(2012, 1) = 29` (високосний рік, лютий).

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+
Щоб отримати кількість секунд, ми можемо створити дату, використовуючи поточний день та час 00:00:00, а потім відняти його від "зараз".
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+
Різниця -- це кількість мілісекунд з початку дня, яку ми повинні розділити на 1000, щоб отримати секунди:
44

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

9-
// create an object using the current day/month/year
9+
// створити об’єкт, використовуючи поточний день/місяць/рік
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; // мс різниця
13+
return Math.round(diff / 1000); // зробити секунди
1414
}
1515

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

19-
An alternative solution would be to get hours/minutes/seconds and convert them to seconds:
19+
Альтернативне рішення полягає в тому, щоб отримати години/хвилини/секунди та конвертувати їх до секунд:
2020

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

0 commit comments

Comments
 (0)