Skip to content

Commit

Permalink
Merge pull request #93 from newrelic/fix-timerange-return
Browse files Browse the repository at this point in the history
fix: returns timestamps
  • Loading branch information
amit-y authored Dec 29, 2023
2 parents c5ff58b + 64c627f commit 67db0e3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- TimeRangePicker - return timestamp for `begin_time` and `end_time`

## [1.21.1] - 2023-12-18

### Changed
Expand Down
18 changes: 14 additions & 4 deletions src/components/time-range-picker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,18 @@ const TimeRangePicker = ({ timeRange, onChange }) => {
setEndTime(null);
} else {
setSelected(TEXTS.CUSTOM);
setBeginTime(timeRange['begin_time']);
setEndTime(timeRange['end_time']);
const { begin_time, end_time } = timeRange;
let b, e;
try {
b = begin_time instanceof Date ? begin_time : new Date(begin_time);
e = end_time instanceof Date ? end_time : new Date(end_time);
} catch (_) {
// continue regardless of error
}
if (b && e) {
setBeginTime(b);
setEndTime(e);
}
}
}, [timeRange]);

Expand Down Expand Up @@ -116,9 +126,9 @@ const TimeRangePicker = ({ timeRange, onChange }) => {
const setCustomHandler = useCallback(() => {
if (onChange)
onChange({
begin_time: beginTime,
begin_time: beginTime instanceof Date ? beginTime.getTime() : beginTime,
duration: null,
end_time: endTime,
end_time: endTime instanceof Date ? endTime.getTime() : endTime,
});
setOpened(false);
}, [beginTime, endTime]);
Expand Down

0 comments on commit 67db0e3

Please sign in to comment.