Skip to content

Commit

Permalink
fix(locale): set timezone in moment pipe
Browse files Browse the repository at this point in the history
Issue #3
  • Loading branch information
bravemaster619 committed May 10, 2020
1 parent 57e4167 commit fb6a7c1
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 5 deletions.
17 changes: 17 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"cordova-sqlite-storage": "^5.0.0",
"core-js": "^2.5.4",
"moment": "^2.24.0",
"moment-timezone": "^0.5.28",
"query-string": "^6.12.1",
"rxjs": "~6.5.1",
"stripe-angular": "^1.0.2",
Expand All @@ -52,6 +53,7 @@
"@ionic/angular-toolkit": "^2.1.1",
"@types/jasmine": "~3.3.8",
"@types/jasminewd2": "~2.0.3",
"@types/moment-timezone": "^0.5.13",
"@types/node": "~8.9.4",
"@typescript-eslint/eslint-plugin": "^2.29.0",
"@typescript-eslint/parser": "^2.29.0",
Expand Down
6 changes: 3 additions & 3 deletions src/app/pipes/moment/moment.pipe.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Pipe, PipeTransform } from "@angular/core";
import * as moment from "moment";
import * as moment from "moment-timezone";
import { TranslateService } from "@ngx-translate/core";

import { environment } from "src/environments/environment";
@Pipe({
name: "moment",
pure: false
})
export class MomentPipe implements PipeTransform {
constructor(private lang: TranslateService) {}
transform(value: any, ...args: Array<any>): any {
const date = moment(value);
const date = moment(value).tz(environment.timezone);
date.locale(this.lang.currentLang === "zh" ? "zh-cn" : "en");
const [format] = args;
return date.format(format);
Expand Down
3 changes: 2 additions & 1 deletion src/environments/environment.prod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ export const environment = {
media: "https://duocun.com.cn/media/",
stripe: "pk_live_vV7H1l4X9k2r8uf6JDf9lGsb",
defaultLang: "zh",
gmap: "AIzaSyCEd6D6vc9K-YzMH-QtQWRSs5HZkLKSWyk"
gmap: "AIzaSyCEd6D6vc9K-YzMH-QtQWRSs5HZkLKSWyk",
timezone: "America/Toronto"
};
3 changes: 2 additions & 1 deletion src/environments/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export const environment = {
media: "https://duocun.com.cn/media/",
stripe: "pk_test_FsGoacByMF8lGNcVKveNZFSy00ATWTilJp",
defaultLang: "zh",
gmap: "AIzaSyCEd6D6vc9K-YzMH-QtQWRSs5HZkLKSWyk"
gmap: "AIzaSyCEd6D6vc9K-YzMH-QtQWRSs5HZkLKSWyk",
timezone: "Asia/Shanghai"
};

/*
Expand Down

0 comments on commit fb6a7c1

Please sign in to comment.