This repository has been archived by the owner on Mar 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
counters.js
49 lines (41 loc) · 1.17 KB
/
counters.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import config from './config.js'
const daysInYear = (year) => {
let currentMonthsLength = config.monthsLength[year]
if (currentMonthsLength === undefined) {
currentMonthsLength = config.monthsLength.standart
return (
currentMonthsLength.reduce((acc, cur) => {
return acc + cur
}, 0) + (config.additionalDay.includes(year % config.cycle) ? 1 : 0)
)
}
return currentMonthsLength.reduce((acc, cur) => {
return acc + cur
}, 0)
}
const searchMonth = (month) => {
return config.monthsNames.reduce((acc, cur, ind) => {
return acc === false && cur.includes(month) ? ind + 1 : acc
}, false)
}
const daysInYears = (year, acc = 0) => {
if (year === 0) {
return acc
}
return daysInYears(year - 1, acc + daysInYear(year))
}
const daysInMonths = (month, year) => {
if (month === 0) {
return 0
}
let currentMonthsLength = config.monthsLength[year]
if (currentMonthsLength === undefined) {
currentMonthsLength = config.monthsLength.standart
}
return currentMonthsLength[month - 1] + daysInMonths(month - 1, year)
}
export default {
searchMonth: searchMonth,
daysInYears: daysInYears,
daysInMonths: daysInMonths,
}