date-fns#max TypeScript Examples
The following examples show how to use
date-fns#max.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: getLastLogin.ts From staticshield with MIT License | 6 votes |
getLastLogin = (data: HarperDBRecord[]) => {
if (!data) {
return new Date().valueOf();
}
const timestamps = [];
data?.forEach((site) => {
timestamps.push(site.last_login);
});
const latest = max(timestamps);
return +latest;
}
Example #2
Source File: document.ts From MDDL with MIT License | 6 votes |
documentsInAnyCollectionWithGrantAndOwner = async (
ownerId: string,
requirementType: string,
requirementValue: string,
): Promise<SharedDocument[]> => {
const foundDocuments = (await Document.query()
.join(
CollectionDocument.tableName,
Document.ref('id'),
CollectionDocument.ref('documentId'),
)
.join(
CollectionGrant.tableName,
CollectionDocument.ref('collectionId'),
CollectionGrant.ref('collectionId'),
)
.where(CollectionGrant.ref('requirementType'), requirementType)
.where(CollectionGrant.ref('requirementValue'), requirementValue)
.where(CollectionGrant.ref('ownerId'), ownerId)
.modify('fieldsForList')
.select(
CollectionGrant.ref('createdBy as grantCreatedBy'),
CollectionGrant.ref('createdAt as grantCreatedAt'),
CollectionDocument.ref('createdBy as documentCollectionCreatedBy'),
CollectionDocument.ref('createdAt as documentCollectionCreatedAt'),
)
.orderBy(Document.ref('createdAt'))) as SharedDocument[]
// we sort ascending here as we will flip the array after removing duplicates
const sortedDocuments = foundDocuments.sort((d1, d2) => {
return compareAsc(
max([d1.documentCollectionCreatedAt, d1.grantCreatedAt]),
max([d2.documentCollectionCreatedAt, d2.grantCreatedAt]),
)
})
const deduplicatedDocumentsObj: { [index: string]: SharedDocument } = {}
sortedDocuments.map((d) => (deduplicatedDocumentsObj[d.id] = d))
return Object.values(deduplicatedDocumentsObj).reverse()
}