Skip to content

Commit 5e8cd3d

Browse files
committed
🔥 refactor(code): remove unused subtractYears function
1 parent 716f0e7 commit 5e8cd3d

File tree

2 files changed

+1
-30
lines changed

2 files changed

+1
-30
lines changed

src/code.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -103,19 +103,6 @@ function findMatchGroup(text, pattern) {
103103
return result === null ? null : result.groups?.exp || true;
104104
}
105105

106-
/**
107-
* The function subtracts a specified number of years from a given date without mutating the original date.
108-
* @param {Date} date - The date parameter is a JavaScript Date object, representing a specific date and time.
109-
* @param {number} years - The "years" parameter is the number of years that you want to subtract from the given
110-
* date.
111-
* @returns {Date} the updated date after subtracting the specified number of years.
112-
*/
113-
function subtractYears(date, years) {
114-
const newDate = new Date(date);
115-
newDate.setFullYear(newDate.getFullYear() - years);
116-
return newDate;
117-
}
118-
119106
/**
120107
* The main function searches for messages that match a given query string, extracts text using a
121108
* pattern, and checks if the extracted text is overdue based on a date formatter function.
@@ -182,7 +169,6 @@ function main(
182169
});
183170
}
184171

185-
globalThis.subtractYears = subtractYears;
186172
globalThis.checkOverdue = checkOverdue;
187173
globalThis.findMatchGroup = findMatchGroup;
188174
globalThis.getLastMessageDate = getLastMessageDate;
@@ -191,7 +177,6 @@ globalThis.main = main;
191177

192178
if (typeof module !== 'undefined' && module.exports) {
193179
module.exports = {
194-
subtractYears,
195180
checkOverdue,
196181
findMessages,
197182
findMatchGroup,

test/code.test.js

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,6 @@
1-
const { subtractYears, checkOverdue, findMessages } = require('../src/code.js');
1+
const { checkOverdue, findMessages } = require('../src/code.js');
22

33
describe('Core Functions', () => {
4-
describe('subtractYears', () => {
5-
it('should subtract 1 year from the given date', () => {
6-
const date = new Date('2025-01-01');
7-
const newDate = subtractYears(date, 1);
8-
expect(newDate.getFullYear()).toBe(2024);
9-
});
10-
11-
it('should return a new date object and not mutate the original', () => {
12-
const originalDate = new Date('2025-01-01');
13-
const originalTime = originalDate.getTime();
14-
subtractYears(originalDate, 1);
15-
expect(originalDate.getTime()).toBe(originalTime);
16-
});
17-
});
184

195
describe('checkOverdue', () => {
206
const mockNow = new Date('2025-08-19T00:00:00.000Z').getTime();

0 commit comments

Comments
 (0)