-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzodiac.js
More file actions
52 lines (48 loc) · 1.29 KB
/
zodiac.js
File metadata and controls
52 lines (48 loc) · 1.29 KB
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
/**
Created by Complynx on 22.03.2019,
http://complynx.net
<[email protected]> Daniel Drizhuk
*/
let zodiac_cfg = [20,19,20,20,21,21,22,23,23,23,22,21]; // rollover days of month
let zodiac_names = [
"Capricorn",
"Aquarius",
"Pisces",
"Aries",
"Taurus",
"Gemini",
"Cancer",
"Leo",
"Virgo",
"Libra",
"Scorpio",
"Sagittarius",
"Ophiuchus"
];
/**
* returns zodiac number, where:
* Capricorn = 0
* Aquarius = 1
* ...
* Sagittarius = 11
*
* If `ophiuchus` is true, then 12 will be returned in it's dates
* @param {Date} birth_date
* @param {boolean=} ophiuchus check for 13'th sign
* @return {number}*/
export function Z(birth_date, ophiuchus) {
let month = birth_date.getMonth() + 1;
let day = birth_date.getDate();
if(ophiuchus && ((month === 11 && day > 29) || (month === 12 && day < 18))) return 12;
return day > zodiac_cfg[month-1] ? (month) % 12 : (month - 1);
}
/**
* returns zodiac name regarding the date provided
* If `ophiuchus` is true, then it will be returned as well.
* @param {Date} birth_date
* @param {boolean=} ophiuchus check for 13'th sign
* @returns {string} zodiac sign
*/
export function zodiac(birth_date, ophiuchus) {
return zodiac_names[Z(birth_date, ophiuchus)];
}