Skip to content
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

Merged
merged 9 commits into from
Sep 10, 2018
Merged

Handle "ambiguous durations" #5785

merged 9 commits into from
Sep 10, 2018

Conversation

betodealmeida
Copy link
Member

The play slider currently doesn't handle "ambiguous durations" like P1M (1 month) or P1Y (1 year), since these can't be converted into seconds by the module parse-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.

@@ -1,38 +1,155 @@
import parseIsoDuration from 'parse-iso-duration';


export class IsoDuration {
Copy link
Contributor

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.

// special cases not handled by parse-iso-duration
this.pattern = /P(\d+)(M|Y)/;

this.addTo = this.addTo.bind(this);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to bind

this.isoDuration = isoDuration;

// special cases not handled by parse-iso-duration
this.pattern = /P(\d+)(M|Y)/;
Copy link
Contributor

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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

step: PropTypes.instanceOf(IsoDuration)

let foundDifference = false;
const args = [];
const lowest = [1, 1, 1, 0, 0, 0, 0];
for (let i = 0; i < explodedTimestamp.length; i++) {
Copy link
Contributor

@kristw kristw Aug 31, 2018

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)

const explodedLowerBound = this.explode(lowerBound);
let foundDifference = false;
const args = [];
const lowest = [1, 1, 1, 0, 0, 0, 0];
Copy link
Contributor

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-io
Copy link

codecov-io commented Sep 1, 2018

Codecov Report

Merging #5785 into master will increase coverage by 0.03%.
The diff coverage is 80%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
...ts/src/visualizations/deckgl/layers/screengrid.jsx 0% <0%> (ø) ⬆️
...isualizations/deckgl/AnimatableDeckGLContainer.jsx 0% <0%> (ø) ⬆️
...sualizations/deckgl/CategoricalDeckGLContainer.jsx 0% <0%> (ø) ⬆️
superset/assets/src/modules/time.js 93.75% <93.02%> (+3.27%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8a4b1b7...9e30fc7. Read the comment docs.

@mistercrunch
Copy link
Member

LGTM

@mistercrunch mistercrunch merged commit f740974 into apache:master Sep 10, 2018
@mistercrunch mistercrunch deleted the DPTOOLS-1014 branch September 10, 2018 17:28
mistercrunch pushed a commit to lyft/incubator-superset that referenced this pull request Sep 21, 2018
* 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)
(cherry picked from commit c57f772)
mistercrunch pushed a commit to lyft/incubator-superset that referenced this pull request Sep 21, 2018
* 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)
mistercrunch pushed a commit to lyft/incubator-superset that referenced this pull request Sep 21, 2018
* 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)
mistercrunch pushed a commit to lyft/incubator-superset that referenced this pull request Sep 21, 2018
* 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)
(cherry picked from commit c57f772)
mistercrunch pushed a commit to lyft/incubator-superset that referenced this pull request Sep 21, 2018
* 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)
mistercrunch pushed a commit to lyft/incubator-superset that referenced this pull request Sep 21, 2018
* 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)
mistercrunch pushed a commit to lyft/incubator-superset that referenced this pull request Sep 21, 2018
* 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)
mistercrunch pushed a commit to lyft/incubator-superset that referenced this pull request Sep 21, 2018
* 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)
(cherry picked from commit c57f772)
mistercrunch pushed a commit to lyft/incubator-superset that referenced this pull request Sep 21, 2018
* 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)
(cherry picked from commit c57f772)
betodealmeida added a commit to lyft/incubator-superset that referenced this pull request Oct 11, 2018
* 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)
(cherry picked from commit c57f772)
betodealmeida added a commit to lyft/incubator-superset that referenced this pull request Oct 11, 2018
* 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)
betodealmeida added a commit to lyft/incubator-superset that referenced this pull request Oct 11, 2018
* 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 25ac26d)
betodealmeida added a commit to lyft/incubator-superset that referenced this pull request Oct 12, 2018
* WIP

* Update interface

* Fix truncate

* Improve unit tests

* Improve code

* Use moment.js to parse ISO durations

* Fix typo and React props
betodealmeida added a commit to lyft/incubator-superset that referenced this pull request Oct 12, 2018
* 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 25ac26d)
betodealmeida added a commit to lyft/incubator-superset that referenced this pull request Oct 12, 2018
* 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 25ac26d)
youngyjd pushed a commit to lyft/incubator-superset that referenced this pull request Oct 17, 2018
* 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 25ac26d)
youngyjd pushed a commit to lyft/incubator-superset that referenced this pull request Oct 17, 2018
* 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 25ac26d)
youngyjd pushed a commit to lyft/incubator-superset that referenced this pull request Oct 17, 2018
* 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 25ac26d)
youngyjd pushed a commit to lyft/incubator-superset that referenced this pull request Oct 17, 2018
* 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 25ac26d)
youngyjd pushed a commit to lyft/incubator-superset that referenced this pull request Oct 17, 2018
* 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 25ac26d)
mistercrunch pushed a commit to lyft/incubator-superset that referenced this pull request Oct 29, 2018
* 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 25ac26d)
betodealmeida added a commit to lyft/incubator-superset that referenced this pull request Oct 30, 2018
* 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 25ac26d)
betodealmeida added a commit to lyft/incubator-superset that referenced this pull request Oct 30, 2018
* 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 25ac26d)
betodealmeida added a commit to lyft/incubator-superset that referenced this pull request Oct 30, 2018
* 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 25ac26d)
betodealmeida added a commit to lyft/incubator-superset that referenced this pull request Oct 30, 2018
* 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 25ac26d)
betodealmeida added a commit to lyft/incubator-superset that referenced this pull request Oct 30, 2018
* 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 25ac26d)
youngyjd pushed a commit to lyft/incubator-superset that referenced this pull request Nov 2, 2018
* 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 25ac26d)
youngyjd pushed a commit to lyft/incubator-superset that referenced this pull request Nov 2, 2018
* 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 25ac26d)
wenchma pushed a commit to wenchma/incubator-superset that referenced this pull request Nov 16, 2018
* WIP

* Update interface

* Fix truncate

* Improve unit tests

* Improve code

* Use moment.js to parse ISO durations

* Fix typo and React props
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.28.0 labels Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.28.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants