Skip to content

Instantly share code, notes, and snippets.

@joyeecheung
Created April 8, 2018 07:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joyeecheung/34d1660322adf2e47211757916dc269f to your computer and use it in GitHub Desktop.
Save joyeecheung/34d1660322adf2e47211757916dc269f to your computer and use it in GitHub Desktop.
Get frequency of committed time, in UTC hours
'use strict';
const child_process = require('child_process');
const log = child_process.spawnSync('git', ['log', '--format=%cI', '-n', '10000'], {
cwd: process.cwd()
});
const dates = log.stdout.toString().trim();
const hours = dates.split('\n').map(d => new Date(d).getUTCHours());
const map = new Map();
for (const h of hours) {
if (map.has(h)) {
map.set(h, map.get(h) + 1);
} else {
map.set(h, 1);
}
}
const pairs = [...map.entries()].sort((a, b) => a[1] > b[1] ? -1 : 1);
console.log(pairs);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment