Sha256: ec06c02754bb0828593bb56959d4de7893650407773b708b975e439cf9f8839e

Contents?: true

Size: 1.32 KB

Versions: 1

Compression:

Stored size: 1.32 KB

Contents

<span class="glyphicon glyphicon-globe"></span>
<span id="sell-usd-exchange-rates"></span>
<span class="glyphicon glyphicon-info-sign hidden-xs"></span>
<span id="updated-at-usd-exchange-rates" class="hidden-xs"></span>

<script>
  function capitalize(string) {
    return string.charAt(0).toUpperCase() + string.slice(1);
  }

  function monthName(date, locale, type){
    name = date.toLocaleString(locale, { month: type });
    return capitalize(name);
  }

  function parseDate(date){
    return  date.getDate() + " / " +
            monthName(date, 'es-MX', "short") + " / " +
            date.getFullYear() + " " +
            ((date.getHours()%12)?(date.getHours()%12):12) + ":" +
            (date.getMinutes()<10?'0':'') + date.getMinutes() +
            (date.getHours()>=12?' PM':' AM');
  }

  getRealtimeExchangeRates = function() {
    const docRef = firestoredb.doc("exchange-rates/usd");
    const usdSell = document.querySelector("#sell-usd-exchange-rates");
    const usdUpdatedAt = document.querySelector("#updated-at-usd-exchange-rates");

    docRef.onSnapshot(function (doc){
      if (doc && doc.exists) {
        const data = doc.data();
        usdSell.innerText = "USD: " + data.sell.toFixed(2);
        usdUpdatedAt.innerText = parseDate(new Date(data.updated_at));
      }
    });
  }

  getRealtimeExchangeRates();
</script>

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jekyll-theme-marketing-0.5.0 _includes/body/header/exchange-rates/usd.html