@thisisagile/easy 8.13.1 → 8.14.0
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,11 +1,15 @@
|
|
|
1
1
|
import { Value } from '../../types';
|
|
2
2
|
import { Moment } from 'moment';
|
|
3
|
+
import 'moment/min/locales';
|
|
3
4
|
export declare type DateTimeUnit = 'year' | 'years' | 'y' | 'quarter' | 'quarters' | 'Q' | 'month' | 'months' | 'M' | 'week' | 'weeks' | 'w' | 'day' | 'days' | 'd' | 'hour' | 'hours' | 'h' | 'minute' | 'minutes' | 'm' | 'second' | 'seconds' | 's' | 'millisecond' | 'milliseconds' | 'ms';
|
|
4
5
|
export declare class DateTime extends Value<string | undefined> {
|
|
5
6
|
constructor(value?: string | number | Date, format?: string);
|
|
6
7
|
static get now(): DateTime;
|
|
7
8
|
get isValid(): boolean;
|
|
8
9
|
get fromNow(): string;
|
|
10
|
+
from(date?: DateTime): string;
|
|
11
|
+
from(locales?: string | string[]): string;
|
|
12
|
+
from(date?: DateTime, locales?: string | string[]): string;
|
|
9
13
|
protected get utc(): Moment;
|
|
10
14
|
isAfter(dt: DateTime): boolean;
|
|
11
15
|
isBefore(dt: DateTime): boolean;
|
|
@@ -7,6 +7,7 @@ exports.DateTime = void 0;
|
|
|
7
7
|
const types_1 = require("../../types");
|
|
8
8
|
const moment_1 = __importDefault(require("moment"));
|
|
9
9
|
const utils_1 = require("../../utils");
|
|
10
|
+
require("moment/min/locales");
|
|
10
11
|
class DateTime extends types_1.Value {
|
|
11
12
|
constructor(value, format) {
|
|
12
13
|
super((0, types_1.tryTo)(value).is.defined().map(v => moment_1.default.utc(v, format, true).toISOString()).orElse());
|
|
@@ -25,7 +26,12 @@ class DateTime extends types_1.Value {
|
|
|
25
26
|
return (0, types_1.isDefined)(this.value) && this.utc.isValid();
|
|
26
27
|
}
|
|
27
28
|
get fromNow() {
|
|
28
|
-
return this.
|
|
29
|
+
return this.from();
|
|
30
|
+
}
|
|
31
|
+
from(param, other) {
|
|
32
|
+
const date = (0, types_1.isA)(param) ? param : undefined;
|
|
33
|
+
const locales = (0, types_1.isString)(param) || (0, types_1.isArray)(param) ? param : ((0, types_1.isString)(other) || (0, types_1.isArray)(other) ? other : 'en');
|
|
34
|
+
return (0, types_1.isDefined)(date) ? this.utc.locale(locales).from(date.utc) : this.utc.locale(locales).fromNow();
|
|
29
35
|
}
|
|
30
36
|
get utc() {
|
|
31
37
|
return moment_1.default.utc(this.value);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DateTime.js","sourceRoot":"","sources":["../../../src/domain/values/DateTime.ts"],"names":[],"mappings":";;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"DateTime.js","sourceRoot":"","sources":["../../../src/domain/values/DateTime.ts"],"names":[],"mappings":";;;;;;AAAA,uCAA8E;AAC9E,oDAAwC;AACxC,uCAAyC;AACzC,8BAA4B;AAc5B,MAAa,QAAS,SAAQ,aAAyB;IACrD,YAAY,KAA8B,EAAE,MAAe;QACzD,KAAK,CAAC,IAAA,aAAK,EAAC,KAAK,CAAC,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,gBAAM,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;QA2ChG,QAAG,GAAG,CAAC,CAAS,EAAE,OAAqB,MAAM,EAAY,EAAE,CAAC,IAAI,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;QAE9G,aAAQ,GAAG,CAAC,CAAS,EAAE,OAAqB,MAAM,EAAY,EAAE,CAAC,IAAI,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,WAAW,EAAE,C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CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;IACtD,CAAC;CACF;AAlED,4BAkEC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thisisagile/easy",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.14.0",
|
|
4
4
|
"description": "Straightforward library for building domain-driven microservice architectures",
|
|
5
5
|
"author": "Sander Hoogendoorn",
|
|
6
6
|
"license": "MIT",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"access": "public"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@thisisagile/easy-test": "8.
|
|
34
|
+
"@thisisagile/easy-test": "8.14.0",
|
|
35
35
|
"@types/form-urlencoded": "^4.4.0",
|
|
36
36
|
"@types/jsonwebtoken": "^8.5.6",
|
|
37
37
|
"@types/validator": "^13.7.0"
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { isDefined, tryTo, Value } from '../../types';
|
|
1
|
+
import { isA, isArray, isDefined, isString, tryTo, Value } from '../../types';
|
|
2
2
|
import moment, { Moment } from 'moment';
|
|
3
3
|
import { ifNotEmpty } from '../../utils';
|
|
4
|
+
import 'moment/min/locales';
|
|
4
5
|
|
|
5
6
|
export type DateTimeUnit =
|
|
6
7
|
'year' | 'years' | 'y' |
|
|
@@ -27,8 +28,20 @@ export class DateTime extends Value<string | undefined> {
|
|
|
27
28
|
return isDefined(this.value) && this.utc.isValid();
|
|
28
29
|
}
|
|
29
30
|
|
|
31
|
+
/**
|
|
32
|
+
* @deprecated Deprecated in favor for DateTime.from as that also accepts locales and another DateTime
|
|
33
|
+
*/
|
|
30
34
|
get fromNow(): string {
|
|
31
|
-
return this.
|
|
35
|
+
return this.from();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
from(date?: DateTime): string;
|
|
39
|
+
from(locales?: string | string[]): string;
|
|
40
|
+
from(date?: DateTime, locales?: string | string[]): string;
|
|
41
|
+
from(param?: string | string[] | DateTime, other?: string | string[]): string {
|
|
42
|
+
const date: DateTime | undefined = isA<DateTime>(param) ? param : undefined;
|
|
43
|
+
const locales: string | string[] = isString(param) || isArray<string>(param) ? param : (isString(other) || isArray<string>(other) ? other : 'en');
|
|
44
|
+
return isDefined(date) ? this.utc.locale(locales).from(date.utc) : this.utc.locale(locales).fromNow();
|
|
32
45
|
}
|
|
33
46
|
|
|
34
47
|
protected get utc(): Moment {
|