Skip to content

Commit

Permalink
[ACS-5861] Replace moment to date-fns in process-name.pipe.ts (#8831)
Browse files Browse the repository at this point in the history
  • Loading branch information
rbahirsheth committed Aug 25, 2023
1 parent 837b3b1 commit b77691b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
5 changes: 2 additions & 3 deletions lib/process-services/src/lib/pipes/process-name.pipe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import { TestBed } from '@angular/core/testing';
import { ProcessNamePipe } from './process-name.pipe';
import { TranslateModule } from '@ngx-translate/core';
import moment from 'moment';
import { LocalizedDatePipe, CoreTestingModule } from '@alfresco/adf-core';
import { ProcessInstance } from '../process-list';

Expand Down Expand Up @@ -57,13 +56,13 @@ describe('ProcessNamePipe', () => {
});

it('should add the current datetime to the process name', () => {
spyOn(moment, 'now').and.returnValue(mockCurrentDate);
spyOn(Date.prototype, 'getTime').and.returnValue(mockCurrentDate);
const transformResult = processNamePipe.transform(nameWithDatetimeIdentifier);
expect(transformResult).toEqual(`${defaultName} - ${mockLocalizedCurrentDate}`);
});

it('should add the current datetime and the selected process definition name when both identifiers are present', () => {
spyOn(moment, 'now').and.returnValue(mockCurrentDate);
spyOn(Date.prototype, 'getTime').and.returnValue(mockCurrentDate);
const transformResult = processNamePipe.transform(nameWithAllIdentifiers, fakeProcessInstanceDetails);
expect(transformResult).toEqual(`${defaultName} ${fakeProcessInstanceDetails.processDefinitionName} - ${mockLocalizedCurrentDate}`);
});
Expand Down
4 changes: 2 additions & 2 deletions lib/process-services/src/lib/pipes/process-name.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

import { Pipe, PipeTransform } from '@angular/core';
import moment from 'moment';
import { getTime } from 'date-fns';
import { LocalizedDatePipe } from '@alfresco/adf-core';
import { ProcessInstance } from '../process-list';

Expand All @@ -31,7 +31,7 @@ export class ProcessNamePipe implements PipeTransform {
transform(processNameFormat: string, processInstance?: ProcessInstance): string {
let processName = processNameFormat;
if (processName.match(DATE_TIME_IDENTIFIER_REG_EXP)) {
const presentDateTime = moment.now();
const presentDateTime = getTime(new Date());
processName = processName.replace(
DATE_TIME_IDENTIFIER_REG_EXP,
this.localizedDatePipe.transform(presentDateTime, 'medium')
Expand Down

0 comments on commit b77691b

Please sign in to comment.