@acorex/core 5.8.0 → 6.0.1
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/.browserslistrc +16 -0
- package/README.md +24 -24
- package/config/ax-preset.js +8 -26
- package/config/index.ts +1 -0
- package/config/ng-package.json +6 -0
- package/config/public-api.ts +1 -0
- package/config/src/configs.ts +37 -0
- package/dateTime/index.ts +1 -0
- package/dateTime/ng-package.json +6 -0
- package/dateTime/public-api.ts +5 -0
- package/dateTime/src/datetime.class.ts +452 -0
- package/dateTime/src/datetime.module.ts +29 -0
- package/dateTime/src/datetime.pipe.ts +21 -0
- package/dateTime/src/georgian.calendar.ts +205 -0
- package/dateTime/src/jalali.calendar.ts +416 -0
- package/events/index.ts +1 -0
- package/events/ng-package.json +6 -0
- package/events/public-api.ts +1 -0
- package/events/src/event.service.ts +31 -0
- package/http/index.ts +1 -0
- package/http/ng-package.json +6 -0
- package/http/public-api.ts +5 -0
- package/http/src/http-error.class.ts +7 -0
- package/http/src/http-events.interceptor.ts +14 -0
- package/http/src/http-request.class.ts +14 -0
- package/http/src/http-result.class.ts +34 -0
- package/http/src/http.module.ts +25 -0
- package/http/src/http.service.ts +161 -0
- package/index.ts +1 -0
- package/karma.conf.js +44 -0
- package/ng-package.json +7 -0
- package/package.json +23 -40
- package/pipes/index.ts +1 -0
- package/pipes/ng-package.json +6 -0
- package/pipes/public-api.ts +2 -0
- package/pipes/src/pipes.module.ts +11 -0
- package/pipes/src/safe.pipe.ts +24 -0
- package/platform/index.ts +1 -0
- package/platform/ng-package.json +6 -0
- package/platform/public-api.ts +1 -0
- package/platform/src/platform.service.ts +207 -0
- package/public-api.ts +4 -0
- package/test.ts +27 -0
- package/translation/index.ts +1 -0
- package/translation/ng-package.json +6 -0
- package/translation/public-api.ts +3 -0
- package/translation/src/translation.module.ts +12 -0
- package/translation/src/translator.pipe.ts +9 -0
- package/translation/src/translator.ts +49 -0
- package/tsconfig.lib.json +15 -0
- package/tsconfig.lib.prod.json +10 -0
- package/tsconfig.spec.json +17 -0
- package/utils/index.ts +1 -0
- package/utils/ng-package.json +6 -0
- package/utils/public-api.ts +4 -0
- package/utils/src/color-util.ts +83 -0
- package/utils/src/drawing-util.ts +43 -0
- package/utils/src/object-util.ts +82 -0
- package/utils/src/string-util.ts +25 -0
- package/esm2020/acorex-core.mjs +0 -5
- package/esm2020/lib/config/configs.mjs +0 -29
- package/esm2020/lib/core.module.mjs +0 -18
- package/esm2020/lib/dateTime/datetime.class.mjs +0 -295
- package/esm2020/lib/dateTime/datetime.module.mjs +0 -33
- package/esm2020/lib/dateTime/datetime.pipe.mjs +0 -26
- package/esm2020/lib/dateTime/georgian.calendar.mjs +0 -189
- package/esm2020/lib/dateTime/index.mjs +0 -6
- package/esm2020/lib/dateTime/jalali.calendar.mjs +0 -359
- package/esm2020/lib/events/event.service.mjs +0 -36
- package/esm2020/lib/events/index.mjs +0 -2
- package/esm2020/lib/hotkeys/hotkeys.service.mjs +0 -38
- package/esm2020/lib/hotkeys/index.mjs +0 -2
- package/esm2020/lib/platform/index.mjs +0 -2
- package/esm2020/lib/platform/platform.service.mjs +0 -138
- package/esm2020/lib/translation/index.mjs +0 -4
- package/esm2020/lib/translation/translation.module.mjs +0 -18
- package/esm2020/lib/translation/translator.mjs +0 -43
- package/esm2020/lib/translation/translator.pipe.mjs +0 -15
- package/esm2020/lib/utils/color-util.mjs +0 -71
- package/esm2020/lib/utils/drawing-util.mjs +0 -27
- package/esm2020/lib/utils/index.mjs +0 -6
- package/esm2020/lib/utils/object-util.mjs +0 -39
- package/esm2020/lib/utils/safe.pipe.mjs +0 -30
- package/esm2020/lib/utils/string-util.mjs +0 -19
- package/esm2020/public-api.mjs +0 -13
- package/fesm2015/acorex-core.mjs +0 -1405
- package/fesm2015/acorex-core.mjs.map +0 -1
- package/fesm2020/acorex-core.mjs +0 -1402
- package/fesm2020/acorex-core.mjs.map +0 -1
- package/index.d.ts +0 -5
- package/lib/config/configs.d.ts +0 -9
- package/lib/core.module.d.ts +0 -7
- package/lib/dateTime/datetime.class.d.ts +0 -100
- package/lib/dateTime/datetime.module.d.ts +0 -8
- package/lib/dateTime/datetime.pipe.d.ts +0 -8
- package/lib/dateTime/georgian.calendar.d.ts +0 -20
- package/lib/dateTime/index.d.ts +0 -5
- package/lib/dateTime/jalali.calendar.d.ts +0 -35
- package/lib/events/event.service.d.ts +0 -9
- package/lib/events/index.d.ts +0 -1
- package/lib/hotkeys/hotkeys.service.d.ts +0 -17
- package/lib/hotkeys/index.d.ts +0 -1
- package/lib/platform/index.d.ts +0 -1
- package/lib/platform/platform.service.d.ts +0 -25
- package/lib/translation/index.d.ts +0 -3
- package/lib/translation/translation.module.d.ts +0 -7
- package/lib/translation/translator.d.ts +0 -11
- package/lib/translation/translator.pipe.d.ts +0 -7
- package/lib/utils/color-util.d.ts +0 -20
- package/lib/utils/drawing-util.d.ts +0 -17
- package/lib/utils/index.d.ts +0 -5
- package/lib/utils/object-util.d.ts +0 -4
- package/lib/utils/safe.pipe.d.ts +0 -10
- package/lib/utils/string-util.d.ts +0 -6
- package/public-api.d.ts +0 -12
package/.browserslistrc
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# This file is used by the build system to adjust CSS and JS output to support the specified browsers below.
|
|
2
|
+
# For additional information regarding the format and rule options, please see:
|
|
3
|
+
# https://github.com/browserslist/browserslist#queries
|
|
4
|
+
|
|
5
|
+
# For the full list of supported browsers by the Angular framework, please see:
|
|
6
|
+
# https://angular.io/guide/browser-support
|
|
7
|
+
|
|
8
|
+
# You can see what browsers were selected by your queries by running:
|
|
9
|
+
# npx browserslist
|
|
10
|
+
|
|
11
|
+
last 1 Chrome version
|
|
12
|
+
last 1 Firefox version
|
|
13
|
+
last 2 Edge major versions
|
|
14
|
+
last 2 Safari major versions
|
|
15
|
+
last 2 iOS major versions
|
|
16
|
+
Firefox ESR
|
package/README.md
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
# Core
|
|
2
|
-
|
|
3
|
-
This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version
|
|
4
|
-
|
|
5
|
-
## Code scaffolding
|
|
6
|
-
|
|
7
|
-
Run `ng generate component component-name --project core` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module --project core`.
|
|
8
|
-
> Note: Don't forget to add `--project core` or else it will be added to the default project in your `angular.json` file.
|
|
9
|
-
|
|
10
|
-
## Build
|
|
11
|
-
|
|
12
|
-
Run `ng build core` to build the project. The build artifacts will be stored in the `dist/` directory.
|
|
13
|
-
|
|
14
|
-
## Publishing
|
|
15
|
-
|
|
16
|
-
After building your library with `ng build core`, go to the dist folder `cd dist/core` and run `npm publish`.
|
|
17
|
-
|
|
18
|
-
## Running unit tests
|
|
19
|
-
|
|
20
|
-
Run `ng test core` to execute the unit tests via [Karma](https://karma-runner.github.io).
|
|
21
|
-
|
|
22
|
-
## Further help
|
|
23
|
-
|
|
24
|
-
To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page.
|
|
1
|
+
# Core
|
|
2
|
+
|
|
3
|
+
This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 14.0.0.
|
|
4
|
+
|
|
5
|
+
## Code scaffolding
|
|
6
|
+
|
|
7
|
+
Run `ng generate component component-name --project core` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module --project core`.
|
|
8
|
+
> Note: Don't forget to add `--project core` or else it will be added to the default project in your `angular.json` file.
|
|
9
|
+
|
|
10
|
+
## Build
|
|
11
|
+
|
|
12
|
+
Run `ng build core` to build the project. The build artifacts will be stored in the `dist/` directory.
|
|
13
|
+
|
|
14
|
+
## Publishing
|
|
15
|
+
|
|
16
|
+
After building your library with `ng build core`, go to the dist folder `cd dist/core` and run `npm publish`.
|
|
17
|
+
|
|
18
|
+
## Running unit tests
|
|
19
|
+
|
|
20
|
+
Run `ng test core` to execute the unit tests via [Karma](https://karma-runner.github.io).
|
|
21
|
+
|
|
22
|
+
## Further help
|
|
23
|
+
|
|
24
|
+
To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page.
|
package/config/ax-preset.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const plugin = require('tailwindcss/plugin');
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
function withOpacityValue(variable) {
|
|
4
4
|
return ({ opacityValue }) => {
|
|
5
5
|
if (opacityValue === undefined) {
|
|
@@ -9,7 +9,7 @@ function withOpacityValue(variable) {
|
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
module.exports =
|
|
12
|
+
module.exports = {
|
|
13
13
|
prefix: 'ax-',
|
|
14
14
|
darkMode: 'class',
|
|
15
15
|
mode: "jit",
|
|
@@ -17,7 +17,7 @@ module.exports = withAnimations({
|
|
|
17
17
|
"./src/**/*.{html,ts,scss}",
|
|
18
18
|
"./projects/**/*.{html,ts,scss}",
|
|
19
19
|
"./dist/acorex/**/*.{html,ts,scss}",
|
|
20
|
-
"./node_modules/@acorex/**/*.{html,ts,
|
|
20
|
+
"./node_modules/@acorex/**/*.{html,ts,scss}",
|
|
21
21
|
],
|
|
22
22
|
darkMode: "class", // or 'media' or 'class'
|
|
23
23
|
theme: {
|
|
@@ -133,24 +133,8 @@ module.exports = withAnimations({
|
|
|
133
133
|
},
|
|
134
134
|
|
|
135
135
|
},
|
|
136
|
-
width: {
|
|
137
|
-
'base': 'calc((var(--ax-base-size) * var(--ax-base-ratio)))'
|
|
138
|
-
},
|
|
139
|
-
minWidth: {
|
|
140
|
-
'base': 'calc((var(--ax-base-size) * var(--ax-base-ratio)))'
|
|
141
|
-
},
|
|
142
136
|
maxWidth: {
|
|
143
137
|
'8xl': '90rem',
|
|
144
|
-
'base': 'calc((var(--ax-base-size) * var(--ax-base-ratio)))'
|
|
145
|
-
},
|
|
146
|
-
height: {
|
|
147
|
-
'base': 'calc((var(--ax-base-size) * var(--ax-base-ratio)))'
|
|
148
|
-
},
|
|
149
|
-
minHeight: {
|
|
150
|
-
'base': 'calc((var(--ax-base-size) * var(--ax-base-ratio)))'
|
|
151
|
-
},
|
|
152
|
-
maxHeight: {
|
|
153
|
-
'base': 'calc((var(--ax-base-size) * var(--ax-base-ratio)))'
|
|
154
138
|
},
|
|
155
139
|
keyframes: {
|
|
156
140
|
fadeIn: {
|
|
@@ -185,12 +169,6 @@ module.exports = withAnimations({
|
|
|
185
169
|
},
|
|
186
170
|
'.text-default': {
|
|
187
171
|
backgroundColor: 'rgb(var(--ax-color-default-color) / var(--tw-text-opacity))'
|
|
188
|
-
},
|
|
189
|
-
'.rtl': {
|
|
190
|
-
direction: 'rtl'
|
|
191
|
-
},
|
|
192
|
-
'.ltr': {
|
|
193
|
-
direction: 'ltr'
|
|
194
172
|
}
|
|
195
173
|
}
|
|
196
174
|
addUtilities(acorexClasses, ['responsive', 'hover', 'focus'])
|
|
@@ -200,5 +178,9 @@ module.exports = withAnimations({
|
|
|
200
178
|
require('tailwindcss'),
|
|
201
179
|
require('autoprefixer'),
|
|
202
180
|
require('tailwind-rtl-utilities')
|
|
181
|
+
// require('@tailwindcss/aspect-ratio'),
|
|
182
|
+
// require('@tailwindcss/forms'),
|
|
183
|
+
// require('@tailwindcss/line-clamp'),
|
|
184
|
+
// require('@tailwindcss/typography')
|
|
203
185
|
],
|
|
204
|
-
}
|
|
186
|
+
};
|
package/config/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './public-api';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './src/configs';
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { get, set, merge } from 'lodash-es';
|
|
2
|
+
import { Subject, Observable } from 'rxjs';
|
|
3
|
+
|
|
4
|
+
// @dynamic
|
|
5
|
+
export class AXConfig {
|
|
6
|
+
private static dataModel: any = {};
|
|
7
|
+
private static dataChangeSubject = new Subject<any>();
|
|
8
|
+
|
|
9
|
+
static get onChange(): Observable<any> {
|
|
10
|
+
return AXConfig.dataChangeSubject.asObservable();
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
static set(config: any): any;
|
|
14
|
+
static set(path: string, value?: any): void;
|
|
15
|
+
static set(arg1?: any, arg2?: any) {
|
|
16
|
+
if (arg1 && typeof arg1 == 'string') {
|
|
17
|
+
set(AXConfig.dataModel, arg1, arg2);
|
|
18
|
+
AXConfig.dataChangeSubject.next(AXConfig.dataModel);
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
if (arg1 && typeof arg1 == 'object') {
|
|
22
|
+
merge(AXConfig.dataModel, arg1);
|
|
23
|
+
AXConfig.dataChangeSubject.next(AXConfig.dataModel);
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
if (!arg1 && !arg2) {
|
|
27
|
+
return AXConfig.dataChangeSubject.asObservable();
|
|
28
|
+
}
|
|
29
|
+
// TODO: Arash please check 'Not all code paths return a value.'.
|
|
30
|
+
// if remove return you can see error on line 15.
|
|
31
|
+
return '';
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
static get(path: string, defaultValue?: any): any {
|
|
35
|
+
return get(AXConfig.dataModel, path, defaultValue);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './public-api';
|
|
@@ -0,0 +1,452 @@
|
|
|
1
|
+
import * as _ from 'lodash';
|
|
2
|
+
import { AXConfig } from '@acorex/core/config';
|
|
3
|
+
|
|
4
|
+
export type TimeUnit =
|
|
5
|
+
| 'ms'
|
|
6
|
+
| 'second'
|
|
7
|
+
| 'minute'
|
|
8
|
+
| 'hour'
|
|
9
|
+
| 'day'
|
|
10
|
+
| 'month'
|
|
11
|
+
| 'year'
|
|
12
|
+
| 'week';
|
|
13
|
+
|
|
14
|
+
export interface AXDateValue {
|
|
15
|
+
year: number,
|
|
16
|
+
month: number,
|
|
17
|
+
date: number,
|
|
18
|
+
hours?: number,
|
|
19
|
+
minutes?: number,
|
|
20
|
+
seconds?: number,
|
|
21
|
+
ms?: number
|
|
22
|
+
calendar: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
export interface AXCalendar {
|
|
27
|
+
monthNames: string[];
|
|
28
|
+
|
|
29
|
+
monthShortNames: string[];
|
|
30
|
+
|
|
31
|
+
dayNames: string[];
|
|
32
|
+
|
|
33
|
+
dayShortNames: string[];
|
|
34
|
+
|
|
35
|
+
name(): string;
|
|
36
|
+
|
|
37
|
+
dayOfMonth(date: Date): number;
|
|
38
|
+
|
|
39
|
+
dayOfYear(date: Date): number;
|
|
40
|
+
|
|
41
|
+
dayOfWeek(date: Date): number;
|
|
42
|
+
|
|
43
|
+
monthOfYear(date: Date): number;
|
|
44
|
+
|
|
45
|
+
weekOfYear(date: Date): number;
|
|
46
|
+
|
|
47
|
+
year(date: Date): number;
|
|
48
|
+
|
|
49
|
+
add(date: Date, unit: TimeUnit, amount: number): AXDateTime;
|
|
50
|
+
|
|
51
|
+
set(date: Date, unit: TimeUnit, value: number): AXDateTime;
|
|
52
|
+
|
|
53
|
+
startOf(date: Date, unit: TimeUnit): AXDateTime;
|
|
54
|
+
|
|
55
|
+
endOf(date: Date, unit: TimeUnit): AXDateTime;
|
|
56
|
+
|
|
57
|
+
create(value: AXDateValue): AXDateTime;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
// @dynamic
|
|
64
|
+
export class AXDateTime {
|
|
65
|
+
static convert(
|
|
66
|
+
value: Date | AXDateTime | string,
|
|
67
|
+
calendar: string = AXConfig.get('dateTime.calendar')
|
|
68
|
+
): AXDateTime {
|
|
69
|
+
let date: AXDateTime;
|
|
70
|
+
if (typeof value === 'string' || value instanceof String) {
|
|
71
|
+
date = new AXDateTime(value as string, calendar);
|
|
72
|
+
} else if (value instanceof Date) {
|
|
73
|
+
date = new AXDateTime(value as Date, calendar);
|
|
74
|
+
} else if (value instanceof AXDateTime) {
|
|
75
|
+
date = new AXDateTime(value.date, calendar);
|
|
76
|
+
}
|
|
77
|
+
return date!;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
static from(value: AXDateValue = {
|
|
81
|
+
calendar: AXConfig.get('dateTime.calendar'),
|
|
82
|
+
year: 1,
|
|
83
|
+
month: 1,
|
|
84
|
+
date: 1,
|
|
85
|
+
hours: 0,
|
|
86
|
+
minutes: 0,
|
|
87
|
+
seconds: 0,
|
|
88
|
+
ms: 0
|
|
89
|
+
}): AXDateTime {
|
|
90
|
+
// let date: AXDateTime = new AXDateTime(new Date(), value.calendar);
|
|
91
|
+
// date.set('year', value.year);
|
|
92
|
+
// date.set('month', value.month);
|
|
93
|
+
// date.set('day', value.date);
|
|
94
|
+
// date.set('hour', value.hours);
|
|
95
|
+
// date.set('minute', value.minutes);
|
|
96
|
+
// date.set('second', value.seconds);
|
|
97
|
+
// date.set('ms', value.ms);
|
|
98
|
+
|
|
99
|
+
return AXDateTime.resolveCalendar(value.calendar).create(value);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
static resolveCalendar(calendar: string | AXCalendar): AXCalendar {
|
|
104
|
+
return typeof calendar == 'string'
|
|
105
|
+
? AXConfig.get(`dateTime.calendars.${calendar}`)
|
|
106
|
+
: calendar;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
private _date: Date;
|
|
111
|
+
|
|
112
|
+
get date(): Date {
|
|
113
|
+
return this._date;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
private _calendar: AXCalendar;
|
|
117
|
+
get calendar(): AXCalendar {
|
|
118
|
+
return this._calendar;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
constructor(
|
|
124
|
+
value: Date | string = new Date(),
|
|
125
|
+
calendar: string | AXCalendar = AXConfig.get(`dateTime.calendar`)
|
|
126
|
+
) {
|
|
127
|
+
this._calendar = AXDateTime.resolveCalendar(calendar);
|
|
128
|
+
if (value instanceof Date) {
|
|
129
|
+
this._date = value as Date;
|
|
130
|
+
} else {
|
|
131
|
+
//TODO: parse jalali
|
|
132
|
+
this._date = new Date(value);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
clone(): AXDateTime {
|
|
137
|
+
return new AXDateTime(this.date, this.calendar);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
get dayOfMonth(): number {
|
|
141
|
+
return this._calendar.dayOfMonth(this.date);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
get dayOfYear(): number {
|
|
145
|
+
return this._calendar.dayOfYear(this.date);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
get dayOfWeek(): number {
|
|
149
|
+
return this._calendar.dayOfWeek(this.date);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
get hour(): number {
|
|
153
|
+
return this._date.getHours();
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
get minute(): number {
|
|
157
|
+
return this._date.getMinutes();
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
get second(): number {
|
|
161
|
+
return this._date.getSeconds();
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
get year(): number {
|
|
165
|
+
return this._calendar.year(this.date);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
get monthOfYear(): number {
|
|
169
|
+
return this._calendar.monthOfYear(this.date);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
get weekOfYear(): number {
|
|
173
|
+
return this._calendar.weekOfYear(this.date);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
get month(): AXCalendarMonth {
|
|
177
|
+
return new AXCalendarMonth(this);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
add(unit: TimeUnit, amount: number): AXDateTime {
|
|
181
|
+
return this._calendar.add(this.date, unit, amount);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
set(unit: TimeUnit = 'day', value: number): AXDateTime {
|
|
185
|
+
return this._calendar.set(this.date, unit, value);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
duration(
|
|
189
|
+
end: Date | AXDateTime,
|
|
190
|
+
unit: TimeUnit = 'day'
|
|
191
|
+
): AXTimeSpan {
|
|
192
|
+
const range = new AXDateTimeRange(
|
|
193
|
+
this,
|
|
194
|
+
AXDateTime.convert(end, this.calendar.name())
|
|
195
|
+
);
|
|
196
|
+
return range.duration();
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
startOf(unit: TimeUnit = 'day'): AXDateTime {
|
|
200
|
+
return this._calendar.startOf(this.date, unit);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
endOf(unit: TimeUnit = 'day'): AXDateTime {
|
|
204
|
+
return this._calendar.endOf(this.date, unit);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
private _formatKeys = {
|
|
208
|
+
ss: () => this.pad(this.date.getSeconds(), 2),
|
|
209
|
+
s: () => this.date.getSeconds().toString(),
|
|
210
|
+
//
|
|
211
|
+
dd: () => this.pad(this.calendar.dayOfMonth(this.date), 2),
|
|
212
|
+
d: () => this.calendar.dayOfMonth(this.date).toString(),
|
|
213
|
+
//
|
|
214
|
+
mm: () => this.pad(this.date.getMinutes(), 2),
|
|
215
|
+
m: () => this.date.getMinutes().toString(),
|
|
216
|
+
//
|
|
217
|
+
MMMM: () => this.calendar.monthNames[this.calendar.monthOfYear(this.date) - 1],
|
|
218
|
+
MMM: () => this.calendar.monthShortNames[this.calendar.monthOfYear(this.date) - 1],
|
|
219
|
+
MM: () => this.pad(this.calendar.monthOfYear(this.date), 2),
|
|
220
|
+
//
|
|
221
|
+
DDDD: () => this.calendar.dayNames[this.calendar.dayOfWeek(this.date) - 1],
|
|
222
|
+
DDD: () => this.calendar.dayShortNames[this.calendar.dayOfWeek(this.date) - 1],
|
|
223
|
+
//
|
|
224
|
+
yyyy: () => this.calendar.year(this.date).toString(),
|
|
225
|
+
YYYY: () => this.calendar.year(this.date).toString(),
|
|
226
|
+
yy: () => this.calendar.year(this.date).toString().substring(2),
|
|
227
|
+
YY: () => this.calendar.year(this.date).toString().substring(2),
|
|
228
|
+
//
|
|
229
|
+
HH: () => this.pad(this.date.getHours(), 2),
|
|
230
|
+
H: () => this.date.getHours().toString(),
|
|
231
|
+
//
|
|
232
|
+
hh: () => this.pad((this.date.getHours() % 12 || 12), 2),
|
|
233
|
+
h: () => (this.date.getHours() % 12 || 12).toString(),
|
|
234
|
+
//
|
|
235
|
+
A: () => (this.date.getHours() < 12) ? 'am' : 'pm',
|
|
236
|
+
a: () => (this.date.getHours() < 12) ? 'am' : 'pm',
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
format(
|
|
240
|
+
format: string = AXConfig.get('dateTime.shortDateFormat')
|
|
241
|
+
): string {
|
|
242
|
+
const re = new RegExp(_.orderBy(Object.keys(this._formatKeys), c => c.length, ['desc']).join("|"), "gi");
|
|
243
|
+
return format.replace(re, (matched) => {
|
|
244
|
+
return this._formatKeys[matched]();
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
private pad(n, width, z = '0') {
|
|
249
|
+
n = n + '';
|
|
250
|
+
return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
toString(format: string = AXConfig.get('dateTime.shortDateFormat')): string {
|
|
254
|
+
return this.format(format);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
equal(value: Date | AXDateTime, unit: TimeUnit = 'day') {
|
|
258
|
+
return this.compare(value, unit) == 0;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
compare(value: Date | AXDateTime, unit: TimeUnit = 'day') {
|
|
262
|
+
const val = AXDateTime.convert(value, this.calendar.name());
|
|
263
|
+
const func = (v1: number, v2: number) => {
|
|
264
|
+
if (v1 == v2) {
|
|
265
|
+
return 0;
|
|
266
|
+
} else if (v1 > v2) {
|
|
267
|
+
return 1;
|
|
268
|
+
} else {
|
|
269
|
+
return -1;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
let p = 0;
|
|
273
|
+
switch (unit) {
|
|
274
|
+
case 'year':
|
|
275
|
+
return func(this.year, val.year);
|
|
276
|
+
case 'week':
|
|
277
|
+
p = this.compare(val, 'year');
|
|
278
|
+
return p == 0 ? func(this.weekOfYear, val.weekOfYear) : p;
|
|
279
|
+
case 'month':
|
|
280
|
+
p = this.compare(val, 'year');
|
|
281
|
+
return p == 0 ? func(this.monthOfYear, val.monthOfYear) : p;
|
|
282
|
+
case 'day':
|
|
283
|
+
p = this.compare(val, 'year');
|
|
284
|
+
return p == 0 ? func(this.dayOfYear, val.dayOfYear) : p;
|
|
285
|
+
case 'hour':
|
|
286
|
+
p = this.compare(val, 'day');
|
|
287
|
+
return p == 0 ? func(this.hour, val.hour) : p;
|
|
288
|
+
case 'minute':
|
|
289
|
+
p = this.compare(val, 'hour');
|
|
290
|
+
return p == 0 ? func(this.minute, val.minute) : p;
|
|
291
|
+
case 'second':
|
|
292
|
+
p = this.compare(val, 'minute');
|
|
293
|
+
return p == 0 ? func(this.second, val.second) : p;
|
|
294
|
+
default:
|
|
295
|
+
return func(this.date.getTime(), val.date.getTime());
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
convert(calendar: string) {
|
|
301
|
+
return AXDateTime.convert(this, calendar);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
export class AXCalendarMonth {
|
|
306
|
+
private _range: AXDateTimeRange;
|
|
307
|
+
public get range(): AXDateTimeRange {
|
|
308
|
+
return this._range;
|
|
309
|
+
}
|
|
310
|
+
public set range(v: AXDateTimeRange) {
|
|
311
|
+
this._range = v;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
constructor(date: AXDateTime) {
|
|
315
|
+
this.index = date.date.getMonth();
|
|
316
|
+
this.name = date.format('MMMM');
|
|
317
|
+
this.range = new AXDateTimeRange(
|
|
318
|
+
new AXDateTime(date.startOf('month').date, date.calendar),
|
|
319
|
+
new AXDateTime(date.endOf('month').date, date.calendar)
|
|
320
|
+
);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
private readonly index: number;
|
|
324
|
+
private readonly name: string;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
export interface AXTimeSpanTotal {
|
|
328
|
+
miliseconds: number;
|
|
329
|
+
seconds: number;
|
|
330
|
+
minutes: number;
|
|
331
|
+
hours: number;
|
|
332
|
+
days: number;
|
|
333
|
+
weeks: number;
|
|
334
|
+
months: number;
|
|
335
|
+
years: number;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
export interface AXTimeSpan {
|
|
339
|
+
miliseconds: number;
|
|
340
|
+
seconds: number;
|
|
341
|
+
minutes: number;
|
|
342
|
+
hours: number;
|
|
343
|
+
days: number;
|
|
344
|
+
months: number;
|
|
345
|
+
years: number;
|
|
346
|
+
total: AXTimeSpanTotal;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
export class AXDateTimeRange {
|
|
350
|
+
private _startTime: AXDateTime;
|
|
351
|
+
private _endTime: AXDateTime;
|
|
352
|
+
|
|
353
|
+
public get startTime(): AXDateTime {
|
|
354
|
+
return this._startTime;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
public get endTime(): AXDateTime {
|
|
358
|
+
return this._endTime;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
constructor(startTime: AXDateTime, endTime: AXDateTime) {
|
|
362
|
+
this._startTime = startTime;
|
|
363
|
+
this._endTime = endTime;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
duration(): AXTimeSpan {
|
|
367
|
+
const result: AXTimeSpan = {
|
|
368
|
+
miliseconds: 0,
|
|
369
|
+
seconds: 0,
|
|
370
|
+
minutes: 0,
|
|
371
|
+
hours: 0,
|
|
372
|
+
days: 0,
|
|
373
|
+
months: 0,
|
|
374
|
+
years: 0,
|
|
375
|
+
total: {
|
|
376
|
+
miliseconds: 0,
|
|
377
|
+
seconds: 0,
|
|
378
|
+
minutes: 0,
|
|
379
|
+
hours: 0,
|
|
380
|
+
days: 0,
|
|
381
|
+
weeks: 0,
|
|
382
|
+
months: 0,
|
|
383
|
+
years: 0,
|
|
384
|
+
},
|
|
385
|
+
};
|
|
386
|
+
|
|
387
|
+
const one_second = 1000;
|
|
388
|
+
const one_min = one_second * 60;
|
|
389
|
+
const one_hour = one_min * 60;
|
|
390
|
+
const one_day = one_hour * 24;
|
|
391
|
+
const one_week = one_day * 7;
|
|
392
|
+
const one_year = 365.25 * one_day;
|
|
393
|
+
const one_month = one_year / 12;
|
|
394
|
+
const startTime = this._startTime.date.getTime();
|
|
395
|
+
const endTime = this._endTime.date.getTime();
|
|
396
|
+
const diff = Math.abs(endTime - startTime);
|
|
397
|
+
//
|
|
398
|
+
result.total.miliseconds = diff;
|
|
399
|
+
result.total.seconds = Number((diff / one_second).toFixed(2));
|
|
400
|
+
result.total.minutes = Number((diff / one_min).toFixed(2));
|
|
401
|
+
result.total.hours = Number((diff / one_hour).toFixed(2));
|
|
402
|
+
result.total.days = Number((diff / one_day).toFixed(2));
|
|
403
|
+
result.total.weeks = Number((diff / one_week).toFixed(2));
|
|
404
|
+
//
|
|
405
|
+
// let months = (this.endTime.year - this.startTime.year) * 12;
|
|
406
|
+
// months += this.endTime.monthOfYear - this.startTime.monthOfYear + 1;
|
|
407
|
+
// if (this.endTime.dayOfYear < this.startTime.dayOfYear) {
|
|
408
|
+
// months--;
|
|
409
|
+
// }
|
|
410
|
+
// result.total.months = Math.abs(months);
|
|
411
|
+
// TODO: review
|
|
412
|
+
result.total.months = Number((diff / one_month).toFixed(2));
|
|
413
|
+
result.total.years = Number((diff / one_year).toFixed(2));
|
|
414
|
+
//
|
|
415
|
+
result.miliseconds = result.total.miliseconds % 1000;
|
|
416
|
+
result.seconds = Number((result.total.seconds % 60).toFixed(0));
|
|
417
|
+
result.minutes = Number((result.total.minutes % 60).toFixed(0));
|
|
418
|
+
result.hours = Number((result.total.hours % 24).toFixed(0));
|
|
419
|
+
// TODO: review
|
|
420
|
+
result.days = Number((result.total.days % 30.4).toFixed(0));
|
|
421
|
+
result.months = Number((result.total.months % 12).toFixed(0));
|
|
422
|
+
result.years = Number(result.total.years.toFixed(0));
|
|
423
|
+
return result;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
enumurate(unit: TimeUnit = 'day', amount: number = 1): AXDateTime[] {
|
|
427
|
+
// TODO: setptemper savingtime issue
|
|
428
|
+
const result: AXDateTime[] = [];
|
|
429
|
+
let item = this._startTime.clone();
|
|
430
|
+
while (item.compare(this._endTime, unit) < 1) {
|
|
431
|
+
result.push(item);
|
|
432
|
+
item = item.add(unit, amount)
|
|
433
|
+
}
|
|
434
|
+
return result;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
includes(value: AXDateTime, unit: TimeUnit = 'day'): boolean {
|
|
438
|
+
// TODO: ??
|
|
439
|
+
return true;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
// getViewCompaire(view) {
|
|
443
|
+
// switch (view) {
|
|
444
|
+
// case 'day':
|
|
445
|
+
// return 'YMD';
|
|
446
|
+
// case 'month':
|
|
447
|
+
// return 'YM';
|
|
448
|
+
// case 'year':
|
|
449
|
+
// return 'Y';
|
|
450
|
+
// }
|
|
451
|
+
// }
|
|
452
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { NgModule } from '@angular/core';
|
|
2
|
+
import { AXConfig } from '@acorex/core/config';
|
|
3
|
+
import { AXDateTimePipe } from './datetime.pipe';
|
|
4
|
+
import { GeorgianCalendar } from './georgian.calendar';
|
|
5
|
+
import { JalaliCalendar } from './jalali.calendar';
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@NgModule({
|
|
9
|
+
imports: [],
|
|
10
|
+
exports: [AXDateTimePipe],
|
|
11
|
+
declarations: [AXDateTimePipe],
|
|
12
|
+
providers: [],
|
|
13
|
+
})
|
|
14
|
+
export class AXDateTimeModule {
|
|
15
|
+
|
|
16
|
+
constructor() {
|
|
17
|
+
AXConfig.set({
|
|
18
|
+
dateTime: {
|
|
19
|
+
calendars: {
|
|
20
|
+
jalali: new JalaliCalendar(),
|
|
21
|
+
gregorian: new GeorgianCalendar()
|
|
22
|
+
},
|
|
23
|
+
calendar:'gregorian',
|
|
24
|
+
shortDateFormat:'DDDD, d MMM yyyy'
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
}
|
|
29
|
+
}
|