@tsdotnet/date-time 1.1.0 → 1.1.2
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/dist/cjs/ClockTime.js +13 -18
- package/dist/cjs/ClockTime.js.map +1 -1
- package/dist/cjs/DateTime.js +9 -96
- package/dist/cjs/DateTime.js.map +1 -1
- package/dist/cjs/TimeQuantity.js +10 -43
- package/dist/cjs/TimeQuantity.js.map +1 -1
- package/dist/cjs/TimeSpan.js +5 -30
- package/dist/cjs/TimeSpan.js.map +1 -1
- package/dist/cjs/TimeStamp.js +1 -6
- package/dist/cjs/TimeStamp.js.map +1 -1
- package/dist/cjs/TimeUnit.js +11 -40
- package/dist/cjs/TimeUnit.js.map +1 -1
- package/dist/cjs/TimeUnitValue.js +0 -4
- package/dist/cjs/TimeUnitValue.js.map +1 -1
- package/dist/cjs/howMany.js +0 -46
- package/dist/cjs/howMany.js.map +1 -1
- package/dist/esm/ClockTime.js +19 -22
- package/dist/esm/ClockTime.js.map +1 -1
- package/dist/esm/DateTime.js +18 -102
- package/dist/esm/DateTime.js.map +1 -1
- package/dist/esm/TimeQuantity.js +19 -49
- package/dist/esm/TimeQuantity.js.map +1 -1
- package/dist/esm/TimeSpan.js +15 -56
- package/dist/esm/TimeSpan.js.map +1 -1
- package/dist/esm/TimeStamp.js +7 -10
- package/dist/esm/TimeStamp.js.map +1 -1
- package/dist/esm/TimeUnit.js +16 -43
- package/dist/esm/TimeUnit.js.map +1 -1
- package/dist/esm/TimeUnitValue.js +7 -8
- package/dist/esm/TimeUnitValue.js.map +1 -1
- package/dist/esm/date-time.js +10 -14
- package/dist/esm/date-time.js.map +1 -1
- package/dist/esm/howMany.js +1 -46
- package/dist/esm/howMany.js.map +1 -1
- package/dist/types/Calendars/Gregorian.d.ts +37 -0
- package/dist/types/DateTime.d.ts +60 -0
- package/dist/types/TimeQuantity.d.ts +19 -0
- package/dist/{TimeSpan.d.ts → types/TimeSpan.d.ts} +0 -40
- package/dist/{TimeStamp.d.ts → types/TimeStamp.d.ts} +0 -3
- package/dist/types/TimeUnit.d.ts +21 -0
- package/dist/{TimeUnitValue.d.ts → types/TimeUnitValue.d.ts} +0 -3
- package/dist/{howMany.d.ts → types/howMany.d.ts} +5 -5
- package/package.json +33 -43
- package/rollup.config.js +37 -0
- package/dist/Calendars/Gregorian.d.ts +0 -30
- package/dist/DateTime.d.ts +0 -154
- package/dist/TimeQuantity.d.ts +0 -50
- package/dist/TimeUnit.d.ts +0 -47
- package/dist/cjs/Calendars/Gregorian.js +0 -7
- package/dist/cjs/Calendars/Gregorian.js.map +0 -1
- package/dist/esm/Calendars/Gregorian.js +0 -6
- package/dist/esm/Calendars/Gregorian.js.map +0 -1
- package/dist/esm/DateTimeKind.js +0 -6
- package/dist/esm/DateTimeKind.js.map +0 -1
- package/dist/umd/Calendars/Gregorian.js +0 -17
- package/dist/umd/Calendars/Gregorian.js.map +0 -1
- package/dist/umd/ClockTime.js +0 -86
- package/dist/umd/ClockTime.js.map +0 -1
- package/dist/umd/DateTime.js +0 -320
- package/dist/umd/DateTime.js.map +0 -1
- package/dist/umd/DateTimeKind.js +0 -17
- package/dist/umd/DateTimeKind.js.map +0 -1
- package/dist/umd/TimeQuantity.js +0 -108
- package/dist/umd/TimeQuantity.js.map +0 -1
- package/dist/umd/TimeSpan.js +0 -148
- package/dist/umd/TimeSpan.js.map +0 -1
- package/dist/umd/TimeStamp.js +0 -65
- package/dist/umd/TimeStamp.js.map +0 -1
- package/dist/umd/TimeUnit.js +0 -111
- package/dist/umd/TimeUnit.js.map +0 -1
- package/dist/umd/TimeUnitValue.js +0 -58
- package/dist/umd/TimeUnitValue.js.map +0 -1
- package/dist/umd/date-time.js +0 -35
- package/dist/umd/date-time.js.map +0 -1
- package/dist/umd/howMany.js +0 -63
- package/dist/umd/howMany.js.map +0 -1
- /package/dist/{CalendarDate.d.ts → types/CalendarDate.d.ts} +0 -0
- /package/dist/{ClockTime.d.ts → types/ClockTime.d.ts} +0 -0
- /package/dist/{ClockTimeValue.d.ts → types/ClockTimeValue.d.ts} +0 -0
- /package/dist/{DateTimeKind.d.ts → types/DateTimeKind.d.ts} +0 -0
- /package/dist/{JsDateConvertible.d.ts → types/JsDateConvertible.d.ts} +0 -0
- /package/dist/{TimeMeasurement.d.ts → types/TimeMeasurement.d.ts} +0 -0
- /package/dist/{TimeStampValue.d.ts → types/TimeStampValue.d.ts} +0 -0
- /package/dist/{date-time.d.ts → types/date-time.d.ts} +0 -0
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Gregorian.js","sourceRoot":"","sources":["../../../src/Calendars/Gregorian.ts"],"names":[],"mappings":";AAAA;;;GAGG"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Gregorian.js","sourceRoot":"","sources":["../../../src/Calendars/Gregorian.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
|
package/dist/esm/DateTimeKind.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DateTimeKind.js","sourceRoot":"","sources":["../../src/DateTimeKind.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* @author electricessence / https://github.com/electricessence/
|
|
3
|
-
* @license MIT
|
|
4
|
-
*/
|
|
5
|
-
(function (factory) {
|
|
6
|
-
if (typeof module === "object" && typeof module.exports === "object") {
|
|
7
|
-
var v = factory(require, exports);
|
|
8
|
-
if (v !== undefined) module.exports = v;
|
|
9
|
-
}
|
|
10
|
-
else if (typeof define === "function" && define.amd) {
|
|
11
|
-
define(["require", "exports"], factory);
|
|
12
|
-
}
|
|
13
|
-
})(function (require, exports) {
|
|
14
|
-
"use strict";
|
|
15
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
});
|
|
17
|
-
//# sourceMappingURL=Gregorian.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Gregorian.js","sourceRoot":"","sources":["../../../src/Calendars/Gregorian.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
|
package/dist/umd/ClockTime.js
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* @author electricessence / https://github.com/electricessence/
|
|
3
|
-
* @license MIT
|
|
4
|
-
*/
|
|
5
|
-
(function (factory) {
|
|
6
|
-
if (typeof module === "object" && typeof module.exports === "object") {
|
|
7
|
-
var v = factory(require, exports);
|
|
8
|
-
if (v !== undefined) module.exports = v;
|
|
9
|
-
}
|
|
10
|
-
else if (typeof define === "function" && define.amd) {
|
|
11
|
-
define(["require", "exports", "tslib", "./howMany", "./TimeQuantity"], factory);
|
|
12
|
-
}
|
|
13
|
-
})(function (require, exports) {
|
|
14
|
-
"use strict";
|
|
15
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.ClockTime = void 0;
|
|
17
|
-
const tslib_1 = require("tslib");
|
|
18
|
-
const howMany = tslib_1.__importStar(require("./howMany"));
|
|
19
|
-
const TimeQuantity_1 = tslib_1.__importDefault(require("./TimeQuantity"));
|
|
20
|
-
var msPer = howMany.milliseconds.per;
|
|
21
|
-
class ClockTime extends TimeQuantity_1.default {
|
|
22
|
-
day;
|
|
23
|
-
hour;
|
|
24
|
-
minute;
|
|
25
|
-
second;
|
|
26
|
-
millisecond;
|
|
27
|
-
tick;
|
|
28
|
-
constructor(...args) {
|
|
29
|
-
super(args.length > 1
|
|
30
|
-
? ClockTime.millisecondsFromTime(args[0] || 0, args[1] || 0, args.length > 2 && args[2] || 0, args.length > 3 && args[3] || 0)
|
|
31
|
-
: (args.length > 0 && args[0] || 0));
|
|
32
|
-
const ms = Math.abs(this.getTotalMilliseconds());
|
|
33
|
-
let msi = Math.floor(ms);
|
|
34
|
-
this.tick = (ms - msi) * howMany.ticks.per.millisecond;
|
|
35
|
-
this.day = (msi / msPer.day) | 0;
|
|
36
|
-
msi -= this.day * howMany.milliseconds.per.day;
|
|
37
|
-
this.hour = (msi / msPer.hour) | 0;
|
|
38
|
-
msi -= this.hour * msPer.hour;
|
|
39
|
-
this.minute = (msi / msPer.minute) | 0;
|
|
40
|
-
msi -= this.minute * msPer.minute;
|
|
41
|
-
this.second = (msi / msPer.second) | 0;
|
|
42
|
-
msi -= this.second * msPer.second;
|
|
43
|
-
this.millisecond = msi;
|
|
44
|
-
Object.freeze(this);
|
|
45
|
-
}
|
|
46
|
-
// Static version for relative consistency. Constructor does allow this format.
|
|
47
|
-
static from(hours, minutes, seconds = 0, milliseconds = 0) {
|
|
48
|
-
return new ClockTime(hours, minutes, seconds, milliseconds);
|
|
49
|
-
}
|
|
50
|
-
static millisecondsFromTime(hours, minutes, seconds = 0, milliseconds = 0) {
|
|
51
|
-
let value = hours;
|
|
52
|
-
value *= howMany.minutes.per.hour;
|
|
53
|
-
value += minutes;
|
|
54
|
-
value *= howMany.seconds.per.minute;
|
|
55
|
-
value += seconds;
|
|
56
|
-
value *= howMany.milliseconds.per.second;
|
|
57
|
-
value += milliseconds;
|
|
58
|
-
return value;
|
|
59
|
-
}
|
|
60
|
-
toString( /*format?:string, formatProvider?:IFormatProvider*/) {
|
|
61
|
-
/* INSERT CUSTOM FORMATTING CODE HERE */
|
|
62
|
-
const _ = this;
|
|
63
|
-
const a = [];
|
|
64
|
-
if (_.day)
|
|
65
|
-
a.push(pluralize(_.day, 'day'));
|
|
66
|
-
if (_.hour)
|
|
67
|
-
a.push(pluralize(_.hour, 'hour'));
|
|
68
|
-
if (_.minute)
|
|
69
|
-
a.push(pluralize(_.minute, 'minute'));
|
|
70
|
-
if (_.second)
|
|
71
|
-
a.push(pluralize(_.second, 'second'));
|
|
72
|
-
if (a.length > 1)
|
|
73
|
-
a.splice(a.length - 1, 0, 'and');
|
|
74
|
-
return a.join(', ').replace(', and, ', ' and ');
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
exports.ClockTime = ClockTime;
|
|
78
|
-
// Temporary until the full TimeSpanFormat is available.
|
|
79
|
-
function pluralize(value, label) {
|
|
80
|
-
if (Math.abs(value) !== 1)
|
|
81
|
-
label += 's';
|
|
82
|
-
return label;
|
|
83
|
-
}
|
|
84
|
-
exports.default = ClockTime;
|
|
85
|
-
});
|
|
86
|
-
//# sourceMappingURL=ClockTime.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ClockTime.js","sourceRoot":"","sources":["../../src/ClockTime.ts"],"names":[],"mappings":"AAAA;;;GAGG;;;;;;;;;;;;;;IAGH,2DAAqC;IACrC,0EAA0C;IAC1C,IAAO,KAAK,GAAG,OAAO,CAAC,YAAY,CAAC,GAAG,CAAC;IAExC,MAAa,SACZ,SAAQ,sBAAY;QAIX,GAAG,CAAS;QACZ,IAAI,CAAS;QACb,MAAM,CAAS;QACf,MAAM,CAAS;QACf,WAAW,CAAS;QACpB,IAAI,CAAS;QAItB,YAAa,GAAG,IAAc;YAE7B,KAAK,CACJ,IAAI,CAAC,MAAM,GAAC,CAAC;gBACZ,CAAC,CAAC,SAAS,CAAC,oBAAoB,CAC/B,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,EACZ,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,EACZ,IAAI,CAAC,MAAM,GAAC,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,EAC7B,IAAI,CAAC,MAAM,GAAC,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAC7B;gBACD,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,GAAC,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAClC,CAAC;YAEF,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,oBAAoB,EAAE,CAAC,CAAC;YACjD,IAAI,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YAEzB,IAAI,CAAC,IAAI,GAAG,CAAC,EAAE,GA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rB,KAAK,IAAI,GAAG,CAAC;QAEd,OAAO,KAAK,CAAC;IACd,CAAC;IAED,kBAAe,SAAS,CAAC"}
|
package/dist/umd/DateTime.js
DELETED
|
@@ -1,320 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* @author electricessence / https://github.com/electricessence/
|
|
3
|
-
* Based on .NET DateTime's interface.
|
|
4
|
-
* @license MIT
|
|
5
|
-
*/
|
|
6
|
-
(function (factory) {
|
|
7
|
-
if (typeof module === "object" && typeof module.exports === "object") {
|
|
8
|
-
var v = factory(require, exports);
|
|
9
|
-
if (v !== undefined) module.exports = v;
|
|
10
|
-
}
|
|
11
|
-
else if (typeof define === "function" && define.amd) {
|
|
12
|
-
define(["require", "exports", "tslib", "@tsdotnet/exceptions", "./ClockTime", "./howMany", "./TimeSpan", "./TimeStamp"], factory);
|
|
13
|
-
}
|
|
14
|
-
})(function (require, exports) {
|
|
15
|
-
"use strict";
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
const tslib_1 = require("tslib");
|
|
18
|
-
const exceptions_1 = require("@tsdotnet/exceptions");
|
|
19
|
-
const ClockTime_1 = tslib_1.__importDefault(require("./ClockTime"));
|
|
20
|
-
const howMany_1 = require("./howMany");
|
|
21
|
-
const TimeSpan_1 = tslib_1.__importDefault(require("./TimeSpan"));
|
|
22
|
-
const TimeStamp_1 = tslib_1.__importDefault(require("./TimeStamp"));
|
|
23
|
-
const VOID0 = void 0;
|
|
24
|
-
class DateTime {
|
|
25
|
-
_value;
|
|
26
|
-
_kind;
|
|
27
|
-
_time;
|
|
28
|
-
constructor(value = new Date(), kind = 1 /* DateTimeKind.Local */) {
|
|
29
|
-
this._kind = kind;
|
|
30
|
-
if (value instanceof DateTime) {
|
|
31
|
-
this._value = value.toJsDate();
|
|
32
|
-
if (kind === VOID0)
|
|
33
|
-
this._kind = value._kind;
|
|
34
|
-
}
|
|
35
|
-
else { // noinspection SuspiciousInstanceOfGuard
|
|
36
|
-
if (value instanceof Date)
|
|
37
|
-
this._value = new Date(value.getTime());
|
|
38
|
-
else
|
|
39
|
-
this._value = value === VOID0
|
|
40
|
-
? new Date()
|
|
41
|
-
: new Date(value);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Returns the now local time.
|
|
46
|
-
* @returns {DateTime}
|
|
47
|
-
*/
|
|
48
|
-
static get now() {
|
|
49
|
-
return new DateTime();
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* The date component for now.
|
|
53
|
-
* @returns {DateTime}
|
|
54
|
-
*/
|
|
55
|
-
static get today() {
|
|
56
|
-
return DateTime.now.date;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Midnight tomorrow.
|
|
60
|
-
* @returns {DateTime}
|
|
61
|
-
*/
|
|
62
|
-
static get tomorrow() {
|
|
63
|
-
const today = DateTime.today;
|
|
64
|
-
return today.addDays(1);
|
|
65
|
-
}
|
|
66
|
-
get kind() {
|
|
67
|
-
return this._kind;
|
|
68
|
-
}
|
|
69
|
-
get year() {
|
|
70
|
-
return this._value.getFullYear();
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Returns the Gregorian Month (zero indexed).
|
|
74
|
-
* @returns {number}
|
|
75
|
-
*/
|
|
76
|
-
get month() {
|
|
77
|
-
return this._value.getMonth();
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Returns the month number (1-12).
|
|
81
|
-
* @returns {number}
|
|
82
|
-
*/
|
|
83
|
-
get calendarMonth() {
|
|
84
|
-
return this._value.getMonth() + 1;
|
|
85
|
-
}
|
|
86
|
-
get calendar() {
|
|
87
|
-
return {
|
|
88
|
-
year: this.year,
|
|
89
|
-
month: this.calendarMonth,
|
|
90
|
-
day: this.day
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Returns the day of the month. An integer between 1 and 31.
|
|
95
|
-
* @returns {number}
|
|
96
|
-
*/
|
|
97
|
-
get day() {
|
|
98
|
-
return this._value.getDate();
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Returns the day of the month indexed starting at zero.
|
|
102
|
-
* @returns {number}
|
|
103
|
-
*/
|
|
104
|
-
get dayIndex() {
|
|
105
|
-
return this._value.getDate() - 1;
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Returns the zero indexed day of the week. (Sunday == 0)
|
|
109
|
-
* @returns {number}
|
|
110
|
-
*/
|
|
111
|
-
get dayOfWeek() {
|
|
112
|
-
return this._value.getDay();
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Returns a DateTime object for 00:00 of this date.
|
|
116
|
-
*/
|
|
117
|
-
get date() {
|
|
118
|
-
const _ = this;
|
|
119
|
-
return new DateTime(new Date(_.year, _.month, _.day), _._kind);
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Returns the time of day represented by a ClockTime object.
|
|
123
|
-
* @returns {ClockTime}
|
|
124
|
-
*/
|
|
125
|
-
get timeOfDay() {
|
|
126
|
-
const _ = this;
|
|
127
|
-
let t = _._time;
|
|
128
|
-
if (!t) {
|
|
129
|
-
const d = this._value;
|
|
130
|
-
_._time = t = new ClockTime_1.default(d.getHours(), d.getMinutes(), d.getSeconds(), d.getMilliseconds());
|
|
131
|
-
}
|
|
132
|
-
return t;
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Measures the difference between two dates as a TimeSpan.
|
|
136
|
-
* @param first
|
|
137
|
-
* @param last
|
|
138
|
-
*/
|
|
139
|
-
static between(first, last) {
|
|
140
|
-
const f = first instanceof DateTime ? first._value : first, l = last instanceof DateTime ? last._value : last;
|
|
141
|
-
return TimeSpan_1.default.fromMilliseconds(l.getTime() - f.getTime());
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* Calculates if the given year is a leap year using the formula:
|
|
145
|
-
* ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)
|
|
146
|
-
* @param year
|
|
147
|
-
* @returns {boolean}
|
|
148
|
-
*/
|
|
149
|
-
static isLeapYear(year) {
|
|
150
|
-
return ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0);
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* Returns the number of days for the specific year and month.
|
|
154
|
-
* @param year
|
|
155
|
-
* @param month
|
|
156
|
-
* @returns {any}
|
|
157
|
-
*/
|
|
158
|
-
static daysInMonth(year, month) {
|
|
159
|
-
// Basically, add 1 month, subtract a day... What's the date?
|
|
160
|
-
return (new Date(year, month + 1, 0)).getDate();
|
|
161
|
-
}
|
|
162
|
-
static from(yearOrDate, month = 0, day = 1) {
|
|
163
|
-
let year;
|
|
164
|
-
if (typeof yearOrDate == 'object') {
|
|
165
|
-
day = yearOrDate.day;
|
|
166
|
-
month = yearOrDate.month;
|
|
167
|
-
year = yearOrDate.year;
|
|
168
|
-
}
|
|
169
|
-
else {
|
|
170
|
-
year = yearOrDate;
|
|
171
|
-
}
|
|
172
|
-
return new DateTime(new Date(year, month, day));
|
|
173
|
-
}
|
|
174
|
-
static fromCalendarDate(yearOrDate, month = 1, day = 1) {
|
|
175
|
-
let year;
|
|
176
|
-
if (typeof yearOrDate == 'object') {
|
|
177
|
-
day = yearOrDate.day;
|
|
178
|
-
month = yearOrDate.month;
|
|
179
|
-
year = yearOrDate.year;
|
|
180
|
-
}
|
|
181
|
-
else {
|
|
182
|
-
year = yearOrDate;
|
|
183
|
-
}
|
|
184
|
-
return new DateTime(new Date(year, month - 1, day));
|
|
185
|
-
}
|
|
186
|
-
toJsDate() {
|
|
187
|
-
return new Date(this._value.getTime()); // return a clone.
|
|
188
|
-
}
|
|
189
|
-
addMilliseconds(ms) {
|
|
190
|
-
ms = ms || 0;
|
|
191
|
-
return new DateTime(this._value.getTime() + ms, this._kind);
|
|
192
|
-
}
|
|
193
|
-
addSeconds(seconds) {
|
|
194
|
-
seconds = seconds || 0;
|
|
195
|
-
return this.addMilliseconds(seconds * howMany_1.milliseconds.per.second);
|
|
196
|
-
}
|
|
197
|
-
addMinutes(minutes) {
|
|
198
|
-
minutes = minutes || 0;
|
|
199
|
-
return this.addMilliseconds(minutes * howMany_1.milliseconds.per.minute);
|
|
200
|
-
}
|
|
201
|
-
addHours(hours) {
|
|
202
|
-
hours = hours || 0;
|
|
203
|
-
return this.addMilliseconds(hours * howMany_1.milliseconds.per.hour);
|
|
204
|
-
}
|
|
205
|
-
addDays(days) {
|
|
206
|
-
days = days || 0;
|
|
207
|
-
return this.addMilliseconds(days * howMany_1.milliseconds.per.day);
|
|
208
|
-
}
|
|
209
|
-
addMonths(months) {
|
|
210
|
-
months = months || 0;
|
|
211
|
-
const d = this.toJsDate();
|
|
212
|
-
d.setMonth(d.getMonth() + months);
|
|
213
|
-
return new DateTime(d, this._kind);
|
|
214
|
-
}
|
|
215
|
-
addYears(years) {
|
|
216
|
-
years = years || 0;
|
|
217
|
-
const d = this.toJsDate();
|
|
218
|
-
d.setFullYear(d.getFullYear() + years);
|
|
219
|
-
return new DateTime(d, this._kind);
|
|
220
|
-
}
|
|
221
|
-
/**
|
|
222
|
-
* Receives an TimeQuantity value and adds based on the total milliseconds.
|
|
223
|
-
* @param {TimeQuantity} time
|
|
224
|
-
* @returns {DateTime}
|
|
225
|
-
*/
|
|
226
|
-
add(time) {
|
|
227
|
-
return this.addMilliseconds(time.getTotalMilliseconds());
|
|
228
|
-
}
|
|
229
|
-
/**
|
|
230
|
-
* Receives an TimeQuantity value and subtracts based on the total milliseconds.
|
|
231
|
-
* @param {TimeQuantity} time
|
|
232
|
-
* @returns {DateTime}
|
|
233
|
-
*/
|
|
234
|
-
subtract(time) {
|
|
235
|
-
return this.addMilliseconds(-time.getTotalMilliseconds());
|
|
236
|
-
}
|
|
237
|
-
/**
|
|
238
|
-
* Returns a TimeSpan representing the amount of time between two dates.
|
|
239
|
-
* @param previous
|
|
240
|
-
* @returns {TimeSpan}
|
|
241
|
-
*/
|
|
242
|
-
timePassedSince(previous) {
|
|
243
|
-
return DateTime.between(previous, this);
|
|
244
|
-
}
|
|
245
|
-
/**
|
|
246
|
-
* Returns a readonly object which contains all the date and time components.
|
|
247
|
-
*/
|
|
248
|
-
toTimeStamp() {
|
|
249
|
-
return TimeStamp_1.default.from(this);
|
|
250
|
-
}
|
|
251
|
-
/**
|
|
252
|
-
* Returns a UTC version of this date if its kind is local.
|
|
253
|
-
* @returns {DateTime}
|
|
254
|
-
*/
|
|
255
|
-
toUniversalTime() {
|
|
256
|
-
const _ = this;
|
|
257
|
-
if (_._kind != 1 /* DateTimeKind.Local */)
|
|
258
|
-
return new DateTime(_, _._kind);
|
|
259
|
-
const d = _._value;
|
|
260
|
-
return new DateTime(new Date(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate(), d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds(), d.getUTCMilliseconds()), 2 /* DateTimeKind.Utc */);
|
|
261
|
-
}
|
|
262
|
-
equals(other, strict = false) {
|
|
263
|
-
if (!other)
|
|
264
|
-
return false;
|
|
265
|
-
if (other == this)
|
|
266
|
-
return true;
|
|
267
|
-
if (other instanceof Date) {
|
|
268
|
-
const v = this._value;
|
|
269
|
-
return other == v || other.getTime() == v.getTime();
|
|
270
|
-
}
|
|
271
|
-
if (other instanceof DateTime) {
|
|
272
|
-
if (strict) {
|
|
273
|
-
const ok = other._kind;
|
|
274
|
-
if (!ok && this._kind || ok != this._kind)
|
|
275
|
-
return false;
|
|
276
|
-
}
|
|
277
|
-
return this.equals(other._value);
|
|
278
|
-
}
|
|
279
|
-
else if (strict)
|
|
280
|
-
return false;
|
|
281
|
-
return this.equals(other.toJsDate());
|
|
282
|
-
}
|
|
283
|
-
// https://msdn.microsoft.com/en-us/library/System.IComparable.CompareTo(v=vs.110).aspx
|
|
284
|
-
compareTo(other) {
|
|
285
|
-
if (!other)
|
|
286
|
-
throw new exceptions_1.ArgumentNullException('other');
|
|
287
|
-
if (other == this)
|
|
288
|
-
return 0;
|
|
289
|
-
if (other instanceof DateTime) {
|
|
290
|
-
other = other._value;
|
|
291
|
-
}
|
|
292
|
-
const ms = this._value.getTime();
|
|
293
|
-
if (other instanceof Date) {
|
|
294
|
-
return ms - other.getTime();
|
|
295
|
-
}
|
|
296
|
-
return ms - other.toJsDate().getTime();
|
|
297
|
-
}
|
|
298
|
-
/**
|
|
299
|
-
* Returns true if the value is the same UTC time.
|
|
300
|
-
* @param {Date | JsDateConvertible} other
|
|
301
|
-
* @return {boolean}
|
|
302
|
-
*/
|
|
303
|
-
equivalent(other) {
|
|
304
|
-
if (!other)
|
|
305
|
-
return false;
|
|
306
|
-
if (other == this)
|
|
307
|
-
return true;
|
|
308
|
-
if (other instanceof Date) {
|
|
309
|
-
const v = this._value;
|
|
310
|
-
// TODO: What is the best way to handle this when kinds match or don't?
|
|
311
|
-
return v.toUTCString() == other.toUTCString();
|
|
312
|
-
}
|
|
313
|
-
if (this.equals(other, true))
|
|
314
|
-
return true;
|
|
315
|
-
return this.equivalent(other.toJsDate());
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
exports.default = DateTime;
|
|
319
|
-
});
|
|
320
|
-
//# sourceMappingURL=DateTime.js.map
|
package/dist/umd/DateTime.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DateTime.js","sourceRoot":"","sources":["../../src/DateTime.ts"],"names":[],"mappings":"AAAA;;;;GAIG;;;;;;;;;;;;;IAEH,qDAA2D;IAG3D,oEAAoC;IAEpC,uCAAuC;IAGvC,kEAAkC;IAClC,oEAAoC;IAEpC,MAAM,KAAK,GAAc,KAAK,CAAC,CAAC;IAEhC,MAAqB,QAAQ;QAGX,MAAM,CAAO;QACb,KAAK,CAAe;QAC7B,KAAK,CAAwB;QAYrC,YAAa,QAAa,IAAI,IAAI,EAAE,EAAE,iCAAuC;YAE5E,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;YAClB,IAAG,KAAK,YAAY,QAAQ,EAC5B,CAAC;gBACA,IAAI,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
if (typeof module === "object" && typeof module.exports === "object") {
|
|
7
|
-
var v = factory(require, exports);
|
|
8
|
-
if (v !== undefined) module.exports = v;
|
|
9
|
-
}
|
|
10
|
-
else if (typeof define === "function" && define.amd) {
|
|
11
|
-
define(["require", "exports"], factory);
|
|
12
|
-
}
|
|
13
|
-
})(function (require, exports) {
|
|
14
|
-
"use strict";
|
|
15
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
});
|
|
17
|
-
//# sourceMappingURL=DateTimeKind.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DateTimeKind.js","sourceRoot":"","sources":["../../src/DateTimeKind.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
|
package/dist/umd/TimeQuantity.js
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* @author electricessence / https://github.com/electricessence/
|
|
3
|
-
* @license MIT
|
|
4
|
-
*/
|
|
5
|
-
(function (factory) {
|
|
6
|
-
if (typeof module === "object" && typeof module.exports === "object") {
|
|
7
|
-
var v = factory(require, exports);
|
|
8
|
-
if (v !== undefined) module.exports = v;
|
|
9
|
-
}
|
|
10
|
-
else if (typeof define === "function" && define.amd) {
|
|
11
|
-
define(["require", "exports", "tslib", "@tsdotnet/compare", "@tsdotnet/exceptions", "@tsdotnet/lazy", "./howMany", "./TimeUnit"], factory);
|
|
12
|
-
}
|
|
13
|
-
})(function (require, exports) {
|
|
14
|
-
"use strict";
|
|
15
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
const tslib_1 = require("tslib");
|
|
17
|
-
const compare_1 = require("@tsdotnet/compare");
|
|
18
|
-
const exceptions_1 = require("@tsdotnet/exceptions");
|
|
19
|
-
const lazy_1 = require("@tsdotnet/lazy");
|
|
20
|
-
const howMany_1 = require("./howMany");
|
|
21
|
-
const TimeUnit_1 = tslib_1.__importDefault(require("./TimeUnit"));
|
|
22
|
-
/**
|
|
23
|
-
* This class provides a simple means for storing and calculating time quantities.
|
|
24
|
-
*/
|
|
25
|
-
class TimeQuantity {
|
|
26
|
-
_quantity;
|
|
27
|
-
constructor(_quantity = 0) {
|
|
28
|
-
this._quantity = _quantity;
|
|
29
|
-
this._total = lazy_1.ResettableLazy.create(() => {
|
|
30
|
-
const ms = this.getTotalMilliseconds();
|
|
31
|
-
return Object.freeze({
|
|
32
|
-
ticks: ms * howMany_1.ticks.per.millisecond,
|
|
33
|
-
milliseconds: ms,
|
|
34
|
-
seconds: ms / howMany_1.milliseconds.per.second,
|
|
35
|
-
minutes: ms / howMany_1.milliseconds.per.minute,
|
|
36
|
-
hours: ms / howMany_1.milliseconds.per.hour,
|
|
37
|
-
days: ms / howMany_1.milliseconds.per.day
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Combine total values by time unit.
|
|
43
|
-
* @param {Partial<TimeMeasurement>} values
|
|
44
|
-
* @return {number}
|
|
45
|
-
*/
|
|
46
|
-
static getTotalMillisecondsFrom(values) {
|
|
47
|
-
if (!values)
|
|
48
|
-
return 0;
|
|
49
|
-
return (values.days || 0) * howMany_1.milliseconds.per.day +
|
|
50
|
-
(values.hours || 0) * howMany_1.milliseconds.per.hour +
|
|
51
|
-
(values.minutes || 0) * howMany_1.milliseconds.per.minute +
|
|
52
|
-
(values.seconds || 0) * howMany_1.milliseconds.per.second +
|
|
53
|
-
(values.milliseconds || 0) +
|
|
54
|
-
(values.ticks || 0) / howMany_1.ticks.per.millisecond;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* +1, 0, or -1 depending on the time direction.
|
|
58
|
-
* @returns {number}
|
|
59
|
-
*/
|
|
60
|
-
get direction() {
|
|
61
|
-
return (0, compare_1.compare)(this.getTotalMilliseconds(), 0);
|
|
62
|
-
}
|
|
63
|
-
_total;
|
|
64
|
-
/**
|
|
65
|
-
* Returns an object with all units exposed as totals.
|
|
66
|
-
* @returns {TimeMeasurement}
|
|
67
|
-
*/
|
|
68
|
-
get total() {
|
|
69
|
-
return this._total.value;
|
|
70
|
-
}
|
|
71
|
-
// Provides an overridable mechanism for extending this class.
|
|
72
|
-
getTotalMilliseconds() {
|
|
73
|
-
return this._quantity;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Compares this instance against any other time quantity instance and return true if the amount of time is the same.
|
|
77
|
-
* @param other
|
|
78
|
-
* @returns {boolean}
|
|
79
|
-
*/
|
|
80
|
-
equals(other) {
|
|
81
|
-
if (!other || !other.total)
|
|
82
|
-
return false;
|
|
83
|
-
return (0, compare_1.areEqual)(this.getTotalMilliseconds(), other.total.milliseconds);
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Compares this instance against any other time quantity instance.
|
|
87
|
-
* @param other
|
|
88
|
-
* @returns {number}
|
|
89
|
-
*/
|
|
90
|
-
compareTo(other) {
|
|
91
|
-
if (!other)
|
|
92
|
-
throw new exceptions_1.ArgumentNullException('other');
|
|
93
|
-
if (!other.total)
|
|
94
|
-
throw new exceptions_1.ArgumentNullException('other.total');
|
|
95
|
-
return (0, compare_1.compare)(this.getTotalMilliseconds(), other && other.total && other.total.milliseconds);
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Returns the total amount of time measured in the requested TimeUnit.
|
|
99
|
-
* @param units
|
|
100
|
-
* @returns {number}
|
|
101
|
-
*/
|
|
102
|
-
getTotal(units) {
|
|
103
|
-
return TimeUnit_1.default.fromMilliseconds(this.getTotalMilliseconds(), units);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
exports.default = TimeQuantity;
|
|
107
|
-
});
|
|
108
|
-
//# sourceMappingURL=TimeQuantity.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TimeQuantity.js","sourceRoot":"","sources":["../../src/TimeQuantity.ts"],"names":[],"mappings":"AAAA;;;GAGG;;;;;;;;;;;;;IAEH,+CAAoD;IACpD,qDAA2D;IAC3D,yCAA8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