Skip to content

Commit 86d2ce6

Browse files
mohas22mohas22
authored andcommitted
added new function in formatters
1 parent 25be564 commit 86d2ce6

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { ComponentMapperComponent } from '../../../_bridge/component-mapper/comp
1313
import { dateFormatInfoDefault, getDateFormatInfo } from '../../../_helpers/date-format-utils';
1414
import { PConnFieldProps } from '../../../_types/PConnProps.interface';
1515
import { handleEvent } from '../../../_helpers/event-util';
16-
import { format } from '../../../_helpers/formatters';
16+
import { format, convertToTimezone } from '../../../_helpers/formatters';
1717

1818
interface DateTimeProps extends PConnFieldProps {
1919
// If any, enter additional props that only exist on DateTime here
@@ -92,7 +92,7 @@ export class DateTimeComponent implements OnInit, OnDestroy {
9292
this.formGroup$.addControl(this.controlName$, this.fieldControl);
9393
let dateTimeValue = this.value$ ?? '';
9494
if (this.value$) {
95-
dateTimeValue = dayjs(format(this.value$, 'convertToTimezone', { timezone: this.timezone }))?.toISOString();
95+
dateTimeValue = dayjs(convertToTimezone(this.value$, { timezone: this.timezone }))?.toISOString();
9696
}
9797
this.fieldControl.setValue(dateTimeValue);
9898
this.bHasForm$ = true;
@@ -140,7 +140,7 @@ export class DateTimeComponent implements OnInit, OnDestroy {
140140
this.value$ = this.configProps$?.value;
141141
let dateTimeValue = this.configProps$?.value ?? '';
142142
if (this.value$) {
143-
dateTimeValue = dayjs(format(this.value$, 'convertToTimezone', { timezone: this.timezone }))?.toISOString();
143+
dateTimeValue = dayjs(convertToTimezone(this.value$, { timezone: this.timezone }))?.toISOString();
144144
}
145145
this.fieldControl.setValue(dateTimeValue);
146146
// timeout and detectChanges to avoid ExpressionChangedAfterItHasBeenCheckedError

packages/angular-sdk-components/src/lib/_helpers/formatters/index.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -136,19 +136,21 @@ export function format(value, type, options = {}): string {
136136
break;
137137
}
138138

139-
case 'converttotimezone': {
140-
const defaultOptions = {
141-
type: 'customFormat',
142-
format: 'YYYY-MM-DDTHH:mm:ss',
143-
timezone: getCurrentTimezone()
144-
};
145-
const params = { ...defaultOptions, ...options };
146-
formattedValue = DateFormatter.convertToTimezone(value, params);
147-
break;
148-
}
149-
150139
default:
151140
formattedValue = value;
152141
}
153142
return formattedValue;
154143
}
144+
145+
export function convertToTimezone(value, options) {
146+
if (value && options) {
147+
const defaultOptions = {
148+
type: 'customFormat',
149+
format: 'YYYY-MM-DDTHH:mm:ss',
150+
timezone: getCurrentTimezone()
151+
};
152+
const params = { ...defaultOptions, ...options };
153+
return DateFormatter.convertToTimezone(value, params);
154+
}
155+
return value;
156+
}

0 commit comments

Comments
 (0)