-
Notifications
You must be signed in to change notification settings - Fork 1
/
years.js
146 lines (139 loc) · 5.39 KB
/
years.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
class YearController {
firstYear(years, months, weeks, days, hours, minutes, seconds) {
if (months === 0 && weeks === 0 && days === 0 && hours < 24 && minutes <= 29 && seconds <= 59) {
return {
value: `${years} year`,
prefix: "",
distance: `${years} year`
}
} else if (months < 1 && weeks <= 1 && days <= 3 && hours < 24 && minutes <= 59 && seconds <= 59) {
return {
value: `${years} year`,
prefix: "about",
distance: `about a year`
}
} else if (months === 11 && weeks >= 2 && weeks < 3 && days > 3 && hours < 24 && minutes <= 59 && seconds <= 59) {
return {
value: `${years + 1} years`,
prefix: "less than",
distance: `less than ${years + 1} years`
}
} else if (months >= 11 && weeks >= 3 && days >= 0 && hours < 24 && minutes <= 59 && seconds <= 59) {
return {
value: `${years + 1} year`,
prefix: "about",
distance: `about ${years + 1} years`
}
} else {
return {
value: `${years} year`,
prefix: "more than",
distance: `more than ${years} year`
}
}
}
years(years, months, weeks, days, hours, minutes, seconds) {
if (months === 0 && weeks === 0 && days <= 1 && hours < 24 && minutes <= 29 && seconds <= 59) {
return {
value: `${years} years`,
prefix: "",
distance: `${years} years`
}
} else if (months === 0 && weeks <= 2 && days <= 6 && hours < 24 && minutes <= 59 && seconds <= 59) {
return {
value: `${years} years`,
prefix: "about",
distance: `about ${years} years`
}
} else if (months === 11) {
if (weeks >= 3) {
return {
value: `${years + 1} years`,
prefix: "about",
distance: `about ${years + 1} years`
}
} else if (weeks >= 1 && days >= 3) {
return {
value: `${years + 1} year`,
prefix: "less than",
distance: `less than ${years + 1} years`
}
} else {
return {
value: `${years} year`,
prefix: "more than",
distance: `more than ${years} years`
}
}
} else {
return {
value: `${years} ${years === 1 ? "year" : "years"}`,
prefix: "more than",
distance: `more than ${years} ${years === 1 ? "year" : "years"}`
}
}
}
decades(years) {
const reminder = years % 10
let distance = `${years} ${years === 1 ? "year" : "years"}`
let prefix = "more than"
if (reminder === 0) {
return {
value: `${years} years`,
prefix: "",
distance: `${Math.floor(years / 10) === 1 ? "a decade" : `${Math.floor(years / 10)} decades`}`
}
}
else if (reminder == 8 || reminder == 7) {
return {
value: `${Math.floor(years / 10) + 1} decades`,
prefix: "less than",
distance: `less than ${Math.floor(years / 10) + 1} decades`
}
} else if (reminder <= 3 || reminder >= 7) {
return {
value: `${Math.floor(years / 10) === 1 ? "a decade" : `${Math.floor(years / 10)} decades`}`,
prefix: "about",
distance: `about ${Math.floor(years / 10) === 1 ? "a decade" : `${Math.floor(years / 10)} decades`}`
}
} else {
return {
value: `${Math.floor(years / 10)} decades`,
prefix: "more than",
distance: `more than ${Math.floor(years / 10)} decades`
}
}
}
centuries(years) {
const reminder = years % 100
let distance = `${years} ${years === 1 ? "year" : "years"}`
let prefix = "more than"
if (reminder === 0) {
return {
value: `${years} years`,
prefix: "",
distance: `${Math.floor(years / 100) === 1 ? "a century" : `${Math.floor(years / 100)} centuries`}`
}
}
else if (reminder == 80 || reminder == 70) {
return {
value: `${Math.floor(years / 100) + 1} centuries`,
prefix: "less than",
distance: `less than ${Math.floor(years / 100) + 1} centuries`
}
} else if (reminder <= 30 || reminder >= 70) {
return {
value: `${Math.floor(years / 100) === 1 ? "a century" : `${Math.floor(years / 100)} centuries`}`,
prefix: "about",
distance: `about ${Math.floor(years / 100) === 1 ? "a century" : `${Math.floor(years / 100)} centuries`}`
}
} else {
return {
value: `${Math.floor(years / 100)} centuries`,
prefix: "more than",
distance: `more than ${Math.floor(years / 100)} centuries`
}
}
}
}
module.exports = YearController;