How to use the duration function in duration

To help you get started, we’ve selected a few duration examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mozilla / fxa / packages / fxa-content-server / app / scripts / lib / assertion.js View on Github external
'use strict';

import Duration from 'duration';
import P from './promise';

// The CERT_DURATION_MS is an offset from the fxa-auth-server clock, which we can reasonably assume to
// be accurate and, more importantly, in sync with the clocks of fxa-oauth-server and other consumers
// of these assertions.
const CERT_DURATION_MS =  new Duration('6h').milliseconds();
// The ASSERTION_DURATION_MS is an offset from the client's local clock, which may be wildly
// inaccurate in practice. If a user's local clock is more than ASSERTION_DURATION_MS off
// from the clock on fxa-oauth-server, then it will generate assertions with an expiry timestamp
// in the past, which will always be rejected by the server. The Firefox desktop code uses a 25-year
// assertion lifetime too, giving this clock-skew issue as the explicit reason:
// https://dxr.mozilla.org/mozilla-central/rev/ffe6cc09ccf38cca6f0e727837bbc6cb722d1e71/services/fxaccounts/FxAccountsCommon.js#70
const ASSERTION_DURATION_MS = new Duration('52w').milliseconds() * 25; //25 years

function importJwCrypto () {
  return import(/* webpackChunkName: "jwcryptoShim" */ './jwcrypto-shim')
    .then(module => module.default);
}

function ensureCryptoIsSeeded() {
  // The jwcrypto RNG needs to be seeded with entropy. If the browser
  // supports window.crypto.getRandomValues, it will fetch its entropy
  // from there, otherwise it collects entropy from the user's mouse
  // movements. In older browsers that do not support crypto.getRandomValues,
  // the tests timeout waiting for entropy, which is not awesome. If
  // the browser does not support crypto.getRandomValues, go collect
  // entropy from the server and seed the RNG.

  // browser has native crypto, no need to fetch entropy from the server.
github treasure-data / digdag / digdag-ui / console.jsx View on Github external
function formatDuration (startTime: ?string, endTime: ?string) {
  if (!startTime || !endTime) {
    return ''
  }
  const duration = new Duration(new Date(startTime), new Date(endTime)).toString(1, 1) // format: 10y 2m 6d 3h 23m 8s
  return <span>{duration}</span>
}
github mozilla / fxa / packages / fxa-content-server / app / scripts / lib / metrics.js View on Github external
'screen',
  'service',
  'syncEngines',
  'startTime',
  'timers',
  'uid',
  'uniqueUserId',
  'userPreferences',
  'utm_campaign',
  'utm_content',
  'utm_medium',
  'utm_source',
  'utm_term',
];

var DEFAULT_INACTIVITY_TIMEOUT_MS = new Duration('10s').milliseconds();
var NOT_REPORTED_VALUE = 'none';
var UNKNOWN_CAMPAIGN_ID = 'unknown';

// convert a hash of metrics impressions into an array of objects.
function flattenHashIntoArrayOfObjects(hashTable) {
  return _.reduce(
    hashTable,
    function(memo, key) {
      return memo.concat(
        _.map(key, function(value) {
          return value;
        })
      );
    },
    []
  );
github mozilla / fxa-content-server / app / scripts / views / form.js View on Github external
* @returns {Function}
   */
function ifFormValuesChanged(handler) {
  return function () {
    if (this.updateFormValueChanges()) {
      return this.invokeHandler(handler, arguments);
    }
  };
}

const proto = BaseView.prototype;

var FormView = BaseView.extend({

  // Time to wait for a request to finish before showing a notice
  LONGER_THAN_EXPECTED: new Duration('10s').milliseconds(),

  events: {
    'change form': ifFormValuesChanged(cancelEventThen('onFormChange')),
    'input form': ifFormValuesChanged(cancelEventThen('onFormChange')),
    'keyup form': ifFormValuesChanged(cancelEventThen('onFormChange')),
    'submit form': preventDefaultThen('onFormSubmit')
  },

  _notifiedOfEngaged: false,
  onFormChange () {
    // the change event can be called after the form is already
    // submitted if the user presses "enter" in the form. If the
    // form is in the midst of being submitted, bail out now.
    if (this.isSubmitting() || this.isHalted()) {
      return;
    }
github mozilla / fxa / packages / fxa-content-server / app / scripts / lib / channels / duplex.js View on Github external
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

/**
 * A two way channel. Messages can be sent and received. The channel requires
 * both a sender and a receiver. A sender and a receiver are the concrete
 * strategies used to send and receive messages. The decoupling of each
 * direction allows a channel to e.g., send messages via a CustomEvent and
 * receive messages via a postMessage (Fx Desktop Sync v1).
 */

import _ from 'underscore';
import BaseChannel from 'lib/channels/base';
import Duration from 'duration';
import Logger from 'lib/logger';

var DEFAULT_SEND_TIMEOUT_LENGTH_MS = new Duration('90s').milliseconds();

function OutstandingRequests(options) {
  this._window = options.window;
  this._sendTimeoutLength =
    options.sendTimeoutLength || DEFAULT_SEND_TIMEOUT_LENGTH_MS;
  this._requests = {};
  this._logger = new Logger(this._window);
}

OutstandingRequests.prototype = {
  add(messageId, request) {
    // remove any old outstanding messages with the same messageId
    this.remove(messageId);

    request.timeout = this._window.setTimeout(
      function(command) {
github cucumber / cucumber-js / src / formatter / helpers / summary_helpers.js View on Github external
function getDurationSummary(durationMsg) {
  const start = new Date(0)
  const end = new Date(durationToMilliseconds(durationMsg))
  const duration = new Duration(start, end)

  return (
    `${duration.minutes}m${duration.toString('%S')}.${duration.toString(
      '%L'
    )}s` + `\n`
  )
}
github patternplate / patternplate / packages / server / source / library / log / decorations.js View on Github external
function formatDuration(start, end = new Date()) {
  return new Duration(start, end).toString(1);
}
github midwayjs / pandora-dashboard / public / src / utils / Common.jsx View on Github external
export function displayDuration(ms) {
  if(ms == null) {
    return null;
  }
  const duration = new Duration(new Date(0), new Date(ms));
  return duration.toString(1);
}
github mozilla / fxa / packages / fxa-content-server / app / scripts / views / mixins / resend-mixin.js View on Github external
* Consumers must expose a `resend` function which returns a promise
 * and actually resends the message.
 *
 * When #resend is clicked, a .resend event is logged.
 *
 * @module ResendMixin
 */

import _ from 'underscore';
import Duration from 'duration';
import EmailResend from '../../models/email-resend';
import preventDefaultThen from '../decorators/prevent_default_then';

const t = msg =&gt; msg;

const SHOW_RESEND_IN_MS = new Duration('5m').milliseconds();

/**
 * Creates the mixin to be used by views.
 *
 * @param {Object} [options={}] options
 *   @param {String} successMessage success message to display when complete.
 *     Defaults to `Email resent`. If falsey, no message is displayed.
 * @return {Function} the mixin to be consumed by views.
 */
export default function(options = {}) {
  const { successMessage } = _.defaults(options, {
    successMessage: t(
      'Email resent. Add accounts@firefox.com to your contacts to ensure a smooth delivery.'
    ),
  });