Skip to content

Instantly share code, notes, and snippets.

@sramam
Last active January 27, 2018 16:07
Show Gist options
  • Select an option

  • Save sramam/f47e418299465f08ba5954e115a2822e to your computer and use it in GitHub Desktop.

Select an option

Save sramam/f47e418299465f08ba5954e115a2822e to your computer and use it in GitHub Desktop.
creating files with specific dates in the past - for testing file cleanup logic. (node.js)
const fs = require('fs');
const dir = '/tmp';
const now = Date.now();
const tmp = Date.now();
const dates = {
_31days: new Date(now - 31 * 24 * 60 * 60 * 1000),
_30days: new Date(now - 30 * 24 * 60 * 60 * 1000),
_29days: new Date(now - 29 * 24 * 60 * 60 * 1000),
_28days: new Date(now - 28 * 24 * 60 * 60 * 1000),
_27days: new Date(now - 27 * 24 * 60 * 60 * 1000),
_26days: new Date(now - 26 * 24 * 60 * 60 * 1000),
_25days: new Date(now - 25 * 24 * 60 * 60 * 1000),
_24days: new Date(now - 24 * 24 * 60 * 60 * 1000),
_23days: new Date(now - 23 * 24 * 60 * 60 * 1000),
_22days: new Date(now - 22 * 24 * 60 * 60 * 1000),
_21days: new Date(now - 21 * 24 * 60 * 60 * 1000),
_20days: new Date(now - 20 * 24 * 60 * 60 * 1000),
_19days: new Date(now - 19 * 24 * 60 * 60 * 1000),
_18days: new Date(now - 18 * 24 * 60 * 60 * 1000),
_17days: new Date(now - 17 * 24 * 60 * 60 * 1000),
_16days: new Date(now - 16 * 24 * 60 * 60 * 1000),
_15days: new Date(now - 15 * 24 * 60 * 60 * 1000),
_14days: new Date(now - 14 * 24 * 60 * 60 * 1000),
_13days: new Date(now - 13 * 24 * 60 * 60 * 1000),
_12days: new Date(now - 12 * 24 * 60 * 60 * 1000),
_11days: new Date(now - 11 * 24 * 60 * 60 * 1000),
_10days: new Date(now - 10 * 24 * 60 * 60 * 1000),
};
Object.keys(dates).map(k => {
const v = dates[k];
console.log(`${k}: ${v.toISOString()}`);
const fname = `${dir}/log${k}.json`;
fs.writeFileSync(fname, '');
fs.utimesSync(fname, v, v);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment