Browse Source
Merge pull request #9753 from abpframework/fix/9752
fix: creating wrong dates when timezone is utc-
pull/9754/head
Muhammed Altuğ
5 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with
13 additions and
2 deletions
-
npm/ng-packs/packages/theme-shared/extensions/src/lib/adapters/date.adapter.ts
|
|
|
@ -7,9 +7,15 @@ export class DateAdapter extends NgbDateAdapter<string> { |
|
|
|
fromModel(value: string | Date): NgbDateStruct | null { |
|
|
|
if (!value) return null; |
|
|
|
|
|
|
|
const date = new Date(value); |
|
|
|
let date: Date; |
|
|
|
|
|
|
|
if (isNaN((date as unknown) as number)) return null; |
|
|
|
if (typeof value === 'string') { |
|
|
|
date = this.dateOf(value); |
|
|
|
} else { |
|
|
|
date = new Date(value); |
|
|
|
} |
|
|
|
|
|
|
|
if (isNaN(date as unknown as number)) return null; |
|
|
|
|
|
|
|
return { |
|
|
|
day: date.getDate(), |
|
|
|
@ -26,4 +32,9 @@ export class DateAdapter extends NgbDateAdapter<string> { |
|
|
|
|
|
|
|
return formattedDate; |
|
|
|
} |
|
|
|
|
|
|
|
protected dateOf(value: string): Date { |
|
|
|
const dateUtc = new Date(Date.parse(value)); |
|
|
|
return new Date(dateUtc.getTime() + Math.abs(dateUtc.getTimezoneOffset() * 60000)); |
|
|
|
} |
|
|
|
} |
|
|
|
|