Files
overleaf-cep/services/history-v1/backupVerifier/utils.mjs
T
Andrew Rumble 9d72eeeeac Add new strategy to verify_sampled_projects
GitOrigin-RevId: d967da41250bb5945d5b8668b212d4a61b4f9d69
2025-03-18 09:04:50 +00:00

28 lines
692 B
JavaScript

import { ObjectId } from 'mongodb'
import config from 'config'
export const RPO = parseInt(config.get('backupRPOInMS'), 10)
/**
* @param {Date} time
* @return {ObjectId}
*/
export function objectIdFromDate(time) {
return ObjectId.createFromTime(time.getTime() / 1000)
}
/**
* Creates a startDate, endDate pair that checks a period of time before the RPO horizon
*
* @param {number} offset - How many seconds we should check
* @return {{endDate: Date, startDate: Date}}
*/
export function getDatesBeforeRPO(offset) {
const now = new Date()
const endDate = new Date(now.getTime() - RPO)
return {
endDate,
startDate: new Date(endDate.getTime() - offset * 1000),
}
}