@imihai/angular-datetime-picker 21.0.2 → 22.0.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.
- package/.browserslistrc +9 -0
- package/.editorconfig +13 -0
- package/.eslintrc.js +208 -0
- package/.github/workflows/ci_test.yml +35 -0
- package/.prettierrc +2 -0
- package/.travis.yml +16 -0
- package/angular.json +221 -0
- package/e2e/protractor.conf.js +28 -0
- package/e2e/src/app.e2e-spec.ts +14 -0
- package/e2e/src/app.po.ts +11 -0
- package/e2e/tsconfig.e2e.json +13 -0
- package/package.json +77 -33
- package/projects/picker/karma.conf.js +62 -0
- package/projects/picker/ng-package.json +7 -0
- package/projects/picker/package.json +23 -0
- package/projects/picker/src/lib/date-time/adapter/date-time-adapter.class.ts +313 -0
- package/projects/picker/src/lib/date-time/adapter/date-time-format.class.ts +18 -0
- package/projects/picker/src/lib/date-time/adapter/luxon-date-time-adapter.class.ts +307 -0
- package/projects/picker/src/lib/date-time/adapter/luxon-date-time-format.class.ts +11 -0
- package/projects/picker/src/lib/date-time/adapter/luxon-date-time.module.ts +31 -0
- package/projects/picker/src/lib/date-time/adapter/unix-timestamp-adapter/unix-timestamp-date-time-adapter.class.ts +356 -0
- package/projects/picker/src/lib/date-time/adapter/unix-timestamp-adapter/unix-timestamp-date-time-format.class.ts +14 -0
- package/projects/picker/src/lib/date-time/adapter/unix-timestamp-adapter/unix-timestamp-date-time.module.ts +26 -0
- package/projects/picker/src/lib/date-time/calendar-body.component.html +38 -0
- package/projects/picker/src/lib/date-time/calendar-body.component.scss +0 -0
- package/projects/picker/src/lib/date-time/calendar-body.component.spec.ts +120 -0
- package/projects/picker/src/lib/date-time/calendar-body.component.ts +190 -0
- package/projects/picker/src/lib/date-time/calendar-month-view.component.html +47 -0
- package/projects/picker/src/lib/date-time/calendar-month-view.component.scss +16 -0
- package/projects/picker/src/lib/date-time/calendar-month-view.component.spec.ts +394 -0
- package/projects/picker/src/lib/date-time/calendar-month-view.component.ts +705 -0
- package/projects/picker/src/lib/date-time/calendar-multi-year-view.component.html +44 -0
- package/projects/picker/src/lib/date-time/calendar-multi-year-view.component.scss +0 -0
- package/projects/picker/src/lib/date-time/calendar-multi-year-view.component.spec.ts +343 -0
- package/projects/picker/src/lib/date-time/calendar-multi-year-view.component.ts +465 -0
- package/projects/picker/src/lib/date-time/calendar-year-view.component.html +16 -0
- package/projects/picker/src/lib/date-time/calendar-year-view.component.scss +0 -0
- package/projects/picker/src/lib/date-time/calendar-year-view.component.spec.ts +381 -0
- package/projects/picker/src/lib/date-time/calendar-year-view.component.ts +549 -0
- package/projects/picker/src/lib/date-time/calendar.component.html +169 -0
- package/projects/picker/src/lib/date-time/calendar.component.scss +0 -0
- package/projects/picker/src/lib/date-time/calendar.component.spec.ts +592 -0
- package/projects/picker/src/lib/date-time/calendar.component.ts +496 -0
- package/projects/picker/src/lib/date-time/date-time-inline.component.html +1 -0
- package/projects/picker/src/lib/date-time/date-time-inline.component.scss +4 -0
- package/projects/picker/src/lib/date-time/date-time-inline.component.ts +365 -0
- package/projects/picker/src/lib/date-time/date-time-picker-animation-event.ts +4 -0
- package/projects/picker/src/lib/date-time/date-time-picker-container.component.html +126 -0
- package/projects/picker/src/lib/date-time/date-time-picker-container.component.scss +0 -0
- package/projects/picker/src/lib/date-time/date-time-picker-container.component.ts +631 -0
- package/projects/picker/src/lib/date-time/date-time-picker-input.directive.ts +851 -0
- package/projects/picker/src/lib/date-time/date-time-picker-intl.service.ts +76 -0
- package/projects/picker/src/lib/date-time/date-time-picker-trigger.directive.ts +88 -0
- package/projects/picker/src/lib/date-time/date-time-picker.component.html +0 -0
- package/projects/picker/src/lib/date-time/date-time-picker.component.scss +0 -0
- package/projects/picker/src/lib/date-time/date-time-picker.component.spec.ts +2648 -0
- package/projects/picker/src/lib/date-time/date-time-picker.component.ts +731 -0
- package/projects/picker/src/lib/date-time/date-time.class.ts +256 -0
- package/projects/picker/src/lib/date-time/date-time.module.ts +61 -0
- package/projects/picker/src/lib/date-time/numberedFixLen.pipe.ts +28 -0
- package/projects/picker/src/lib/date-time/options-provider.ts +44 -0
- package/projects/picker/src/lib/date-time/timer-box.component.html +79 -0
- package/projects/picker/src/lib/date-time/timer-box.component.scss +0 -0
- package/projects/picker/src/lib/date-time/timer-box.component.ts +175 -0
- package/projects/picker/src/lib/date-time/timer.component.html +58 -0
- package/projects/picker/src/lib/date-time/timer.component.scss +0 -0
- package/projects/picker/src/lib/date-time/timer.component.spec.ts +399 -0
- package/projects/picker/src/lib/date-time/timer.component.ts +371 -0
- package/projects/picker/src/lib/dialog/dialog-config.class.ts +220 -0
- package/projects/picker/src/lib/dialog/dialog-container.component.html +1 -0
- package/projects/picker/src/lib/dialog/dialog-container.component.scss +0 -0
- package/projects/picker/src/lib/dialog/dialog-container.component.ts +231 -0
- package/projects/picker/src/lib/dialog/dialog-ref.class.ts +178 -0
- package/projects/picker/src/lib/dialog/dialog.module.ts +25 -0
- package/projects/picker/src/lib/dialog/dialog.service.ts +353 -0
- package/projects/picker/src/lib/utils/array.utils.ts +12 -0
- package/projects/picker/src/lib/utils/constants.ts +59 -0
- package/projects/picker/src/lib/utils/date.utils.ts +97 -0
- package/projects/picker/src/lib/utils/index.ts +5 -0
- package/projects/picker/src/lib/utils/object.utils.ts +29 -0
- package/projects/picker/src/public_api.ts +56 -0
- package/projects/picker/src/sass/picker.scss +743 -0
- package/projects/picker/src/test-helpers.ts +125 -0
- package/projects/picker/src/test.ts +52 -0
- package/projects/picker/tsconfig.lib.json +19 -0
- package/projects/picker/tsconfig.lib.prod.json +7 -0
- package/projects/picker/tsconfig.spec.json +17 -0
- package/projects/picker/tslint.json +8 -0
- package/src/app/app.component.html +77 -0
- package/src/app/app.component.scss +32 -0
- package/src/app/app.component.spec.ts +16 -0
- package/src/app/app.component.ts +35 -0
- package/src/assets/.gitkeep +0 -0
- package/src/environments/environment.prod.ts +3 -0
- package/src/environments/environment.ts +16 -0
- package/src/favicon.ico +0 -0
- package/src/index.html +14 -0
- package/src/karma.conf.js +31 -0
- package/src/main.ts +16 -0
- package/src/polyfills.ts +53 -0
- package/src/styles.scss +7 -0
- package/src/test.ts +50 -0
- package/src/tsconfig.app.json +16 -0
- package/src/tsconfig.spec.json +18 -0
- package/src/tslint.json +17 -0
- package/tsconfig.base.json +31 -0
- package/tsconfig.json +30 -0
- package/tslint.json +130 -0
- package/assets/style/picker.min.css +0 -1
- package/fesm2022/imihai-angular-datetime-picker.mjs +0 -5845
- package/fesm2022/imihai-angular-datetime-picker.mjs.map +0 -1
- package/imihai-angular-datetime-picker-21.0.2.tgz +0 -0
- package/types/imihai-angular-datetime-picker.d.ts +0 -2193
package/package.json
CHANGED
|
@@ -1,33 +1,77 @@
|
|
|
1
|
-
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
},
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@imihai/angular-datetime-picker",
|
|
3
|
+
"version": "22.0.0",
|
|
4
|
+
"description": "Angular Date Time Picker",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"ng": "ng",
|
|
8
|
+
"start": "ng serve",
|
|
9
|
+
"build": "ng build picker",
|
|
10
|
+
"test": "ng test picker",
|
|
11
|
+
"test:ci": "ng test --watch=false --no-progress --browsers=ChromeHeadlessCI --code-coverage=true picker",
|
|
12
|
+
"lint": "ng lint",
|
|
13
|
+
"e2e": "ng e2e",
|
|
14
|
+
"build_lib_onWindows": "ng build picker --configuration production",
|
|
15
|
+
"build_lib_onLinux": "ng build picker --configuration production",
|
|
16
|
+
"build_css_onWindows": "mkdir \"dist/picker/assets/style\" && sass --style=compressed projects/picker/src/sass/picker.scss > dist/picker/assets/style/picker.min.css",
|
|
17
|
+
"build_css_onLinux": "mkdir -p dist/picker/assets/style && sass --style=compressed projects/picker/src/sass/picker.scss > dist/picker/assets/style/picker.min.css",
|
|
18
|
+
"npm_pack": "cd dist/picker && npm pack",
|
|
19
|
+
"package_windows": "npm run build_lib_onWindows && npm run build_css_onWindows && npm run npm_pack",
|
|
20
|
+
"package_linux": "npm run build_lib_onLinux && npm run build_css_onLinux && npm run npm_pack"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@angular/cdk": "^22.0.4",
|
|
24
|
+
"@angular/common": "^22.0.6",
|
|
25
|
+
"@angular/compiler": "^22.0.6",
|
|
26
|
+
"@angular/core": "^22.0.6",
|
|
27
|
+
"@angular/forms": "^22.0.6",
|
|
28
|
+
"@angular/platform-browser": "^22.0.6",
|
|
29
|
+
"@angular/platform-browser-dynamic": "^22.0.6",
|
|
30
|
+
"@angular/router": "^22.0.6",
|
|
31
|
+
"core-js": "^3.45.1",
|
|
32
|
+
"luxon": "^3.7.2",
|
|
33
|
+
"np": "^10.2.0",
|
|
34
|
+
"rxjs": "^7.8.2",
|
|
35
|
+
"tslib": "^2.8.1",
|
|
36
|
+
"zone.js": "^0.15.1"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@angular-devkit/build-angular": "^22.0.5",
|
|
40
|
+
"@angular-eslint/eslint-plugin": "^22.0.0",
|
|
41
|
+
"@angular-eslint/eslint-plugin-template": "^22.0.0",
|
|
42
|
+
"@angular-eslint/schematics": "^22.0.0",
|
|
43
|
+
"@angular-eslint/template-parser": "^22.0.0",
|
|
44
|
+
"@angular/cli": "^22.0.5",
|
|
45
|
+
"@types/luxon": "^3.7.1",
|
|
46
|
+
"@angular/compiler-cli": "^22.0.6",
|
|
47
|
+
"@angular/language-service": "^22.0.6",
|
|
48
|
+
"@types/jasmine": "^5.1.9",
|
|
49
|
+
"@types/jasminewd2": "^2.0.13",
|
|
50
|
+
"@types/node": "^26.1.1",
|
|
51
|
+
"@typescript-eslint/eslint-plugin": "^8.54.0",
|
|
52
|
+
"@typescript-eslint/parser": "^8.54.0",
|
|
53
|
+
"codecov": "^3.8.3",
|
|
54
|
+
"eslint": "^10.6.0",
|
|
55
|
+
"jasmine-core": "~5.1.2",
|
|
56
|
+
"jasmine-spec-reporter": "~7.0.0",
|
|
57
|
+
"karma": "~6.4.3",
|
|
58
|
+
"karma-chrome-launcher": "^3.2.0",
|
|
59
|
+
"karma-coverage": "^2.2.1",
|
|
60
|
+
"karma-jasmine": "~5.1.0",
|
|
61
|
+
"karma-jasmine-html-reporter": "^2.1.0",
|
|
62
|
+
"ng-packagr": "^22.0.1",
|
|
63
|
+
"protractor": "~7.0.0",
|
|
64
|
+
"sass": "^1.93.2",
|
|
65
|
+
"ts-node": "^10.9.2",
|
|
66
|
+
"typescript": "~6.0.3"
|
|
67
|
+
},
|
|
68
|
+
"overrides": {
|
|
69
|
+
"@lmdb/lmdb-darwin-arm64": "3.0.12"
|
|
70
|
+
},
|
|
71
|
+
"optionalDependencies": {
|
|
72
|
+
"@nx/nx-darwin-arm64": "21.5.3",
|
|
73
|
+
"@nx/nx-darwin-x64": "21.5.3",
|
|
74
|
+
"@nx/nx-linux-x64-gnu": "21.5.3",
|
|
75
|
+
"@nx/nx-win32-x64-msvc": "21.5.3"
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// Karma configuration file, see link for more information
|
|
2
|
+
// https://karma-runner.github.io/1.0/config/configuration-file.html
|
|
3
|
+
|
|
4
|
+
module.exports = function (config) {
|
|
5
|
+
config.set({
|
|
6
|
+
basePath: '',
|
|
7
|
+
frameworks: ['jasmine', '@angular-devkit/build-angular'],
|
|
8
|
+
plugins: [
|
|
9
|
+
require('karma-jasmine'),
|
|
10
|
+
require('karma-chrome-launcher'),
|
|
11
|
+
require('karma-jasmine-html-reporter'),
|
|
12
|
+
require('karma-coverage'),
|
|
13
|
+
require('@angular-devkit/build-angular/plugins/karma')
|
|
14
|
+
],
|
|
15
|
+
client: {
|
|
16
|
+
clearContext: false // leave Jasmine Spec Runner output visible in browser
|
|
17
|
+
},
|
|
18
|
+
coverageIstanbulReporter: {
|
|
19
|
+
dir: require('path').join(__dirname, '../../coverage'),
|
|
20
|
+
reports: ['html', 'lcovonly', 'json'],
|
|
21
|
+
fixWebpackSourcePaths: true
|
|
22
|
+
},
|
|
23
|
+
customLaunchers: {
|
|
24
|
+
ChromeHeadlessNoSandbox: {
|
|
25
|
+
base: 'ChromeHeadless',
|
|
26
|
+
flags: [
|
|
27
|
+
'--no-sandbox',
|
|
28
|
+
'--disable-web-security',
|
|
29
|
+
'--disable-gpu',
|
|
30
|
+
'--disable-dev-shm-usage',
|
|
31
|
+
'--disable-extensions',
|
|
32
|
+
'--remote-debugging-port=9222',
|
|
33
|
+
'--headless'
|
|
34
|
+
]
|
|
35
|
+
},
|
|
36
|
+
ChromeHeadlessCI: {
|
|
37
|
+
base: 'ChromeHeadless',
|
|
38
|
+
flags: [
|
|
39
|
+
'--no-sandbox',
|
|
40
|
+
'--disable-web-security',
|
|
41
|
+
'--disable-gpu',
|
|
42
|
+
'--disable-dev-shm-usage',
|
|
43
|
+
'--disable-extensions',
|
|
44
|
+
'--disable-background-timer-throttling',
|
|
45
|
+
'--disable-backgrounding-occluded-windows',
|
|
46
|
+
'--disable-renderer-backgrounding',
|
|
47
|
+
'--remote-debugging-port=9222',
|
|
48
|
+
'--headless'
|
|
49
|
+
]
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
reporters: ['progress', 'kjhtml'],
|
|
53
|
+
port: 9876,
|
|
54
|
+
colors: true,
|
|
55
|
+
logLevel: config.LOG_INFO,
|
|
56
|
+
autoWatch: true,
|
|
57
|
+
// Use different browsers based on environment
|
|
58
|
+
browsers: process.env.CI ? ['ChromeHeadlessCI'] : ['Chrome'],
|
|
59
|
+
singleRun: process.env.CI ? true : false,
|
|
60
|
+
restartOnFileChange: false
|
|
61
|
+
});
|
|
62
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@imihai/angular-datetime-picker",
|
|
3
|
+
"version": "22.0.0",
|
|
4
|
+
"description": "Angular Date Time Picker",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"peerDependencies": {
|
|
10
|
+
"@angular/common": "^22.0.6",
|
|
11
|
+
"@angular/core": "^22.0.6",
|
|
12
|
+
"@angular/cdk": "^22.0.4",
|
|
13
|
+
"luxon": "^3.7.2"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"tslib": "^2.6.2"
|
|
17
|
+
},
|
|
18
|
+
"exports": {
|
|
19
|
+
"./assets/style/picker.min.css": {
|
|
20
|
+
"default": "./assets/style/picker.min.css"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* date-time-adapter.class
|
|
3
|
+
*/
|
|
4
|
+
import { Observable, Subject } from 'rxjs';
|
|
5
|
+
import { inject, InjectionToken, LOCALE_ID } from '@angular/core';
|
|
6
|
+
|
|
7
|
+
/** InjectionToken for date time picker that can be used to override default locale code. */
|
|
8
|
+
export const OWL_DATE_TIME_LOCALE = new InjectionToken<string>(
|
|
9
|
+
'OWL_DATE_TIME_LOCALE',
|
|
10
|
+
{
|
|
11
|
+
providedIn: 'root',
|
|
12
|
+
factory: OWL_DATE_TIME_LOCALE_FACTORY
|
|
13
|
+
}
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
/** @docs-private */
|
|
17
|
+
export function OWL_DATE_TIME_LOCALE_FACTORY(): string {
|
|
18
|
+
return inject(LOCALE_ID);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Provider for OWL_DATE_TIME_LOCALE injection token. */
|
|
22
|
+
export const OWL_DATE_TIME_LOCALE_PROVIDER = {
|
|
23
|
+
provide: OWL_DATE_TIME_LOCALE,
|
|
24
|
+
useExisting: LOCALE_ID
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export abstract class DateTimeAdapter<T> {
|
|
28
|
+
/** The locale to use for all dates. */
|
|
29
|
+
protected locale: any;
|
|
30
|
+
|
|
31
|
+
/** A stream that emits when the locale changes. */
|
|
32
|
+
protected _localeChanges = new Subject<string>();
|
|
33
|
+
get localeChanges(): Observable<string> {
|
|
34
|
+
return this._localeChanges;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public firstMonthOfTheYear: number = 0;
|
|
38
|
+
public firstDayOfTheWeek: number = 0;
|
|
39
|
+
|
|
40
|
+
/** total milliseconds in a day. */
|
|
41
|
+
protected readonly millisecondsInDay = 86400000;
|
|
42
|
+
|
|
43
|
+
/** total milliseconds in a minute. */
|
|
44
|
+
protected readonly millisecondsInMinute = 60000;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Get the year of the given date
|
|
48
|
+
*/
|
|
49
|
+
abstract getYear(date: T): number;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Get the month of the given date
|
|
53
|
+
* 0 -- January
|
|
54
|
+
* 11 -- December
|
|
55
|
+
* */
|
|
56
|
+
abstract getMonth(date: T): number;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Get the day of the week of the given date
|
|
60
|
+
* 0 -- Sunday
|
|
61
|
+
* 6 -- Saturday
|
|
62
|
+
* */
|
|
63
|
+
abstract getDay(date: T): number;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Get the day num of the given date
|
|
67
|
+
*/
|
|
68
|
+
abstract getDate(date: T): number;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Get the hours of the given date
|
|
72
|
+
*/
|
|
73
|
+
abstract getHours(date: T): number;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Get the minutes of the given date
|
|
77
|
+
*/
|
|
78
|
+
abstract getMinutes(date: T): number;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Get the seconds of the given date
|
|
82
|
+
*/
|
|
83
|
+
abstract getSeconds(date: T): number;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Get the milliseconds timestamp of the given date
|
|
87
|
+
*/
|
|
88
|
+
abstract getTime(date: T): number;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Gets the number of days in the month of the given date.
|
|
92
|
+
*/
|
|
93
|
+
abstract getNumDaysInMonth(date: T): number;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Get the number of calendar days between the given dates.
|
|
97
|
+
* If dateLeft is before dateRight, it would return positive value
|
|
98
|
+
* If dateLeft is after dateRight, it would return negative value
|
|
99
|
+
*/
|
|
100
|
+
abstract differenceInCalendarDays(dateLeft: T, dateRight: T): number;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Gets the name for the year of the given date.
|
|
104
|
+
*/
|
|
105
|
+
abstract getYearName(date: T): string;
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Get a list of month names
|
|
109
|
+
*/
|
|
110
|
+
abstract getMonthNames(style: 'long' | 'short' | 'narrow'): string[];
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Get a list of week names
|
|
114
|
+
*/
|
|
115
|
+
abstract getDayOfWeekNames(style: 'long' | 'short' | 'narrow'): string[];
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Gets a list of names for the dates of the month.
|
|
119
|
+
*/
|
|
120
|
+
abstract getDateNames(): string[];
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Return a Date object as a string, using the ISO standard
|
|
124
|
+
*/
|
|
125
|
+
abstract toIso8601(date: T): string;
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Check if the give dates are equal
|
|
129
|
+
*/
|
|
130
|
+
abstract isEqual(dateLeft: T, dateRight: T): boolean;
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Check if the give dates are the same day
|
|
134
|
+
*/
|
|
135
|
+
abstract isSameDay(dateLeft: T, dateRight: T): boolean;
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Checks whether the given date is valid.
|
|
139
|
+
*/
|
|
140
|
+
abstract isValid(date: T): boolean;
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Gets date instance that is not valid.
|
|
144
|
+
*/
|
|
145
|
+
abstract invalid(): T;
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Checks whether the given object is considered a date instance by this DateTimeAdapter.
|
|
149
|
+
*/
|
|
150
|
+
abstract isDateInstance(obj: any): boolean;
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Add the specified number of years to the given date
|
|
154
|
+
*/
|
|
155
|
+
abstract addCalendarYears(date: T, amount: number): T;
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Add the specified number of months to the given date
|
|
159
|
+
*/
|
|
160
|
+
abstract addCalendarMonths(date: T, amount: number): T;
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Add the specified number of days to the given date
|
|
164
|
+
*/
|
|
165
|
+
abstract addCalendarDays(date: T, amount: number): T;
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Set the hours to the given date.
|
|
169
|
+
*/
|
|
170
|
+
abstract setHours(date: T, amount: number): T;
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Set the minutes to the given date.
|
|
174
|
+
*/
|
|
175
|
+
abstract setMinutes(date: T, amount: number): T;
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Set the seconds to the given date.
|
|
179
|
+
*/
|
|
180
|
+
abstract setSeconds(date: T, amount: number): T;
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Creates a date with the given year, month, date, hour, minute and second. Does not allow over/under-flow of the
|
|
184
|
+
* month and date.
|
|
185
|
+
*/
|
|
186
|
+
abstract createDate(year: number, month: number, date: number): T;
|
|
187
|
+
abstract createDate(
|
|
188
|
+
year: number,
|
|
189
|
+
month: number,
|
|
190
|
+
date: number,
|
|
191
|
+
hours: number,
|
|
192
|
+
minutes: number,
|
|
193
|
+
seconds: number
|
|
194
|
+
): T;
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Clone the given date
|
|
198
|
+
*/
|
|
199
|
+
abstract clone(date: T): T;
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Get a new moment
|
|
203
|
+
* */
|
|
204
|
+
abstract now(): T;
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Formats a date as a string according to the given format.
|
|
208
|
+
*/
|
|
209
|
+
abstract format(date: T, displayFormat: any): string;
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Parse a user-provided value to a Date Object
|
|
213
|
+
*/
|
|
214
|
+
abstract parse(value: any, parseFormat: any): T | null;
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Compare two given dates
|
|
218
|
+
* 1 if the first date is after the second,
|
|
219
|
+
* -1 if the first date is before the second
|
|
220
|
+
* 0 if dates are equal.
|
|
221
|
+
* */
|
|
222
|
+
compare(first: T, second: T): number {
|
|
223
|
+
if (!this.isValid(first) || !this.isValid(second)) {
|
|
224
|
+
throw Error('JSNativeDate: Cannot compare invalid dates.');
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const dateFirst = this.clone(first);
|
|
228
|
+
const dateSecond = this.clone(second);
|
|
229
|
+
|
|
230
|
+
const diff = this.getTime(dateFirst) - this.getTime(dateSecond);
|
|
231
|
+
|
|
232
|
+
if (diff < 0) {
|
|
233
|
+
return -1;
|
|
234
|
+
} else if (diff > 0) {
|
|
235
|
+
return 1;
|
|
236
|
+
} else {
|
|
237
|
+
// Return 0 if diff is 0; return NaN if diff is NaN
|
|
238
|
+
return diff;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Check if two given dates are in the same year
|
|
244
|
+
* 1 if the first date's year is after the second,
|
|
245
|
+
* -1 if the first date's year is before the second
|
|
246
|
+
* 0 if two given dates are in the same year
|
|
247
|
+
* */
|
|
248
|
+
compareYear(first: T, second: T): number {
|
|
249
|
+
if (!this.isValid(first) || !this.isValid(second)) {
|
|
250
|
+
throw Error('JSNativeDate: Cannot compare invalid dates.');
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
const yearLeft = this.getYear(first);
|
|
254
|
+
const yearRight = this.getYear(second);
|
|
255
|
+
|
|
256
|
+
const diff = yearLeft - yearRight;
|
|
257
|
+
|
|
258
|
+
if (diff < 0) {
|
|
259
|
+
return -1;
|
|
260
|
+
} else if (diff > 0) {
|
|
261
|
+
return 1;
|
|
262
|
+
} else {
|
|
263
|
+
return 0;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Attempts to deserialize a value to a valid date object. This is different from parsing in that
|
|
269
|
+
* deserialize should only accept non-ambiguous, locale-independent formats (e.g. a ISO 8601
|
|
270
|
+
* string). The default implementation does not allow any deserialization, it simply checks that
|
|
271
|
+
* the given value is already a valid date object or null. The `<mat-datepicker>` will call this
|
|
272
|
+
* method on all of it's `@Input()` properties that accept dates. It is therefore possible to
|
|
273
|
+
* support passing values from your backend directly to these properties by overriding this method
|
|
274
|
+
* to also deserialize the format used by your backend.
|
|
275
|
+
*/
|
|
276
|
+
deserialize(value: any): T | null {
|
|
277
|
+
if (
|
|
278
|
+
value == null ||
|
|
279
|
+
(this.isDateInstance(value) && this.isValid(value))
|
|
280
|
+
) {
|
|
281
|
+
return value;
|
|
282
|
+
}
|
|
283
|
+
return this.invalid();
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Sets the locale used for all dates.
|
|
288
|
+
*/
|
|
289
|
+
setLocale(locale: string) {
|
|
290
|
+
this.locale = locale;
|
|
291
|
+
this._localeChanges.next(locale);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Get the locale used for all dates.
|
|
296
|
+
* */
|
|
297
|
+
getLocale() {
|
|
298
|
+
return this.locale;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Clamp the given date between min and max dates.
|
|
303
|
+
*/
|
|
304
|
+
clampDate(date: T, min?: T | null, max?: T | null): T {
|
|
305
|
+
if (min && this.compare(date, min) < 0) {
|
|
306
|
+
return min;
|
|
307
|
+
}
|
|
308
|
+
if (max && this.compare(date, max) > 0) {
|
|
309
|
+
return max;
|
|
310
|
+
}
|
|
311
|
+
return date;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* date-time-format.class
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { InjectionToken } from '@angular/core';
|
|
6
|
+
|
|
7
|
+
export interface OwlDateTimeFormats {
|
|
8
|
+
parseInput: any;
|
|
9
|
+
fullPickerInput: any;
|
|
10
|
+
datePickerInput: any;
|
|
11
|
+
timePickerInput: any;
|
|
12
|
+
monthYearLabel: any;
|
|
13
|
+
dateA11yLabel: any;
|
|
14
|
+
monthYearA11yLabel: any;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** InjectionToken for date time picker that can be used to override default format. */
|
|
18
|
+
export const OWL_DATE_TIME_FORMATS = new InjectionToken<OwlDateTimeFormats>('OWL_DATE_TIME_FORMATS');
|