zone.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import { ZoneIsAbstractError } from "./errors.js";
  2. /**
  3. * @interface
  4. */
  5. export default class Zone {
  6. /**
  7. * The type of zone
  8. * @abstract
  9. * @type {string}
  10. */
  11. get type() {
  12. throw new ZoneIsAbstractError();
  13. }
  14. /**
  15. * The name of this zone.
  16. * @abstract
  17. * @type {string}
  18. */
  19. get name() {
  20. throw new ZoneIsAbstractError();
  21. }
  22. /**
  23. * The IANA name of this zone.
  24. * Defaults to `name` if not overwritten by a subclass.
  25. * @abstract
  26. * @type {string}
  27. */
  28. get ianaName() {
  29. return this.name;
  30. }
  31. /**
  32. * Returns whether the offset is known to be fixed for the whole year.
  33. * @abstract
  34. * @type {boolean}
  35. */
  36. get isUniversal() {
  37. throw new ZoneIsAbstractError();
  38. }
  39. /**
  40. * Returns the offset's common name (such as EST) at the specified timestamp
  41. * @abstract
  42. * @param {number} ts - Epoch milliseconds for which to get the name
  43. * @param {Object} opts - Options to affect the format
  44. * @param {string} opts.format - What style of offset to return. Accepts 'long' or 'short'.
  45. * @param {string} opts.locale - What locale to return the offset name in.
  46. * @return {string}
  47. */
  48. offsetName(ts, opts) {
  49. throw new ZoneIsAbstractError();
  50. }
  51. /**
  52. * Returns the offset's value as a string
  53. * @abstract
  54. * @param {number} ts - Epoch milliseconds for which to get the offset
  55. * @param {string} format - What style of offset to return.
  56. * Accepts 'narrow', 'short', or 'techie'. Returning '+6', '+06:00', or '+0600' respectively
  57. * @return {string}
  58. */
  59. formatOffset(ts, format) {
  60. throw new ZoneIsAbstractError();
  61. }
  62. /**
  63. * Return the offset in minutes for this zone at the specified timestamp.
  64. * @abstract
  65. * @param {number} ts - Epoch milliseconds for which to compute the offset
  66. * @return {number}
  67. */
  68. offset(ts) {
  69. throw new ZoneIsAbstractError();
  70. }
  71. /**
  72. * Return whether this Zone is equal to another zone
  73. * @abstract
  74. * @param {Zone} otherZone - the zone to compare
  75. * @return {boolean}
  76. */
  77. equals(otherZone) {
  78. throw new ZoneIsAbstractError();
  79. }
  80. /**
  81. * Return whether this Zone is valid.
  82. * @abstract
  83. * @type {boolean}
  84. */
  85. get isValid() {
  86. throw new ZoneIsAbstractError();
  87. }
  88. }