mybase 1.1.36 → 1.1.38
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/package.json +1 -1
- package/ts/index.ts +2 -0
- package/ts/models/Timespan.d.ts +4 -0
- package/ts/models/Timespan.js +6 -0
- package/ts/models/Timespan.ts +6 -1
- package/ts/models/Unixtime.d.ts +5 -0
- package/ts/models/Unixtime.js +9 -0
- package/ts/models/Unixtime.test.ts +7 -0
- package/ts/models/Unixtime.ts +11 -0
package/package.json
CHANGED
package/ts/index.ts
CHANGED
package/ts/models/Timespan.d.ts
CHANGED
package/ts/models/Timespan.js
CHANGED
|
@@ -47,6 +47,12 @@ class Timespan {
|
|
|
47
47
|
static months(months) {
|
|
48
48
|
return new Timespan(months * 30 * 24 * 60 * 60 * 1000);
|
|
49
49
|
}
|
|
50
|
+
toJSON() {
|
|
51
|
+
return {
|
|
52
|
+
__type: 'Timespan',
|
|
53
|
+
value: this.ms
|
|
54
|
+
};
|
|
55
|
+
}
|
|
50
56
|
}
|
|
51
57
|
exports.Timespan = Timespan;
|
|
52
58
|
//# sourceMappingURL=Timespan.js.map
|
package/ts/models/Timespan.ts
CHANGED
package/ts/models/Unixtime.d.ts
CHANGED
|
@@ -8,6 +8,10 @@ export declare class Unixtime {
|
|
|
8
8
|
isEmpty(): boolean;
|
|
9
9
|
lessThan(other: Unixtime): boolean;
|
|
10
10
|
get elapsed(): Timespan;
|
|
11
|
+
toJSON(): {
|
|
12
|
+
__type: string;
|
|
13
|
+
value: number;
|
|
14
|
+
};
|
|
11
15
|
constructor(value: Date | string | number);
|
|
12
16
|
addTimespan(timespan: Timespan): Unixtime;
|
|
13
17
|
subtractTimespan(timespan: Timespan): Unixtime;
|
|
@@ -28,5 +32,6 @@ export declare class Unixtime {
|
|
|
28
32
|
toISOString(): string;
|
|
29
33
|
elapsedSeconds(): number;
|
|
30
34
|
elapsedMinutes(): number;
|
|
35
|
+
clone(): Unixtime;
|
|
31
36
|
static try(value: Date | string | number): Unixtime | null;
|
|
32
37
|
}
|
package/ts/models/Unixtime.js
CHANGED
|
@@ -22,6 +22,12 @@ class Unixtime {
|
|
|
22
22
|
get elapsed() {
|
|
23
23
|
return new Timespan_1.Timespan(Date.now() - this.toLongUnixtime());
|
|
24
24
|
}
|
|
25
|
+
toJSON() {
|
|
26
|
+
return {
|
|
27
|
+
__type: 'Unixtime',
|
|
28
|
+
value: this.toLongUnixtime()
|
|
29
|
+
};
|
|
30
|
+
}
|
|
25
31
|
constructor(value) {
|
|
26
32
|
if (typeof value === 'string') {
|
|
27
33
|
this.value = new Date(value);
|
|
@@ -123,6 +129,9 @@ class Unixtime {
|
|
|
123
129
|
elapsedMinutes() {
|
|
124
130
|
return Math.round(this.elapsedSeconds() / 60);
|
|
125
131
|
}
|
|
132
|
+
clone() {
|
|
133
|
+
return new Unixtime(this.toLongUnixtime());
|
|
134
|
+
}
|
|
126
135
|
static try(value) {
|
|
127
136
|
try {
|
|
128
137
|
return new Unixtime(value);
|
|
@@ -99,4 +99,11 @@ describe('Unixtime', () => {
|
|
|
99
99
|
const addedUnixtime = unixtime.addYears(1);
|
|
100
100
|
expect(addedUnixtime.toDate()).toEqual(new Date(date.setFullYear(date.getFullYear() + 1)));
|
|
101
101
|
});
|
|
102
|
+
|
|
103
|
+
it('clone should create brand new object', () => {
|
|
104
|
+
const unixtime0 = new Unixtime(new Date())
|
|
105
|
+
const unixtime1 = unixtime0.clone();
|
|
106
|
+
expect(unixtime1).not.toBe(unixtime0);
|
|
107
|
+
expect(unixtime0.toDate()).toEqual(unixtime1.toDate());
|
|
108
|
+
});
|
|
102
109
|
});
|
package/ts/models/Unixtime.ts
CHANGED
|
@@ -31,6 +31,13 @@ export class Unixtime {
|
|
|
31
31
|
return new Timespan(Date.now() - this.toLongUnixtime())
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
toJSON() {
|
|
35
|
+
return {
|
|
36
|
+
__type:'Unixtime',
|
|
37
|
+
value:this.toLongUnixtime()
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
34
41
|
|
|
35
42
|
constructor(value: Date | string | number) {
|
|
36
43
|
if (typeof value === 'string') {
|
|
@@ -153,6 +160,10 @@ export class Unixtime {
|
|
|
153
160
|
return Math.round(this.elapsedSeconds() / 60)
|
|
154
161
|
}
|
|
155
162
|
|
|
163
|
+
clone():Unixtime {
|
|
164
|
+
return new Unixtime(this.toLongUnixtime())
|
|
165
|
+
}
|
|
166
|
+
|
|
156
167
|
|
|
157
168
|
static try(value: Date | string | number): Unixtime | null {
|
|
158
169
|
try {
|