Skip to content

Instantly share code, notes, and snippets.

@loopj
Created December 15, 2019 03:47
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 loopj/75a7654af0f9bc958b853cd1f4842d5b to your computer and use it in GitHub Desktop.
Save loopj/75a7654af0f9bc958b853cd1f4842d5b to your computer and use it in GitHub Desktop.
// // cur_evnt_full.begin format
// {
// "day":12,
// "month":9,
// "year":2019,
// "hour24":15,
// "hour12":3,
// "minutes":0,
// "ampm":"pm",
// // offset in minutes from now,
// // can be negative when the end
// // is in the past
// "offset": 122
// }
// event.begin.offset doesn't seem to update frequently enough
// and you can't use Date() objects in Pujie Black's JavaScript
function minsUntil(event) {
var e = event.begin;
if (
e.year == [year] &&
e.month == [month_n] &&
e.day == [day_n]
) {
return (e.hour24 - [h24]) * 60 + (e.minutes - [m])
} else {
return e.offset
}
}
function getEvent() {
return [cal_events].find(function (event) {
var offset = minsUntil(event)
return offset > -5 && offset < 60
})
}
function eventTime(event) {
var offset = minsUntil(event)
if (offset <= 0) {
return 'now'
} else if (offset == 1) {
return 'in 1 min'
} else {
return 'in ' + offset.toString() + ' mins'
}
}
function eventTitle(event) {
var max = 22
return event.title.length > max ?
event.title.substring(0, max) + '…' :
event.title
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment