Skip to content

Commit

Permalink
Merge branch 'develop' into task/CMPDC-909
Browse files Browse the repository at this point in the history
  • Loading branch information
biancarosa committed Sep 11, 2018
2 parents e0ca98c + 0aeaee5 commit 480fa43
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @leofavre @caiomdias @biancarosa
* @leofavre @caiomdias @biancarosa @joselitojunior1
13 changes: 13 additions & 0 deletions packages/sling-helpers/src/global/globalHelper.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import moment from '../lib/moment.bundle.js';

export const isString = arg =>
typeof arg === 'string' || arg instanceof String;

Expand All @@ -12,6 +14,17 @@ export const createRangeArray = (start, end = start) =>

export const isDateRange = (startDate, finalDate) => startDate !== finalDate;

export const getDateRangeArray = (startDateStr, finalDateStr, dateFormat) => {
const dateRangeDays = [];
for (const currentDate = moment(startDateStr);
currentDate <= moment(finalDateStr);
currentDate.add(1, 'days')) {
dateRangeDays.push(currentDate.format(dateFormat));
}

return dateRangeDays;
};

export const toFlatArray = (result, arg) => (Array.isArray(arg)
? [...result, ...arg]
: [...result, arg]);
Expand Down
26 changes: 25 additions & 1 deletion packages/sling-helpers/src/global/globalHelper.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import {
set,
groupByDeep,
mapByKey,
getDateRangeArray,
} from './globalHelper.js';

const { expect } = chai;

describe('isString', () => {
it('Should return true for a string.', () => {
expect(isString('a')).to.equal(true);
Expand Down Expand Up @@ -529,4 +529,28 @@ describe('mapByKey', () => {
};
expect(mapByKey(test, 'cool_name', 'cool_value')).to.eql(expected);
});

describe('getDateRangeArray', () => {
it('should return array of days in YYYY-MM-DD for a date range', () => {
expect(getDateRangeArray('2018-01-31', '2018-02-04', 'YYYY-MM-DD'))
.to.deep.equal([
'2018-01-31',
'2018-02-01',
'2018-02-02',
'2018-02-03',
'2018-02-04',
]);
});

it('should return array of days in DD/MM for a date range', () => {
expect(getDateRangeArray('2018-01-31', '2018-02-04', 'DD/MM'))
.to.deep.equal([
'31/01',
'01/02',
'02/02',
'03/02',
'04/02',
]);
});
});
});

0 comments on commit 480fa43

Please sign in to comment.