Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there any way of sorting the output from a Google calendar? #90

Open
ghost opened this issue Aug 2, 2018 · 0 comments
Open

Is there any way of sorting the output from a Google calendar? #90

ghost opened this issue Aug 2, 2018 · 0 comments

Comments

@ghost
Copy link

ghost commented Aug 2, 2018

With the URL:
https://calendar.google.com/calendar/ical/kingstonassoc%40gmail.com/public/basic.ics

And the following code:

function updateCalendar() {
  ical.fromURL(eventsFeed, {}, function (err, data) {
    for (let k in data) {
      if (data.hasOwnProperty(k)) {
        var ev = data[k];
        if (data[k].type == 'VEVENT') {
          if (dateNow < ev.start) {
            let tts = `On <say-as interpret-as="date" format="ymd">${ev.start.toISOString().slice(0,10)}</say-as> at ${ev.start.toLocaleTimeString('en-GB')}: ${ev.summary}. ${ev.description}`;
            console.log(tts);
          }
        }
      }
    }
  });
}

I get this output:

On <say-as interpret-as="date" format="ymd">2018-10-13</say-as> at 1:00:00 PM: KAB Autumn Social. Save the Date - More details will  follow
On <say-as interpret-as="date" format="ymd">2018-09-06</say-as> at 12:00:00 AM: Eye Contact Trip to Coast. For more information contact Anne Bleckwen
On <say-as interpret-as="date" format="ymd">2018-08-08</say-as> at 12:30:00 PM: Lawn Bowls Friendly - Metro Blind Bowls. Pick Up from Kingston Police station 12.30pm
On <say-as interpret-as="date" format="ymd">2018-09-15</say-as> at 9:00:00 AM: Surbiton Farmers Market.

Which is clearly in the wrong order, but for some reason, Google has the dates in random order in the ical output. I've temporarily worked around it with the following code:

function updateCalendar() {
  ical.fromURL(eventsFeed, {}, function (err, data) {
    var ttsorted = [];
    for (let k in data) {
      if (data.hasOwnProperty(k)) {
        var ev = data[k];
        if (data[k].type == 'VEVENT') {
          if (dateNow < ev.start) {
            let tts = `On <say-as interpret-as="date" format="ymd">${ev.start.toISOString().slice(0,10)}</say-as> at ${ev.start.toLocaleTimeString('en-GB')}: ${ev.summary}. ${ev.description}`;
            ttsorted.push(tts);
          }
        }
      }
    }
    console.log(ttsorted.sort());
  });
}

which gives me this.

'On <say-as interpret-as="date" format="ymd">2018-08-08</say-as> at 12:30:00 PM: Lawn Bowls Friendly - Metro Blind Bowls. Pick Up from Kingston Police station 12.30pm',
  'On <say-as interpret-as="date" format="ymd">2018-09-06</say-as> at 12:00:00 AM: Eye Contact Trip to Coast. For more information contact Anne Bleckwen',
  'On <say-as interpret-as="date" format="ymd">2018-09-15</say-as> at 9:00:00 AM: Surbiton Farmers Market. ',
  'On <say-as interpret-as="date" format="ymd">2018-10-13</say-as> at 1:00:00 PM: KAB Autumn Social. Save the Date - More details will  follow'

It works, but it would be nice to have a built-in "sort-by-date"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants