Files
weave-scope/client/app/scripts/utils/time-utils.js
Filip Barl 2183a93916 Time Travel 3.0 (#2703)
* Experimental.

* Getting somewhere.

* Good zooming behaviour.

* Working timeline zooming & panning.

* Clickable timestamps.

* Dragging cursor

* Timeline panning buttons.

* Capping at current time.

* Scale limits.

* Better ticks.

* Time tags fading in smoothly.

* Removed seconds.

* Better tick spacing.

* Vertical panning as zooming.

* Organizing the code..

* Replaced d3-zoom with native events.

* Got rid of scaleX

* More code beautified.

* Almost done polishing the code.

* Some cleanup.

* Better request triggers.

* More cleaning up.

* Styled the timestamp input.

* Final cleanup.

* Update yarn.lock

* Zoom tracking.

* Animate timeline translations.

* Fixed the PAUSE button glitch and updating the time control info.

* Opacity fix and timeline arrows removed.

* Fixed the red vertical bar.

* Use preventDefault() on timeline scrolling.
2017-07-27 14:40:20 +02:00

27 lines
674 B
JavaScript

import moment from 'moment';
// Replacement for timely dependency
export function timer(fn) {
const timedFn = (...args) => {
const start = new Date();
const result = fn.apply(fn, args);
timedFn.time = new Date() - start;
return result;
};
return timedFn;
}
export function nowInSecondsPrecision() {
return moment().startOf('second');
}
export function clampToNowInSecondsPrecision(timestamp) {
const now = nowInSecondsPrecision();
return timestamp.isAfter(now) ? now : timestamp;
}
// This is unfortunately not there in moment.js
export function scaleDuration(duration, scale) {
return moment.duration(duration.asMilliseconds() * scale);
}