Skip to content

Commit 65af44d

Browse files
mohas22mohas22
authored andcommitted
changes for datetime component to use timezone
1 parent e29e3db commit 65af44d

File tree

4 files changed

+28
-19
lines changed

4 files changed

+28
-19
lines changed

packages/angular-sdk-components/src/lib/_components/field/date-time/date-time.component.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
[placeholder]="placeholder"
1414
[formControl]="fieldControl"
1515
(dateTimeChange)="fieldOnDateChange($event)"
16-
[value]="value$"
1716
[required]="bRequired$"
1817
/>
1918
<mat-datepicker-toggle matSuffix [owlDateTimeTrigger]="dtPicker"></mat-datepicker-toggle>

packages/angular-sdk-components/src/lib/_components/field/date-time/date-time.component.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,11 @@ export class DateTimeComponent implements OnInit, OnDestroy {
9292
if (this.formGroup$) {
9393
// add control to formGroup
9494
this.formGroup$.addControl(this.controlName$, this.fieldControl);
95-
this.fieldControl.setValue(dayjs(DateFormatter?.convertToTimezone(this.value$, { timezone: this.timezone }))?.toISOString());
95+
let dateTimeValue = this.value$ ?? '';
96+
if (this.value$ && this.value$ !== '') {
97+
dateTimeValue = dayjs(DateFormatter?.convertToTimezone(this.value$, { timezone: this.timezone }))?.toISOString();
98+
}
99+
this.fieldControl.setValue(dateTimeValue);
96100
this.bHasForm$ = true;
97101
} else {
98102
this.bReadonly$ = true;
@@ -136,7 +140,11 @@ export class DateTimeComponent implements OnInit, OnDestroy {
136140
this.testId = this.configProps$.testId;
137141
this.helperText = this.configProps$.helperText;
138142
this.value$ = this.configProps$?.value;
139-
this.fieldControl.setValue(dayjs(DateFormatter?.convertToTimezone(this.value$, { timezone: this.timezone }))?.toISOString());
143+
let dateTimeValue = this.configProps$?.value ?? '';
144+
if (this.value$ && this.value$ !== '') {
145+
dateTimeValue = dayjs(DateFormatter?.convertToTimezone(this.value$, { timezone: this.timezone }))?.toISOString();
146+
}
147+
this.fieldControl.setValue(dateTimeValue);
140148
// timeout and detectChanges to avoid ExpressionChangedAfterItHasBeenCheckedError
141149
setTimeout(() => {
142150
if (this.configProps$.required != null) {

packages/angular-sdk-components/src/lib/_components/field/text/text.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ export class TextComponent implements OnInit, OnDestroy {
144144
generateDateTime(sVal): string {
145145
if (!sVal) return '';
146146
if (sVal.length === 10) return this.generateDate(sVal);
147-
const value = sVal.substring(0, sVal.length - 1);
147+
// const value = sVal.substring(0, sVal.length - 1);
148148
// value = new Intl.DateTimeFormat('default', {
149149
// year: 'numeric',
150150
// month: 'numeric',
@@ -155,6 +155,6 @@ export class TextComponent implements OnInit, OnDestroy {
155155
// hour12: true,
156156
// }).format(new Date(value))
157157

158-
return this.utils.generateDateTime(value, 'DateTime-Long-YYYY-Custom');
158+
return this.utils.generateDateTime(sVal, 'DateTime-Long-YYYY-Custom');
159159
}
160160
}

packages/angular-sdk-components/src/lib/_helpers/utils.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ export class Utils {
1717

1818
viewContainerCount = 0;
1919

20+
timezone = PCore.getEnvironmentInfo()?.getTimeZone();
21+
2022
constructor(private scService: ServerConfigService) {}
2123

2224
getSDKStaticContentUrl() {
@@ -271,61 +273,61 @@ export class Utils {
271273
switch (dateFormat) {
272274
case 'DateTime-Short':
273275
// 1/1/01 1:00 AM
274-
sReturnDate = dayjs(dateTimeVal).format('M/D/YY h:mm A');
276+
sReturnDate = dayjs(dateTimeVal).tz(this.timezone).format('M/D/YY h:mm A');
275277
break;
276278
case 'DateTime-Short-Custom':
277279
// 01/01/01 01:00 AM
278-
sReturnDate = dayjs(dateTimeVal).format('MM/DD/YY hh:mm A');
280+
sReturnDate = dayjs(dateTimeVal).tz(this.timezone).format('MM/DD/YY hh:mm A');
279281
break;
280282
case 'DateTime-Short-YYYY-Custom':
281283
// 01/01/2001 01:00 AM
282-
sReturnDate = dayjs(dateTimeVal).format('M/D/YYYY hh:mm A');
284+
sReturnDate = dayjs(dateTimeVal).tz(this.timezone).format('M/D/YYYY hh:mm A');
283285
break;
284286
case 'DateTime-Long-YYYY-Custom':
285287
// 01/01/01 01:00 AM
286-
sReturnDate = dayjs(dateTimeVal).format('MM/DD/YYYY, hh:mm A');
288+
sReturnDate = dayjs(dateTimeVal).tz(this.timezone).format('MM/DD/YYYY, hh:mm A');
287289
break;
288290
case 'DateTime-Short-YYYY':
289291
// 1/1/2001 1:00 AM
290-
sReturnDate = dayjs(dateTimeVal).format('M/D/YYYY h:mm A');
292+
sReturnDate = dayjs(dateTimeVal).tz(this.timezone).format('M/D/YYYY h:mm A');
291293
break;
292294
case 'DateTime-Medium':
293295
// Jan 1, 2001 1:00:00 AM
294-
sReturnDate = dayjs(dateTimeVal).format('MMM D, YYYY h:mm:ss A');
296+
sReturnDate = dayjs(dateTimeVal).tz(this.timezone).format('MMM D, YYYY h:mm:ss A');
295297
break;
296298
case 'DateTime-Long':
297299
// January 1, 2001 1:00:00 AM
298-
sReturnDate = dayjs(dateTimeVal).format('MMMM D, YYYY h:mm:ss A');
300+
sReturnDate = dayjs(dateTimeVal).tz(this.timezone).format('MMMM D, YYYY h:mm:ss A');
299301
break;
300302
case 'DateTime-DayMonthYear-Custom':
301303
// 01-Jan-2001 1:00:00 AM
302-
sReturnDate = dayjs(dateTimeVal).format('DD-MMM-YYYY h:mm:ss A');
304+
sReturnDate = dayjs(dateTimeVal).tz(this.timezone).format('DD-MMM-YYYY h:mm:ss A');
303305
break;
304306
case 'DateTime-Full':
305307
// Monday, January 1, 2001 1:00 AM EDT
306-
sReturnDate = dayjs(dateTimeVal).format('dddd, MMMM D, YYYY h:mm A z');
308+
sReturnDate = dayjs(dateTimeVal).tz(this.timezone).format('dddd, MMMM D, YYYY h:mm A z');
307309
break;
308310
case 'DateTime-Frame':
309311
case 'DateTime-Frame-Short':
310312
case 'DateTime-Since':
311313
// 2 days, 5 hours ago
312-
sReturnDate = dayjs(dateTimeVal).fromNow();
314+
sReturnDate = dayjs(dateTimeVal).tz(this.timezone).fromNow();
313315
break;
314316
case 'DateTime-ISO-8601':
315317
// 2001/01/01 1:00:00 AM y/m/d
316-
sReturnDate = dayjs(dateTimeVal).format('YYYY/MM/DD h:mm:ss A');
318+
sReturnDate = dayjs(dateTimeVal).tz(this.timezone).format('YYYY/MM/DD h:mm:ss A');
317319
break;
318320
case 'DateTime-Gregorian-1':
319321
// 01 January, 2001 1:00:00 AM
320-
sReturnDate = dayjs(dateTimeVal).format('DD MMMM, YYYY h:mm:ss A');
322+
sReturnDate = dayjs(dateTimeVal).tz(this.timezone).format('DD MMMM, YYYY h:mm:ss A');
321323
break;
322324
case 'DateTime-Gregorian-2':
323325
// January 01, 2001 1:00:00 AM
324-
sReturnDate = dayjs(dateTimeVal).format('MMMM DD, YYYY h:mm:ss A');
326+
sReturnDate = dayjs(dateTimeVal).tz(this.timezone).format('MMMM DD, YYYY h:mm:ss A');
325327
break;
326328
case 'DateTime-Gregorian-3':
327329
// 2001, January 01 1:00:00 AM
328-
sReturnDate = dayjs(dateTimeVal).format('YYYY, MMMM DD h:mm:ss A');
330+
sReturnDate = dayjs(dateTimeVal).tz(this.timezone).format('YYYY, MMMM DD h:mm:ss A');
329331
break;
330332
case 'DateTime-Custom':
331333
break;

0 commit comments

Comments
 (0)