date-fns#fromUnixTime JavaScript Examples

The following examples show how to use date-fns#fromUnixTime. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: formatDate.js    From pooltogether-governance-ui with MIT License 6 votes vote down vote up
formatDate = (date, options = {}) => {
  if (!date) {
    return
  }

  let formatStr = 'MMM do, yyyy, HH:mm'

  if (options.short) {
    formatStr = 'MMM do, yyyy'

    if (!isUndefined(options.year) && options.year === false) {
      formatStr = 'MMM do'
    }
  }

  date = typeof fromUnixTime(date) === 'object' ? date : fromUnixTime(date)

  return poolFormat(date, currentLang, formatStr, options.noAbbrev)
}
Example #2
Source File: formatDate.js    From v3-ui with MIT License 6 votes vote down vote up
formatDate = (date, options = {}) => {
  if (!date) {
    return
  }

  let formatStr = 'MMM do, yyyy, HH:mm'

  if (options.short) {
    formatStr = 'MMM do, yyyy'

    if (!isUndefined(options.year) && options.year === false) {
      formatStr = 'MMM do'
    }
  }

  date = typeof fromUnixTime(date) === 'object' ? date : fromUnixTime(date)

  return poolFormat(date, currentLang, formatStr, options.noTimezone)
}
Example #3
Source File: TicketsSoldGraph.jsx    From v3-ui with MIT License 5 votes vote down vote up
TicketsSoldGraph = (props) => {
  const { pool } = props

  const { t } = useTranslation()

  let { data: prizes } = usePastPrizes(pool, 1, CHART_PRIZE_PAGE_SIZE)

  const { symbol, decimals } = pool.tokens.underlyingToken

  // Filter out prize objects that are being awarded right now
  prizes = prizes.filter((prize) => !isEmpty(prize))

  const lastPrize = prizes[0]
  let currentPrize

  if (lastPrize?.awardedBlock) {
    currentPrize = {
      ticketSupply: pool.tokens.ticket.totalSupplyUnformatted,
      awardedTimestamp: Date.now() / 1000
    }

    prizes.unshift(currentPrize)
  }

  const dataArray = prizes.map((prize) => {
    const tickets = prize?.awardedBlock ? prize?.totalTicketSupply : prize?.ticketSupply

    const ticketsSold = ethers.utils.formatUnits(
      tickets || '0',
      decimals || DEFAULT_TOKEN_PRECISION
    )

    return {
      value: parseFloat(ticketsSold),
      date: fromUnixTime(prize.awardedTimestamp)
    }
  })

  if (dataArray.length < CHART_PRIZE_PAGE_SIZE) {
    dataArray.push({
      value: 0,
      date: sub(dataArray[dataArray.length - 1]?.date, {
        years: 0,
        months: 0,
        weeks: 1,
        days: 0,
        hours: 0,
        minutes: 0,
        seconds: 0
      })
    })
  }

  return (
    <DateValueLineGraph
      id='tickets-sold-graph'
      valueLabel={t('depositedTicker', { ticker: symbol.toUpperCase() })}
      data={[dataArray]}
    />
  )
}