Published
Edited
Dec 20, 2020
Importers
5 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function dateToEpoch(date) {
var diff_ms = (date - filecoinNetworkStartTime)
if (diff_ms < 0) {
throw new Error("date must be greater than filecoinNetworkStartTime")
}
var diff_s = Math.floor(Math.abs(diff_ms) / 1000)
var epoch = Math.floor(diff_s / blockTimeSec)
return epoch
}
Insert cell
function epochToDate(epoch) {
var diff_s = blockTimeSec * epoch
var diff_ms = diff_s * 1000
var date = new Date(filecoinNetworkStartTime.getTime() + diff_ms)
return date
}
Insert cell
function parseInput(input) {
console.log('input:', input)
var intStr = input.replaceAll(",", "")
var e = parseInt(intStr, 10)
if (("" + e) != intStr) {
// maybe it's a date
var d = moment(input).toDate()
e = dateToEpoch(d)
}
// convert back to date always, to get the right seconds for the epoch.
return { epoch: e, date: epochToDate(e) }
}
Insert cell
function genZones(parsed) {
var d = parsed.date
var f = 'YYYY-MM-DD HH:mm:ss'
var fmt = (d, tz) => moment(d).tz(tz).format(f)
var o = (a, b) => ({'Zone': a, 'Time': b })
return [
o('Filecoin Epoch', parsed.epoch),
o('local', moment(d).format(f)),
o('', ''),
o('PST / PDT', fmt(d, "America/Los_Angeles")),
o('EST / EDT', fmt(d, "America/New_York")),
o('UTC', moment(d).utc().format(f)),
o('CET / CEST', fmt(d, "Europe/Berlin")),
o('CST', fmt(d, "Asia/Shanghai")),
]
}
Insert cell
Type JavaScript, then Shift-Enter. Ctrl-space for more options. Arrow ↑/↓ to switch modes.

Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more