Skip to content

Instantly share code, notes, and snippets.

@shotarok
Created January 8, 2018 03:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shotarok/20ed0cdc4074332bb72747fc9ad81f2b to your computer and use it in GitHub Desktop.
Save shotarok/20ed0cdc4074332bb72747fc9ad81f2b to your computer and use it in GitHub Desktop.
function LavaYoga() {
var criteria = "from:reserve@yoga-lava.com 予約完了";
eachUnreadMessage(criteria, function (message) {
var subject = message.getSubject();
Logger.log(subject);
var [matched, place] = /【LAVA】([^\n]+店)予約完了/.exec(subject);
var body = message.getBody();
Logger.log(body);
var [matched, month, day, sh, sm, eh, em, kind] = /(\d*)月(\d*)日\([月火水木金土日]\) (\d\d):(\d\d)~(\d\d):(\d\d)[^\n]*\n([^\n]+)/.exec(body);
Logger.log(matched);
var year = estimateYear(month, day, sh, sm)
Logger.log(year)
createEvent("LAVA Yoga [" + kind + "]@" + place,
new Date(year, month-1, day, sh, sm),
new Date(year, month-1, day, eh, em));
}
);
}
function estimateYear(month, day, sh, sm) {
var current = new Date;
var thisYear = new Date(current.getFullYear(), month-1, day, sh, sm);
var nextYear = new Date(current.getFullYear()+1, month-1, day, sh, sm);
var d = (current <= thisYear) ? thisYear : nextYear;
return d.getFullYear()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment