Skip to content

Commit 492268a

Browse files
authored
feat(material-luxon-adapter): add luxon date adapter (#23167)
Adds a new package called `@angular/material-luxon-adapter` that provides a date adapter to be used together with Luxon dates.
1 parent bca634b commit 492268a

32 files changed

+1007
-4
lines changed

.github/CODEOWNERS

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,9 @@
8888
/src/cdk/text-field/** @mmalerba
8989
/src/cdk/tree/** @jelbourn @andrewseguin
9090

91-
# Moment adapter package
91+
# Date adapters
9292
/src/material-moment-adapter/** @mmalerba
93+
/src/material-luxon-adapter/** @crisbeto
9394

9495
# Material experimental package
9596
/src/material-experimental/* @jelbourn

.ng-dev/commit-message.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export const commitMessage: CommitMessageConfig = {
7272
'material-experimental/popover-edit',
7373
'material-experimental/selection',
7474
'material-moment-adapter',
75+
'material-luxon-adapter',
7576
'material/autocomplete',
7677
'material/badge',
7778
'material/bottom-sheet',

angular-tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"node_modules/@angular/material/**",
3838
"node_modules/@angular/material-experimental/**",
3939
"node_modules/@angular/material-moment-adapter/**",
40+
"node_modules/@angular/material-luxon-adapter/**",
4041
"node_modules/@angular/youtube-player/**"
4142
]
4243
}

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@
153153
"@types/gulp": "4.0.8",
154154
"@types/inquirer": "^7.3.1",
155155
"@types/jasmine": "^3.6.0",
156+
"@types/luxon": "^1.27.0",
156157
"@types/marked": "^2.0.0",
157158
"@types/merge2": "^0.3.30",
158159
"@types/minimist": "^1.2.0",
@@ -200,6 +201,7 @@
200201
"minimatch": "^3.0.4",
201202
"minimist": "^1.2.0",
202203
"moment": "^2.18.1",
204+
"luxon": "^2.0.0",
203205
"node-fetch": "^2.6.0",
204206
"parse5": "^6.0.1",
205207
"postcss": "^8.2.1",

rollup-globals.bzl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ ROLLUP_GLOBALS = {
3434
"@angular/material": "ng.material",
3535
"@angular/material-experimental": "ng.materialExperimental",
3636
"@angular/material-moment-adapter": "ng.materialMomentAdapter",
37+
"@angular/material-luxon-adapter": "ng.materialLuxonAdapter",
3738
"@angular/youtube-player": "ng.youtubePlayer",
3839

3940
# MDC Web
@@ -78,6 +79,7 @@ ROLLUP_GLOBALS = {
7879
"moment": "moment",
7980
"moment/locale/fr": "moment.locale.fr",
8081
"moment/locale/ja": "moment.locale.ja",
82+
"luxon": "luxon",
8183
"protractor": "protractor",
8284
"rxjs": "rxjs",
8385
"rxjs/operators": "rxjs.operators",

scripts/deploy/publish-build-artifacts.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ PACKAGES=(
2222
material
2323
material-experimental
2424
material-moment-adapter
25+
# material-luxon-adapter TODO(crisbeto): enable this once we have a builds repo
2526
google-maps
2627
youtube-player
2728
)

src/components-examples/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
"@angular/common": "0.0.0-NG",
2626
"@angular/material": "0.0.0-PLACEHOLDER",
2727
"@angular/material-experimental": "0.0.0-PLACEHOLDER",
28-
"@angular/material-moment-adapter": "0.0.0-PLACEHOLDER"
28+
"@angular/material-moment-adapter": "0.0.0-PLACEHOLDER",
29+
"@angular/material-luxon-adapter": "0.0.0-PLACEHOLDER"
2930
},
3031
"dependencies": {
3132
"tslib": "0.0.0-TSLIB"

src/components-examples/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"@angular/cdk-experimental/*": ["../cdk-experimental/*"],
1212
"@angular/material/*": ["../material/*"],
1313
"@angular/material-experimental/*": ["../material-experimental/*"],
14-
"@angular/material-moment-adapter": ["../material-moment-adapter/public-api.ts"]
14+
"@angular/material-moment-adapter": ["../material-moment-adapter/public-api.ts"],
15+
"@angular/material-luxon-adapter": ["../material-luxon-adapter/public-api.ts"]
1516
}
1617
},
1718
"include": ["./**/*.ts"]

src/dev-app/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"@angular/cdk-experimental/*": ["../cdk-experimental/*"],
1515
"@angular/cdk-experimental": ["../cdk-experimental"],
1616
"@angular/material-moment-adapter": ["../material-moment-adapter/public-api.ts"],
17+
"@angular/material-luxon-adapter": ["../material-luxon-adapter/public-api.ts"],
1718
"@angular/google-maps": ["../google-maps"],
1819
"@angular/components-examples": ["../components-examples"],
1920
"@angular/components-examples/*": ["../components-examples/*"],

src/e2e-app/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"@angular/cdk-experimental/*": ["../cdk-experimental/*"],
1313
"@angular/cdk-experimental": ["../cdk-experimental/"],
1414
"@angular/material-moment-adapter": ["../material-moment-adapter/"],
15+
"@angular/material-luxon-adapter": ["../material-luxon-adapter/"],
1516
"@angular/components-examples": ["../components-examples/"],
1617
"@angular/components-examples/*": ["../components-examples/*"]
1718
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
load("//tools:defaults.bzl", "ng_module", "ng_package", "ng_test_library", "ng_web_test_suite")
2+
3+
package(default_visibility = ["//visibility:public"])
4+
5+
ng_module(
6+
name = "material-luxon-adapter",
7+
srcs = glob(
8+
["**/*.ts"],
9+
exclude = ["**/*.spec.ts"],
10+
),
11+
deps = [
12+
"//src:dev_mode_types",
13+
"//src/material/core",
14+
"@npm//@angular/core",
15+
"@npm//@types/luxon",
16+
"@npm//luxon",
17+
],
18+
)
19+
20+
ng_test_library(
21+
name = "unit_test_sources",
22+
srcs = glob(
23+
["**/*.spec.ts"],
24+
exclude = ["**/*.e2e.spec.ts"],
25+
),
26+
deps = [
27+
":material-luxon-adapter",
28+
"//src/material/core",
29+
"@npm//@types/luxon",
30+
"@npm//luxon",
31+
],
32+
)
33+
34+
ng_web_test_suite(
35+
name = "unit_tests",
36+
# We need to load Luxon statically since it is not a named AMD module and needs to
37+
# be manually configured through "require.js" which is used by "karma_web_test_suite".
38+
static_files = [
39+
"@npm//luxon",
40+
],
41+
deps = [
42+
":require-config.js",
43+
":unit_test_sources",
44+
],
45+
)
46+
47+
ng_package(
48+
name = "npm_package",
49+
srcs = ["package.json"],
50+
entry_point = ":public-api.ts",
51+
tags = ["release-package"],
52+
deps = [":material-luxon-adapter"],
53+
)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import {NgModule} from '@angular/core';
10+
import {DateAdapter, MAT_DATE_FORMATS, MAT_DATE_LOCALE} from '@angular/material/core';
11+
import {MAT_LUXON_DATE_ADAPTER_OPTIONS, LuxonDateAdapter} from './luxon-date-adapter';
12+
import {MAT_LUXON_DATE_FORMATS} from './luxon-date-formats';
13+
14+
export * from './luxon-date-adapter';
15+
export * from './luxon-date-formats';
16+
17+
@NgModule({
18+
providers: [{
19+
provide: DateAdapter,
20+
useClass: LuxonDateAdapter,
21+
deps: [MAT_DATE_LOCALE, MAT_LUXON_DATE_ADAPTER_OPTIONS]
22+
}],
23+
})
24+
export class LuxonDateModule {}
25+
26+
27+
@NgModule({
28+
imports: [LuxonDateModule],
29+
providers: [{provide: MAT_DATE_FORMATS, useValue: MAT_LUXON_DATE_FORMATS}],
30+
})
31+
export class MatLuxonDateModule {}

0 commit comments

Comments
 (0)