-
Notifications
You must be signed in to change notification settings - Fork 14.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle "ambiguous durations" #5785
Conversation
superset/assets/src/modules/time.js
Outdated
@@ -1,38 +1,155 @@ | |||
import parseIsoDuration from 'parse-iso-duration'; | |||
|
|||
|
|||
export class IsoDuration { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps create a new file called IsoDuration
.
superset/assets/src/modules/time.js
Outdated
// special cases not handled by parse-iso-duration | ||
this.pattern = /P(\d+)(M|Y)/; | ||
|
||
this.addTo = this.addTo.bind(this); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to bind
superset/assets/src/modules/time.js
Outdated
this.isoDuration = isoDuration; | ||
|
||
// special cases not handled by parse-iso-duration | ||
this.pattern = /P(\d+)(M|Y)/; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is a constant, declare outside class
@@ -8,7 +8,7 @@ const propTypes = { | |||
getLayers: PropTypes.func.isRequired, | |||
start: PropTypes.number.isRequired, | |||
end: PropTypes.number.isRequired, | |||
step: PropTypes.number.isRequired, | |||
step: PropTypes.object, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
step: PropTypes.instanceOf(IsoDuration)
superset/assets/src/modules/time.js
Outdated
let foundDifference = false; | ||
const args = []; | ||
const lowest = [1, 1, 1, 0, 0, 0, 0]; | ||
for (let i = 0; i < explodedTimestamp.length; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid naming the variable args
as it is usually used for the entire function arguments
.
Can also simplify the code
const firstDiffIndex = explodedTimestamp
.map((part, i) => (explodedLowerBound[i] !== part))
.indexOf(true);
const dateParts = firstDiffIndex > -1
? explodedTimestamp.map((part, i) => i >= firstDiffIndex ? lowest[i] : part)
: explodedTimestamp;
return Date.UTC(...dateParts)
superset/assets/src/modules/time.js
Outdated
const explodedLowerBound = this.explode(lowerBound); | ||
let foundDifference = false; | ||
const args = []; | ||
const lowest = [1, 1, 1, 0, 0, 0, 0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is a constant, please declare outside the class. Perhaps choose a bit more descriptive name or add comment what lowest
means?
Codecov Report
@@ Coverage Diff @@
## master #5785 +/- ##
==========================================
+ Coverage 63.78% 63.82% +0.03%
==========================================
Files 364 364
Lines 23111 23138 +27
Branches 2587 2589 +2
==========================================
+ Hits 14741 14767 +26
- Misses 8355 8356 +1
Partials 15 15
Continue to review full report at Codecov.
|
LGTM |
* WIP * Update interface * Fix truncate * Improve unit tests * Improve code * Use moment.js to parse ISO durations * Fix typo and React props (cherry picked from commit f740974) (cherry picked from commit 4a9274c40c17e2a12d97cf28074a1e876dee732f)
* WIP * Update interface * Fix truncate * Improve unit tests * Improve code * Use moment.js to parse ISO durations * Fix typo and React props (cherry picked from commit f740974) (cherry picked from commit 4a9274c40c17e2a12d97cf28074a1e876dee732f)
* WIP * Update interface * Fix truncate * Improve unit tests * Improve code * Use moment.js to parse ISO durations * Fix typo and React props (cherry picked from commit f740974) (cherry picked from commit 4a9274c40c17e2a12d97cf28074a1e876dee732f)
* WIP * Update interface * Fix truncate * Improve unit tests * Improve code * Use moment.js to parse ISO durations * Fix typo and React props (cherry picked from commit f740974) (cherry picked from commit 4a9274c40c17e2a12d97cf28074a1e876dee732f)
* WIP * Update interface * Fix truncate * Improve unit tests * Improve code * Use moment.js to parse ISO durations * Fix typo and React props (cherry picked from commit f740974) (cherry picked from commit 4a9274c40c17e2a12d97cf28074a1e876dee732f)
* WIP * Update interface * Fix truncate * Improve unit tests * Improve code * Use moment.js to parse ISO durations * Fix typo and React props (cherry picked from commit f740974)
* WIP * Update interface * Fix truncate * Improve unit tests * Improve code * Use moment.js to parse ISO durations * Fix typo and React props
* WIP * Update interface * Fix truncate * Improve unit tests * Improve code * Use moment.js to parse ISO durations * Fix typo and React props
The play slider currently doesn't handle "ambiguous durations" like
P1M
(1 month) orP1Y
(1 year), since these can't be converted into seconds by the moduleparse-iso-duration
. I created a wrapper class that correctly handles these cases, incrementing the month/year number instead of adding a fixed number of seconds.