TimeUtil.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  2. /*
  3. * Copyright 2020 Red Hat, Inc. and/or its affiliates.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /**
  18. * @author Stan Silvert
  19. */
  20. class TimeUtil {
  21. constructor() {
  22. _defineProperty(this, "options", {
  23. year: 'numeric',
  24. month: 'long',
  25. day: 'numeric',
  26. hour: 'numeric',
  27. minute: 'numeric'
  28. });
  29. _defineProperty(this, "formatter", void 0);
  30. try {
  31. this.formatter = new Intl.DateTimeFormat(locale, this.options);
  32. } catch (e) {
  33. // unknown locale falling back to English
  34. this.formatter = new Intl.DateTimeFormat('en', this.options);
  35. }
  36. }
  37. format(time) {
  38. return this.formatter.format(time);
  39. }
  40. }
  41. const TimeUtilInstance = new TimeUtil();
  42. export default TimeUtilInstance;
  43. //# sourceMappingURL=TimeUtil.js.map