Skip to content

Commit

Permalink
[ACS-5876] Change from moment to date-fns for lock.service. (#8862)
Browse files Browse the repository at this point in the history
* [ACS-5876] Change from moment to date-fns for lock.service.

* [ACS-5876] Unit test update.
  • Loading branch information
arohilaGL authored Aug 31, 2023
1 parent c83d92c commit c6fdbd6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import { TestBed } from '@angular/core/testing';
import { LockService } from './lock.service';
import { CoreTestingModule, AlfrescoApiService } from '@alfresco/adf-core';
import { Node } from '@alfresco/js-api';
import moment from 'moment';
import { TranslateModule } from '@ngx-translate/core';
import { addDays, subDays } from 'date-fns';

describe('PeopleProcessService', () => {

Expand Down Expand Up @@ -75,7 +75,7 @@ describe('PeopleProcessService', () => {
'cm:lockType': 'WRITE_LOCK',
'cm:lockLifetime': 'PERSISTENT',
'cm:lockOwner': { id: 'lock-owner-user' },
'cm:expiryDate': moment().subtract(4, 'days')
'cm:expiryDate': subDays(new Date(), 4)
}
} as Node;

Expand All @@ -88,7 +88,7 @@ describe('PeopleProcessService', () => {
'cm:lockType': 'WRITE_LOCK',
'cm:lockLifetime': 'PERSISTENT',
'cm:lockOwner': { id: 'lock-owner-user' },
'cm:expiryDate': moment().add(4, 'days')
'cm:expiryDate': addDays(new Date(), 4)
}
} as Node;

Expand Down Expand Up @@ -127,7 +127,7 @@ describe('PeopleProcessService', () => {
'cm:lockType': 'WRITE_LOCK',
'cm:lockLifetime': 'PERSISTENT',
'cm:lockOwner': { id: 'lock-owner-user' },
'cm:expiryDate': moment().subtract(4, 'days')
'cm:expiryDate': subDays(new Date(), 4)
}
} as Node;

Expand All @@ -140,7 +140,7 @@ describe('PeopleProcessService', () => {
'cm:lockType': 'WRITE_LOCK',
'cm:lockLifetime': 'PERSISTENT',
'cm:lockOwner': { id: 'lock-owner-user' },
'cm:expiryDate': moment().add(4, 'days')
'cm:expiryDate': addDays(new Date(), 4)
}
} as Node;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import { Injectable } from '@angular/core';
import { Node } from '@alfresco/js-api';
import { AuthenticationService } from '@alfresco/adf-core';
import moment, { Moment } from 'moment';
import { isAfter } from 'date-fns';

@Injectable({
providedIn: 'root'
Expand Down Expand Up @@ -55,17 +55,17 @@ export class LockService {
return node.properties['cm:lockType'] === 'WRITE_LOCK' && node.properties['cm:lockLifetime'] === 'PERSISTENT';
}

private getLockExpiryTime(node: Node): Moment | undefined {
private getLockExpiryTime(node: Node): Date | undefined {
if (node.properties['cm:expiryDate']) {
return moment(node.properties['cm:expiryDate'], 'yyyy-MM-ddThh:mm:ssZ');
return new Date(node.properties['cm:expiryDate']);
}
return undefined;
}

private isLockExpired(node: Node): boolean {
const expiryLockTime = this.getLockExpiryTime(node);
if (expiryLockTime) {
return moment().isAfter(expiryLockTime);
return isAfter(new Date(), expiryLockTime);
}
return false;
}
Expand Down

0 comments on commit c6fdbd6

Please sign in to comment.