Skip to content

Commit 2c31890

Browse files
committed
chore: 🔖 Bump version to 11.1.0. Update root README
Update version to 11.1.0 from 11.1.0-beta.0 Update README.md in root directory with the latest changes. #4
1 parent 943f325 commit 2c31890

File tree

3 files changed

+49
-4
lines changed

3 files changed

+49
-4
lines changed

README.md

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,11 @@ import { NgxMatDateFnsDateModule } from "ngx-mat-datefns-date-adapter";
6363
export class AppModule {}
6464
```
6565

66-
2. Register custom locale token in providers if needed.
67-
> `providers: [{ provide: MAT_DATE_LOCALE, useValue: 'ja' }],`
66+
2. Register custom locale token in providers if needed. Also register required locales in NGX_MAT_DATEFNS_LOCALES array.
67+
> `providers: [`
68+
> `{ provide: MAT_DATE_LOCALE, useValue: 'ja' },`
69+
> `{ provide: NGX_MAT_DATEFNS_LOCALES, useValue: [ja] }`
70+
> `],`
6871
6972
```typescript
7073
import { NgModule } from "@angular/core";
@@ -77,6 +80,7 @@ import { BrowserModule } from "@angular/platform-browser";
7780
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
7881
import { AppComponent } from "./app.component";
7982
import { NgxMatDateFnsDateModule } from "ngx-mat-datefns-date-adapter";
83+
import { da, ja } from 'date-fns/esm/locale'
8084

8185
@NgModule({
8286
declarations: [AppComponent],
@@ -95,12 +99,53 @@ import { NgxMatDateFnsDateModule } from "ngx-mat-datefns-date-adapter";
9599
provide: MAT_DATE_LOCALE,
96100
useValue: "ja",
97101
},
102+
{
103+
provide: NGX_MAT_DATEFNS_LOCALES,
104+
useValue: [da, ja]
105+
}
98106
],
99107
bootstrap: [AppComponent],
100108
})
101109
export class AppModule {}
102110
```
103111

112+
## Default locale
113+
114+
When MAT_DATE_LOCALE and NGX_MAT_DATEFNS_LOCALES tokens are not provided, `en-US` locale is used by default. When empty or null value is provided to the MAT_DATE_LOCALE token, `en-US` locale is also used.
115+
116+
## Change locale dynamically
117+
118+
Use `setLocale()` method of the `DateAdapter`.
119+
In case of using `setLocale` with a string argument, target locale should be imported into NGX_MAT_DATEFNS_LOCALES array.
120+
121+
```typescript
122+
import { Component } from '@angular/core';
123+
import { DateAdapter } from '@angular/material/core';
124+
import { fr } from 'date-fns/esm/locale';
125+
126+
@Component({
127+
selector: 'app-root',
128+
templateUrl: './app.component.html',
129+
styleUrls: ['./app.component.scss'],
130+
})
131+
export class AppComponent {
132+
133+
constructor(private readonly dateAdapter: DateAdapter<any>) {}
134+
135+
setLocaleWithString(): void {
136+
this.dateAdapter.setLocale('fr');
137+
}
138+
139+
setLocaleWithLocaleObject(): void {
140+
this.dateAdapter.setLocale(fr);
141+
}
142+
}
143+
```
144+
145+
## ES modules and Tree-shaking
146+
147+
Import date-fns locales from 'date-fns/esm/locale' entrypoint. This enables tree-shaking by the Angular builder.
148+
104149
## Build
105150

106151
Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `--prod` flag for a production build.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ngx-mat-datefns-date-adapter",
3-
"version": "11.0.3",
3+
"version": "11.1.0",
44
"scripts": {
55
"start": "ng serve",
66
"build": "ng-packagr -p ./projects/ngx-mat-datefns-date-adapter/ng-package.json",

projects/ngx-mat-datefns-date-adapter/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ngx-mat-datefns-date-adapter",
3-
"version": "11.1.0-beta.0",
3+
"version": "11.1.0",
44
"description": "",
55
"author": "Alexey Sapozhnikov",
66
"license": "MIT",

0 commit comments

Comments
 (0)