Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Фирсов Николай #111

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
53b1912
Перевод времени
kolyafirsov Oct 10, 2016
f65d244
Исправление табуляции
kolyafirsov Oct 10, 2016
277fb94
Исправление табуляции 2
kolyafirsov Oct 10, 2016
9e93b78
Исправление табуляции 3
kolyafirsov Oct 10, 2016
b0ce1de
Исправление табуляции 4
kolyafirsov Oct 10, 2016
2e0f617
Исправление табуляции 5
kolyafirsov Oct 10, 2016
5532d35
Исправление табуляции 6
kolyafirsov Oct 10, 2016
b90a58d
Исправление табуляции 7
kolyafirsov Oct 10, 2016
f191ece
Исправление табуляции 8
kolyafirsov Oct 10, 2016
500cf4d
Исправление табуляции 9
kolyafirsov Oct 10, 2016
335ede4
Исправление табуляции 10
kolyafirsov Oct 10, 2016
4c220c2
Исправление табуляции 11
kolyafirsov Oct 10, 2016
bc18dc6
Исправление TypeError
kolyafirsov Oct 11, 2016
ebaf074
fix TypeError
kolyafirsov Oct 11, 2016
8ff2062
Исправление условий
kolyafirsov Oct 11, 2016
223102f
spaces TypeError
kolyafirsov Oct 11, 2016
049d9a3
Исправление TypeError 2
kolyafirsov Oct 11, 2016
6d97cb6
Исправление TypeError 3
kolyafirsov Oct 11, 2016
e179be7
Буквы исправлены
kolyafirsov Oct 11, 2016
3e52379
fix :
kolyafirsov Oct 11, 2016
bfcc69a
fix string
kolyafirsov Oct 11, 2016
3fe910a
пробел
kolyafirsov Oct 11, 2016
89e369d
fix fix
kolyafirsov Oct 11, 2016
d32039f
fix 6
kolyafirsov Oct 11, 2016
ede8ed3
fix string
kolyafirsov Oct 11, 2016
f10dd5a
7:10
kolyafirsov Oct 11, 2016
b61f437
fix ЖЖЭ
kolyafirsov Oct 11, 2016
58bf147
fix ::
kolyafirsov Oct 11, 2016
293e0b0
fix
kolyafirsov Oct 11, 2016
7ce4c4b
fix 2
kolyafirsov Oct 11, 2016
a15bb96
fix 3
kolyafirsov Oct 11, 2016
4664962
fix 4
kolyafirsov Oct 11, 2016
73bfdeb
fix inc
kolyafirsov Oct 12, 2016
6c271a8
fix spaces
kolyafirsov Oct 12, 2016
bf055e8
fix inc 2
kolyafirsov Oct 12, 2016
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
66 changes: 65 additions & 1 deletion roman-time.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,72 @@
* @param {String} time – время в формате HH:MM (например, 09:05)
* @returns {String} – время римскими цифрами (IX:V)
*/

function translate(timeRoman) {
var romanNumber = ['N', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII',
'VIII', 'IX', 'X', 'XX', 'XXX', 'XL', 'L', 'LX'];
var arabicNumber = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50, 60];

var timeTranslate;
if (timeRoman <= 10) {
timeTranslate = romanNumber[arabicNumber.indexOf(timeRoman)];
} else {
timeTranslate = romanNumber[arabicNumber.indexOf(parseInt(timeRoman / 10) * 10)] +
romanNumber[arabicNumber.indexOf(timeRoman % 10)];
}

return timeTranslate;
}

function range(hour, minutes) {
if (hour > 23 || minutes >= 60 || hour < 0 || minutes < 0) {
return true;
}

return false;
}

function whole(arr) {
if (isNaN(arr[0]) || isNaN(arr[1]) || arr[0].indexOf('.') !== -1 ||
arr[1].indexOf('.') !== -1) {
return true;
}

return false;
}

function notNull(time) {
if (time === '' || time === ':' || typeof time !== 'string') {
return true;
}

return false;
}

function notNan(arr) {
if (arr[0] === ' ' || arr[1] === ' ' || arr[2] !== undefined) {
return true;
}

return false;
}

function romanTime(time) {
// Немного авторского кода и замечательной магии
if (time === '' || time.length !== 5) {
throw new TypeError('Неверное время', 'roman-time.js');
} else {
var arr = time.split(':');
var hour = parseInt(arr[0]);
var minutes = parseInt(arr[1]);
}


if (range(hour, minutes, arr) || whole(arr) || notNull(time) || notNan(arr)) {
throw new TypeError('Неверное время', 'roman-time.js');
} else {
time = translate(hour) + ':' + translate(minutes);
}

return time;
}

Expand Down