/**
 * Sort predicates for dates.
 */ import Post from "../models/Post.d" ; export const byCreatedAtLatestFirst = ( first , second ) : number => { if ( ! first || ! first . createdAt ) { return 1 ; } if ( ! second || ! second . createdAt ) { return - 1 ; } const firstDate = new Date ( first . createdAt ) ; const secondDate = new Date ( second . createdAt ) ; return secondDate - firstDate ; } ; export const byCreatedAtOldestFirst = ( first , second ) : number => { return byCreatedAtLatestFirst ( second , first ) ; } ; export const byCommentedAtLatestFirst = ( first , second ) : number => { if ( ! first || ! first . lastCommentedAt ) { return 1 ; } if ( ! second || ! second . lastCommentedAt ) { return - 1 ; } const firstDate = new Date ( first . lastCommentedAt ) ; const secondDate = new Date ( second . lastCommentedAt ) ; return secondDate - firstDate ; } ; export const byCommentedAtOldestFirst = ( first , second ) : number => { return byCommentedAtLatestFirst ( second , first ) ; } ;