File tree Expand file tree Collapse file tree 2 files changed +1
-30
lines changed
Expand file tree Collapse file tree 2 files changed +1
-30
lines changed Original file line number Diff line number Diff 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 ;
186172globalThis . checkOverdue = checkOverdue ;
187173globalThis . findMatchGroup = findMatchGroup ;
188174globalThis . getLastMessageDate = getLastMessageDate ;
@@ -191,7 +177,6 @@ globalThis.main = main;
191177
192178if ( typeof module !== 'undefined' && module . exports ) {
193179 module . exports = {
194- subtractYears,
195180 checkOverdue,
196181 findMessages,
197182 findMatchGroup,
Original file line number Diff line number Diff line change 1- const { subtractYears , checkOverdue, findMessages } = require ( '../src/code.js' ) ;
1+ const { checkOverdue, findMessages } = require ( '../src/code.js' ) ;
22
33describe ( '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 ( ) ;
You can’t perform that action at this time.
0 commit comments