From 6877adb5fb93f7887aabacd9c3769e1bd7a0fb05 Mon Sep 17 00:00:00 2001 From: SheenaMalhotra182 Date: Wed, 4 Oct 2023 13:37:52 +0530 Subject: [PATCH] [ACS-5857] cleanup --- lib/core/src/lib/form/public-api.ts | 1 - .../date-format-translation.service.spec.ts | 72 ------------------- .../date-format-translation.service.ts | 60 ---------------- 3 files changed, 133 deletions(-) delete mode 100644 lib/core/src/lib/form/services/date-format-translation.service.spec.ts delete mode 100644 lib/core/src/lib/form/services/date-format-translation.service.ts diff --git a/lib/core/src/lib/form/public-api.ts b/lib/core/src/lib/form/public-api.ts index 15f0303eca..fa80753e8b 100644 --- a/lib/core/src/lib/form/public-api.ts +++ b/lib/core/src/lib/form/public-api.ts @@ -26,7 +26,6 @@ export * from './services/form-rendering.service'; export * from './services/form.service'; export * from './services/form-validation-service.interface'; export * from './services/widget-visibility.service'; -export * from './services/date-format-translation.service'; export * from './events'; diff --git a/lib/core/src/lib/form/services/date-format-translation.service.spec.ts b/lib/core/src/lib/form/services/date-format-translation.service.spec.ts deleted file mode 100644 index 171aa4e044..0000000000 --- a/lib/core/src/lib/form/services/date-format-translation.service.spec.ts +++ /dev/null @@ -1,72 +0,0 @@ -/*! - * @license - * Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { TestBed } from '@angular/core/testing'; -import { DateFormatTranslationService } from './date-format-translation.service'; -import { TranslateModule } from '@ngx-translate/core'; -import { CoreTestingModule } from '../../testing/core.testing.module'; - -describe('DateFormatTranslationService', () => { - let service: DateFormatTranslationService; - - beforeEach(() => { - TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), CoreTestingModule], - providers: [DateFormatTranslationService] - }); - - service = TestBed.inject(DateFormatTranslationService); - }); - - it('should convert moment to date-fns format correctly', () => { - const momentFormat = 'YYYY-MM-DD'; - const expectedDateFnsFormat = 'yyyy-MM-dd'; - - const result = service.convertMomentToDateFnsFormat(momentFormat); - - expect(result).toBe(expectedDateFnsFormat); - }); - - it('should convert date-fns to moment format correctly', () => { - const dateFnsFormat = 'yyyy-MM-dd'; - const expectedMomentFormat = 'YYYY-MM-DD'; - - const result = service.convertDateFnsToMomentFormat(dateFnsFormat); - - expect(result).toBe(expectedMomentFormat); - }); - - it('should format a date correctly', () => { - const date = new Date('2023-09-22T12:00:00Z'); - const dateFormat = 'yyyy-MM-dd'; - const expectedFormattedDate = '2023-09-22'; - - const result = service.format(date, dateFormat); - - expect(result).toBe(expectedFormattedDate); - }); - - it('should parse a date correctly', () => { - const dateString = '2023-09-22'; - const dateFormat = 'yyyy-MM-dd'; - const expectedParsedDate = new Date('2023-09-22T00:00:00Z'); - - const result = service.parse(dateString, dateFormat); - - expect(result).toEqual(expectedParsedDate); - }); -}); diff --git a/lib/core/src/lib/form/services/date-format-translation.service.ts b/lib/core/src/lib/form/services/date-format-translation.service.ts deleted file mode 100644 index 4016f96bda..0000000000 --- a/lib/core/src/lib/form/services/date-format-translation.service.ts +++ /dev/null @@ -1,60 +0,0 @@ -/*! - * @license - * Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { Injectable } from '@angular/core'; -import { format, parse } from 'date-fns'; - -@Injectable({ - providedIn: 'root' -}) -export class DateFormatTranslationService { - private momentToDateFnsMap = { - M: 'M', - D: 'd', - Y: 'y', - A: 'a' - }; - - private dateFnsToMomentMap = { - M: 'M', - d: 'D', - y: 'Y', - a: 'A' - }; - - convertMomentToDateFnsFormat(dateDisplayFormat: string): string { - for (const [search, replace] of Object.entries(this.momentToDateFnsMap)) { - dateDisplayFormat = dateDisplayFormat.replace(new RegExp(search, 'g'), replace); - } - return dateDisplayFormat; - } - - convertDateFnsToMomentFormat(dateDisplayFormat: string): string { - for (const [search, replace] of Object.entries(this.dateFnsToMomentMap)) { - dateDisplayFormat = dateDisplayFormat.replace(new RegExp(search, 'g'), replace); - } - return dateDisplayFormat; - } - - format(date: number|Date, dateFormat: string): string { - return format(date, this.convertMomentToDateFnsFormat(dateFormat)); - } - - parse(value: string, dateFormat: string, date = new Date()): Date { - return parse(value, this.convertMomentToDateFnsFormat(dateFormat), date); - } -}