Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
molekilla committed May 2, 2019
1 parent 55eb3a4 commit bc73c6d
Show file tree
Hide file tree
Showing 6 changed files with 3,999 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export declare class BlockNumberDateConverter {
constructor();
static getPastBlockNumber(currentBlock: any, date: any): number;
}
13 changes: 13 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import moment from 'moment';
export class BlockNumberDateConverter {
constructor() { }
static getPastBlockNumber(currentBlock, date) {
const BLOCK_PERIOD = 10;
const now = moment();
const query = moment(date);
const seconds = now.diff(query, 'seconds');
const blocks = Math.round(seconds / BLOCK_PERIOD);
const findBlock = currentBlock - blocks;
return findBlock;
}
}
Loading

0 comments on commit bc73c6d

Please sign in to comment.