Files

157 lines
5.4 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
id: bd7158d8c443edefaeb5bdef
title: Мікросервіс часової мітки
challengeType: 4
forumTopicId: 301508
dashedName: timestamp-microservice
---
# --description--
Створіть full stack додаток на JavaScript, який функціонально схожий до цього: <https://timestamp-microservice.freecodecamp.rocks/>. Робота над цим проектом залучатиме тебе писати свій код використовуючи один з наступних методів:
- Клонувати [цей репозиторій з GitHub](https://github.com/freeCodeCamp/boilerplate-project-timestamp/) та локально завершити свій проект.
- Використати [наш проект для початківців на Replit](https://replit.com/github/freeCodeCamp/boilerplate-project-timestamp) для завершення свого проекту.
- Використати конструктор сайтів на свій вибір для завершення проекту. Впевніться, що ви зберегли всі файли із нашого GitHub репозиторію.
По завершенню переконайтеся, що працююча демоверсія вашого проєкту розміщена у відкритому доступі. Потім введіть його URL-адресу в поле `Solution Link`. За бажанням також можете ввести посилання на вихідний код вашого проєкту в полі `GitHub Link`.
**Зверніть увагу:** оскільки мета проєкту не в перетворенні часу, припускайте, що усі відправлені дати будуть розглянуті `new Date()` як GMT.
# --hints--
Вам необхідно вказати свій власний проект, а не приклад URL-адреси.
```js
(getUserInput) => {
assert(
!/.*\/timestamp-microservice\.freecodecamp\.rocks/.test(getUserInput('url'))
);
};
```
Запит на `/api/:date?` з дійсною датою має повернути об’єкт JSON з `unix` ключем, який є часовою міткою Unix введеної дати в мілісекундах
```js
(getUserInput) =>
$.get(getUserInput('url') + '/api/2016-12-25').then(
(data) => {
assert.equal(
data.unix,
1482624000000,
'Should be a valid unix timestamp'
);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
Запит на `/api/:date?` з дійсною датою має повернути об'єкт JSON з `utc` ключем, який є рядком введеної дати в форматі: `Thu, 01 Jan 1970 00:00:00 GMT`
```js
(getUserInput) =>
$.get(getUserInput('url') + '/api/2016-12-25').then(
(data) => {
assert.equal(
data.utc,
'Sun, 25 Dec 2016 00:00:00 GMT',
'Should be a valid UTC date string'
);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
Запит до `/api/1451001600000` має повертати `{ unix: 1451001600000, utc: "Fri, 25 Dec 2015 00:00:00 GMT" }`
```js
(getUserInput) =>
$.get(getUserInput('url') + '/api/1451001600000').then(
(data) => {
assert(
data.unix === 1451001600000 &&
data.utc === 'Fri, 25 Dec 2015 00:00:00 GMT'
);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
Ваш проєкт може обробляти дати, які можуть бути успішно розпарсені за допомогою `new Date(date_string)`
```js
(getUserInput) =>
$.get(getUserInput('url') + '/api/05 October 2011, GMT').then(
(data) => {
assert(
data.unix === 1317772800000 &&
data.utc === 'Wed, 05 Oct 2011 00:00:00 GMT'
);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
Якщо введений рядок дати невірний, api повертає об'єкт, що має структуру `{ error : "Invalid Date" }`
```js
(getUserInput) =>
$.get(getUserInput('url') + '/api/this-is-not-a-date').then(
(data) => {
assert.equal(data.error.toLowerCase(), 'invalid date');
},
(xhr) => {
assert(xhr.responseJSON.error.toLowerCase() === 'invalid date');
}
);
```
Порожній параметр дати має повернути поточний час в об'єкті JSON з ключем `unix`
```js
(getUserInput) =>
$.get(getUserInput('url') + '/api').then(
(data) => {
var now = Date.now();
assert.approximately(data.unix, now, 20000);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
Порожній параметр дати має повернути поточний час в об'єкті JSON з ключем `utc`
```js
(getUserInput) =>
$.get(getUserInput('url') + '/api').then(
(data) => {
var now = Date.now();
var serverTime = new Date(data.utc).getTime();
assert.approximately(serverTime, now, 20000);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
# --solutions--
```js
/**
Backend challenges don't need solutions,
because they would need to be tested against a full working project.
Please check our contributing guidelines to learn more.
*/
```