<commit_before>/*

COPYRIGHT

Copyright 2012 <NAME>

This file is part of ServerDate.

ServerDate is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

ServerDate is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with ServerDate.  If not, see <http://www.gnu.org/licenses/>.

*/

'use strict';

//Date.now support for older browsers
if (!Date.now) {
    Date.now = function() { return new Date().getTime(); }
}

var ServerDate = (function(serverNow) {
// This is the first time we align with the server's clock by using the time
// this script was generated (serverNow) and noticing the client time before
// and after the script was loaded.  This gives us a good estimation of the
// server's clock right away, which we later refine during synchronization.

var
  // Remember when the script was loaded.
  scriptLoadTime = Date.now(),

  // Remember the URL of this script so we can call it again during
  // synchronization.
  scripts = document.getElementsByTagName("script"),
  URL = scripts[scripts.length - 1].src,

  synchronizationIntervalDelay,
  synchronizationInterval,
  precision,
  offset,
  target = null,
  synchronizing = false;

// Everything is in the global function ServerDate.  Unlike Date, there is no
// need for a constructor because there aren't instances.

/// PUBLIC

// Emulate Date's methods.

function ServerDate() {
  // See http://stackoverflow.com/a/18543216/1330099.
  return this
    ? ServerDate
    : ServerDate.toString();
}

ServerDate.parse = Date.parse;
ServerDate.UTC = Date.UTC;

ServerDate.now = function() {
  return Date.now() + offset;
};

// Populate ServerDate with the methods of Date's instances that don't change
// state.

["toString", "toDateString", "toTimeString", "toLocaleString",
  "toLocaleDateString", "toLocaleTimeString", "valueOf", "getTime",
  "getFullYear", "getUTCFullYear", "getMonth", "getUTCMonth", "getDate",
  "getUTCDate", "getDay", "getUTCDay", "getHours", "getUTCHours",
  "getMinutes", "getUTCMinutes", "getSeconds", "getUTCSeconds",
  "getMilliseconds", "getUTCMilliseconds", "getTimezoneOffset", "toUTCString",
  "toISOString", "toJSON"]
  .forEach(function(method) {
    ServerDate[method] = function() {
      return new Date(ServerDate.now())[method]();
    };
  });

// Because of network delays we can't be 100% sure of the server's time.  We do
// know the precision in milliseconds and make it available here.
ServerDate.getPrecision = function() // ms
{
  if (typeof target.precision != "undefined")
    // Take into account the amortization.
    return target.precision + Math.abs(target - offset);
};

// After a synchronization there may be a significant difference between our
// clock and the server's clock.  Rather than make the change abruptly, we
// change our clock by adjusting it once per second by the amortizationRate.
ServerDate.amortizationRate = 25; // ms

// The exception to the above is if the difference between the clock and
// server's clock is too great (threshold set below).  If that's the case then
// we skip amortization and set the clock to match the server's clock
// immediately.
ServerDate.amortizationThreshold = 500; // ms
<commit_msg>serverdate synchronize faster<commit_after>/*

COPYRIGHT

Copyright 2012 <NAME>

This file is part of ServerDate.

ServerDate is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

ServerDate is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with ServerDate.  If not, see <http://www.gnu.org/licenses/>.

*/

'use strict';

//Date.now support for older browsers
if (!Date.now) {
    Date.now = function() { return new Date().getTime(); }
}

var ServerDate = (function(serverNow) {
// This is the first time we align with the server's clock by using the time
// this script was generated (serverNow) and noticing the client time before
// and after the script was loaded.  This gives us a good estimation of the
// server's clock right away, which we later refine during synchronization.

var
  // Remember when the script was loaded.
  scriptLoadTime = Date.now(),

  // Remember the URL of this script so we can call it again during
  // synchronization.
  scripts = document.getElementsByTagName("script"),
  URL = scripts[scripts.length - 1].src,

  synchronizationIntervalDelay,
  synchronizationInterval,
  precision,
  offset,
  target = null,
  synchronizing = false;

// Everything is in the global function ServerDate.  Unlike Date, there is no
// need for a constructor because there aren't instances.

/// PUBLIC

// Emulate Date's methods.

function ServerDate() {
  // See http://stackoverflow.com/a/18543216/1330099.
  return this
    ? ServerDate
    : ServerDate.toString();
}

ServerDate.parse = Date.parse;
ServerDate.UTC = Date.UTC;

ServerDate.now = function() {
  return Date.now() + offset;
};

// Populate ServerDate with the methods of Date's instances that don't change
// state.

["toString", "toDateString", "toTimeString", "toLocaleString",
  "toLocaleDateString", "toLocaleTimeString", "valueOf", "getTime",
  "getFullYear", "getUTCFullYear", "getMonth", "getUTCMonth", "getDate",
  "getUTCDate", "getDay", "getUTCDay", "getHours", "getUTCHours",
  "getMinutes", "getUTCMinutes", "getSeconds", "getUTCSeconds",
  "getMilliseconds", "getUTCMilliseconds", "getTimezoneOffset", "toUTCString",
  "toISOString", "toJSON"]
  .forEach(function(method) {
    ServerDate[method] = function() {
      return new Date(ServerDate.now())[method]();
    };
  });

// Because of network delays we can't be 100% sure of the server's time.  We do
// know the precision in milliseconds and make it available here.
ServerDate.getPrecision = function() // ms
{
  if (typeof target.precision != "undefined")
    // Take into account the amortization.
    return target.precision + Math.abs(target - offset);
};

// After a synchronization there may be a significant difference between our
// clock and the server's clock.  Rather than make the change abruptly, we
// change our clock by adjusting it once per second by the amortizationRate.
ServerDate.amortizationRate = 25; // ms

// The exception to the above is if the difference between the clock and
// server's clock is too great (threshold set below).  If that's the case then
// we skip amortization and set the clock to match the server's clock
// immediately.
ServerDate.amortizationThreshold = 100; // ms

{'fraction_non_alphanumeric': 0.09850166481687014, 'fraction_numerical': 0.00804661487236404, 'mean_word_length': 4.01670146137787, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6626114', 'n_tokens_mistral': 2073, 'n_tokens_neox': 1980, 'n_words': 844}