/** * Population counter for Jakrawal */ import React, { Component, createRef } from 'react' import { commatize } from "app/utils" import "./counter.css" export default class Counter extends Component { constructor(props) { super(props) this.ref = createRef() this.update = this.update.bind(this) } componentDidMount() { this.update() } componentWillUnmount() { clearTimeout(this.timeout) } update() { this.timeout = setTimeout(this.update, 250) const population = getPopulation() if (this.ref.current) { this.ref.current.innerHTML = commatize(population) } } render() { return (
CURRENT GLOBAL POPULATION
) } } const aprilFirst = new Date(2021, 3, 1) function getPopulation() { const popAprilFirst = 7855013899 const popChangePerDay = 219251.934066 const secondsDelta = (new Date() - aprilFirst) / 86400000 // april = month 3 const population = popAprilFirst + secondsDelta * popChangePerDay return Math.round(population) }