From f737dcc3db40fe4b49ae438fbd03d963fc490a59 Mon Sep 17 00:00:00 2001 From: Kira-Floris Date: Sat, 29 Oct 2022 19:21:47 +0200 Subject: [PATCH 1/3] adding formatted dates, upcoming events or last 3 events --- assets/js/calendar.js | 124 ++++++++++++++++++++++++++++++++---------- index.html | 19 ++++--- 2 files changed, 106 insertions(+), 37 deletions(-) diff --git a/assets/js/calendar.js b/assets/js/calendar.js index 94c6676..d103b4f 100644 --- a/assets/js/calendar.js +++ b/assets/js/calendar.js @@ -1,7 +1,8 @@ (function($){ const username = "mbazanlp.community@gmail.com"; const key = "AIzaSyBxDGuEdlEgMyPbyjNjymNwI10vSdByrhs"; - function injectCalendarEvents(title, uri, location, date, time) { + const limit = 4; + function injectCalendarEvents(title, uri, location, start, end, time) { return `
  • @@ -9,17 +10,18 @@
    -
    ${title}
    - ${location}
    - ${date}
    - ${time} +

    ${start}

    + ${title}
    + ${location}
    + ${end}
    + ${time}
  • `; } function getDate(time) { - return time === undefined ? "" : "" + time.split("T")[0] + ""; + return time === undefined ? "" : time.split("T")[0]; } function getTime(time) { return time === undefined ? "" : time.split("T")[1]; @@ -31,6 +33,28 @@ var date = new Date(); return `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`; } + function checkDateOrDateTime(item){ + if(item.date!==undefined){ + return item.date; + }else if(item.dateTime){ + return item.dateTime; + }else{ + return undefined; + } + } + function getMonthName(n){ + var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; + return months[n-1]; + } + function getDateAdd(n){ + var dates = ['st','nd','rd','th','th','th','th','th','th','th','th','th','th','th','th','th','th','th','th','th','st','nd','rd','th','th','th','th','th','th','th','st']; + return n+dates[n-1]; + } + function formatDate(text){ + var t = text.split('-'); + var formattedDate = getMonthName(parseInt(t[1]))+' '+getDateAdd(parseInt(t[2]))+', '+t[0]; + return formattedDate; + } $(window).on('load',async function () { $.ajax({ @@ -38,33 +62,77 @@ "https://www.googleapis.com/calendar/v3/calendars/" + username + "/events?key=" + - key + - "&singleEvents=true&orderBy=startTime&timeMin=" + - getTodayDate() + - "T00:00:00.000Z", + key + + + "&singleEvents=true&orderBy=startTime" + // + '&timeMin='+ + // getTodayDate() + + // "T00:00:00.000Z" + , success: await function (data) { var calendarUl = document.getElementById("calendar-post-list"); let htmlCode = ``; - data.items.forEach(function (item) { + function compareDates(date){ + var dateSplit = date.split('-'); + var currentSplit = getDate(getTodayDate()).split('-'); + if(new Date(dateSplit[0],dateSplit[1],dateSplit[2])>=new Date(currentSplit[0],currentSplit[1],currentSplit[2])){ + return true; + }else{ + return false; + } + } + function fromPresent(data) { + const last = data.length - 1; + if(data[last].start.dateTime>=getTodayDate()){ + return true; + } + return false; + } + var temp = []; + if(compareDates(getDate(checkDateOrDateTime(data.items[data.items.length-1].start)))===true){ + data.items.forEach(function(item){ + if(compareDates(getDate(checkDateOrDateTime(item.start)))===true){ + temp.push(item); + } + }); + }else{ + temp = data.items.slice(-limit); + } + for(var i=0;i0){ + var compare = getDate(checkDateOrDateTime(item.start)).localeCompare(getDate(checkDateOrDateTime(temp[i-1].start))); + if(compare!==0){ + dat = formatDate(getDate(checkDateOrDateTime(item.start))); + }else{ + dat = ""; + } + }else{ + dat = formatDate(getDate(checkDateOrDateTime(item.start))); + } item.summary === undefined - ? "" - : (htmlCode = - htmlCode + - injectCalendarEvents( - item.summary, - undefinedCase(item.htmlLink), - undefinedCase(item.location), - item.start.dateTime === undefined - ? "Pending" - : getDate(item.start.dateTime) + - " to " + - getDate(item.end.dateTime), - getTime(item.start.dateTime) + - " " + - undefinedCase(item.start.timeZone) - )); - }); + ? "" + : (htmlCode = + htmlCode + + injectCalendarEvents( + item.summary, + undefinedCase(item.htmlLink), + undefinedCase(item.location), + dat, + checkDateOrDateTime(item.start) === undefined + ? "Pending" + : formatDate(getDate(checkDateOrDateTime(item.start))) + + " to " + + formatDate(getDate(checkDateOrDateTime(item.start))), + getTime(item.start.dateTime) + + " " + + undefinedCase(item.start.timeZone) + )); + } + calendarUl.innerHTML = htmlCode; + }, error: function (err) { console.log(err); diff --git a/index.html b/index.html index 66b9e12..8413227 100644 --- a/index.html +++ b/index.html @@ -336,16 +336,17 @@
    Gallery
    - -
    +
    -
    -

    Up Coming events

    -
      -
    -
    -
    -
    +
    +

    Up Coming events

    +
      +
    +
    + + + + From bf1960c3fb6d81b09373a99119eaba4631f61665 Mon Sep 17 00:00:00 2001 From: Kira-Floris Date: Sat, 29 Oct 2022 19:31:14 +0200 Subject: [PATCH 2/3] formatting code --- assets/js/calendar.js | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/assets/js/calendar.js b/assets/js/calendar.js index d103b4f..612a466 100644 --- a/assets/js/calendar.js +++ b/assets/js/calendar.js @@ -1,7 +1,7 @@ (function($){ - const username = "mbazanlp.community@gmail.com"; - const key = "AIzaSyBxDGuEdlEgMyPbyjNjymNwI10vSdByrhs"; - const limit = 4; + const username = "nzafloris@gmail.com"; + const key = "AIzaSyCxlpLlJO-pS9OIz6zPoVVUHN9yuSir4M8"; + const limit = 5; function injectCalendarEvents(title, uri, location, start, end, time) { return `
  • @@ -55,6 +55,15 @@ var formattedDate = getMonthName(parseInt(t[1]))+' '+getDateAdd(parseInt(t[2]))+', '+t[0]; return formattedDate; } + function compareDates(date){ + var dateSplit = date.split('-'); + var currentSplit = getDate(getTodayDate()).split('-'); + if(new Date(dateSplit[0],dateSplit[1],dateSplit[2])>=new Date(currentSplit[0],currentSplit[1],currentSplit[2])){ + return true; + }else{ + return false; + } + } $(window).on('load',async function () { $.ajax({ @@ -72,22 +81,7 @@ success: await function (data) { var calendarUl = document.getElementById("calendar-post-list"); let htmlCode = ``; - function compareDates(date){ - var dateSplit = date.split('-'); - var currentSplit = getDate(getTodayDate()).split('-'); - if(new Date(dateSplit[0],dateSplit[1],dateSplit[2])>=new Date(currentSplit[0],currentSplit[1],currentSplit[2])){ - return true; - }else{ - return false; - } - } - function fromPresent(data) { - const last = data.length - 1; - if(data[last].start.dateTime>=getTodayDate()){ - return true; - } - return false; - } + var temp = []; if(compareDates(getDate(checkDateOrDateTime(data.items[data.items.length-1].start)))===true){ data.items.forEach(function(item){ From 2539ab8a5014396b189289a166adf7e22a2c7e7b Mon Sep 17 00:00:00 2001 From: Kira-Floris Date: Sat, 29 Oct 2022 19:32:20 +0200 Subject: [PATCH 3/3] keys change --- assets/js/calendar.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/assets/js/calendar.js b/assets/js/calendar.js index 612a466..5fb8224 100644 --- a/assets/js/calendar.js +++ b/assets/js/calendar.js @@ -1,6 +1,6 @@ (function($){ - const username = "nzafloris@gmail.com"; - const key = "AIzaSyCxlpLlJO-pS9OIz6zPoVVUHN9yuSir4M8"; + const username = "mbazanlp.community@gmail.com"; + const key = "AIzaSyBxDGuEdlEgMyPbyjNjymNwI10vSdByrhs"; const limit = 5; function injectCalendarEvents(title, uri, location, start, end, time) { return `