Highly disastrous internal date bug
Closed this issue · 1 comments
krunkosaurus commented
The code:
const EthDater = require('ethereum-block-by-date');
const { ethers } = require('ethers');
const provider = new ethers.providers.getDefaultProvider('YOUR PROVIDER');
const dater = new EthDater(
provider // Ethers provider, required.
);
async function getBlockFromDate(date){
console.log('for...', date);
let block = await dater.getDate(
//'2016-07-20T13:20:40Z', // Date, required. Any valid moment.js value: string, milliseconds, Date() object, moment() object.
'2022-04-08T03:37:45.000Z',
true, // Block after, optional. Search for the nearest block before or after the given date. By default true.
false // Refresh boundaries, optional. Recheck the latest block before request. By default false.
);
console.log('block', block);
}
const dates = [
'2022-02-08T03:37:45.000Z',
'2022-03-08T03:37:45.000Z',
'2022-04-08T03:37:45.000Z',
];
async function init(){
for (const d of dates){
console.log('d', d);
await getBlockFromDate(d)
}
}
init();
The output:
d 2022-02-08T03:37:45.000Z
for... 2022-02-08T03:37:45.000Z
block {
date: '2022-04-08T03:37:45Z',
block: 26875912,
timestamp: 1649389067
}
d 2022-03-08T03:37:45.000Z
for... 2022-03-08T03:37:45.000Z
block {
date: '2022-04-08T03:37:45Z',
block: 26875912,
timestamp: 1649389067
}
d 2022-04-08T03:37:45.000Z
for... 2022-04-08T03:37:45.000Z
block {
date: '2022-04-08T03:37:45Z',
block: 26875912,
timestamp: 1649389067
}
krunkosaurus commented
Ah I had a typo