Commit 751227258275c4e50803a031d8e66f74e3c68892
Fix month start date calculation
cel committed on 3/6/2021, 7:31:42 PMParent: 9241af5555557951a99069e9e9a1f2c29a6623d6
Files changed
counts.js | changed |
peeks.sh | changed |
counts.js | ||
---|---|---|
@@ -41,14 +41,24 @@ | ||
41 | 41 … | var height = info.max |
42 | 42 … | |
43 | 43 … | var last = Date.now() - 86400e3 |
44 | 44 … | |
45 | -function toISODateString(d) { | |
46 | - return d.toISOString().replace(/T.*/, '') | |
45 … | +function toDateString(ms) { | |
46 … | + var d | |
47 … | + if (series === 'month') { | |
48 … | + // Pick a date in the middle of the month, to correct for variations in | |
49 … | + // month length. | |
50 … | + ms += 3*86400e3 | |
51 … | + d = new Date(ms) | |
52 … | + return d.toISOString().replace(/-..T.*/, '') | |
53 … | + } else { | |
54 … | + d = new Date(ms) | |
55 … | + return d.toISOString().replace(/T.*/, '') | |
56 … | + } | |
47 | 57 … | } |
48 | 58 … | |
49 | 59 … | var max = 0 |
50 | -var maxDate | |
60 … | +var maxTs | |
51 | 61 … | |
52 | 62 … | pull( |
53 | 63 … | File(path.join(__dirname, series + '.jsonp')), |
54 | 64 … | Split(), |
@@ -56,17 +66,12 @@ | ||
56 | 66 … | pull.map(JSON.parse), |
57 | 67 … | pull.drain(function (interval) { |
58 | 68 … | var ms = interval.time * unit |
59 | 69 … | if (ms > last) return |
60 | - if (series === 'month') { | |
61 | - ms += 86400e3 | |
62 | - // TODO: fix month start time | |
63 | - } | |
64 | - var d = new Date(ms) | |
65 | 70 … | var count = interval.ids.length |
66 | - if (count > max) max = count, maxDate = d | |
67 | - console.log(toISODateString(d), count) | |
71 … | + if (count > max) max = count, maxTs = ms | |
72 … | + console.log(toDateString(ms), count) | |
68 | 73 … | }, function (err) { |
69 | 74 … | if (err) throw err |
70 | - console.log(toISODateString(maxDate), max, 'max') | |
75 … | + console.log(toDateString(maxTs), max, 'max') | |
71 | 76 … | }) |
72 | 77 … | ) |
Built with git-ssb-web