From 351d378aab2faa26a9df67ffb7ed01f8795a3fda Mon Sep 17 00:00:00 2001 From: Jeffrey Date: Mon, 18 Mar 2024 04:52:22 +0100 Subject: [PATCH 1/2] fix dao call date --- pages/index.vue | 75 +++++++++++++++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 31 deletions(-) diff --git a/pages/index.vue b/pages/index.vue index 20e2d9e..0fe31e6 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -10,7 +10,7 @@
- Next DAO meeting: {{ nextDaoMeeting }}, 18:00 UTC

+ Next DAO meeting: {{ nextDaoMeeting }}

Join DAO Call @@ -190,6 +190,13 @@ export default { }, data () { return { + // start of the bi-weekly schedule (should be a wednesday) + daoCall: { + startSchedule: new Date('2024-03-06'), + startUTCHours: 18, + startUTCMinutes: 0, + expectedDuration: 2 // in hours + }, efxPrice: 0, efxPoolBalance: 0, nfxPoolBalance: 0, @@ -204,7 +211,6 @@ export default { taskSubmissions: null, daoMembers: null, feePool: null, - dates: [], newsItems: [ { id: 1, @@ -253,24 +259,25 @@ export default { } }, nextDaoMeeting () { - if (this.dates && this.dates.length) { - // find the next date in this.dates - - const nextDate = this.dates.find((date) => { - const parsedDate = new Date(date) - const now = new Date() - console.log(parsedDate, now) - if (parsedDate > now) { - return true - } - }) + const now = new Date() + const nextMeeting = this.getNextBiWeeklyMeeting(now) - const parsedDate = new Date(nextDate) - const options = { weekday: 'long', month: 'long', day: 'numeric' } - return parsedDate.toLocaleDateString('en-US', options) - } else { - return null + // format the start time in minutes for DAO. eg 0 = 00, 1 = 01 etc. + const formattedMinutes = this.daoCall.startUTCMinutes < 10 ? '0' + this.daoCall.startUTCMinutes : this.daoCall.startUTCMinutes + + // calc time until next meeting + const timeUntilMeeting = nextMeeting.getTime() - now.getTime() + const daysUntilMeeting = Math.floor(timeUntilMeeting / (1000 * 60 * 60 * 24)) + const hoursUntilMeeting = Math.floor((timeUntilMeeting % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)) + const minutesUntilMeeting = Math.floor((timeUntilMeeting % (1000 * 60 * 60)) / (1000 * 60)) + + const timeUntilMeetingString = daysUntilMeeting + ' days, ' + hoursUntilMeeting + ' hours, ' + minutesUntilMeeting + ' minutes' + + if (timeUntilMeeting <= 0) { + return 'DAO meeting in progress' } + + return nextMeeting.toLocaleDateString('en-US', { weekday: 'long', month: 'long', day: 'numeric' }) + ` at ${this.daoCall.startUTCHours}:${formattedMinutes} UTC (In ${timeUntilMeetingString})` } }, @@ -286,7 +293,6 @@ export default { methods: { init () { - this.getDaoMeetingDates() this.getVAccountStats() this.getForceSettings() this.getForcePayment() @@ -307,18 +313,6 @@ export default { const options = { weekday: 'long', month: 'long', day: 'numeric' } return parsedDate.toLocaleDateString('en-US', options) }, - /** - * Generate a list of the next 3 dates that fall on a wednesday every two weeks. - */ - getDaoMeetingDates () { - // start date is 28 of july 2022 (first meeting) at 12:00 UTC - const startDate = new Date(2023, 5, 14, 18, 0, 0) - const nextWednesday = new Date(startDate.getFullYear(), startDate.getMonth(), startDate.getDate() + (3 + 7 - startDate.getDay()) % 7) - for (let i = 0; i < 10; i++) { - const nextDate = new Date(nextWednesday.getFullYear(), nextWednesday.getMonth(), nextWednesday.getDate() + (i * 14), 18, 0, 0) - this.dates.push(nextDate) - } - }, /** * Get current circluating supply of EFX */ @@ -479,6 +473,25 @@ export default { } else { console.log('Still waiting for cycle') } + }, + + getNextBiWeeklyMeeting (now) { + const startDate = this.daoCall.startSchedule + const timeDiff = now.getTime() - startDate.getTime() + const weeksPassed = Math.floor(timeDiff / (1000 * 3600 * 24 * 7 * 2)) // Calculate how many bi-weekly cycles have passed + + // Calculate the expected bi-weekly Wednesday based on the start date + const expectedBiWeeklyWednesday = new Date(startDate.getTime() + ((weeksPassed * 14)) * 24 * 60 * 60 * 1000) + expectedBiWeeklyWednesday.setUTCHours(this.daoCall.startUTCHours, this.daoCall.startUTCMinutes, 0, 0) + + // Check if the given dateTime is before the dao call. + if (now.getUTCHours() < (this.daoCall.startUTCHours + this.daoCall.expectedDuration) && now.toDateString() === expectedBiWeeklyWednesday.toDateString()) { + return expectedBiWeeklyWednesday + } else { + const nextBiWeeklyWednesday = new Date(startDate.getTime() + (weeksPassed * 14 + 14) * 24 * 60 * 60 * 1000) + nextBiWeeklyWednesday.setUTCHours(this.daoCall.startUTCHours, this.daoCall.startUTCMinutes, 0, 0) + return nextBiWeeklyWednesday + } } } } From 244b23162848c5d01ac3f021c6845afc49818cff Mon Sep 17 00:00:00 2001 From: Jeffrey Date: Mon, 18 Mar 2024 04:56:54 +0100 Subject: [PATCH 2/2] fix comment --- pages/index.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/index.vue b/pages/index.vue index 0fe31e6..96e4e63 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -190,8 +190,8 @@ export default { }, data () { return { - // start of the bi-weekly schedule (should be a wednesday) daoCall: { + // starting date of the bi-weekly cycle startSchedule: new Date('2024-03-06'), startUTCHours: 18, startUTCMinutes: 0,