Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bugfix] Go-Datepicker: Set timezone based on user's settings #282

Merged
merged 2 commits into from
Oct 23, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions projects/go-lib/src/lib/components/go-datepicker/date-adapter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export class DateAdapter {
private _locale: string;
private _timezone: string;
public monthNames: Array<string>;
public dateNames: Array<string>;
public daysOfWeek: Array<string>;
Expand All @@ -10,13 +11,14 @@ export class DateAdapter {

public setLocale(locale: string): void {
this._locale = locale;
this._timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
this.setMonthNames();
this.setDateNames();
this.setDayOfWeekNames();
}

public getYearName(year: number): string {
const format: Intl.DateTimeFormat = new Intl.DateTimeFormat(this._locale, {year: 'numeric', timeZone: 'utc'});
const format: Intl.DateTimeFormat = new Intl.DateTimeFormat(this._locale, {year: 'numeric', timeZone: this._timezone});
patrick-lewandowski marked this conversation as resolved.
Show resolved Hide resolved

return this.format(format, new Date(year, 0, 1));
}
Expand Down Expand Up @@ -63,7 +65,7 @@ export class DateAdapter {
}

private getMonthNames(style: 'long' | 'short' | 'narrow'): Array<string> {
const format: Intl.DateTimeFormat = new Intl.DateTimeFormat(this._locale, {month: style, timeZone: 'utc'});
const format: Intl.DateTimeFormat = new Intl.DateTimeFormat(this._locale, {month: style, timeZone: this._timezone});
const months: Array<string> = [];
for (let i: number = 0; i < 12; i++) {
months.push(this.format(format, new Date(2017, i, 1)));
Expand All @@ -72,7 +74,7 @@ export class DateAdapter {
}

private getDateNames(): Array<string> {
const format: Intl.DateTimeFormat = new Intl.DateTimeFormat(this._locale, {day: 'numeric', timeZone: 'utc'});
const format: Intl.DateTimeFormat = new Intl.DateTimeFormat(this._locale, {day: 'numeric', timeZone: this._timezone});
const dates: Array<string> = [];

for (let i: number = 0; i < 31; i++) {
Expand All @@ -83,7 +85,7 @@ export class DateAdapter {
}

private getDayOfWeekNames(style: 'long' | 'short' | 'narrow'): Array<string> {
const format: Intl.DateTimeFormat = new Intl.DateTimeFormat(this._locale, {weekday: style, timeZone: 'utc'});
const format: Intl.DateTimeFormat = new Intl.DateTimeFormat(this._locale, {weekday: style, timeZone: this._timezone});
const dayNames: Array<string> = [];

for (let i: number = 0; i < 7; i++) {
Expand Down