git ssb

0+

cel / ssb-activity



Commit 751227258275c4e50803a031d8e66f74e3c68892

Fix month start date calculation

cel committed on 3/6/2021, 7:31:42 PM
Parent: 9241af5555557951a99069e9e9a1f2c29a6623d6

Files changed

counts.jschanged
peeks.shchanged
counts.jsView
@@ -41,14 +41,24 @@
4141 var height = info.max
4242
4343 var last = Date.now() - 86400e3
4444
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 + }
4757 }
4858
4959 var max = 0
50-var maxDate
60 +var maxTs
5161
5262 pull(
5363 File(path.join(__dirname, series + '.jsonp')),
5464 Split(),
@@ -56,17 +66,12 @@
5666 pull.map(JSON.parse),
5767 pull.drain(function (interval) {
5868 var ms = interval.time * unit
5969 if (ms > last) return
60- if (series === 'month') {
61- ms += 86400e3
62- // TODO: fix month start time
63- }
64- var d = new Date(ms)
6570 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)
6873 }, function (err) {
6974 if (err) throw err
70- console.log(toISODateString(maxDate), max, 'max')
75 + console.log(toDateString(maxTs), max, 'max')
7176 })
7277 )
peeks.shView
@@ -1,5 +1,4 @@
11 #!/bin/sh
22 node counts.js day| tail -1
33 node counts.js week| tail -1
4-node counts.js month| tail -1 | sed 's/-01 / /'
5-
4 +node counts.js month| tail -1

Built with git-ssb-web