Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.js
More file actions
Latest commit
101 lines (80 loc) · 2.73 KB
/
Copy pathutils.js
File metadata and controls
101 lines (80 loc) · 2.73 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
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
constslack=require('./models/slack').slack_client;
/**
* function used to send a message to a list of channels
*
* @param channel_list Aarray -- list of channels
* @param message String -- message to be sent
*/
functionmessageChannel(channel_list,message){
channel_list=!Array.isArray(channel_list) ? [channel_list] : channel_list;
channel_list.forEach((channel)=>{
channel=`#${channel}`;
try{
console.log(`Sending message to ${channel}\n ${message}`);
slack.chat.postMessage(channel,message);
}catch(e){
console.info(`Error sending message to ${channel}`);
console.error(e);
}
});
}
/**
* function used to send a message to a list of users
*
* @param user_list Array -- list of users
* @param message String -- message to be sent
*/
functionmessageUser(user_list,message){
user_list=!Array.isArray(user_list) ? [user_list] : user_list;
user_list.forEach((user)=>{
user=`#${user}`;
try{
console.log(`Sending message to ${user}\n ${message}`);
slack.chat.postMessage(user,message);
}catch(e){
console.info(`Error sending message to ${user}`);
console.error(e);
}
});
}
letcolors=['#00E8EF','#5C03DB','#EF005E','#FFBD03','#00D675'],
color_used=0,
color_len=colors.length-1;
functionnextColor(){
if(color_used>color_len){
color_used=0;
}
varcolor=colors[color_used];
color_used+=1;
returncolor;
}
functionrandomColor(){
returncolors[Math.floor(Math.random()*colors.length)];
}
functiongetWeek(date){
if(!(dateinstanceofDate))date=newDate();
// ISO week date weeks start on Monday, so correct the day number
varnDay=(date.getDay()+6)%7;
// ISO 8601 states that week 1 is the week with the first Thursday of that year
// Set the target date to the Thursday in the target week
date.setDate(date.getDate()-nDay+3);
// Store the millisecond value of the target date
varn1stThursday=date.valueOf();
// Set the target to the first Thursday of the year
// First, set the target to January 1st
date.setMonth(0,1);
// Not a Thursday? Correct the date to the next Thursday
if(date.getDay()!==4){
date.setMonth(0,1+((4-date.getDay())+7)%7);
}
// The week number is the number of weeks between the first Thursday of the year
// and the Thursday in the target week (604800000 = 7 * 24 * 3600 * 1000)
return1+Math.ceil((n1stThursday-date)/604800000);
}
module.exports={
'messageChannel': messageChannel,
'messageUser': messageUser,
'nextColor': nextColor,
'randomColor': randomColor,
'getWeek': getWeek,
}