Timer.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. function _defineProperty(obj, key, value) {
  7. if (key in obj) {
  8. Object.defineProperty(obj, key, {
  9. value: value,
  10. enumerable: true,
  11. configurable: true,
  12. writable: true
  13. });
  14. } else {
  15. obj[key] = value;
  16. }
  17. return obj;
  18. }
  19. /**
  20. * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  21. *
  22. * This source code is licensed under the MIT license found in the
  23. * LICENSE file in the root directory of this source tree.
  24. *
  25. */
  26. // This file is a heavily modified fork of Jasmine. Original license:
  27. /*
  28. Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  29. Permission is hereby granted, free of charge, to any person obtaining
  30. a copy of this software and associated documentation files (the
  31. "Software"), to deal in the Software without restriction, including
  32. without limitation the rights to use, copy, modify, merge, publish,
  33. distribute, sublicense, and/or sell copies of the Software, and to
  34. permit persons to whom the Software is furnished to do so, subject to
  35. the following conditions:
  36. The above copyright notice and this permission notice shall be
  37. included in all copies or substantial portions of the Software.
  38. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  39. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  40. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  41. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  42. LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  43. OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  44. WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  45. */
  46. const defaultNow = (function (Date) {
  47. return function () {
  48. return new Date().getTime();
  49. };
  50. })(Date);
  51. class Timer {
  52. constructor(options) {
  53. _defineProperty(this, 'start', void 0);
  54. _defineProperty(this, 'elapsed', void 0);
  55. options = options || {};
  56. const now = options.now || defaultNow;
  57. let startTime;
  58. this.start = function () {
  59. startTime = now();
  60. };
  61. this.elapsed = function () {
  62. return now() - startTime;
  63. };
  64. }
  65. }
  66. exports.default = Timer;