diff --git a/src/dateutils.spec.js b/src/dateutils.spec.js index 3ee87d33b..261ee36e7 100644 --- a/src/dateutils.spec.js +++ b/src/dateutils.spec.js @@ -71,6 +71,22 @@ describe('dateutils', function () { }); describe('isLTE()', function () { + it('a is undefined', function () { + const a = undefined; + const b = XDate(2014, 1, 20); + expect(isLTE(b, a)).toBe(undefined); + }); + + it('b is undefined', function () { + const a = XDate(2013, 12, 31); + const b = undefined; + expect(isLTE(b, a)).toBe(undefined); + }); + + it('both are undefined', function () { + expect(isLTE(undefined, undefined)).toBe(undefined); + }); + it('2014-01-20 >= 2013-12-31', function () { const a = XDate(2013, 12, 31); const b = XDate(2014, 1, 20); @@ -98,6 +114,22 @@ describe('dateutils', function () { }); describe('isGTE()', function () { + it('a is undefined', function () { + const a = undefined; + const b = XDate(2014, 1, 20); + expect(isGTE(b, a)).toBe(undefined); + }); + + it('b is undefined', function () { + const a = XDate(2013, 12, 31); + const b = undefined; + expect(isGTE(b, a)).toBe(undefined); + }); + + it('both are undefined', function () { + expect(isGTE(undefined, undefined)).toBe(undefined); + }); + it('2014-01-20 >= 2013-12-31', function () { const a = XDate(2013, 12, 31); const b = XDate(2014, 1, 20); diff --git a/src/dateutils.ts b/src/dateutils.ts index 815283dd6..14d427fca 100644 --- a/src/dateutils.ts +++ b/src/dateutils.ts @@ -78,11 +78,15 @@ export function isToday(date?: XDate | string) { } export function isGTE(a: XDate, b: XDate) { - return b.diffDays(a) > -1; + if (a && b) { + return b.diffDays(a) > -1; + } } export function isLTE(a: XDate, b: XDate) { - return a.diffDays(b) > -1; + if (a && b) { + return a.diffDays(b) > -1; + } } export function formatNumbers(date: any) { diff --git a/src/interface.ts b/src/interface.ts index 14ab054eb..055743bed 100644 --- a/src/interface.ts +++ b/src/interface.ts @@ -20,7 +20,7 @@ export function xdateToData(date: XDate | string) { } export function parseDate(d?: any) { - if (!d) { + if (d === undefined) { return; } else if (d.timestamp) { // conventional data timestamp diff --git a/src/timeline/Timeline.tsx b/src/timeline/Timeline.tsx index 4072096f5..e2140ce86 100644 --- a/src/timeline/Timeline.tsx +++ b/src/timeline/Timeline.tsx @@ -265,6 +265,7 @@ const Timeline = (props: TimelineProps) => { width={width} numberOfDays={numberOfDays} timelineLeftInset={timelineLeftInset} + testID={`${testID}.hours`} /> {times(numberOfDays, renderTimelineDay)} diff --git a/src/timeline/TimelineHours.tsx b/src/timeline/TimelineHours.tsx index 2bec2cacc..f0366d6f9 100644 --- a/src/timeline/TimelineHours.tsx +++ b/src/timeline/TimelineHours.tsx @@ -27,6 +27,7 @@ export interface TimelineHoursProps { width: number; numberOfDays: number; timelineLeftInset?: number; + testID?: string; } const dimensionWidth = constants.screenWidth; @@ -45,7 +46,8 @@ const TimelineHours = (props: TimelineHoursProps) => { onBackgroundLongPressOut, width, numberOfDays = 1, - timelineLeftInset = 0 + timelineLeftInset = 0, + testID, } = props; const lastLongPressEventTime = useRef(); @@ -121,12 +123,14 @@ const TimelineHours = (props: TimelineHoursProps) => { {time === start ? null : ( )} { }