@sports-alliance/sports-lib
Version:
A Library to for importing / exporting and processing GPX, TCX, FIT and JSON files from services such as Strava, Movescount, Garmin, Polar etc
84 lines (83 loc) • 3.47 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.DataDuration = void 0;
var data_number_1 = require("./data.number");
var DataDuration = /** @class */ (function (_super) {
__extends(DataDuration, _super);
function DataDuration() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**
* Converts to hhh:mmm:ss:ms
* @todo should adopt and round depending if needed to show seconds or not
* @param showDays
* @param showSeconds
* @param showMilliseconds
*/
DataDuration.prototype.getDisplayValue = function (showDays, showSeconds, showMilliseconds) {
if (showDays === void 0) { showDays = false; }
if (showSeconds === void 0) { showSeconds = true; }
if (showMilliseconds === void 0) { showMilliseconds = false; }
var seconds = this.getValue();
var h = Math.floor(seconds / 3600);
var d = Math.floor(h / 24);
var m = Math.floor((seconds % 3600) / 60);
var s = Math.floor((seconds % 3600) % 60);
var ms = (Math.round((seconds % 1) * 10) / 10).toString().substring(1);
if (!m && !h) {
return showSeconds
? ('0' + s).slice(-2) + (showMilliseconds ? ms : '') + 's'
: s + String(showMilliseconds ? ms : '') + "s";
}
else if (!h) {
return (('0' + m).slice(-2) + 'm' + (showSeconds ? ' ' + ('0' + s).slice(-2) + (showMilliseconds ? ms : '') + 's' : ""));
}
else {
if (d) {
if (showDays) {
return (d +
'd ' +
('0' + (h - d * 24)).slice(-2) +
'h ' +
('0' + m).slice(-2) +
'm ' +
(showSeconds ? ('0' + s).slice(-2) + (showMilliseconds ? ms : '') + 's' : ""));
}
return (h +
'h ' +
('0' + m).slice(-2) +
'm ' +
(showSeconds ? ('0' + s).slice(-2) + (showMilliseconds ? ms : '') + 's' : ""));
}
else {
return (('0' + h).slice(-2) +
'h ' +
('0' + m).slice(-2) +
'm ' +
(showSeconds ? ('0' + s).slice(-2) + (showMilliseconds ? ms : '') + 's' : ""));
}
}
};
DataDuration.prototype.getDisplayUnit = function () {
return '';
};
DataDuration.type = 'Duration';
DataDuration.unit = 's';
return DataDuration;
}(data_number_1.DataNumber));
exports.DataDuration = DataDuration;