Skip to content

Commit

Permalink
fix: extend the existing event date range check to prevent creating d…
Browse files Browse the repository at this point in the history
…uplicate events
  • Loading branch information
ngshiheng committed Dec 2, 2023
1 parent 1948e84 commit 510dee7
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,23 @@ function main(): void {
createSavingsBondsIssuanceCalendar(api, startDate, endDate);
}

export function getRelativeDate(daysOffset: number, hour: number, date = new Date()) {
date.setDate(date.getDate() + daysOffset);
date.setHours(hour);
date.setMinutes(0);
date.setSeconds(0);
date.setMilliseconds(0);
return date;
}

function createSGSBondsIssuanceCalendar(api: MASApiService, startDate: string, endDate: string): void {
const calendarName = "SGS Bonds";
const calendar = getOrCreateCalendar(calendarName);

const response = api.getSGSBondsIssuanceCalendar(startDate, endDate);
const records = response.result.records;

const existingEvents = calendar.getEvents(new Date(startDate), new Date(endDate));
const existingEvents = calendar.getEvents(new Date(startDate), getRelativeDate(365, 0, new Date(endDate)));

for (const record of records) {
const eventDescription = createEventDescription(record);
Expand Down Expand Up @@ -55,7 +64,7 @@ function createTBillsIssuanceCalendar(api: MASApiService, startDate: string, end
const response = api.getTBillsIssuanceCalendar(startDate, endDate, auctionTenor);
const records = response.result.records;

const existingEvents = calendar.getEvents(new Date(startDate), new Date(endDate));
const existingEvents = calendar.getEvents(new Date(startDate), getRelativeDate(365, 0, new Date(endDate)));

for (const record of records) {
const eventDescription = createEventDescription(record);
Expand All @@ -77,7 +86,7 @@ function createSavingsBondsIssuanceCalendar(api: MASApiService, startDate: strin
const response = api.getSavingsBondIssuanceCalendar(startDate, endDate);
const records = response.result.records;

const existingEvents = calendar.getEvents(new Date(startDate), new Date(endDate));
const existingEvents = calendar.getEvents(new Date(startDate), getRelativeDate(365, 0, new Date(endDate)));

for (const record of records) {
const eventDescription = createEventDescription(record);
Expand Down

0 comments on commit 510dee7

Please sign in to comment.