@tsdotnet/date-time 1.0.23 → 1.0.27
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.
- package/LICENSE +21 -21
- package/README.md +11 -11
- package/dist/Calendars/Gregorian.d.ts +37 -37
- package/dist/ClockTime.d.ts +20 -20
- package/dist/ClockTime.js +67 -67
- package/dist/ClockTime.js.map +1 -1
- package/dist/DateTime.d.ts +154 -154
- package/dist/DateTime.js +305 -305
- package/dist/DateTime.js.map +1 -1
- package/dist/TimeQuantity.d.ts +50 -50
- package/dist/TimeQuantity.js +95 -95
- package/dist/TimeQuantity.js.map +1 -1
- package/dist/TimeSpan.d.ts +73 -73
- package/dist/TimeSpan.js +111 -111
- package/dist/TimeSpan.js.map +1 -1
- package/dist/TimeStamp.d.ts +25 -25
- package/dist/TimeStamp.js +45 -45
- package/dist/TimeStamp.js.map +1 -1
- package/dist/TimeUnit.d.ts +47 -47
- package/dist/TimeUnit.js +99 -99
- package/dist/TimeUnitValue.d.ts +19 -19
- package/dist/TimeUnitValue.js +46 -46
- package/dist/TimeUnitValue.js.map +1 -1
- package/dist/date-time.d.ts +20 -14
- package/dist/date-time.js +24 -24
- package/dist/date-time.js.map +1 -1
- package/dist-esm/ClockTime.js +62 -62
- package/dist-esm/ClockTime.js.map +1 -1
- package/dist-esm/DateTime.js +301 -301
- package/dist-esm/TimeQuantity.js +91 -91
- package/dist-esm/TimeSpan.js +106 -106
- package/dist-esm/TimeStamp.js +40 -40
- package/dist-esm/TimeUnit.js +96 -96
- package/dist-esm/TimeUnitValue.js +42 -42
- package/dist-esm/date-time.js +13 -13
- package/dist-esm/date-time.js.map +1 -1
- package/package.json +62 -62
- package/dist/CalendarDate.d.ts +0 -12
- package/dist/ClockTimeValue.d.ts +0 -14
- package/dist/DateTimeKind.d.ts +0 -15
- package/dist/JsDateConvertable.d.ts +0 -10
- package/dist/TimeMeasurement.d.ts +0 -15
- package/dist/TimeStampValue.d.ts +0 -13
- package/dist/howMany.d.ts +0 -59
package/dist-esm/TimeQuantity.js
CHANGED
|
@@ -1,92 +1,92 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* @author electricessence / https://github.com/electricessence/
|
|
3
|
-
* @license MIT
|
|
4
|
-
*/
|
|
5
|
-
import areEqual from '@tsdotnet/compare/dist/areEqual';
|
|
6
|
-
import compare from '@tsdotnet/compare/dist/compare';
|
|
7
|
-
import ArgumentNullException from '@tsdotnet/exceptions/dist/ArgumentNullException';
|
|
8
|
-
import ResettableLazy from '@tsdotnet/lazy/dist/ResettableLazy';
|
|
9
|
-
import TimeUnit from './TimeUnit';
|
|
10
|
-
/**
|
|
11
|
-
* This class provides a simple means for storing and calculating time quantities.
|
|
12
|
-
*/
|
|
13
|
-
export default class TimeQuantity {
|
|
14
|
-
constructor(_quantity = 0) {
|
|
15
|
-
this._quantity = _quantity;
|
|
16
|
-
this._total = ResettableLazy.create(() => {
|
|
17
|
-
const ms = this.getTotalMilliseconds();
|
|
18
|
-
return Object.freeze({
|
|
19
|
-
ticks: ms * 10000 /* millisecond */,
|
|
20
|
-
milliseconds: ms,
|
|
21
|
-
seconds: ms / 1000 /* second */,
|
|
22
|
-
minutes: ms / 60000 /* minute */,
|
|
23
|
-
hours: ms / 3600000 /* hour */,
|
|
24
|
-
days: ms / 86400000 /* day */
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Combine total values by time unit.
|
|
30
|
-
* @param {Partial<TimeMeasurement>} values
|
|
31
|
-
* @return {number}
|
|
32
|
-
*/
|
|
33
|
-
static getTotalMillisecondsFrom(values) {
|
|
34
|
-
if (!values)
|
|
35
|
-
return 0;
|
|
36
|
-
return (values.days || 0) * 86400000 /* day */ +
|
|
37
|
-
(values.hours || 0) * 3600000 /* hour */ +
|
|
38
|
-
(values.minutes || 0) * 60000 /* minute */ +
|
|
39
|
-
(values.seconds || 0) * 1000 /* second */ +
|
|
40
|
-
(values.milliseconds || 0) +
|
|
41
|
-
(values.ticks || 0) / 10000 /* millisecond */;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* +1, 0, or -1 depending on the time direction.
|
|
45
|
-
* @returns {number}
|
|
46
|
-
*/
|
|
47
|
-
get direction() {
|
|
48
|
-
return compare(this.getTotalMilliseconds(), 0);
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Returns an object with all units exposed as totals.
|
|
52
|
-
* @returns {TimeMeasurement}
|
|
53
|
-
*/
|
|
54
|
-
get total() {
|
|
55
|
-
return this._total.value;
|
|
56
|
-
}
|
|
57
|
-
// Provides an overridable mechanism for extending this class.
|
|
58
|
-
getTotalMilliseconds() {
|
|
59
|
-
return this._quantity;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Compares this instance against any other time quantity instance and return true if the amount of time is the same.
|
|
63
|
-
* @param other
|
|
64
|
-
* @returns {boolean}
|
|
65
|
-
*/
|
|
66
|
-
equals(other) {
|
|
67
|
-
if (!other || !other.total)
|
|
68
|
-
return false;
|
|
69
|
-
return areEqual(this.getTotalMilliseconds(), other.total.milliseconds);
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Compares this instance against any other time quantity instance.
|
|
73
|
-
* @param other
|
|
74
|
-
* @returns {number}
|
|
75
|
-
*/
|
|
76
|
-
compareTo(other) {
|
|
77
|
-
if (!other)
|
|
78
|
-
throw new ArgumentNullException('other');
|
|
79
|
-
if (!other.total)
|
|
80
|
-
throw new ArgumentNullException('other.total');
|
|
81
|
-
return compare(this.getTotalMilliseconds(), other && other.total && other.total.milliseconds);
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Returns the total amount of time measured in the requested TimeUnit.
|
|
85
|
-
* @param units
|
|
86
|
-
* @returns {number}
|
|
87
|
-
*/
|
|
88
|
-
getTotal(units) {
|
|
89
|
-
return TimeUnit.fromMilliseconds(this.getTotalMilliseconds(), units);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
1
|
+
/*!
|
|
2
|
+
* @author electricessence / https://github.com/electricessence/
|
|
3
|
+
* @license MIT
|
|
4
|
+
*/
|
|
5
|
+
import areEqual from '@tsdotnet/compare/dist/areEqual';
|
|
6
|
+
import compare from '@tsdotnet/compare/dist/compare';
|
|
7
|
+
import ArgumentNullException from '@tsdotnet/exceptions/dist/ArgumentNullException';
|
|
8
|
+
import ResettableLazy from '@tsdotnet/lazy/dist/ResettableLazy';
|
|
9
|
+
import TimeUnit from './TimeUnit';
|
|
10
|
+
/**
|
|
11
|
+
* This class provides a simple means for storing and calculating time quantities.
|
|
12
|
+
*/
|
|
13
|
+
export default class TimeQuantity {
|
|
14
|
+
constructor(_quantity = 0) {
|
|
15
|
+
this._quantity = _quantity;
|
|
16
|
+
this._total = ResettableLazy.create(() => {
|
|
17
|
+
const ms = this.getTotalMilliseconds();
|
|
18
|
+
return Object.freeze({
|
|
19
|
+
ticks: ms * 10000 /* millisecond */,
|
|
20
|
+
milliseconds: ms,
|
|
21
|
+
seconds: ms / 1000 /* second */,
|
|
22
|
+
minutes: ms / 60000 /* minute */,
|
|
23
|
+
hours: ms / 3600000 /* hour */,
|
|
24
|
+
days: ms / 86400000 /* day */
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Combine total values by time unit.
|
|
30
|
+
* @param {Partial<TimeMeasurement>} values
|
|
31
|
+
* @return {number}
|
|
32
|
+
*/
|
|
33
|
+
static getTotalMillisecondsFrom(values) {
|
|
34
|
+
if (!values)
|
|
35
|
+
return 0;
|
|
36
|
+
return (values.days || 0) * 86400000 /* day */ +
|
|
37
|
+
(values.hours || 0) * 3600000 /* hour */ +
|
|
38
|
+
(values.minutes || 0) * 60000 /* minute */ +
|
|
39
|
+
(values.seconds || 0) * 1000 /* second */ +
|
|
40
|
+
(values.milliseconds || 0) +
|
|
41
|
+
(values.ticks || 0) / 10000 /* millisecond */;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* +1, 0, or -1 depending on the time direction.
|
|
45
|
+
* @returns {number}
|
|
46
|
+
*/
|
|
47
|
+
get direction() {
|
|
48
|
+
return compare(this.getTotalMilliseconds(), 0);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Returns an object with all units exposed as totals.
|
|
52
|
+
* @returns {TimeMeasurement}
|
|
53
|
+
*/
|
|
54
|
+
get total() {
|
|
55
|
+
return this._total.value;
|
|
56
|
+
}
|
|
57
|
+
// Provides an overridable mechanism for extending this class.
|
|
58
|
+
getTotalMilliseconds() {
|
|
59
|
+
return this._quantity;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Compares this instance against any other time quantity instance and return true if the amount of time is the same.
|
|
63
|
+
* @param other
|
|
64
|
+
* @returns {boolean}
|
|
65
|
+
*/
|
|
66
|
+
equals(other) {
|
|
67
|
+
if (!other || !other.total)
|
|
68
|
+
return false;
|
|
69
|
+
return areEqual(this.getTotalMilliseconds(), other.total.milliseconds);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Compares this instance against any other time quantity instance.
|
|
73
|
+
* @param other
|
|
74
|
+
* @returns {number}
|
|
75
|
+
*/
|
|
76
|
+
compareTo(other) {
|
|
77
|
+
if (!other)
|
|
78
|
+
throw new ArgumentNullException('other');
|
|
79
|
+
if (!other.total)
|
|
80
|
+
throw new ArgumentNullException('other.total');
|
|
81
|
+
return compare(this.getTotalMilliseconds(), other && other.total && other.total.milliseconds);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Returns the total amount of time measured in the requested TimeUnit.
|
|
85
|
+
* @param units
|
|
86
|
+
* @returns {number}
|
|
87
|
+
*/
|
|
88
|
+
getTotal(units) {
|
|
89
|
+
return TimeUnit.fromMilliseconds(this.getTotalMilliseconds(), units);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
92
|
//# sourceMappingURL=TimeQuantity.js.map
|
package/dist-esm/TimeSpan.js
CHANGED
|
@@ -1,107 +1,107 @@
|
|
|
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 Lazy from '@tsdotnet/lazy';
|
|
7
|
-
import type from '@tsdotnet/type';
|
|
8
|
-
import ClockTime from './ClockTime';
|
|
9
|
-
import TimeQuantity from './TimeQuantity';
|
|
10
|
-
import TimeUnit from './TimeUnit';
|
|
11
|
-
/**
|
|
12
|
-
* TimeSpan expands on TimeQuantity to provide an class that is similar to .NET's TimeSpan including many useful static methods.
|
|
13
|
-
*/
|
|
14
|
-
export class TimeSpan extends TimeQuantity {
|
|
15
|
-
// In .NET the default type is Ticks, but for JavaScript, we will use Milliseconds.
|
|
16
|
-
constructor(value, units = TimeUnit.UnitType.Milliseconds) {
|
|
17
|
-
if (isNaN(value))
|
|
18
|
-
throw Error('Cannot construct a TimeSpan from NaN value.');
|
|
19
|
-
const ms = TimeUnit.toMilliseconds(value, units);
|
|
20
|
-
super(ms);
|
|
21
|
-
this.ticks = ms * 10000 /* millisecond */;
|
|
22
|
-
this.milliseconds = ms;
|
|
23
|
-
this.seconds = ms / 1000 /* second */;
|
|
24
|
-
this.minutes = ms / 60000 /* minute */;
|
|
25
|
-
this.hours = ms / 3600000 /* hour */;
|
|
26
|
-
this.days = ms / 86400000 /* day */;
|
|
27
|
-
this._time = Lazy.create(() => new ClockTime(this.getTotalMilliseconds()));
|
|
28
|
-
Object.freeze(this);
|
|
29
|
-
}
|
|
30
|
-
static get zero() {
|
|
31
|
-
return timeSpanZero || (timeSpanZero = new TimeSpan(0));
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Provides an standard interface for acquiring the total time.
|
|
35
|
-
* @returns {TimeSpan}
|
|
36
|
-
*/
|
|
37
|
-
get total() {
|
|
38
|
-
return this;
|
|
39
|
-
}
|
|
40
|
-
// Instead of the confusing getTotal versus unit name, expose a 'ClockTime' value which reports the individual components.
|
|
41
|
-
/**
|
|
42
|
-
* The value of this TimeSpan reduced to the clock and calendar.
|
|
43
|
-
* @return {ClockTime}
|
|
44
|
-
*/
|
|
45
|
-
get time() {
|
|
46
|
-
return this._time.value;
|
|
47
|
-
}
|
|
48
|
-
static from(value, units) {
|
|
49
|
-
if (!value)
|
|
50
|
-
return TimeSpan.zero;
|
|
51
|
-
if (typeof value === 'number') {
|
|
52
|
-
if (units === undefined)
|
|
53
|
-
throw new Error('A numerical value requires a TimeUnit.');
|
|
54
|
-
return new TimeSpan(value, units);
|
|
55
|
-
}
|
|
56
|
-
const ms = TimeQuantity.getTotalMillisecondsFrom(value);
|
|
57
|
-
return ms ? new TimeSpan(ms) : TimeSpan.zero;
|
|
58
|
-
}
|
|
59
|
-
static fromDays(value) {
|
|
60
|
-
return value ? new TimeSpan(value, TimeUnit.UnitType.Days) : TimeSpan.zero;
|
|
61
|
-
}
|
|
62
|
-
static fromHours(value) {
|
|
63
|
-
return value ? new TimeSpan(value, TimeUnit.UnitType.Hours) : TimeSpan.zero;
|
|
64
|
-
}
|
|
65
|
-
static fromMinutes(value) {
|
|
66
|
-
return value ? new TimeSpan(value, TimeUnit.UnitType.Minutes) : TimeSpan.zero;
|
|
67
|
-
}
|
|
68
|
-
static fromSeconds(value) {
|
|
69
|
-
return value ? new TimeSpan(value, TimeUnit.UnitType.Seconds) : TimeSpan.zero;
|
|
70
|
-
}
|
|
71
|
-
static fromMilliseconds(value) {
|
|
72
|
-
return value ? new TimeSpan(value) : TimeSpan.zero;
|
|
73
|
-
}
|
|
74
|
-
static fromTicks(value) {
|
|
75
|
-
return value ? new TimeSpan(value, TimeUnit.UnitType.Ticks) : TimeSpan.zero;
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Sum the value of this TimeSpan with another time quantity.
|
|
79
|
-
* @param {TimeQuantity | Partial<TimeMeasurement>} other
|
|
80
|
-
* @return {TimeSpan}
|
|
81
|
-
*/
|
|
82
|
-
add(other) {
|
|
83
|
-
if (!other)
|
|
84
|
-
return this;
|
|
85
|
-
if (type.isNumber(other))
|
|
86
|
-
throw new Error('Use .addUnit(value:number, units:TimeUnit) to add a numerical value amount. Default units are milliseconds.\n' +
|
|
87
|
-
'.add only supports quantifiable time values (TimeQuantity).');
|
|
88
|
-
const otherMs = other instanceof TimeQuantity
|
|
89
|
-
? other.total.milliseconds
|
|
90
|
-
: TimeQuantity.getTotalMillisecondsFrom(other);
|
|
91
|
-
return new TimeSpan(this.getTotalMilliseconds() + otherMs);
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Sum the value of this TimeSpan with another unit value.
|
|
95
|
-
* @param {number} value
|
|
96
|
-
* @param {TimeUnit.UnitType} units
|
|
97
|
-
* @return {TimeSpan}
|
|
98
|
-
*/
|
|
99
|
-
addUnit(value, units = TimeUnit.UnitType.Milliseconds) {
|
|
100
|
-
return value
|
|
101
|
-
? new TimeSpan(this.getTotalMilliseconds() + TimeUnit.toMilliseconds(value, units))
|
|
102
|
-
: this;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
let timeSpanZero;
|
|
106
|
-
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 Lazy from '@tsdotnet/lazy';
|
|
7
|
+
import type from '@tsdotnet/type';
|
|
8
|
+
import ClockTime from './ClockTime';
|
|
9
|
+
import TimeQuantity from './TimeQuantity';
|
|
10
|
+
import TimeUnit from './TimeUnit';
|
|
11
|
+
/**
|
|
12
|
+
* TimeSpan expands on TimeQuantity to provide an class that is similar to .NET's TimeSpan including many useful static methods.
|
|
13
|
+
*/
|
|
14
|
+
export class TimeSpan extends TimeQuantity {
|
|
15
|
+
// In .NET the default type is Ticks, but for JavaScript, we will use Milliseconds.
|
|
16
|
+
constructor(value, units = TimeUnit.UnitType.Milliseconds) {
|
|
17
|
+
if (isNaN(value))
|
|
18
|
+
throw Error('Cannot construct a TimeSpan from NaN value.');
|
|
19
|
+
const ms = TimeUnit.toMilliseconds(value, units);
|
|
20
|
+
super(ms);
|
|
21
|
+
this.ticks = ms * 10000 /* millisecond */;
|
|
22
|
+
this.milliseconds = ms;
|
|
23
|
+
this.seconds = ms / 1000 /* second */;
|
|
24
|
+
this.minutes = ms / 60000 /* minute */;
|
|
25
|
+
this.hours = ms / 3600000 /* hour */;
|
|
26
|
+
this.days = ms / 86400000 /* day */;
|
|
27
|
+
this._time = Lazy.create(() => new ClockTime(this.getTotalMilliseconds()));
|
|
28
|
+
Object.freeze(this);
|
|
29
|
+
}
|
|
30
|
+
static get zero() {
|
|
31
|
+
return timeSpanZero || (timeSpanZero = new TimeSpan(0));
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Provides an standard interface for acquiring the total time.
|
|
35
|
+
* @returns {TimeSpan}
|
|
36
|
+
*/
|
|
37
|
+
get total() {
|
|
38
|
+
return this;
|
|
39
|
+
}
|
|
40
|
+
// Instead of the confusing getTotal versus unit name, expose a 'ClockTime' value which reports the individual components.
|
|
41
|
+
/**
|
|
42
|
+
* The value of this TimeSpan reduced to the clock and calendar.
|
|
43
|
+
* @return {ClockTime}
|
|
44
|
+
*/
|
|
45
|
+
get time() {
|
|
46
|
+
return this._time.value;
|
|
47
|
+
}
|
|
48
|
+
static from(value, units) {
|
|
49
|
+
if (!value)
|
|
50
|
+
return TimeSpan.zero;
|
|
51
|
+
if (typeof value === 'number') {
|
|
52
|
+
if (units === undefined)
|
|
53
|
+
throw new Error('A numerical value requires a TimeUnit.');
|
|
54
|
+
return new TimeSpan(value, units);
|
|
55
|
+
}
|
|
56
|
+
const ms = TimeQuantity.getTotalMillisecondsFrom(value);
|
|
57
|
+
return ms ? new TimeSpan(ms) : TimeSpan.zero;
|
|
58
|
+
}
|
|
59
|
+
static fromDays(value) {
|
|
60
|
+
return value ? new TimeSpan(value, TimeUnit.UnitType.Days) : TimeSpan.zero;
|
|
61
|
+
}
|
|
62
|
+
static fromHours(value) {
|
|
63
|
+
return value ? new TimeSpan(value, TimeUnit.UnitType.Hours) : TimeSpan.zero;
|
|
64
|
+
}
|
|
65
|
+
static fromMinutes(value) {
|
|
66
|
+
return value ? new TimeSpan(value, TimeUnit.UnitType.Minutes) : TimeSpan.zero;
|
|
67
|
+
}
|
|
68
|
+
static fromSeconds(value) {
|
|
69
|
+
return value ? new TimeSpan(value, TimeUnit.UnitType.Seconds) : TimeSpan.zero;
|
|
70
|
+
}
|
|
71
|
+
static fromMilliseconds(value) {
|
|
72
|
+
return value ? new TimeSpan(value) : TimeSpan.zero;
|
|
73
|
+
}
|
|
74
|
+
static fromTicks(value) {
|
|
75
|
+
return value ? new TimeSpan(value, TimeUnit.UnitType.Ticks) : TimeSpan.zero;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Sum the value of this TimeSpan with another time quantity.
|
|
79
|
+
* @param {TimeQuantity | Partial<TimeMeasurement>} other
|
|
80
|
+
* @return {TimeSpan}
|
|
81
|
+
*/
|
|
82
|
+
add(other) {
|
|
83
|
+
if (!other)
|
|
84
|
+
return this;
|
|
85
|
+
if (type.isNumber(other))
|
|
86
|
+
throw new Error('Use .addUnit(value:number, units:TimeUnit) to add a numerical value amount. Default units are milliseconds.\n' +
|
|
87
|
+
'.add only supports quantifiable time values (TimeQuantity).');
|
|
88
|
+
const otherMs = other instanceof TimeQuantity
|
|
89
|
+
? other.total.milliseconds
|
|
90
|
+
: TimeQuantity.getTotalMillisecondsFrom(other);
|
|
91
|
+
return new TimeSpan(this.getTotalMilliseconds() + otherMs);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Sum the value of this TimeSpan with another unit value.
|
|
95
|
+
* @param {number} value
|
|
96
|
+
* @param {TimeUnit.UnitType} units
|
|
97
|
+
* @return {TimeSpan}
|
|
98
|
+
*/
|
|
99
|
+
addUnit(value, units = TimeUnit.UnitType.Milliseconds) {
|
|
100
|
+
return value
|
|
101
|
+
? new TimeSpan(this.getTotalMilliseconds() + TimeUnit.toMilliseconds(value, units))
|
|
102
|
+
: this;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
let timeSpanZero;
|
|
106
|
+
export default TimeSpan;
|
|
107
107
|
//# sourceMappingURL=TimeSpan.js.map
|
package/dist-esm/TimeStamp.js
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* @author electricessence / https://github.com/electricessence/
|
|
3
|
-
* @license MIT
|
|
4
|
-
*/
|
|
5
|
-
import type from '@tsdotnet/type';
|
|
6
|
-
/**
|
|
7
|
-
* An alternative to Date or DateTime. Is a model representing the exact date and time.
|
|
8
|
-
*/
|
|
9
|
-
export class TimeStamp {
|
|
10
|
-
constructor(year, month, day = 1, hour = 0, minute = 0, second = 0, millisecond = 0, tick = 0) {
|
|
11
|
-
// Add validation or properly carry out of range values?
|
|
12
|
-
this.year = year;
|
|
13
|
-
this.month = month;
|
|
14
|
-
this.day = day;
|
|
15
|
-
this.hour = hour;
|
|
16
|
-
this.minute = minute;
|
|
17
|
-
this.second = second;
|
|
18
|
-
this.millisecond = millisecond;
|
|
19
|
-
this.tick = tick;
|
|
20
|
-
Object.freeze(this);
|
|
21
|
-
}
|
|
22
|
-
static from(d) {
|
|
23
|
-
if (!(d instanceof Date) && type.hasMember(d, 'toJsDate'))
|
|
24
|
-
d = d.toJsDate();
|
|
25
|
-
if (d instanceof Date) {
|
|
26
|
-
return new TimeStamp(d.getFullYear(), d.getMonth(), d.getDate(), d.getHours(), d.getMinutes(), d.getSeconds(), d.getMilliseconds());
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
throw Error('Invalid date type.');
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
static now() {
|
|
33
|
-
return TimeStamp.from(new Date());
|
|
34
|
-
}
|
|
35
|
-
toJsDate() {
|
|
36
|
-
const _ = this;
|
|
37
|
-
return new Date(_.year, _.month, _.day, _.hour, _.minute, _.second, _.millisecond + _.tick / 10000 /* millisecond */);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
export default TimeStamp;
|
|
1
|
+
/*!
|
|
2
|
+
* @author electricessence / https://github.com/electricessence/
|
|
3
|
+
* @license MIT
|
|
4
|
+
*/
|
|
5
|
+
import type from '@tsdotnet/type';
|
|
6
|
+
/**
|
|
7
|
+
* An alternative to Date or DateTime. Is a model representing the exact date and time.
|
|
8
|
+
*/
|
|
9
|
+
export class TimeStamp {
|
|
10
|
+
constructor(year, month, day = 1, hour = 0, minute = 0, second = 0, millisecond = 0, tick = 0) {
|
|
11
|
+
// Add validation or properly carry out of range values?
|
|
12
|
+
this.year = year;
|
|
13
|
+
this.month = month;
|
|
14
|
+
this.day = day;
|
|
15
|
+
this.hour = hour;
|
|
16
|
+
this.minute = minute;
|
|
17
|
+
this.second = second;
|
|
18
|
+
this.millisecond = millisecond;
|
|
19
|
+
this.tick = tick;
|
|
20
|
+
Object.freeze(this);
|
|
21
|
+
}
|
|
22
|
+
static from(d) {
|
|
23
|
+
if (!(d instanceof Date) && type.hasMember(d, 'toJsDate'))
|
|
24
|
+
d = d.toJsDate();
|
|
25
|
+
if (d instanceof Date) {
|
|
26
|
+
return new TimeStamp(d.getFullYear(), d.getMonth(), d.getDate(), d.getHours(), d.getMinutes(), d.getSeconds(), d.getMilliseconds());
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
throw Error('Invalid date type.');
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
static now() {
|
|
33
|
+
return TimeStamp.from(new Date());
|
|
34
|
+
}
|
|
35
|
+
toJsDate() {
|
|
36
|
+
const _ = this;
|
|
37
|
+
return new Date(_.year, _.month, _.day, _.hour, _.minute, _.second, _.millisecond + _.tick / 10000 /* millisecond */);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export default TimeStamp;
|
|
41
41
|
//# sourceMappingURL=TimeStamp.js.map
|