dive-deco
Version:
A TypeScript implementation of decompression calculation algorithms for scuba diving, featuring Bühlmann ZH-L16C algorithm with gradient factors, gas management, and oxygen toxicity tracking.
65 lines (64 loc) • 1.42 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Time = void 0;
class Time {
s;
constructor(seconds = 0) {
this.s = seconds;
}
static zero() {
return new Time(0);
}
static fromSeconds(val) {
return new Time(val);
}
static fromMinutes(val) {
return new Time(val * 60);
}
asSeconds() {
return this.s;
}
asMinutes() {
return this.s / 60;
}
add(other) {
return new Time(this.s + other.s);
}
subtract(other) {
return new Time(this.s - other.s);
}
multiply(other) {
if (typeof other === 'number') {
return new Time(this.s * other);
}
return new Time(this.s * other.s);
}
divide(other) {
if (typeof other === 'number') {
return new Time(this.s / other);
}
return new Time(this.s / other.s);
}
addAssign(other) {
this.s += other.s;
}
equals(other) {
return this.s === other.s;
}
lessThan(other) {
return this.s < other.s;
}
lessThanOrEqual(other) {
return this.s <= other.s;
}
greaterThan(other) {
return this.s > other.s;
}
greaterThanOrEqual(other) {
return this.s >= other.s;
}
toString() {
return `${this.asMinutes().toFixed(1)}min`;
}
}
exports.Time = Time;