Last active
May 28, 2017 10:34
-
-
Save yyoshiki41/f47f71ddae4f314bdd8fe6e432275cba to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var SLACK_WEBHOOK_URL = 'https://hooks.slack.com/services/***'; | |
var SLACK_CHANNEL = '@yyoshiki41'; | |
var SLACK_USERNAME = 'My Life'; | |
var SLACK_EMOJI = ':books:'; | |
function myFunction() { | |
var birthYear = '1990'; | |
var birthDate = '7/5'; | |
var now = Moment.moment(); | |
var endOfWeek = Moment.moment().endOf('week'); | |
if (now.day() == 0) { | |
// when Sunday | |
endOfWeek = endOfWeek.add(-6,'days'); | |
} | |
var endOfMonth = Moment.moment().add(1, 'months').date(0); | |
var dob = birthYear + '/' + birthDate; | |
var nextBirthday = Moment.moment(now.get('year') + '/' + birthDate); | |
if (now.diff(nextBirthday, 'days') >= 0) { | |
nextBirthday = nextBirthday.add('years', 1); | |
} | |
var targetAge = 30; | |
var targetAgeBirthday = Moment.moment(dob).add('years', targetAge); | |
var message = ''; | |
message += '今週残り *' + -now.diff(endOfWeek, 'hours') + '時間* \n'; | |
message += '今月残り *' + -now.diff(endOfMonth, 'days') + '日* '; | |
message += '( *' + -now.diff(endOfMonth, 'hours') + '時間* )\n'; | |
message += nextBirthday.diff(dob, 'years') + '歳まであと *' + -now.diff(nextBirthday, 'days') + '日* '; | |
message += '( *' + -now.diff(nextBirthday, 'hours') + '時間* )\n'; | |
message += targetAge + '歳まであと *' + -now.diff(targetAgeBirthday, 'days') + '日* '; | |
message += '( *' + -now.diff(targetAgeBirthday, 'hours') + '時間* )\n'; | |
sendToSlack(message); | |
} | |
function sendToSlack(message) { | |
var jsonData = | |
{ | |
"channel" : SLACK_CHANNEL, | |
"username" : SLACK_USERNAME, | |
"icon_emoji": SLACK_EMOJI, | |
"text" : message | |
}; | |
var payload = JSON.stringify(jsonData); | |
var options = | |
{ | |
"method" : "post", | |
"contentType" : "application/json", | |
"payload" : payload | |
}; | |
UrlFetchApp.fetch(SLACK_WEBHOOK_URL, options); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment