Skip to content

Commit 1c1d2df

Browse files
committed
fix timezone issue of gift dates
1 parent 13e7b1a commit 1c1d2df

5 files changed

Lines changed: 75 additions & 32 deletions

File tree

dist/engrid.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*
2020
* ENGRID PAGE TEMPLATE ASSETS
2121
*
22-
* Date: Wednesday, April 29, 2026 @ 09:20:39 ET
22+
* Date: Thursday, May 14, 2026 @ 12:11:14 ET
2323
* By: michael
2424
* ENGrid styles: v0.25.0
2525
* ENGrid scripts: v0.25.1

dist/engrid.js

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*
1818
* ENGRID PAGE TEMPLATE ASSETS
1919
*
20-
* Date: Wednesday, April 29, 2026 @ 09:20:39 ET
20+
* Date: Thursday, May 14, 2026 @ 12:11:14 ET
2121
* By: michael
2222
* ENGrid styles: v0.25.0
2323
* ENGrid scripts: v0.25.1
@@ -28045,9 +28045,31 @@ class GiftHistory {
2804528045
return node.nodeType === Node.ELEMENT_NODE && node.classList.contains(className);
2804628046
}
2804728047

28048+
parseISODate(dateString) {
28049+
const parts = dateString.split("-").map(Number);
28050+
return {
28051+
year: parts[0],
28052+
month: parts[1],
28053+
day: parts[2]
28054+
};
28055+
}
28056+
28057+
dateToComparable(dateString) {
28058+
// Handles both "yyyy-MM-dd" and "MM/dd/yyyy" formats
28059+
if (dateString.includes("-")) {
28060+
const parts = dateString.split("-").map(Number);
28061+
return parts[0] * 10000 + parts[1] * 100 + parts[2];
28062+
} else {
28063+
const parts = dateString.split("/").map(Number);
28064+
return parts[2] * 10000 + parts[0] * 100 + parts[1];
28065+
}
28066+
}
28067+
2804828068
renderMergedGiftHistory() {
2804928069
const transactionsList = document.querySelector(".en__hubTxnGiving__transactions__list");
28050-
transactionsList?.removeAttribute("data-engrid-transactions-loaded");
28070+
transactionsList?.removeAttribute("data-engrid-transactions-loaded"); // Remove previously inserted remote gifts to avoid duplication on pagination
28071+
28072+
transactionsList?.querySelectorAll(".en__hubTxnGiving__transaction--remote").forEach(el => el.remove());
2805128073
const enGiftHistory = this.getENGiftHistoryOnPage();
2805228074
const giftHistoryToRender = this.mergeRemoteGiftHistoryEntries(enGiftHistory);
2805328075
this.addGiftHistoryToDOM(giftHistoryToRender);
@@ -28081,19 +28103,19 @@ class GiftHistory {
2808128103
const onFirstPage = document.querySelector(".en__pagination__prev")?.hasAttribute("disabled");
2808228104
const onLastPage = document.querySelector(".en__pagination__next")?.hasAttribute("disabled");
2808328105
const transactionsDate = document.getElementById("en__hubTxnGiving__transactions__date__select")?.value;
28084-
let remoteGiftHistoryToMerge;
28106+
let remoteGiftHistoryToMerge = [];
2808528107

2808628108
if (enGiftHistory.length > 0) {
2808728109
//if the page has gifts, we want to merge in remote gifts based on the date range of the gifts on the page
28088-
const mostRecentENGift = Date.parse(enGiftHistory[0].date);
28089-
const oldestENGift = Date.parse(enGiftHistory[enGiftHistory.length - 1].date);
28110+
const mostRecentENGift = this.dateToComparable(enGiftHistory[0].date);
28111+
const oldestENGift = this.dateToComparable(enGiftHistory[enGiftHistory.length - 1].date);
2809028112
remoteGiftHistoryToMerge = this.remoteGiftHistory.filter(remoteGift => {
2809128113
//If we're on the first page, merge in gifts that are newer than the oldest gift on the page
2809228114
//If we're on the last page, merge in gifts that are older than the most recent gift on the page
2809328115
//Otherwise, we want to merge in all gifts between the oldest and most recent gifts on the page
2809428116
//Also, make sure the year is the same as the year filter (or "all time");
28095-
const giftYearMatchesOrAllTime = transactionsDate === "0" || transactionsDate === new Date(remoteGift.date).getFullYear().toString();
28096-
const remoteGiftDate = Date.parse(remoteGift.date);
28117+
const giftYearMatchesOrAllTime = transactionsDate === "0" || transactionsDate === this.parseISODate(remoteGift.date).year.toString();
28118+
const remoteGiftDate = this.dateToComparable(remoteGift.date);
2809728119

2809828120
if (onFirstPage) {
2809928121
return remoteGiftDate >= oldestENGift && giftYearMatchesOrAllTime;
@@ -28104,19 +28126,18 @@ class GiftHistory {
2810428126
return remoteGiftDate >= oldestENGift && remoteGiftDate <= mostRecentENGift && giftYearMatchesOrAllTime;
2810528127
});
2810628128
} else {
28107-
// If we don't have any gifts on the page, we want to merge in remote gifts based on the date filter
2810828129
remoteGiftHistoryToMerge = this.remoteGiftHistory.filter(remoteGift => {
2810928130
// If the date filter is set to "All time", merge in all gifts
2811028131
if (transactionsDate === "0") {
2811128132
return true;
2811228133
} // Otherwise, merge in gifts that match the year of the date filter
2811328134

2811428135

28115-
return new Date(remoteGift.date).getFullYear() === parseInt(transactionsDate);
28136+
return this.parseISODate(remoteGift.date).year === parseInt(transactionsDate);
2811628137
});
2811728138
}
2811828139

28119-
return [...enGiftHistory, ...remoteGiftHistoryToMerge].sort((a, b) => Date.parse(b.date) - Date.parse(a.date));
28140+
return [...enGiftHistory, ...remoteGiftHistoryToMerge].sort((a, b) => this.dateToComparable(b.date) - this.dateToComparable(a.date));
2812028141
}
2812128142

2812228143
updateTotalAmountDonated() {
@@ -28133,8 +28154,7 @@ class GiftHistory {
2813328154
// The value of the year select is a year like "2023".
2813428155
// Filter the remote gift history to only include gifts from that year and then sum the USD values
2813528156
remoteTotal = this.remoteGiftHistory.filter(gift => {
28136-
const giftDate = new Date(gift.date);
28137-
return giftDate.getFullYear() === parseInt(transactionsDate);
28157+
return this.parseISODate(gift.date).year === parseInt(transactionsDate);
2813828158
}).reduce((total, gift) => {
2813928159
return total + parseFloat(gift.amount);
2814028160
}, 0);
@@ -28207,8 +28227,8 @@ class GiftHistory {
2820728227
break;
2820828228
}
2820928229

28210-
const date = new Date(gift.date);
28211-
const formattedDate = `${date.getMonth() + 1}/${date.getDate()}/${date.getFullYear()}`;
28230+
const date = this.parseISODate(gift.date);
28231+
const formattedDate = `${date.month}/${date.day}/${date.year}`;
2821228232
const formattedAmount = parseFloat(gift.amount.toString()).toFixed(2);
2821328233
giftEl.innerHTML = `
2821428234
<div class="en__hubTxnGiving__transaction__header">

dist/engrid.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/engrid.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/scripts/gift-history.ts

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,37 @@ export default class GiftHistory {
8585
);
8686
}
8787

88+
private parseISODate(dateString: string): {
89+
year: number;
90+
month: number;
91+
day: number;
92+
} {
93+
const parts = dateString.split("-").map(Number);
94+
return { year: parts[0], month: parts[1], day: parts[2] };
95+
}
96+
97+
private dateToComparable(dateString: string): number {
98+
// Handles both "yyyy-MM-dd" and "MM/dd/yyyy" formats
99+
if (dateString.includes("-")) {
100+
const parts = dateString.split("-").map(Number);
101+
return parts[0] * 10000 + parts[1] * 100 + parts[2];
102+
} else {
103+
const parts = dateString.split("/").map(Number);
104+
return parts[2] * 10000 + parts[0] * 100 + parts[1];
105+
}
106+
}
107+
88108
private renderMergedGiftHistory() {
89109
const transactionsList = document.querySelector(
90110
".en__hubTxnGiving__transactions__list"
91111
);
92112
transactionsList?.removeAttribute("data-engrid-transactions-loaded");
93113

114+
// Remove previously inserted remote gifts to avoid duplication on pagination
115+
transactionsList
116+
?.querySelectorAll(".en__hubTxnGiving__transaction--remote")
117+
.forEach((el) => el.remove());
118+
94119
const enGiftHistory = this.getENGiftHistoryOnPage();
95120

96121
const giftHistoryToRender =
@@ -150,12 +175,12 @@ export default class GiftHistory {
150175
) as HTMLSelectElement
151176
)?.value;
152177

153-
let remoteGiftHistoryToMerge;
178+
let remoteGiftHistoryToMerge: RemoteGift[] = [];
154179

155180
if (enGiftHistory.length > 0) {
156181
//if the page has gifts, we want to merge in remote gifts based on the date range of the gifts on the page
157-
const mostRecentENGift = Date.parse(enGiftHistory[0].date);
158-
const oldestENGift = Date.parse(
182+
const mostRecentENGift = this.dateToComparable(enGiftHistory[0].date);
183+
const oldestENGift = this.dateToComparable(
159184
enGiftHistory[enGiftHistory.length - 1].date
160185
);
161186

@@ -168,9 +193,9 @@ export default class GiftHistory {
168193
const giftYearMatchesOrAllTime =
169194
transactionsDate === "0" ||
170195
transactionsDate ===
171-
new Date(remoteGift.date).getFullYear().toString();
196+
this.parseISODate(remoteGift.date).year.toString();
172197

173-
const remoteGiftDate = Date.parse(remoteGift.date);
198+
const remoteGiftDate = this.dateToComparable(remoteGift.date);
174199

175200
if (onFirstPage) {
176201
return remoteGiftDate >= oldestENGift && giftYearMatchesOrAllTime;
@@ -187,7 +212,6 @@ export default class GiftHistory {
187212
}
188213
);
189214
} else {
190-
// If we don't have any gifts on the page, we want to merge in remote gifts based on the date filter
191215
remoteGiftHistoryToMerge = this.remoteGiftHistory.filter(
192216
(remoteGift: RemoteGift) => {
193217
// If the date filter is set to "All time", merge in all gifts
@@ -196,15 +220,15 @@ export default class GiftHistory {
196220
}
197221
// Otherwise, merge in gifts that match the year of the date filter
198222
return (
199-
new Date(remoteGift.date).getFullYear() ===
223+
this.parseISODate(remoteGift.date).year ===
200224
parseInt(transactionsDate)
201225
);
202226
}
203227
);
204228
}
205229

206230
return [...enGiftHistory, ...remoteGiftHistoryToMerge].sort(
207-
(a, b) => Date.parse(b.date) - Date.parse(a.date)
231+
(a, b) => this.dateToComparable(b.date) - this.dateToComparable(a.date)
208232
);
209233
}
210234

@@ -235,8 +259,9 @@ export default class GiftHistory {
235259
// Filter the remote gift history to only include gifts from that year and then sum the USD values
236260
remoteTotal = this.remoteGiftHistory
237261
.filter((gift: RemoteGift) => {
238-
const giftDate = new Date(gift.date);
239-
return giftDate.getFullYear() === parseInt(transactionsDate);
262+
return (
263+
this.parseISODate(gift.date).year === parseInt(transactionsDate)
264+
);
240265
})
241266
.reduce((total: number, gift: any) => {
242267
return total + parseFloat(gift.amount);
@@ -320,10 +345,8 @@ export default class GiftHistory {
320345
break;
321346
}
322347

323-
const date = new Date(gift.date);
324-
const formattedDate = `${
325-
date.getMonth() + 1
326-
}/${date.getDate()}/${date.getFullYear()}`;
348+
const date = this.parseISODate(gift.date);
349+
const formattedDate = `${date.month}/${date.day}/${date.year}`;
327350

328351
const formattedAmount = parseFloat(gift.amount.toString()).toFixed(2);
329352

0 commit comments

Comments
 (0)