@tsdotnet/date-time 1.0.28 → 1.0.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,50 +1,50 @@
1
- /*!
2
- * @author electricessence / https://github.com/electricessence/
3
- * @license MIT
4
- */
5
- import ResettableLazy from '@tsdotnet/lazy/dist/ResettableLazy';
6
- import TimeMeasurement from './TimeMeasurement';
7
- import TimeUnit from './TimeUnit';
8
- /**
9
- * This class provides a simple means for storing and calculating time quantities.
10
- */
11
- export default class TimeQuantity {
12
- protected _quantity: number;
13
- constructor(_quantity?: number);
14
- /**
15
- * Combine total values by time unit.
16
- * @param {Partial<TimeMeasurement>} values
17
- * @return {number}
18
- */
19
- static getTotalMillisecondsFrom(values: Partial<TimeMeasurement>): number;
20
- /**
21
- * +1, 0, or -1 depending on the time direction.
22
- * @returns {number}
23
- */
24
- get direction(): number;
25
- protected _total: ResettableLazy<Readonly<TimeMeasurement>>;
26
- /**
27
- * Returns an object with all units exposed as totals.
28
- * @returns {TimeMeasurement}
29
- */
30
- get total(): Readonly<TimeMeasurement>;
31
- getTotalMilliseconds(): number;
32
- /**
33
- * Compares this instance against any other time quantity instance and return true if the amount of time is the same.
34
- * @param other
35
- * @returns {boolean}
36
- */
37
- equals(other: TimeQuantity): boolean;
38
- /**
39
- * Compares this instance against any other time quantity instance.
40
- * @param other
41
- * @returns {number}
42
- */
43
- compareTo(other: TimeQuantity): number;
44
- /**
45
- * Returns the total amount of time measured in the requested TimeUnit.
46
- * @param units
47
- * @returns {number}
48
- */
49
- getTotal(units: TimeUnit.UnitType): number;
50
- }
1
+ /*!
2
+ * @author electricessence / https://github.com/electricessence/
3
+ * @license MIT
4
+ */
5
+ import ResettableLazy from '@tsdotnet/lazy/dist/ResettableLazy';
6
+ import TimeMeasurement from './TimeMeasurement';
7
+ import TimeUnit from './TimeUnit';
8
+ /**
9
+ * This class provides a simple means for storing and calculating time quantities.
10
+ */
11
+ export default class TimeQuantity {
12
+ protected _quantity: number;
13
+ constructor(_quantity?: number);
14
+ /**
15
+ * Combine total values by time unit.
16
+ * @param {Partial<TimeMeasurement>} values
17
+ * @return {number}
18
+ */
19
+ static getTotalMillisecondsFrom(values: Partial<TimeMeasurement>): number;
20
+ /**
21
+ * +1, 0, or -1 depending on the time direction.
22
+ * @returns {number}
23
+ */
24
+ get direction(): number;
25
+ protected _total: ResettableLazy<Readonly<TimeMeasurement>>;
26
+ /**
27
+ * Returns an object with all units exposed as totals.
28
+ * @returns {TimeMeasurement}
29
+ */
30
+ get total(): Readonly<TimeMeasurement>;
31
+ getTotalMilliseconds(): number;
32
+ /**
33
+ * Compares this instance against any other time quantity instance and return true if the amount of time is the same.
34
+ * @param other
35
+ * @returns {boolean}
36
+ */
37
+ equals(other: TimeQuantity): boolean;
38
+ /**
39
+ * Compares this instance against any other time quantity instance.
40
+ * @param other
41
+ * @returns {number}
42
+ */
43
+ compareTo(other: TimeQuantity): number;
44
+ /**
45
+ * Returns the total amount of time measured in the requested TimeUnit.
46
+ * @param units
47
+ * @returns {number}
48
+ */
49
+ getTotal(units: TimeUnit.UnitType): number;
50
+ }
@@ -1,96 +1,96 @@
1
- "use strict";
2
- /*!
3
- * @author electricessence / https://github.com/electricessence/
4
- * @license MIT
5
- */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- const tslib_1 = require("tslib");
8
- const areEqual_1 = (0, tslib_1.__importDefault)(require("@tsdotnet/compare/dist/areEqual"));
9
- const compare_1 = (0, tslib_1.__importDefault)(require("@tsdotnet/compare/dist/compare"));
10
- const ArgumentNullException_1 = (0, tslib_1.__importDefault)(require("@tsdotnet/exceptions/dist/ArgumentNullException"));
11
- const ResettableLazy_1 = (0, tslib_1.__importDefault)(require("@tsdotnet/lazy/dist/ResettableLazy"));
12
- const TimeUnit_1 = (0, tslib_1.__importDefault)(require("./TimeUnit"));
13
- /**
14
- * This class provides a simple means for storing and calculating time quantities.
15
- */
16
- class TimeQuantity {
17
- constructor(_quantity = 0) {
18
- this._quantity = _quantity;
19
- this._total = ResettableLazy_1.default.create(() => {
20
- const ms = this.getTotalMilliseconds();
21
- return Object.freeze({
22
- ticks: ms * 10000 /* millisecond */,
23
- milliseconds: ms,
24
- seconds: ms / 1000 /* second */,
25
- minutes: ms / 60000 /* minute */,
26
- hours: ms / 3600000 /* hour */,
27
- days: ms / 86400000 /* day */
28
- });
29
- });
30
- }
31
- /**
32
- * Combine total values by time unit.
33
- * @param {Partial<TimeMeasurement>} values
34
- * @return {number}
35
- */
36
- static getTotalMillisecondsFrom(values) {
37
- if (!values)
38
- return 0;
39
- return (values.days || 0) * 86400000 /* day */ +
40
- (values.hours || 0) * 3600000 /* hour */ +
41
- (values.minutes || 0) * 60000 /* minute */ +
42
- (values.seconds || 0) * 1000 /* second */ +
43
- (values.milliseconds || 0) +
44
- (values.ticks || 0) / 10000 /* millisecond */;
45
- }
46
- /**
47
- * +1, 0, or -1 depending on the time direction.
48
- * @returns {number}
49
- */
50
- get direction() {
51
- return (0, compare_1.default)(this.getTotalMilliseconds(), 0);
52
- }
53
- /**
54
- * Returns an object with all units exposed as totals.
55
- * @returns {TimeMeasurement}
56
- */
57
- get total() {
58
- return this._total.value;
59
- }
60
- // Provides an overridable mechanism for extending this class.
61
- getTotalMilliseconds() {
62
- return this._quantity;
63
- }
64
- /**
65
- * Compares this instance against any other time quantity instance and return true if the amount of time is the same.
66
- * @param other
67
- * @returns {boolean}
68
- */
69
- equals(other) {
70
- if (!other || !other.total)
71
- return false;
72
- return (0, areEqual_1.default)(this.getTotalMilliseconds(), other.total.milliseconds);
73
- }
74
- /**
75
- * Compares this instance against any other time quantity instance.
76
- * @param other
77
- * @returns {number}
78
- */
79
- compareTo(other) {
80
- if (!other)
81
- throw new ArgumentNullException_1.default('other');
82
- if (!other.total)
83
- throw new ArgumentNullException_1.default('other.total');
84
- return (0, compare_1.default)(this.getTotalMilliseconds(), other && other.total && other.total.milliseconds);
85
- }
86
- /**
87
- * Returns the total amount of time measured in the requested TimeUnit.
88
- * @param units
89
- * @returns {number}
90
- */
91
- getTotal(units) {
92
- return TimeUnit_1.default.fromMilliseconds(this.getTotalMilliseconds(), units);
93
- }
94
- }
95
- exports.default = TimeQuantity;
1
+ "use strict";
2
+ /*!
3
+ * @author electricessence / https://github.com/electricessence/
4
+ * @license MIT
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const tslib_1 = require("tslib");
8
+ const areEqual_1 = (0, tslib_1.__importDefault)(require("@tsdotnet/compare/dist/areEqual"));
9
+ const compare_1 = (0, tslib_1.__importDefault)(require("@tsdotnet/compare/dist/compare"));
10
+ const ArgumentNullException_1 = (0, tslib_1.__importDefault)(require("@tsdotnet/exceptions/dist/ArgumentNullException"));
11
+ const ResettableLazy_1 = (0, tslib_1.__importDefault)(require("@tsdotnet/lazy/dist/ResettableLazy"));
12
+ const TimeUnit_1 = (0, tslib_1.__importDefault)(require("./TimeUnit"));
13
+ /**
14
+ * This class provides a simple means for storing and calculating time quantities.
15
+ */
16
+ class TimeQuantity {
17
+ constructor(_quantity = 0) {
18
+ this._quantity = _quantity;
19
+ this._total = ResettableLazy_1.default.create(() => {
20
+ const ms = this.getTotalMilliseconds();
21
+ return Object.freeze({
22
+ ticks: ms * 10000 /* millisecond */,
23
+ milliseconds: ms,
24
+ seconds: ms / 1000 /* second */,
25
+ minutes: ms / 60000 /* minute */,
26
+ hours: ms / 3600000 /* hour */,
27
+ days: ms / 86400000 /* day */
28
+ });
29
+ });
30
+ }
31
+ /**
32
+ * Combine total values by time unit.
33
+ * @param {Partial<TimeMeasurement>} values
34
+ * @return {number}
35
+ */
36
+ static getTotalMillisecondsFrom(values) {
37
+ if (!values)
38
+ return 0;
39
+ return (values.days || 0) * 86400000 /* day */ +
40
+ (values.hours || 0) * 3600000 /* hour */ +
41
+ (values.minutes || 0) * 60000 /* minute */ +
42
+ (values.seconds || 0) * 1000 /* second */ +
43
+ (values.milliseconds || 0) +
44
+ (values.ticks || 0) / 10000 /* millisecond */;
45
+ }
46
+ /**
47
+ * +1, 0, or -1 depending on the time direction.
48
+ * @returns {number}
49
+ */
50
+ get direction() {
51
+ return (0, compare_1.default)(this.getTotalMilliseconds(), 0);
52
+ }
53
+ /**
54
+ * Returns an object with all units exposed as totals.
55
+ * @returns {TimeMeasurement}
56
+ */
57
+ get total() {
58
+ return this._total.value;
59
+ }
60
+ // Provides an overridable mechanism for extending this class.
61
+ getTotalMilliseconds() {
62
+ return this._quantity;
63
+ }
64
+ /**
65
+ * Compares this instance against any other time quantity instance and return true if the amount of time is the same.
66
+ * @param other
67
+ * @returns {boolean}
68
+ */
69
+ equals(other) {
70
+ if (!other || !other.total)
71
+ return false;
72
+ return (0, areEqual_1.default)(this.getTotalMilliseconds(), other.total.milliseconds);
73
+ }
74
+ /**
75
+ * Compares this instance against any other time quantity instance.
76
+ * @param other
77
+ * @returns {number}
78
+ */
79
+ compareTo(other) {
80
+ if (!other)
81
+ throw new ArgumentNullException_1.default('other');
82
+ if (!other.total)
83
+ throw new ArgumentNullException_1.default('other.total');
84
+ return (0, compare_1.default)(this.getTotalMilliseconds(), other && other.total && other.total.milliseconds);
85
+ }
86
+ /**
87
+ * Returns the total amount of time measured in the requested TimeUnit.
88
+ * @param units
89
+ * @returns {number}
90
+ */
91
+ getTotal(units) {
92
+ return TimeUnit_1.default.fromMilliseconds(this.getTotalMilliseconds(), units);
93
+ }
94
+ }
95
+ exports.default = TimeQuantity;
96
96
  //# sourceMappingURL=TimeQuantity.js.map
@@ -1,73 +1,73 @@
1
- /*!
2
- * @author electricessence / https://github.com/electricessence/
3
- * Originally based upon .NET source but with many additions and improvements.
4
- * @license MIT
5
- */
6
- import ClockTime from './ClockTime';
7
- import TimeMeasurement from './TimeMeasurement';
8
- import TimeQuantity from './TimeQuantity';
9
- import TimeUnit from './TimeUnit';
10
- /**
11
- * TimeSpan expands on TimeQuantity to provide an class that is similar to .NET's TimeSpan including many useful static methods.
12
- */
13
- export declare class TimeSpan extends TimeQuantity implements TimeMeasurement {
14
- /**
15
- * The total number of ticks that represent this amount of time.
16
- */
17
- readonly ticks: number;
18
- /**
19
- * The total number of ticks that milliseconds this amount of time.
20
- */
21
- readonly milliseconds: number;
22
- /**
23
- * The total number of ticks that seconds this amount of time.
24
- */
25
- readonly seconds: number;
26
- /**
27
- * The total number of ticks that minutes this amount of time.
28
- */
29
- readonly minutes: number;
30
- /**
31
- * The total number of ticks that hours this amount of time.
32
- */
33
- readonly hours: number;
34
- /**
35
- * The total number of ticks that days this amount of time.
36
- */
37
- readonly days: number;
38
- protected constructor(value: number, units?: TimeUnit.UnitType);
39
- static get zero(): TimeSpan;
40
- /**
41
- * Provides an standard interface for acquiring the total time.
42
- * @returns {TimeSpan}
43
- */
44
- get total(): TimeSpan;
45
- private _time;
46
- /**
47
- * The value of this TimeSpan reduced to the clock and calendar.
48
- * @return {ClockTime}
49
- */
50
- get time(): ClockTime;
51
- static from(values: Partial<TimeMeasurement>): TimeSpan;
52
- static from(value: number, units: TimeUnit.UnitType): TimeSpan;
53
- static fromDays(value: number): TimeSpan;
54
- static fromHours(value: number): TimeSpan;
55
- static fromMinutes(value: number): TimeSpan;
56
- static fromSeconds(value: number): TimeSpan;
57
- static fromMilliseconds(value: number): TimeSpan;
58
- static fromTicks(value: number): TimeSpan;
59
- /**
60
- * Sum the value of this TimeSpan with another time quantity.
61
- * @param {TimeQuantity | Partial<TimeMeasurement>} other
62
- * @return {TimeSpan}
63
- */
64
- add(other: TimeSpan | TimeQuantity | Partial<TimeMeasurement>): TimeSpan;
65
- /**
66
- * Sum the value of this TimeSpan with another unit value.
67
- * @param {number} value
68
- * @param {TimeUnit.UnitType} units
69
- * @return {TimeSpan}
70
- */
71
- addUnit(value: number, units?: TimeUnit.UnitType): TimeSpan;
72
- }
73
- export default TimeSpan;
1
+ /*!
2
+ * @author electricessence / https://github.com/electricessence/
3
+ * Originally based upon .NET source but with many additions and improvements.
4
+ * @license MIT
5
+ */
6
+ import ClockTime from './ClockTime';
7
+ import TimeMeasurement from './TimeMeasurement';
8
+ import TimeQuantity from './TimeQuantity';
9
+ import TimeUnit from './TimeUnit';
10
+ /**
11
+ * TimeSpan expands on TimeQuantity to provide an class that is similar to .NET's TimeSpan including many useful static methods.
12
+ */
13
+ export declare class TimeSpan extends TimeQuantity implements TimeMeasurement {
14
+ /**
15
+ * The total number of ticks that represent this amount of time.
16
+ */
17
+ readonly ticks: number;
18
+ /**
19
+ * The total number of ticks that milliseconds this amount of time.
20
+ */
21
+ readonly milliseconds: number;
22
+ /**
23
+ * The total number of ticks that seconds this amount of time.
24
+ */
25
+ readonly seconds: number;
26
+ /**
27
+ * The total number of ticks that minutes this amount of time.
28
+ */
29
+ readonly minutes: number;
30
+ /**
31
+ * The total number of ticks that hours this amount of time.
32
+ */
33
+ readonly hours: number;
34
+ /**
35
+ * The total number of ticks that days this amount of time.
36
+ */
37
+ readonly days: number;
38
+ protected constructor(value: number, units?: TimeUnit.UnitType);
39
+ static get zero(): TimeSpan;
40
+ /**
41
+ * Provides an standard interface for acquiring the total time.
42
+ * @returns {TimeSpan}
43
+ */
44
+ get total(): TimeSpan;
45
+ private _time;
46
+ /**
47
+ * The value of this TimeSpan reduced to the clock and calendar.
48
+ * @return {ClockTime}
49
+ */
50
+ get time(): ClockTime;
51
+ static from(values: Partial<TimeMeasurement>): TimeSpan;
52
+ static from(value: number, units: TimeUnit.UnitType): TimeSpan;
53
+ static fromDays(value: number): TimeSpan;
54
+ static fromHours(value: number): TimeSpan;
55
+ static fromMinutes(value: number): TimeSpan;
56
+ static fromSeconds(value: number): TimeSpan;
57
+ static fromMilliseconds(value: number): TimeSpan;
58
+ static fromTicks(value: number): TimeSpan;
59
+ /**
60
+ * Sum the value of this TimeSpan with another time quantity.
61
+ * @param {TimeQuantity | Partial<TimeMeasurement>} other
62
+ * @return {TimeSpan}
63
+ */
64
+ add(other: TimeSpan | TimeQuantity | Partial<TimeMeasurement>): TimeSpan;
65
+ /**
66
+ * Sum the value of this TimeSpan with another unit value.
67
+ * @param {number} value
68
+ * @param {TimeUnit.UnitType} units
69
+ * @return {TimeSpan}
70
+ */
71
+ addUnit(value: number, units?: TimeUnit.UnitType): TimeSpan;
72
+ }
73
+ export default TimeSpan;
package/dist/TimeSpan.js CHANGED
@@ -1,112 +1,112 @@
1
- "use strict";
2
- /*!
3
- * @author electricessence / https://github.com/electricessence/
4
- * Originally based upon .NET source but with many additions and improvements.
5
- * @license MIT
6
- */
7
- Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.TimeSpan = void 0;
9
- const tslib_1 = require("tslib");
10
- const lazy_1 = (0, tslib_1.__importDefault)(require("@tsdotnet/lazy"));
11
- const type_1 = (0, tslib_1.__importDefault)(require("@tsdotnet/type"));
12
- const ClockTime_1 = (0, tslib_1.__importDefault)(require("./ClockTime"));
13
- const TimeQuantity_1 = (0, tslib_1.__importDefault)(require("./TimeQuantity"));
14
- const TimeUnit_1 = (0, tslib_1.__importDefault)(require("./TimeUnit"));
15
- /**
16
- * TimeSpan expands on TimeQuantity to provide an class that is similar to .NET's TimeSpan including many useful static methods.
17
- */
18
- class TimeSpan extends TimeQuantity_1.default {
19
- // In .NET the default type is Ticks, but for JavaScript, we will use Milliseconds.
20
- constructor(value, units = TimeUnit_1.default.UnitType.Milliseconds) {
21
- if (isNaN(value))
22
- throw Error('Cannot construct a TimeSpan from NaN value.');
23
- const ms = TimeUnit_1.default.toMilliseconds(value, units);
24
- super(ms);
25
- this.ticks = ms * 10000 /* millisecond */;
26
- this.milliseconds = ms;
27
- this.seconds = ms / 1000 /* second */;
28
- this.minutes = ms / 60000 /* minute */;
29
- this.hours = ms / 3600000 /* hour */;
30
- this.days = ms / 86400000 /* day */;
31
- this._time = lazy_1.default.create(() => new ClockTime_1.default(this.getTotalMilliseconds()));
32
- Object.freeze(this);
33
- }
34
- static get zero() {
35
- return timeSpanZero || (timeSpanZero = new TimeSpan(0));
36
- }
37
- /**
38
- * Provides an standard interface for acquiring the total time.
39
- * @returns {TimeSpan}
40
- */
41
- get total() {
42
- return this;
43
- }
44
- // Instead of the confusing getTotal versus unit name, expose a 'ClockTime' value which reports the individual components.
45
- /**
46
- * The value of this TimeSpan reduced to the clock and calendar.
47
- * @return {ClockTime}
48
- */
49
- get time() {
50
- return this._time.value;
51
- }
52
- static from(value, units) {
53
- if (!value)
54
- return TimeSpan.zero;
55
- if (typeof value === 'number') {
56
- if (units === undefined)
57
- throw new Error('A numerical value requires a TimeUnit.');
58
- return new TimeSpan(value, units);
59
- }
60
- const ms = TimeQuantity_1.default.getTotalMillisecondsFrom(value);
61
- return ms ? new TimeSpan(ms) : TimeSpan.zero;
62
- }
63
- static fromDays(value) {
64
- return value ? new TimeSpan(value, TimeUnit_1.default.UnitType.Days) : TimeSpan.zero;
65
- }
66
- static fromHours(value) {
67
- return value ? new TimeSpan(value, TimeUnit_1.default.UnitType.Hours) : TimeSpan.zero;
68
- }
69
- static fromMinutes(value) {
70
- return value ? new TimeSpan(value, TimeUnit_1.default.UnitType.Minutes) : TimeSpan.zero;
71
- }
72
- static fromSeconds(value) {
73
- return value ? new TimeSpan(value, TimeUnit_1.default.UnitType.Seconds) : TimeSpan.zero;
74
- }
75
- static fromMilliseconds(value) {
76
- return value ? new TimeSpan(value) : TimeSpan.zero;
77
- }
78
- static fromTicks(value) {
79
- return value ? new TimeSpan(value, TimeUnit_1.default.UnitType.Ticks) : TimeSpan.zero;
80
- }
81
- /**
82
- * Sum the value of this TimeSpan with another time quantity.
83
- * @param {TimeQuantity | Partial<TimeMeasurement>} other
84
- * @return {TimeSpan}
85
- */
86
- add(other) {
87
- if (!other)
88
- return this;
89
- if (type_1.default.isNumber(other))
90
- throw new Error('Use .addUnit(value:number, units:TimeUnit) to add a numerical value amount. Default units are milliseconds.\n' +
91
- '.add only supports quantifiable time values (TimeQuantity).');
92
- const otherMs = other instanceof TimeQuantity_1.default
93
- ? other.total.milliseconds
94
- : TimeQuantity_1.default.getTotalMillisecondsFrom(other);
95
- return new TimeSpan(this.getTotalMilliseconds() + otherMs);
96
- }
97
- /**
98
- * Sum the value of this TimeSpan with another unit value.
99
- * @param {number} value
100
- * @param {TimeUnit.UnitType} units
101
- * @return {TimeSpan}
102
- */
103
- addUnit(value, units = TimeUnit_1.default.UnitType.Milliseconds) {
104
- return value
105
- ? new TimeSpan(this.getTotalMilliseconds() + TimeUnit_1.default.toMilliseconds(value, units))
106
- : this;
107
- }
108
- }
109
- exports.TimeSpan = TimeSpan;
110
- let timeSpanZero;
111
- exports.default = TimeSpan;
1
+ "use strict";
2
+ /*!
3
+ * @author electricessence / https://github.com/electricessence/
4
+ * Originally based upon .NET source but with many additions and improvements.
5
+ * @license MIT
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.TimeSpan = void 0;
9
+ const tslib_1 = require("tslib");
10
+ const lazy_1 = (0, tslib_1.__importDefault)(require("@tsdotnet/lazy"));
11
+ const type_1 = (0, tslib_1.__importDefault)(require("@tsdotnet/type"));
12
+ const ClockTime_1 = (0, tslib_1.__importDefault)(require("./ClockTime"));
13
+ const TimeQuantity_1 = (0, tslib_1.__importDefault)(require("./TimeQuantity"));
14
+ const TimeUnit_1 = (0, tslib_1.__importDefault)(require("./TimeUnit"));
15
+ /**
16
+ * TimeSpan expands on TimeQuantity to provide an class that is similar to .NET's TimeSpan including many useful static methods.
17
+ */
18
+ class TimeSpan extends TimeQuantity_1.default {
19
+ // In .NET the default type is Ticks, but for JavaScript, we will use Milliseconds.
20
+ constructor(value, units = TimeUnit_1.default.UnitType.Milliseconds) {
21
+ if (isNaN(value))
22
+ throw Error('Cannot construct a TimeSpan from NaN value.');
23
+ const ms = TimeUnit_1.default.toMilliseconds(value, units);
24
+ super(ms);
25
+ this.ticks = ms * 10000 /* millisecond */;
26
+ this.milliseconds = ms;
27
+ this.seconds = ms / 1000 /* second */;
28
+ this.minutes = ms / 60000 /* minute */;
29
+ this.hours = ms / 3600000 /* hour */;
30
+ this.days = ms / 86400000 /* day */;
31
+ this._time = lazy_1.default.create(() => new ClockTime_1.default(this.getTotalMilliseconds()));
32
+ Object.freeze(this);
33
+ }
34
+ static get zero() {
35
+ return timeSpanZero || (timeSpanZero = new TimeSpan(0));
36
+ }
37
+ /**
38
+ * Provides an standard interface for acquiring the total time.
39
+ * @returns {TimeSpan}
40
+ */
41
+ get total() {
42
+ return this;
43
+ }
44
+ // Instead of the confusing getTotal versus unit name, expose a 'ClockTime' value which reports the individual components.
45
+ /**
46
+ * The value of this TimeSpan reduced to the clock and calendar.
47
+ * @return {ClockTime}
48
+ */
49
+ get time() {
50
+ return this._time.value;
51
+ }
52
+ static from(value, units) {
53
+ if (!value)
54
+ return TimeSpan.zero;
55
+ if (typeof value === 'number') {
56
+ if (units === undefined)
57
+ throw new Error('A numerical value requires a TimeUnit.');
58
+ return new TimeSpan(value, units);
59
+ }
60
+ const ms = TimeQuantity_1.default.getTotalMillisecondsFrom(value);
61
+ return ms ? new TimeSpan(ms) : TimeSpan.zero;
62
+ }
63
+ static fromDays(value) {
64
+ return value ? new TimeSpan(value, TimeUnit_1.default.UnitType.Days) : TimeSpan.zero;
65
+ }
66
+ static fromHours(value) {
67
+ return value ? new TimeSpan(value, TimeUnit_1.default.UnitType.Hours) : TimeSpan.zero;
68
+ }
69
+ static fromMinutes(value) {
70
+ return value ? new TimeSpan(value, TimeUnit_1.default.UnitType.Minutes) : TimeSpan.zero;
71
+ }
72
+ static fromSeconds(value) {
73
+ return value ? new TimeSpan(value, TimeUnit_1.default.UnitType.Seconds) : TimeSpan.zero;
74
+ }
75
+ static fromMilliseconds(value) {
76
+ return value ? new TimeSpan(value) : TimeSpan.zero;
77
+ }
78
+ static fromTicks(value) {
79
+ return value ? new TimeSpan(value, TimeUnit_1.default.UnitType.Ticks) : TimeSpan.zero;
80
+ }
81
+ /**
82
+ * Sum the value of this TimeSpan with another time quantity.
83
+ * @param {TimeQuantity | Partial<TimeMeasurement>} other
84
+ * @return {TimeSpan}
85
+ */
86
+ add(other) {
87
+ if (!other)
88
+ return this;
89
+ if (type_1.default.isNumber(other))
90
+ throw new Error('Use .addUnit(value:number, units:TimeUnit) to add a numerical value amount. Default units are milliseconds.\n' +
91
+ '.add only supports quantifiable time values (TimeQuantity).');
92
+ const otherMs = other instanceof TimeQuantity_1.default
93
+ ? other.total.milliseconds
94
+ : TimeQuantity_1.default.getTotalMillisecondsFrom(other);
95
+ return new TimeSpan(this.getTotalMilliseconds() + otherMs);
96
+ }
97
+ /**
98
+ * Sum the value of this TimeSpan with another unit value.
99
+ * @param {number} value
100
+ * @param {TimeUnit.UnitType} units
101
+ * @return {TimeSpan}
102
+ */
103
+ addUnit(value, units = TimeUnit_1.default.UnitType.Milliseconds) {
104
+ return value
105
+ ? new TimeSpan(this.getTotalMilliseconds() + TimeUnit_1.default.toMilliseconds(value, units))
106
+ : this;
107
+ }
108
+ }
109
+ exports.TimeSpan = TimeSpan;
110
+ let timeSpanZero;
111
+ exports.default = TimeSpan;
112
112
  //# sourceMappingURL=TimeSpan.js.map