/*  Date class extention
    v1.0.1, 2009-09-10
    Copyright: Paul Philippov, paul@ppds.ws
    Homepage: http://themactep.com/jquery/beats/javascript_date_to_internet_time/
    License: BSD
*/

// Date.toInternetTime(n)
// Converts time to Swatch Internet Time format.
// n - the number of digits after decimal point.
Date.prototype.toInternetTime = function(n)
{
  const BEAT_IN_SECONDS = 86.4;

  var seconds = this.getUTCSeconds();
  var minutes = this.getUTCMinutes();
  var hours   = this.getUTCHours();
  hours = (hours == 23) ? 0 : hours + 1;

  var biel_mean_time = (hours * 60 + minutes) * 60 + seconds;
  var beats = Math.abs(biel_mean_time / BEAT_IN_SECONDS).toFixed(parseInt(n));

  var length = (n > 0) ? 1 + n : 0;

  return '@'.concat( '000'.concat(beats).slice(beats.length - length) );
}

// Date.getDayOfYear()
// Returns the number of days from the beginning of year to the date.
Date.prototype.getDayOfYear = function() {
  const DAY_IN_SECONDS = 86400000;
  var beginning_of_year = new Date(this.getFullYear(), 0, 1);
  return Math.ceil((this - beginning_of_year) / DAY_IN_SECONDS);
}
