@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.
package/dist/date-time.js CHANGED
@@ -1,25 +1,25 @@
1
- "use strict";
2
- /*!
3
- * @author electricessence / https://github.com/electricessence/
4
- * @license MIT
5
- */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.TimeUnitValue = exports.TimeUnit = exports.TimeStamp = exports.TimeSpan = exports.TimeQuantity = exports.howMany = exports.DateTime = exports.ClockTime = void 0;
8
- const tslib_1 = require("tslib");
9
- const ClockTime_1 = (0, tslib_1.__importDefault)(require("./ClockTime"));
10
- exports.ClockTime = ClockTime_1.default;
11
- const DateTime_1 = (0, tslib_1.__importDefault)(require("./DateTime"));
12
- exports.DateTime = DateTime_1.default;
13
- const howMany = (0, tslib_1.__importStar)(require("./howMany"));
14
- exports.howMany = howMany;
15
- const TimeQuantity_1 = (0, tslib_1.__importDefault)(require("./TimeQuantity"));
16
- exports.TimeQuantity = TimeQuantity_1.default;
17
- const TimeSpan_1 = (0, tslib_1.__importDefault)(require("./TimeSpan"));
18
- exports.TimeSpan = TimeSpan_1.default;
19
- const TimeStamp_1 = (0, tslib_1.__importDefault)(require("./TimeStamp"));
20
- exports.TimeStamp = TimeStamp_1.default;
21
- const TimeUnit_1 = (0, tslib_1.__importDefault)(require("./TimeUnit"));
22
- exports.TimeUnit = TimeUnit_1.default;
23
- const TimeUnitValue_1 = (0, tslib_1.__importDefault)(require("./TimeUnitValue"));
24
- exports.TimeUnitValue = TimeUnitValue_1.default;
1
+ "use strict";
2
+ /*!
3
+ * @author electricessence / https://github.com/electricessence/
4
+ * @license MIT
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.TimeUnitValue = exports.TimeUnit = exports.TimeStamp = exports.TimeSpan = exports.TimeQuantity = exports.howMany = exports.DateTime = exports.ClockTime = void 0;
8
+ const tslib_1 = require("tslib");
9
+ const ClockTime_1 = (0, tslib_1.__importDefault)(require("./ClockTime"));
10
+ exports.ClockTime = ClockTime_1.default;
11
+ const DateTime_1 = (0, tslib_1.__importDefault)(require("./DateTime"));
12
+ exports.DateTime = DateTime_1.default;
13
+ const howMany = (0, tslib_1.__importStar)(require("./howMany"));
14
+ exports.howMany = howMany;
15
+ const TimeQuantity_1 = (0, tslib_1.__importDefault)(require("./TimeQuantity"));
16
+ exports.TimeQuantity = TimeQuantity_1.default;
17
+ const TimeSpan_1 = (0, tslib_1.__importDefault)(require("./TimeSpan"));
18
+ exports.TimeSpan = TimeSpan_1.default;
19
+ const TimeStamp_1 = (0, tslib_1.__importDefault)(require("./TimeStamp"));
20
+ exports.TimeStamp = TimeStamp_1.default;
21
+ const TimeUnit_1 = (0, tslib_1.__importDefault)(require("./TimeUnit"));
22
+ exports.TimeUnit = TimeUnit_1.default;
23
+ const TimeUnitValue_1 = (0, tslib_1.__importDefault)(require("./TimeUnitValue"));
24
+ exports.TimeUnitValue = TimeUnitValue_1.default;
25
25
  //# sourceMappingURL=date-time.js.map
@@ -0,0 +1,59 @@
1
+ /*!
2
+ * @author electricessence / https://github.com/electricessence/
3
+ * @license MIT
4
+ */
5
+
6
+
7
+ export declare namespace hours
8
+ {
9
+ export const enum per
10
+ {
11
+ day = 24
12
+ }
13
+ }
14
+
15
+ export declare namespace minutes
16
+ {
17
+ export const enum per
18
+ {
19
+ hour = 60,
20
+ day = hour*hours.per.day
21
+ }
22
+
23
+ }
24
+
25
+ export declare namespace seconds
26
+ {
27
+ export const enum per
28
+ {
29
+ minute = 60,
30
+ hour = minute*minutes.per.hour,
31
+ day = hour*hours.per.day
32
+ }
33
+
34
+ }
35
+
36
+ export declare namespace milliseconds
37
+ {
38
+ export const enum per
39
+ {
40
+ second = 1000,
41
+ minute = second*seconds.per.minute,
42
+ hour = minute*minutes.per.hour,
43
+ day = hour*hours.per.day
44
+ }
45
+
46
+ }
47
+
48
+ export declare namespace ticks
49
+ {
50
+ export const enum per
51
+ {
52
+ millisecond = 10000,
53
+ second = millisecond*milliseconds.per.second,
54
+ minute = second*seconds.per.minute,
55
+ hour = minute*minutes.per.hour,
56
+ day = hour*hours.per.day
57
+ }
58
+
59
+ }
@@ -1,63 +1,63 @@
1
- /*!
2
- * @author electricessence / https://github.com/electricessence/
3
- * @license MIT
4
- */
5
- import TimeQuantity from './TimeQuantity';
6
- export class ClockTime extends TimeQuantity {
7
- constructor(...args) {
8
- super(args.length > 1
9
- ? ClockTime.millisecondsFromTime(args[0] || 0, args[1] || 0, args.length > 2 && args[2] || 0, args.length > 3 && args[3] || 0)
10
- : (args.length > 0 && args[0] || 0));
11
- const ms = Math.abs(this.getTotalMilliseconds());
12
- let msi = Math.floor(ms);
13
- this.tick = (ms - msi) * 10000 /* millisecond */;
14
- this.day = (msi / 86400000 /* day */) | 0;
15
- msi -= this.day * 86400000 /* day */;
16
- this.hour = (msi / 3600000 /* hour */) | 0;
17
- msi -= this.hour * 3600000 /* hour */;
18
- this.minute = (msi / 60000 /* minute */) | 0;
19
- msi -= this.minute * 60000 /* minute */;
20
- this.second = (msi / 1000 /* second */) | 0;
21
- msi -= this.second * 1000 /* second */;
22
- this.millisecond = msi;
23
- Object.freeze(this);
24
- }
25
- // Static version for relative consistency. Constructor does allow this format.
26
- static from(hours, minutes, seconds = 0, milliseconds = 0) {
27
- return new ClockTime(hours, minutes, seconds, milliseconds);
28
- }
29
- static millisecondsFromTime(hours, minutes, seconds = 0, milliseconds = 0) {
30
- let value = hours;
31
- value *= 60 /* hour */;
32
- value += minutes;
33
- value *= 60 /* minute */;
34
- value += seconds;
35
- value *= 1000 /* second */;
36
- value += milliseconds;
37
- return value;
38
- }
39
- toString( /*format?:string, formatProvider?:IFormatProvider*/) {
40
- /* INSERT CUSTOM FORMATTING CODE HERE */
41
- const _ = this;
42
- const a = [];
43
- if (_.day)
44
- a.push(pluralize(_.day, 'day'));
45
- if (_.hour)
46
- a.push(pluralize(_.hour, 'hour'));
47
- if (_.minute)
48
- a.push(pluralize(_.minute, 'minute'));
49
- if (_.second)
50
- a.push(pluralize(_.second, 'second'));
51
- if (a.length > 1)
52
- a.splice(a.length - 1, 0, 'and');
53
- return a.join(', ').replace(', and, ', ' and ');
54
- }
55
- }
56
- // Temporary until the full TimeSpanFormat is available.
57
- function pluralize(value, label) {
58
- if (Math.abs(value) !== 1)
59
- label += 's';
60
- return label;
61
- }
62
- export default ClockTime;
1
+ /*!
2
+ * @author electricessence / https://github.com/electricessence/
3
+ * @license MIT
4
+ */
5
+ import TimeQuantity from './TimeQuantity';
6
+ export class ClockTime extends TimeQuantity {
7
+ constructor(...args) {
8
+ super(args.length > 1
9
+ ? ClockTime.millisecondsFromTime(args[0] || 0, args[1] || 0, args.length > 2 && args[2] || 0, args.length > 3 && args[3] || 0)
10
+ : (args.length > 0 && args[0] || 0));
11
+ const ms = Math.abs(this.getTotalMilliseconds());
12
+ let msi = Math.floor(ms);
13
+ this.tick = (ms - msi) * 10000 /* millisecond */;
14
+ this.day = (msi / 86400000 /* day */) | 0;
15
+ msi -= this.day * 86400000 /* day */;
16
+ this.hour = (msi / 3600000 /* hour */) | 0;
17
+ msi -= this.hour * 3600000 /* hour */;
18
+ this.minute = (msi / 60000 /* minute */) | 0;
19
+ msi -= this.minute * 60000 /* minute */;
20
+ this.second = (msi / 1000 /* second */) | 0;
21
+ msi -= this.second * 1000 /* second */;
22
+ this.millisecond = msi;
23
+ Object.freeze(this);
24
+ }
25
+ // Static version for relative consistency. Constructor does allow this format.
26
+ static from(hours, minutes, seconds = 0, milliseconds = 0) {
27
+ return new ClockTime(hours, minutes, seconds, milliseconds);
28
+ }
29
+ static millisecondsFromTime(hours, minutes, seconds = 0, milliseconds = 0) {
30
+ let value = hours;
31
+ value *= 60 /* hour */;
32
+ value += minutes;
33
+ value *= 60 /* minute */;
34
+ value += seconds;
35
+ value *= 1000 /* second */;
36
+ value += milliseconds;
37
+ return value;
38
+ }
39
+ toString( /*format?:string, formatProvider?:IFormatProvider*/) {
40
+ /* INSERT CUSTOM FORMATTING CODE HERE */
41
+ const _ = this;
42
+ const a = [];
43
+ if (_.day)
44
+ a.push(pluralize(_.day, 'day'));
45
+ if (_.hour)
46
+ a.push(pluralize(_.hour, 'hour'));
47
+ if (_.minute)
48
+ a.push(pluralize(_.minute, 'minute'));
49
+ if (_.second)
50
+ a.push(pluralize(_.second, 'second'));
51
+ if (a.length > 1)
52
+ a.splice(a.length - 1, 0, 'and');
53
+ return a.join(', ').replace(', and, ', ' and ');
54
+ }
55
+ }
56
+ // Temporary until the full TimeSpanFormat is available.
57
+ function pluralize(value, label) {
58
+ if (Math.abs(value) !== 1)
59
+ label += 's';
60
+ return label;
61
+ }
62
+ export default ClockTime;
63
63
  //# sourceMappingURL=ClockTime.js.map