-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(date): adding negated date maching condition operator
- Loading branch information
1 parent
5dd4171
commit 6081df9
Showing
6 changed files
with
68 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { convertDate } from './convertDate'; | ||
|
||
describe('convertDate', () => { | ||
describe('when passing a Date instance', () => { | ||
it('returns time in milliseconds', () => { | ||
expect(convertDate(new Date('December 17, 1995 03:24:00'))).toBe(819188640000); | ||
expect(convertDate(new Date('December 18, 1995 03:24:00'))).toBe(819275040000); | ||
}); | ||
}); | ||
|
||
describe('when passing a string', () => { | ||
it('returns time in milliseconds', () => { | ||
expect(convertDate('December 17, 1995 03:24:00')).toBe(819188640000); | ||
expect(convertDate('December 15, 1991 03:24:00')).toBe(692785440000); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export type DateType = Date | string; | ||
|
||
export const convertDate = (date: DateType): number=>{ | ||
if(date instanceof Date){ | ||
return date.getTime(); | ||
} | ||
|
||
return Date.parse(date); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { dateNotEquals } from './dateNotEquals'; | ||
|
||
describe('dateNotEquals', () => { | ||
it('returns true', () => { | ||
expect(dateNotEquals(new Date('December 17, 1995 03:24:00'), new Date('December 18, 1995 03:24:00'))).toBeTruthy; | ||
expect(dateNotEquals('December 15, 1991 03:24:00', new Date('December 17, 1995 03:24:00'))).toBeTruthy; | ||
}); | ||
|
||
it('returns false', () => { | ||
expect(dateNotEquals(new Date('December 17, 1995 03:24:00'), 'December 17, 1995 03:24:00')).toBeFalsy; | ||
expect(dateNotEquals('December 15, 1994 03:24:00', new Date('December 15, 1994 03:24:00'))).toBeFalsy; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import {DateType, convertDate} from './convertDate'; | ||
|
||
/** | ||
* Negated date matching. | ||
* | ||
* @since 4.9.0 | ||
* @category Date | ||
* @param {Date} data The value to be compared. | ||
* @param {Date} expected The expected value. | ||
* @returns {boolean} Returns `true` if `value` is not equal to `expected value`. | ||
* @example | ||
* ```javascript | ||
* dateNotEquals('December 15, 1994 03:24:00', 'December 16, 1995 03:24:00') | ||
* // => true | ||
* | ||
* dateNotEquals('December 15, 2000 03:24:00', 'December 15, 2000 03:24:00') | ||
* // => false | ||
* ``` | ||
*/ | ||
export function dateNotEquals(data: DateType, expected: DateType): boolean { | ||
const convertedData = convertDate(data); | ||
const convertedExpectation = convertDate(expected); | ||
return ( | ||
convertedData !== convertedExpectation | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters