Skip to content

Commit

Permalink
feat(date): adding matching at or after a specific date and time oper…
Browse files Browse the repository at this point in the history
…ator (dateGreaterThanEquals)
  • Loading branch information
roggervalf committed May 31, 2021
1 parent 9e5c93d commit a0e84ca
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 23 deletions.
8 changes: 3 additions & 5 deletions src/conditionOperators/date/dateGreaterThan.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {DateType, convertDate} from './convertDate';
import { DateType, convertDate } from './convertDate';

/**
* Matching after a specific a date and time
* Matching after a specific date and time
*
* @since 4.11.0
* @category Date
Expand All @@ -20,7 +20,5 @@ import {DateType, convertDate} from './convertDate';
export function dateGreaterThan(data: DateType, expected: DateType): boolean {
const convertedData = convertDate(data);
const convertedExpectation = convertDate(expected);
return (
convertedData > convertedExpectation
);
return convertedData > convertedExpectation;
}
33 changes: 33 additions & 0 deletions src/conditionOperators/date/dateGreaterThanEquals.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { dateGreaterThanEquals } from './dateGreaterThanEquals';

describe('dateGreaterThanEquals', () => {
it('returns true', () => {
expect(
dateGreaterThanEquals(
new Date('December 17, 1995 03:24:00'),
'December 16, 2000 03:24:00'
)
).toBeTruthy;
expect(
dateGreaterThanEquals(
'December 15, 1994 03:24:00',
new Date('December 15, 1994 03:24:00')
)
).toBeTruthy;
});

it('returns false', () => {
expect(
dateGreaterThanEquals(
new Date('December 17, 1995 03:24:00'),
'December 17, 1995 03:25:00'
)
).toBeFalsy;
expect(
dateGreaterThanEquals(
new Date('December 15, 1995 03:24:00'),
new Date('December 16, 1995 03:24:00')
)
).toBeFalsy;
});
});
27 changes: 27 additions & 0 deletions src/conditionOperators/date/dateGreaterThanEquals.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { DateType, convertDate } from './convertDate';

/**
* Matching at or after a specific date and time
*
* @since 4.11.0
* @category Date
* @param {Date} data The value to be compared.
* @param {Date} expected The expected value.
* @returns {boolean} Returns `true` if `value` is after than or equals `expected value`.
* @example
* ```javascript
* dateGreaterThanEquals('December 17, 1994 03:24:00', 'December 16, 1994 03:24:00')
* // => true
*
* dateGreaterThanEquals('December 15, 2000 03:24:00', 'December 15, 2000 03:25:00')
* // => false
* ```
*/
export function dateGreaterThanEquals(
data: DateType,
expected: DateType
): boolean {
const convertedData = convertDate(data);
const convertedExpectation = convertDate(expected);
return convertedData >= convertedExpectation;
}
38 changes: 20 additions & 18 deletions src/conditionOperators/index.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
import {bool} from './boolean/bool';
import {dateEquals} from './date/dateEquals';
import {dateGreaterThan} from './date/dateGreaterThan';
import {dateLessThan} from './date/dateLessThan';
import {dateLessThanEquals} from './date/dateLessThanEquals';
import {dateNotEquals} from './date/dateNotEquals';
import {numericEquals} from './numeric/numericEquals';
import {numericGreaterThan} from './numeric/numericGreaterThan';
import {numericGreaterThanEquals} from './numeric/numericGreaterThanEquals';
import {numericLessThan} from './numeric/numericLessThan';
import {numericLessThanEquals} from './numeric/numericLessThanEquals';
import {numericNotEquals} from './numeric/numericNotEquals';
import {stringEquals} from './string/stringEquals';
import {stringEqualsIgnoreCase} from './string/stringEqualsIgnoreCase';
import {stringLike} from './string/stringLike';
import {stringNotEquals} from './string/stringNotEquals';
import {stringNotEqualsIgnoreCase} from './string/stringNotEqualsIgnoreCase';
import { bool } from './boolean/bool';
import { dateEquals } from './date/dateEquals';
import { dateGreaterThan } from './date/dateGreaterThan';
import { dateGreaterThanEquals } from './date/dateGreaterThanEquals';
import { dateLessThan } from './date/dateLessThan';
import { dateLessThanEquals } from './date/dateLessThanEquals';
import { dateNotEquals } from './date/dateNotEquals';
import { numericEquals } from './numeric/numericEquals';
import { numericGreaterThan } from './numeric/numericGreaterThan';
import { numericGreaterThanEquals } from './numeric/numericGreaterThanEquals';
import { numericLessThan } from './numeric/numericLessThan';
import { numericLessThanEquals } from './numeric/numericLessThanEquals';
import { numericNotEquals } from './numeric/numericNotEquals';
import { stringEquals } from './string/stringEquals';
import { stringEqualsIgnoreCase } from './string/stringEqualsIgnoreCase';
import { stringLike } from './string/stringLike';
import { stringNotEquals } from './string/stringNotEquals';
import { stringNotEqualsIgnoreCase } from './string/stringNotEqualsIgnoreCase';

export const operators: Record<string, unknown>={
export const operators: Record<string, unknown> = {
bool,
dateEquals,
dateGreaterThan,
dateGreaterThanEquals,
dateLessThan,
dateLessThanEquals,
dateNotEquals,
Expand Down

0 comments on commit a0e84ca

Please sign in to comment.