Skip to content

Commit c8659d3

Browse files
CSimoesJrrafaellmarques
authored andcommitted
feat(datepicker): implementa timezone na data extendida
Implementa timezone de acordo com o fuso horário na data extendida fixes DTHFUI-7436
1 parent 383e37b commit c8659d3

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

projects/ui/src/lib/components/po-field/po-datepicker/po-datepicker-base.component.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,16 @@ describe('PoDatepickerBaseComponent:', () => {
505505
expect(component['onChangeModel']).toBe(undefined);
506506
expect(spyCallOnChange).toHaveBeenCalledTimes(1);
507507
}));
508+
509+
it('formatTimeAndHour: should call `formatTimeAndHour` with timezone negative', () => {
510+
component.formatTimezoneAndHour(180);
511+
expect(component['hour']).toBe('T00:00:00-03:00');
512+
});
513+
514+
it('formatTimeAndHour: should call `formatTimeAndHour` with timezone positive', () => {
515+
component.formatTimezoneAndHour(-180);
516+
expect(component['hour']).toBe('T00:00:00+03:00');
517+
});
508518
});
509519

510520
describe('Properties:', () => {

projects/ui/src/lib/components/po-field/po-datepicker/po-datepicker-base.component.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ export abstract class PoDatepickerBaseComponent implements ControlValueAccessor,
122122
*/
123123
@Output('p-change') onchange: EventEmitter<any> = new EventEmitter<any>();
124124

125+
offset: number;
125126
protected firstStart = true;
126127
protected hour: string = 'T00:00:00-00:00';
127128
protected isExtendedISO: boolean = false;
@@ -357,7 +358,10 @@ export abstract class PoDatepickerBaseComponent implements ControlValueAccessor,
357358
return this._locale || this.shortLanguage;
358359
}
359360

360-
constructor(protected languageService: PoLanguageService) {}
361+
constructor(protected languageService: PoLanguageService) {
362+
this.offset = new Date().getTimezoneOffset();
363+
this.formatTimezoneAndHour(this.offset);
364+
}
361365

362366
set date(value: any) {
363367
this._date = typeof value === 'string' ? convertIsoToDate(value, false, false) : value;
@@ -495,6 +499,16 @@ export abstract class PoDatepickerBaseComponent implements ControlValueAccessor,
495499
return new PoMask(mask, true);
496500
}
497501

502+
formatTimezoneAndHour(offset: number) {
503+
const offsetAbsolute = Math.abs(offset);
504+
const timezone =
505+
(offset < 0 ? '+' : '-') +
506+
('00' + Math.floor(offsetAbsolute / 60)).slice(-2) +
507+
':' +
508+
('00' + (offsetAbsolute % 60)).slice(-2);
509+
this.hour = 'T00:00:00' + timezone;
510+
}
511+
498512
abstract writeValue(value: any): void;
499513

500514
abstract refreshValue(value: Date): void;

projects/ui/src/lib/components/po-field/po-datepicker/po-datepicker.component.spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -998,10 +998,11 @@ describe('PoDatepickerComponent:', () => {
998998
expect(component.hour).toBe('T00:00:00-03:00');
999999
});
10001000

1001-
it('writeValue: should keep `hour` with it`s default value if date isn`t an extended iso format', () => {
1001+
it('writeValue: should keep `hour` with it`s default value if date isn`t an extended iso format and set other timezone', () => {
1002+
component.formatTimezoneAndHour(-180);
10021003
component.writeValue('2019-11-21');
10031004

1004-
expect(component.hour).toBe('T00:00:00-00:00');
1005+
expect(component.hour).toBe('T00:00:00+03:00');
10051006
});
10061007

10071008
it('onKeyup: should change value of the mask when typing', () => {

0 commit comments

Comments
 (0)