forked from electricessence/TypeScript.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimeUnitValue.js
More file actions
73 lines (73 loc) · 2.83 KB
/
Copy pathTimeUnitValue.js
File metadata and controls
73 lines (73 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
* @author electricessence / https://github.com/electricessence/
* Licensing: MIT https://github.com/electricessence/TypeScript.NET/blob/master/LICENSE.md
*/
define(["require", "exports", '../Compare', './TimeUnit', './TimeSpan'], function (require, exports, Compare_1, TimeUnit_1, TimeSpan_1) {
var TimeUnitValue = (function () {
function TimeUnitValue(value, _type) {
this.value = value;
this._type = _type;
assertValidUnit(_type);
}
TimeUnitValue.prototype.coerce = function (other) {
var type = this._type;
assertValidUnit(type);
if (other instanceof TimeSpan_1.default) {
other = other.toTimeUnitValue(type);
}
else if (other instanceof TimeUnitValue) {
if (type !== other.type)
other = other.to(type);
}
else
return null;
return other;
};
TimeUnitValue.prototype.equals = function (other) {
var o = this.coerce(other);
if (o == null)
return false;
return Compare_1.areEqual(this.value, o.value);
};
TimeUnitValue.prototype.compareTo = function (other) {
if (other == null)
return 1 | 0;
assertComparisonType(other);
return Compare_1.compare(this.value, this.coerce(other).value);
};
Object.defineProperty(TimeUnitValue.prototype, "type", {
get: function () {
return this._type;
},
enumerable: true,
configurable: true
});
TimeUnitValue.prototype.toTimeSpan = function () {
return new TimeSpan_1.default(this.value, this.type);
};
Object.defineProperty(TimeUnitValue.prototype, "total", {
get: function () {
return this.toTimeSpan();
},
enumerable: true,
configurable: true
});
TimeUnitValue.prototype.to = function (units) {
if (units === void 0) { units = this.type; }
return this.toTimeSpan().toTimeUnitValue(units);
};
return TimeUnitValue;
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = TimeUnitValue;
function assertComparisonType(other) {
if (!(other instanceof TimeUnitValue || other instanceof TimeSpan_1.default))
throw new Error("Invalid comparison type. Must be of type TimeUnitValue or TimeSpan.");
}
function assertValidUnit(unit) {
if (isNaN(unit) || unit > TimeUnit_1.default.Days || unit < TimeUnit_1.default.Ticks || Math.floor(unit) !== unit)
throw new Error("Invalid TimeUnit.");
return true;
}
});
//# sourceMappingURL=TimeUnitValue.js.map