Skip to content

Instantly share code, notes, and snippets.

@odedhb
Last active October 7, 2016 10:51
Show Gist options
  • Save odedhb/d7de843c810cd556a9f5e0933e4f3d61 to your computer and use it in GitHub Desktop.
Save odedhb/d7de843c810cd556a9f5e0933e4f3d61 to your computer and use it in GitHub Desktop.
calendar.js
var requireFromUrl = require('require-from-url');
requireFromUrl("https://rawgit.com/wanasit/chrono/master/chrono.min.js")
.on('Resolved', function (next, chrono) {
let query = '{QUERY}';
if (!query) return;
let dateResults = chrono.parse(query);
let results = [];
dateResults.forEach(function (dateResult) {
let date = dateResult.start.date();
var month = date.getMonth() + 1;
var day = date.getDate();
if (day < 10)day = '0' + day;
if (month < 10)month = '0' + month;
var formattedDate = '' + date.getFullYear() + month + day;
var calUrl = 'https://calendar.google.com/calendar/render?date=' + formattedDate + '#main_7%7Cday-1';
results.push({
title: dateResult.text,
description: date.toLocaleDateString(),
link: calUrl,
time: date.getTime()
})
});
addResults(results);
}
)
.on('Rejected', function (next, e) {
console.log(e);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment