Skip to content

Commit

Permalink
fix: calculating everything in utc and added unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
manish339k committed Jan 14, 2025
1 parent 7359fad commit fe48359
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/cdk/v2/destinations/clicksend/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ const deduceSchedule = (eventLevelSchedule, timestamp, destConfig) => {
}

if (defaultCampaignScheduleUnit === 'day') {
date.setDate(date.getDate() + defaultCampaignScheduleInt);
date.setUTCDate(date.getUTCDate() + defaultCampaignScheduleInt);
} else if (defaultCampaignScheduleUnit === 'minute') {
date.setMinutes(date.getMinutes() + defaultCampaignScheduleInt);
date.setUTCMinutes(date.getUTCMinutes() + defaultCampaignScheduleInt);
} else {
throw new Error("Invalid delta unit. Use 'day' or 'minute'.");
}
Expand Down
14 changes: 14 additions & 0 deletions src/cdk/v2/destinations/clicksend/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,20 @@ describe('deduceSchedule', () => {
expect(result).toBe(expectedTimestamp);
});

it('should calculate timestamp when defaultCampaignSchedule has trailing invalid text and/or leading space', () => {
const eventLevelSchedule = null;
const timestamp = '2023-10-01T00:00:00Z';
const destConfig = {
defaultCampaignScheduleUnit: 'minute',
defaultCampaignSchedule: ' 5Invalid.String ',
};

const result = deduceSchedule(eventLevelSchedule, timestamp, destConfig);
const expectedTimestamp = new Date('2023-10-01T00:05:00Z').getTime() / 1000;

expect(result).toBe(expectedTimestamp);
});

// returns UNIX timestamp in seconds
it('should return UNIX timestamp in seconds', () => {
const eventLevelSchedule = null;
Expand Down

0 comments on commit fe48359

Please sign in to comment.