@flarehr/apollo-benefits 0.1.106 → 0.3.53396

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (219) hide show
  1. package/README.md +19 -0
  2. package/dist/assets/@splitsoftware-7d799540.js +18 -0
  3. package/dist/assets/all_tab_color-548783b9.svg +21 -0
  4. package/dist/assets/all_tab_gray-a5051313.svg +6 -0
  5. package/dist/assets/check-57fe1dcb.svg +15 -0
  6. package/dist/assets/datadog-c7ede347.js +5 -0
  7. package/dist/assets/date-fns-c5d8fbc0.js +1 -0
  8. package/dist/assets/default_backdrop-fdd955b8.png +0 -0
  9. package/dist/assets/external_link-599a0aec.svg +3 -0
  10. package/dist/assets/external_link_white-55111b2e.svg +3 -0
  11. package/dist/assets/framer-motion-bb8d6b82.js +1 -0
  12. package/dist/assets/index-87923fdc.js +35 -0
  13. package/dist/assets/index-cfa25e28.css +1 -0
  14. package/dist/assets/index-ee9d2045.js +5 -0
  15. package/dist/assets/lodash-5d893f8c.js +1 -0
  16. package/dist/assets/logo-a34e9b4b.png +0 -0
  17. package/dist/assets/oidc-client-6f6e47c2.js +101 -0
  18. package/dist/assets/padlock-8c081120.svg +26 -0
  19. package/dist/assets/suitcase-6471ad05.svg +17 -0
  20. package/dist/assets/vendor-2d0139ca.js +788 -0
  21. package/dist/assets/warning-a7f1af23.svg +14 -0
  22. package/dist/assets/welcome_image_mobile-dbde6c80.png +0 -0
  23. package/dist/assets/welcome_image_v2-869c59e4.png +0 -0
  24. package/dist/assets/wellbeing_banner-6903d615.png +0 -0
  25. package/dist/assets/workplace_link_banner_mobile-6ebaa24b.png +0 -0
  26. package/dist/assets/workplace_link_banner_v2-c81ed849.png +0 -0
  27. package/dist/config.json +14 -0
  28. package/dist/favicon.ico +0 -0
  29. package/dist/icons/android-chrome-192x192.png +0 -0
  30. package/dist/icons/android-chrome-512x512.png +0 -0
  31. package/dist/icons/apple-touch-icon.png +0 -0
  32. package/dist/icons/favicon-16x16.png +0 -0
  33. package/dist/icons/favicon-32x32.png +0 -0
  34. package/dist/index.html +114 -0
  35. package/dist/manifest.json +21 -0
  36. package/dist/sw-esm.js +16 -0
  37. package/package.json +129 -60
  38. package/LICENSE +0 -21
  39. package/dist/lib/apollo-benefits/apollo-benefits.esm.js +0 -1
  40. package/dist/lib/apollo-benefits/assets/car-placeholder.svg +0 -5
  41. package/dist/lib/apollo-benefits/assets/check.svg +0 -13
  42. package/dist/lib/apollo-benefits/index.esm.js +0 -0
  43. package/dist/lib/apollo-benefits/p-06a1f65f.js +0 -1
  44. package/dist/lib/apollo-benefits/p-077d7f8d.entry.js +0 -1
  45. package/dist/lib/apollo-benefits/p-0a21a709.entry.js +0 -1
  46. package/dist/lib/apollo-benefits/p-14054f15.js +0 -1
  47. package/dist/lib/apollo-benefits/p-24a37d64.js +0 -1
  48. package/dist/lib/apollo-benefits/p-2b3f3b72.entry.js +0 -1
  49. package/dist/lib/apollo-benefits/p-3111d565.entry.js +0 -1
  50. package/dist/lib/apollo-benefits/p-327396fa.entry.js +0 -1
  51. package/dist/lib/apollo-benefits/p-3af26279.entry.js +0 -1
  52. package/dist/lib/apollo-benefits/p-3d4d2683.js +0 -1
  53. package/dist/lib/apollo-benefits/p-4474bcf8.entry.js +0 -1
  54. package/dist/lib/apollo-benefits/p-50fe790f.js +0 -1
  55. package/dist/lib/apollo-benefits/p-53bcbd1d.js +0 -1
  56. package/dist/lib/apollo-benefits/p-64a2b03a.entry.js +0 -1
  57. package/dist/lib/apollo-benefits/p-68c136da.js +0 -1
  58. package/dist/lib/apollo-benefits/p-6bd16f5b.js +0 -1
  59. package/dist/lib/apollo-benefits/p-71dbc8ff.entry.js +0 -1
  60. package/dist/lib/apollo-benefits/p-774d9bc5.entry.js +0 -1
  61. package/dist/lib/apollo-benefits/p-7a2ca86d.entry.js +0 -1
  62. package/dist/lib/apollo-benefits/p-7a572b50.js +0 -1
  63. package/dist/lib/apollo-benefits/p-7c2cd94a.entry.js +0 -1
  64. package/dist/lib/apollo-benefits/p-839493d7.entry.js +0 -1
  65. package/dist/lib/apollo-benefits/p-acf61bdc.js +0 -1
  66. package/dist/lib/apollo-benefits/p-b33fc683.js +0 -1
  67. package/dist/lib/apollo-benefits/p-beb8f728.entry.js +0 -1
  68. package/dist/lib/apollo-benefits/p-d7bea1d9.entry.js +0 -1
  69. package/dist/lib/apollo-benefits/p-ddb176cb.entry.js +0 -1
  70. package/dist/lib/apollo-benefits/p-e241f55b.entry.js +0 -1
  71. package/dist/lib/apollo-benefits/p-ef8ea713.entry.js +0 -1
  72. package/dist/lib/apollo-benefits/p-f603197d.js +0 -15
  73. package/dist/lib/cjs/active-router-0ecaf2b8.js +0 -75
  74. package/dist/lib/cjs/ap-ben-choose-vehicle-section_4.cjs.entry.js +0 -2684
  75. package/dist/lib/cjs/ap-ben-complete-section_4.cjs.entry.js +0 -108
  76. package/dist/lib/cjs/ap-ben-notifications-section.cjs.entry.js +0 -238
  77. package/dist/lib/cjs/apollo-benefits.cjs.js +0 -25
  78. package/dist/lib/cjs/app-globals-67583b8b.js +0 -12
  79. package/dist/lib/cjs/async-6a7926f0.js +0 -753
  80. package/dist/lib/cjs/cars-calculator-app.cjs.entry.js +0 -52
  81. package/dist/lib/cjs/cars-calculator.service-11b0cd88.js +0 -901
  82. package/dist/lib/cjs/context-consumer.cjs.entry.js +0 -29
  83. package/dist/lib/cjs/datorama-akita-31d23240.js +0 -2551
  84. package/dist/lib/cjs/delay-d31618c3.js +0 -206
  85. package/dist/lib/cjs/distinctUntilChanged-e8538790.js +0 -371
  86. package/dist/lib/cjs/dom-utils-b8befdd5.js +0 -63
  87. package/dist/lib/cjs/fl-button.cjs.entry.js +0 -30
  88. package/dist/lib/cjs/fl-dropdown-async_2.cjs.entry.js +0 -467
  89. package/dist/lib/cjs/fl-dropdown.cjs.entry.js +0 -232
  90. package/dist/lib/cjs/fl-loading-indicator.cjs.entry.js +0 -26
  91. package/dist/lib/cjs/fl-style-guide.cjs.entry.js +0 -91
  92. package/dist/lib/cjs/index-f1fadf90.js +0 -1735
  93. package/dist/lib/cjs/index.cjs.js +0 -2
  94. package/dist/lib/cjs/loader.cjs.js +0 -27
  95. package/dist/lib/cjs/location-utils-36fe7e5e.js +0 -237
  96. package/dist/lib/cjs/match-path-be4ea5f6.js +0 -279
  97. package/dist/lib/cjs/session.query-d61ba7ec.js +0 -1731
  98. package/dist/lib/cjs/stencil-async-content.cjs.entry.js +0 -32
  99. package/dist/lib/cjs/stencil-route-link.cjs.entry.js +0 -78
  100. package/dist/lib/cjs/stencil-route-switch.cjs.entry.js +0 -104
  101. package/dist/lib/cjs/stencil-route-title.cjs.entry.js +0 -32
  102. package/dist/lib/cjs/stencil-route.cjs.entry.js +0 -97
  103. package/dist/lib/cjs/stencil-router-prompt.cjs.entry.js +0 -59
  104. package/dist/lib/cjs/stencil-router-redirect.cjs.entry.js +0 -32
  105. package/dist/lib/cjs/stencil-router.cjs.entry.js +0 -640
  106. package/dist/lib/collection/assets/image/complete.svg +0 -122
  107. package/dist/lib/collection/collection-manifest.json +0 -53
  108. package/dist/lib/collection/components/cars-calculator-app/api/api-client.js +0 -5
  109. package/dist/lib/collection/components/cars-calculator-app/api/cars-calculator.api.js +0 -45
  110. package/dist/lib/collection/components/cars-calculator-app/cars-calculator-app.css +0 -22
  111. package/dist/lib/collection/components/cars-calculator-app/cars-calculator-app.js +0 -93
  112. package/dist/lib/collection/components/cars-calculator-app/modal-section/modal-section.css +0 -0
  113. package/dist/lib/collection/components/cars-calculator-app/modal-section/modal-section.js +0 -144
  114. package/dist/lib/collection/components/cars-calculator-app/notifications-section/notifications-section.js +0 -25
  115. package/dist/lib/collection/components/cars-calculator-app/pages/assets/car-placeholder.svg +0 -5
  116. package/dist/lib/collection/components/cars-calculator-app/pages/assets/check.svg +0 -13
  117. package/dist/lib/collection/components/cars-calculator-app/pages/choose-vehicle-section.component.js +0 -193
  118. package/dist/lib/collection/components/cars-calculator-app/pages/complete-section.component.js +0 -38
  119. package/dist/lib/collection/components/cars-calculator-app/pages/cost-breakdown-section.component.js +0 -47
  120. package/dist/lib/collection/components/cars-calculator-app/pages/model-variants-section.component.css +0 -34
  121. package/dist/lib/collection/components/cars-calculator-app/pages/model-variants-section.component.js +0 -64
  122. package/dist/lib/collection/components/cars-calculator-app/pages/personal-info-section.component.js +0 -66
  123. package/dist/lib/collection/components/cars-calculator-app/pages/quote-result-section.component.js +0 -86
  124. package/dist/lib/collection/components/cars-calculator-app/pages/submit-quote-section.component.js +0 -75
  125. package/dist/lib/collection/components/cars-calculator-app/services/app-configuration.service.js +0 -13
  126. package/dist/lib/collection/components/cars-calculator-app/services/cars-calculator.service.js +0 -103
  127. package/dist/lib/collection/components/cars-calculator-app/services/notifications.service.js +0 -37
  128. package/dist/lib/collection/components/cars-calculator-app/services/notifications.store.js +0 -3
  129. package/dist/lib/collection/components/cars-calculator-app/services/session.query.js +0 -35
  130. package/dist/lib/collection/components/cars-calculator-app/services/session.store.js +0 -78
  131. package/dist/lib/collection/global/config.js +0 -2
  132. package/dist/lib/collection/global/main.dev.js +0 -5
  133. package/dist/lib/collection/global/main.js +0 -5
  134. package/dist/lib/collection/index.js +0 -2
  135. package/dist/lib/collection/utils/config.js +0 -2
  136. package/dist/lib/collection/utils/index.js +0 -15
  137. package/dist/lib/collection/utils/lazy.js +0 -29
  138. package/dist/lib/esm/active-router-7c2ca849.js +0 -73
  139. package/dist/lib/esm/ap-ben-choose-vehicle-section_4.entry.js +0 -2677
  140. package/dist/lib/esm/ap-ben-complete-section_4.entry.js +0 -101
  141. package/dist/lib/esm/ap-ben-notifications-section.entry.js +0 -234
  142. package/dist/lib/esm/apollo-benefits.js +0 -23
  143. package/dist/lib/esm/app-globals-65714cca.js +0 -10
  144. package/dist/lib/esm/async-68e9cad7.js +0 -738
  145. package/dist/lib/esm/cars-calculator-app.entry.js +0 -48
  146. package/dist/lib/esm/cars-calculator.service-2cde6288.js +0 -894
  147. package/dist/lib/esm/context-consumer.entry.js +0 -25
  148. package/dist/lib/esm/datorama-akita-c87196a0.js +0 -2545
  149. package/dist/lib/esm/delay-115d4292.js +0 -200
  150. package/dist/lib/esm/distinctUntilChanged-bf69e0f8.js +0 -363
  151. package/dist/lib/esm/dom-utils-109a7d75.js +0 -55
  152. package/dist/lib/esm/fl-button.entry.js +0 -26
  153. package/dist/lib/esm/fl-dropdown-async_2.entry.js +0 -462
  154. package/dist/lib/esm/fl-dropdown.entry.js +0 -228
  155. package/dist/lib/esm/fl-loading-indicator.entry.js +0 -22
  156. package/dist/lib/esm/fl-style-guide.entry.js +0 -87
  157. package/dist/lib/esm/index-19c4d245.js +0 -1703
  158. package/dist/lib/esm/index.js +0 -1
  159. package/dist/lib/esm/loader.js +0 -23
  160. package/dist/lib/esm/location-utils-312665d3.js +0 -226
  161. package/dist/lib/esm/match-path-4b5c7d98.js +0 -276
  162. package/dist/lib/esm/polyfills/core-js.js +0 -11
  163. package/dist/lib/esm/polyfills/css-shim.js +0 -1
  164. package/dist/lib/esm/polyfills/dom.js +0 -79
  165. package/dist/lib/esm/polyfills/es5-html-element.js +0 -1
  166. package/dist/lib/esm/polyfills/index.js +0 -34
  167. package/dist/lib/esm/polyfills/system.js +0 -6
  168. package/dist/lib/esm/session.query-0f1c9503.js +0 -1719
  169. package/dist/lib/esm/stencil-async-content.entry.js +0 -28
  170. package/dist/lib/esm/stencil-route-link.entry.js +0 -74
  171. package/dist/lib/esm/stencil-route-switch.entry.js +0 -100
  172. package/dist/lib/esm/stencil-route-title.entry.js +0 -28
  173. package/dist/lib/esm/stencil-route.entry.js +0 -93
  174. package/dist/lib/esm/stencil-router-prompt.entry.js +0 -55
  175. package/dist/lib/esm/stencil-router-redirect.entry.js +0 -28
  176. package/dist/lib/esm/stencil-router.entry.js +0 -636
  177. package/dist/lib/index.cjs.js +0 -1
  178. package/dist/lib/index.js +0 -1
  179. package/dist/lib/loader/cdn.js +0 -3
  180. package/dist/lib/loader/index.cjs.js +0 -3
  181. package/dist/lib/loader/index.d.ts +0 -13
  182. package/dist/lib/loader/index.es2017.js +0 -3
  183. package/dist/lib/loader/index.js +0 -4
  184. package/dist/lib/loader/package.json +0 -10
  185. package/dist/lib/node_modules/@flarehr/beacon/dist/collection/components/button/button.css +0 -45
  186. package/dist/lib/node_modules/@flarehr/beacon/dist/collection/components/dropdown/dropdown.css +0 -9
  187. package/dist/lib/node_modules/@flarehr/beacon/dist/collection/components/dropdown-async/dropdown-async.css +0 -9
  188. package/dist/lib/node_modules/@flarehr/beacon/dist/collection/components/loading-indicator/loading-indicator.css +0 -141
  189. package/dist/lib/node_modules/@flarehr/beacon/dist/collection/components/promise-button/promise-button.css +0 -5
  190. package/dist/lib/node_modules/@flarehr/beacon/dist/collection/components/style-guide/style-guide.css +0 -0
  191. package/dist/lib/node_modules/@stencil/router/dist/collection/components/route/route.css +0 -3
  192. package/dist/lib/types/components/cars-calculator-app/api/api-client.d.ts +0 -2
  193. package/dist/lib/types/components/cars-calculator-app/api/cars-calculator.api.d.ts +0 -96
  194. package/dist/lib/types/components/cars-calculator-app/cars-calculator-app.d.ts +0 -15
  195. package/dist/lib/types/components/cars-calculator-app/modal-section/modal-section.d.ts +0 -16
  196. package/dist/lib/types/components/cars-calculator-app/notifications-section/notifications-section.d.ts +0 -5
  197. package/dist/lib/types/components/cars-calculator-app/pages/choose-vehicle-section.component.d.ts +0 -23
  198. package/dist/lib/types/components/cars-calculator-app/pages/complete-section.component.d.ts +0 -5
  199. package/dist/lib/types/components/cars-calculator-app/pages/cost-breakdown-section.component.d.ts +0 -6
  200. package/dist/lib/types/components/cars-calculator-app/pages/model-variants-section.component.d.ts +0 -12
  201. package/dist/lib/types/components/cars-calculator-app/pages/personal-info-section.component.d.ts +0 -10
  202. package/dist/lib/types/components/cars-calculator-app/pages/quote-result-section.component.d.ts +0 -13
  203. package/dist/lib/types/components/cars-calculator-app/pages/submit-quote-section.component.d.ts +0 -10
  204. package/dist/lib/types/components/cars-calculator-app/services/app-configuration.service.d.ts +0 -7
  205. package/dist/lib/types/components/cars-calculator-app/services/cars-calculator.service.d.ts +0 -11
  206. package/dist/lib/types/components/cars-calculator-app/services/notifications.service.d.ts +0 -15
  207. package/dist/lib/types/components/cars-calculator-app/services/notifications.store.d.ts +0 -14
  208. package/dist/lib/types/components/cars-calculator-app/services/session.query.d.ts +0 -25
  209. package/dist/lib/types/components/cars-calculator-app/services/session.store.d.ts +0 -74
  210. package/dist/lib/types/components.d.ts +0 -170
  211. package/dist/lib/types/global/config.d.ts +0 -2
  212. package/dist/lib/types/global/main.d.ts +0 -1
  213. package/dist/lib/types/global/main.dev.d.ts +0 -1
  214. package/dist/lib/types/index.d.ts +0 -2
  215. package/dist/lib/types/stencil-public-runtime.d.ts +0 -1555
  216. package/dist/lib/types/utils/config.d.ts +0 -2
  217. package/dist/lib/types/utils/index.d.ts +0 -7
  218. package/dist/lib/types/utils/lazy.d.ts +0 -12
  219. package/readme.md +0 -1
@@ -1,2684 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- const index = require('./index-f1fadf90.js');
6
- require('./datorama-akita-31d23240.js');
7
- require('./async-6a7926f0.js');
8
- require('./delay-d31618c3.js');
9
- require('./distinctUntilChanged-e8538790.js');
10
- const carsCalculator_service = require('./cars-calculator.service-11b0cd88.js');
11
- const session_query = require('./session.query-d61ba7ec.js');
12
-
13
- var __asyncValues = (undefined && undefined.__asyncValues) || function (o) {
14
- if (!Symbol.asyncIterator)
15
- throw new TypeError("Symbol.asyncIterator is not defined.");
16
- var m = o[Symbol.asyncIterator], i;
17
- return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
18
- function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
19
- function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
20
- };
21
- const ChooseVehicleSection = class {
22
- constructor(hostRef) {
23
- index.registerInstance(this, hostRef);
24
- this.toCapitalCase = (str) => str === null || str === void 0 ? void 0 : str.split(' ').map((part) => part.charAt(0).toUpperCase() + part.slice(1).toLowerCase()).join(' ');
25
- session_query.sessionQuery.vehicle$.subscribe((state) => (this.vehicleInfo = state));
26
- session_query.sessionQuery.makeList$.subscribe((state) => (this.makeList = carsCalculator_service.getOrDefault(state, [])));
27
- session_query.sessionQuery.modelList$.subscribe((state) => (this.modelList = carsCalculator_service.getOrDefault(state, [])));
28
- session_query.sessionQuery.yearList$.subscribe((state) => (this.yearList = carsCalculator_service.getOrDefault(state, [])));
29
- session_query.sessionQuery.bodyTypeList$.subscribe((state) => (this.bodyTypeList = carsCalculator_service.getOrDefault(state, [])));
30
- }
31
- render() {
32
- return (index.h(index.Host, null, index.h("div", { class: "d-flex flex-column flex-wrap flex-md-row align-items-center justify-content-center h4" }, index.h("div", { class: "d-flex align-items-center" }, "I'm looking to buy a"), index.h("div", { class: "d-flex mx-2 my-2 my-md-0" }, index.h("div", { class: "btn-group", role: "group", "aria-label": "New or used vehicle" }, index.h("button", { type: "button", class: {
33
- 'btn btn-outline-dark px-5': true,
34
- active: !this.isUsedCarSelected()
35
- }, onClick: (_event) => session_query.sessionStore.setVehicleState('isUsedCarRequested', false) }, "New"), index.h("button", { type: "button", class: {
36
- 'btn btn-outline-dark px-5': true,
37
- active: this.isUsedCarSelected()
38
- }, onClick: (_event) => session_query.sessionStore.setVehicleState('isUsedCarRequested', true) }, "Used"))), this.isUsedCarSelected() ? (index.h("div", { class: "d-flex flex-column flex-md-row align-items-center justify-content-center my-0 my-md-2 my-xl-0" }, index.h("span", { class: "pr-0 pr-sm-2 d-flex text-center" }, "vehicle, with a purchase price of"), index.h("input", { placeholder: "25000", type: "text", class: "form-control d-flex w-auto mt-2 mt-md-0", value: '$' + this.getVehicleInfo('approximatePrice'), onInput: (e) => {
39
- const el = e.target;
40
- el.value = el.value.replace(/\D/g, '');
41
- }, onFocus: (e) => {
42
- const el = e.target;
43
- el.value = el.value.replace('$', '');
44
- }, onBlur: (e) => {
45
- const el = e.target;
46
- el.value = '$' + el.value;
47
- }, onChange: (e) => session_query.sessionStore.setVehicleState('approximatePrice', parseFloat(e.target.value)) }))) : (index.h("div", { class: "d-flex align-items-center" }, "vehicle"))), index.h("div", { class: "d-flex flex-wrap flex-column flex-md-row align-items-center justify-content-center mt-5 h4" }, index.h("div", { class: "d-flex align-items-center" }, "I'm interested in a"), index.h("div", { class: "d-flex mx-2 my-2 my-md-0" }, index.h("fl-dropdown", { options: this.makeList, requiredValidationMessage: "Select an option", placeholder: "select make", value: this.getVehicleInfo('makeId'), onValueChanged: (e) => this.chooseMake(e.detail.label, e.detail.value) })), index.h("div", { class: "d-flex mx-2 my-2 my-md-0" }, index.h("fl-dropdown", { options: this.modelList, requiredValidationMessage: "Select an option", placeholder: "select model", value: this.getVehicleInfo('modelId'), disabled: session_query.isNone(this.vehicleInfo.makeId), onValueChanged: (e) => this.chooseModel(e.detail.label, e.detail.value) })), index.h("div", { class: "d-flex align-items-center" }, "built in"), index.h("div", { class: "d-flex mx-2 my-2 my-xl-0" }, index.h("fl-dropdown", { options: this.yearList, requiredValidationMessage: "Select an option", placeholder: "select year", value: this.getVehicleInfo('year'), disabled: session_query.isNone(this.vehicleInfo.modelId), onValueChanged: (e) => this.chooseYear(e.detail.value) }))), index.h("div", { class: "d-flex align-items-center justify-content-center justify-content-md-start mt-5" }, index.h("div", { class: "btn-group", role: "group", "aria-label": "Body types" }, this.bodyTypeList.map((bodyType) => (index.h("button", { type: "button", class: {
48
- 'btn btn-sm btn-outline-dark px-5': true,
49
- active: this.isBodyTypeSelected(bodyType.value)
50
- }, onClick: (_event) => this.chooseBodyType(bodyType.label, bodyType.value) }, bodyType.label)))))));
51
- }
52
- async componentDidLoad() {
53
- var _a;
54
- if (((_a = this.makeList) === null || _a === void 0 ? void 0 : _a.length) > 0)
55
- return;
56
- const carsMakes = await carsCalculator_service.backendApi.getCarsMakes();
57
- session_query.sessionStore.updateList('makeList', carsMakes.map((make) => ({
58
- label: this.toCapitalCase(make.name),
59
- value: make.make_id
60
- })));
61
- }
62
- async chooseMake(make, makeId) {
63
- var _a;
64
- this.clearModelStates();
65
- this.clearYearStates();
66
- this.clearBodyTypeStates();
67
- this.clearVariantsList();
68
- if (((_a = this.modelList) === null || _a === void 0 ? void 0 : _a.length) === 0) {
69
- session_query.sessionStore.updateList('modelList', (await carsCalculator_service.backendApi.getCarsModels(makeId)).map((model) => ({
70
- label: this.toCapitalCase(model.model_code),
71
- value: model.model_id
72
- })));
73
- }
74
- session_query.sessionStore.setVehicleState('make', make);
75
- session_query.sessionStore.setVehicleState('makeId', makeId);
76
- }
77
- async chooseModel(model, modelId) {
78
- var _a;
79
- this.clearYearStates();
80
- this.clearBodyTypeStates();
81
- this.clearVariantsList();
82
- if (((_a = this.yearList) === null || _a === void 0 ? void 0 : _a.length) === 0) {
83
- session_query.sessionStore.updateList('yearList', (await carsCalculator_service.backendApi.getCarsModelYears(modelId))
84
- .sort()
85
- .reverse()
86
- .map((year) => ({
87
- label: year.toString(),
88
- value: year
89
- })));
90
- }
91
- session_query.sessionStore.setVehicleState('model', model);
92
- session_query.sessionStore.setVehicleState('modelId', modelId);
93
- }
94
- async chooseYear(year) {
95
- var _a;
96
- this.clearBodyTypeStates();
97
- this.clearVariantsList();
98
- const modelId = carsCalculator_service.getOrError(this.vehicleInfo.modelId);
99
- if (((_a = this.bodyTypeList) === null || _a === void 0 ? void 0 : _a.length) === 0) {
100
- session_query.sessionStore.updateList('bodyTypeList', (await carsCalculator_service.backendApi.getCarsModelBodyTypes(modelId, year)).map((bodyType) => ({
101
- label: bodyType.body_type,
102
- value: bodyType.body_type_id
103
- })));
104
- }
105
- session_query.sessionStore.setVehicleState('year', year);
106
- await this.chooseBodyType(this.bodyTypeList[0].label, this.bodyTypeList[0].value);
107
- }
108
- async chooseBodyType(bodyType, bodyTypeId) {
109
- var e_1, _a;
110
- this.clearVariantsList();
111
- const modelId = carsCalculator_service.getOrError(this.vehicleInfo.modelId);
112
- const year = carsCalculator_service.getOrError(this.vehicleInfo.year);
113
- const variantPromises = (await carsCalculator_service.backendApi.getCarsModelVariant(modelId, year, bodyTypeId)).map(async (variant) => {
114
- var _a;
115
- const photoUri = await carsCalculator_service.backendApi.getCarsVariantPhotos(variant.variant_id);
116
- return {
117
- variantId: variant.variant_id,
118
- description: variant.short_description,
119
- buildYear: variant.build_year,
120
- modelMonth: variant.model_month,
121
- listPriceGross: variant.list_price_gross,
122
- photoUri: session_query.fromNullable((_a = photoUri === null || photoUri === void 0 ? void 0 : photoUri[0]) === null || _a === void 0 ? void 0 : _a.photo_uri)
123
- };
124
- });
125
- const variantList = [];
126
- try {
127
- for (var variantPromises_1 = __asyncValues(variantPromises), variantPromises_1_1; variantPromises_1_1 = await variantPromises_1.next(), !variantPromises_1_1.done;) {
128
- const variant = variantPromises_1_1.value;
129
- variantList.push(variant);
130
- }
131
- }
132
- catch (e_1_1) {
133
- e_1 = { error: e_1_1 };
134
- }
135
- finally {
136
- try {
137
- if (variantPromises_1_1 && !variantPromises_1_1.done && (_a = variantPromises_1.return))
138
- await _a.call(variantPromises_1);
139
- }
140
- finally {
141
- if (e_1)
142
- throw e_1.error;
143
- }
144
- }
145
- session_query.sessionStore.updateList('modelVariantsList', variantList);
146
- session_query.sessionStore.setVehicleState('bodyType', bodyType);
147
- session_query.sessionStore.setVehicleState('bodyTypeId', bodyTypeId);
148
- }
149
- clearModelStates() {
150
- this.modelList = [];
151
- this.clearVehicleState('model');
152
- this.clearVehicleState('modelId');
153
- }
154
- clearYearStates() {
155
- this.yearList = [];
156
- this.clearVehicleState('year');
157
- }
158
- clearBodyTypeStates() {
159
- this.bodyTypeList = [];
160
- this.clearVehicleState('bodyType');
161
- this.clearVehicleState('bodyTypeId');
162
- }
163
- clearVariantsList() {
164
- session_query.sessionStore.updateList('modelVariantsList', []);
165
- }
166
- clearVehicleState(key) {
167
- session_query.sessionStore.setVehicleState(key, null);
168
- }
169
- getVehicleInfo(key) {
170
- return carsCalculator_service.pipe(this.vehicleInfo[key], session_query.getOrElse(() => ''));
171
- }
172
- isBodyTypeSelected(bodyTypeId) {
173
- return carsCalculator_service.pipe(this.vehicleInfo.bodyTypeId, session_query.fold(() => false, (selectedBodyTypeId) => selectedBodyTypeId === bodyTypeId));
174
- }
175
- isUsedCarSelected() {
176
- return carsCalculator_service.pipe(this.vehicleInfo.isUsedCarRequested, session_query.getOrElse(() => false));
177
- }
178
- };
179
-
180
- function toInteger(dirtyNumber) {
181
- if (dirtyNumber === null || dirtyNumber === true || dirtyNumber === false) {
182
- return NaN;
183
- }
184
-
185
- var number = Number(dirtyNumber);
186
-
187
- if (isNaN(number)) {
188
- return number;
189
- }
190
-
191
- return number < 0 ? Math.ceil(number) : Math.floor(number);
192
- }
193
-
194
- function requiredArgs(required, args) {
195
- if (args.length < required) {
196
- throw new TypeError(required + ' argument' + (required > 1 ? 's' : '') + ' required, but only ' + args.length + ' present');
197
- }
198
- }
199
-
200
- /**
201
- * @name toDate
202
- * @category Common Helpers
203
- * @summary Convert the given argument to an instance of Date.
204
- *
205
- * @description
206
- * Convert the given argument to an instance of Date.
207
- *
208
- * If the argument is an instance of Date, the function returns its clone.
209
- *
210
- * If the argument is a number, it is treated as a timestamp.
211
- *
212
- * If the argument is none of the above, the function returns Invalid Date.
213
- *
214
- * **Note**: *all* Date arguments passed to any *date-fns* function is processed by `toDate`.
215
- *
216
- * @param {Date|Number} argument - the value to convert
217
- * @returns {Date} the parsed date in the local time zone
218
- * @throws {TypeError} 1 argument required
219
- *
220
- * @example
221
- * // Clone the date:
222
- * const result = toDate(new Date(2014, 1, 11, 11, 30, 30))
223
- * //=> Tue Feb 11 2014 11:30:30
224
- *
225
- * @example
226
- * // Convert the timestamp to date:
227
- * const result = toDate(1392098430000)
228
- * //=> Tue Feb 11 2014 11:30:30
229
- */
230
-
231
- function toDate(argument) {
232
- requiredArgs(1, arguments);
233
- var argStr = Object.prototype.toString.call(argument); // Clone the date
234
-
235
- if (argument instanceof Date || typeof argument === 'object' && argStr === '[object Date]') {
236
- // Prevent the date to lose the milliseconds when passed to new Date() in IE10
237
- return new Date(argument.getTime());
238
- } else if (typeof argument === 'number' || argStr === '[object Number]') {
239
- return new Date(argument);
240
- } else {
241
- if ((typeof argument === 'string' || argStr === '[object String]') && typeof console !== 'undefined') {
242
- // eslint-disable-next-line no-console
243
- console.warn("Starting with v2.0.0-beta.1 date-fns doesn't accept strings as date arguments. Please use `parseISO` to parse strings. See: https://git.io/fjule"); // eslint-disable-next-line no-console
244
-
245
- console.warn(new Error().stack);
246
- }
247
-
248
- return new Date(NaN);
249
- }
250
- }
251
-
252
- /**
253
- * @name addMilliseconds
254
- * @category Millisecond Helpers
255
- * @summary Add the specified number of milliseconds to the given date.
256
- *
257
- * @description
258
- * Add the specified number of milliseconds to the given date.
259
- *
260
- * ### v2.0.0 breaking changes:
261
- *
262
- * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
263
- *
264
- * @param {Date|Number} date - the date to be changed
265
- * @param {Number} amount - the amount of milliseconds to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
266
- * @returns {Date} the new date with the milliseconds added
267
- * @throws {TypeError} 2 arguments required
268
- *
269
- * @example
270
- * // Add 750 milliseconds to 10 July 2014 12:45:30.000:
271
- * var result = addMilliseconds(new Date(2014, 6, 10, 12, 45, 30, 0), 750)
272
- * //=> Thu Jul 10 2014 12:45:30.750
273
- */
274
-
275
- function addMilliseconds(dirtyDate, dirtyAmount) {
276
- requiredArgs(2, arguments);
277
- var timestamp = toDate(dirtyDate).getTime();
278
- var amount = toInteger(dirtyAmount);
279
- return new Date(timestamp + amount);
280
- }
281
-
282
- var MILLISECONDS_IN_MINUTE = 60000;
283
-
284
- function getDateMillisecondsPart(date) {
285
- return date.getTime() % MILLISECONDS_IN_MINUTE;
286
- }
287
- /**
288
- * Google Chrome as of 67.0.3396.87 introduced timezones with offset that includes seconds.
289
- * They usually appear for dates that denote time before the timezones were introduced
290
- * (e.g. for 'Europe/Prague' timezone the offset is GMT+00:57:44 before 1 October 1891
291
- * and GMT+01:00:00 after that date)
292
- *
293
- * Date#getTimezoneOffset returns the offset in minutes and would return 57 for the example above,
294
- * which would lead to incorrect calculations.
295
- *
296
- * This function returns the timezone offset in milliseconds that takes seconds in account.
297
- */
298
-
299
-
300
- function getTimezoneOffsetInMilliseconds(dirtyDate) {
301
- var date = new Date(dirtyDate.getTime());
302
- var baseTimezoneOffset = Math.ceil(date.getTimezoneOffset());
303
- date.setSeconds(0, 0);
304
- var hasNegativeUTCOffset = baseTimezoneOffset > 0;
305
- var millisecondsPartOfTimezoneOffset = hasNegativeUTCOffset ? (MILLISECONDS_IN_MINUTE + getDateMillisecondsPart(date)) % MILLISECONDS_IN_MINUTE : getDateMillisecondsPart(date);
306
- return baseTimezoneOffset * MILLISECONDS_IN_MINUTE + millisecondsPartOfTimezoneOffset;
307
- }
308
-
309
- /**
310
- * @name isValid
311
- * @category Common Helpers
312
- * @summary Is the given date valid?
313
- *
314
- * @description
315
- * Returns false if argument is Invalid Date and true otherwise.
316
- * Argument is converted to Date using `toDate`. See [toDate]{@link https://date-fns.org/docs/toDate}
317
- * Invalid Date is a Date, whose time value is NaN.
318
- *
319
- * Time value of Date: http://es5.github.io/#x15.9.1.1
320
- *
321
- * ### v2.0.0 breaking changes:
322
- *
323
- * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
324
- *
325
- * - Now `isValid` doesn't throw an exception
326
- * if the first argument is not an instance of Date.
327
- * Instead, argument is converted beforehand using `toDate`.
328
- *
329
- * Examples:
330
- *
331
- * | `isValid` argument | Before v2.0.0 | v2.0.0 onward |
332
- * |---------------------------|---------------|---------------|
333
- * | `new Date()` | `true` | `true` |
334
- * | `new Date('2016-01-01')` | `true` | `true` |
335
- * | `new Date('')` | `false` | `false` |
336
- * | `new Date(1488370835081)` | `true` | `true` |
337
- * | `new Date(NaN)` | `false` | `false` |
338
- * | `'2016-01-01'` | `TypeError` | `false` |
339
- * | `''` | `TypeError` | `false` |
340
- * | `1488370835081` | `TypeError` | `true` |
341
- * | `NaN` | `TypeError` | `false` |
342
- *
343
- * We introduce this change to make *date-fns* consistent with ECMAScript behavior
344
- * that try to coerce arguments to the expected type
345
- * (which is also the case with other *date-fns* functions).
346
- *
347
- * @param {*} date - the date to check
348
- * @returns {Boolean} the date is valid
349
- * @throws {TypeError} 1 argument required
350
- *
351
- * @example
352
- * // For the valid date:
353
- * var result = isValid(new Date(2014, 1, 31))
354
- * //=> true
355
- *
356
- * @example
357
- * // For the value, convertable into a date:
358
- * var result = isValid(1393804800000)
359
- * //=> true
360
- *
361
- * @example
362
- * // For the invalid date:
363
- * var result = isValid(new Date(''))
364
- * //=> false
365
- */
366
-
367
- function isValid(dirtyDate) {
368
- requiredArgs(1, arguments);
369
- var date = toDate(dirtyDate);
370
- return !isNaN(date);
371
- }
372
-
373
- var formatDistanceLocale = {
374
- lessThanXSeconds: {
375
- one: 'less than a second',
376
- other: 'less than {{count}} seconds'
377
- },
378
- xSeconds: {
379
- one: '1 second',
380
- other: '{{count}} seconds'
381
- },
382
- halfAMinute: 'half a minute',
383
- lessThanXMinutes: {
384
- one: 'less than a minute',
385
- other: 'less than {{count}} minutes'
386
- },
387
- xMinutes: {
388
- one: '1 minute',
389
- other: '{{count}} minutes'
390
- },
391
- aboutXHours: {
392
- one: 'about 1 hour',
393
- other: 'about {{count}} hours'
394
- },
395
- xHours: {
396
- one: '1 hour',
397
- other: '{{count}} hours'
398
- },
399
- xDays: {
400
- one: '1 day',
401
- other: '{{count}} days'
402
- },
403
- aboutXWeeks: {
404
- one: 'about 1 week',
405
- other: 'about {{count}} weeks'
406
- },
407
- xWeeks: {
408
- one: '1 week',
409
- other: '{{count}} weeks'
410
- },
411
- aboutXMonths: {
412
- one: 'about 1 month',
413
- other: 'about {{count}} months'
414
- },
415
- xMonths: {
416
- one: '1 month',
417
- other: '{{count}} months'
418
- },
419
- aboutXYears: {
420
- one: 'about 1 year',
421
- other: 'about {{count}} years'
422
- },
423
- xYears: {
424
- one: '1 year',
425
- other: '{{count}} years'
426
- },
427
- overXYears: {
428
- one: 'over 1 year',
429
- other: 'over {{count}} years'
430
- },
431
- almostXYears: {
432
- one: 'almost 1 year',
433
- other: 'almost {{count}} years'
434
- }
435
- };
436
- function formatDistance(token, count, options) {
437
- options = options || {};
438
- var result;
439
-
440
- if (typeof formatDistanceLocale[token] === 'string') {
441
- result = formatDistanceLocale[token];
442
- } else if (count === 1) {
443
- result = formatDistanceLocale[token].one;
444
- } else {
445
- result = formatDistanceLocale[token].other.replace('{{count}}', count);
446
- }
447
-
448
- if (options.addSuffix) {
449
- if (options.comparison > 0) {
450
- return 'in ' + result;
451
- } else {
452
- return result + ' ago';
453
- }
454
- }
455
-
456
- return result;
457
- }
458
-
459
- function buildFormatLongFn(args) {
460
- return function (dirtyOptions) {
461
- var options = dirtyOptions || {};
462
- var width = options.width ? String(options.width) : args.defaultWidth;
463
- var format = args.formats[width] || args.formats[args.defaultWidth];
464
- return format;
465
- };
466
- }
467
-
468
- var dateFormats = {
469
- full: 'EEEE, MMMM do, y',
470
- long: 'MMMM do, y',
471
- medium: 'MMM d, y',
472
- short: 'MM/dd/yyyy'
473
- };
474
- var timeFormats = {
475
- full: 'h:mm:ss a zzzz',
476
- long: 'h:mm:ss a z',
477
- medium: 'h:mm:ss a',
478
- short: 'h:mm a'
479
- };
480
- var dateTimeFormats = {
481
- full: "{{date}} 'at' {{time}}",
482
- long: "{{date}} 'at' {{time}}",
483
- medium: '{{date}}, {{time}}',
484
- short: '{{date}}, {{time}}'
485
- };
486
- var formatLong = {
487
- date: buildFormatLongFn({
488
- formats: dateFormats,
489
- defaultWidth: 'full'
490
- }),
491
- time: buildFormatLongFn({
492
- formats: timeFormats,
493
- defaultWidth: 'full'
494
- }),
495
- dateTime: buildFormatLongFn({
496
- formats: dateTimeFormats,
497
- defaultWidth: 'full'
498
- })
499
- };
500
-
501
- var formatRelativeLocale = {
502
- lastWeek: "'last' eeee 'at' p",
503
- yesterday: "'yesterday at' p",
504
- today: "'today at' p",
505
- tomorrow: "'tomorrow at' p",
506
- nextWeek: "eeee 'at' p",
507
- other: 'P'
508
- };
509
- function formatRelative(token, _date, _baseDate, _options) {
510
- return formatRelativeLocale[token];
511
- }
512
-
513
- function buildLocalizeFn(args) {
514
- return function (dirtyIndex, dirtyOptions) {
515
- var options = dirtyOptions || {};
516
- var context = options.context ? String(options.context) : 'standalone';
517
- var valuesArray;
518
-
519
- if (context === 'formatting' && args.formattingValues) {
520
- var defaultWidth = args.defaultFormattingWidth || args.defaultWidth;
521
- var width = options.width ? String(options.width) : defaultWidth;
522
- valuesArray = args.formattingValues[width] || args.formattingValues[defaultWidth];
523
- } else {
524
- var _defaultWidth = args.defaultWidth;
525
-
526
- var _width = options.width ? String(options.width) : args.defaultWidth;
527
-
528
- valuesArray = args.values[_width] || args.values[_defaultWidth];
529
- }
530
-
531
- var index = args.argumentCallback ? args.argumentCallback(dirtyIndex) : dirtyIndex;
532
- return valuesArray[index];
533
- };
534
- }
535
-
536
- var eraValues = {
537
- narrow: ['B', 'A'],
538
- abbreviated: ['BC', 'AD'],
539
- wide: ['Before Christ', 'Anno Domini']
540
- };
541
- var quarterValues = {
542
- narrow: ['1', '2', '3', '4'],
543
- abbreviated: ['Q1', 'Q2', 'Q3', 'Q4'],
544
- wide: ['1st quarter', '2nd quarter', '3rd quarter', '4th quarter'] // Note: in English, the names of days of the week and months are capitalized.
545
- // If you are making a new locale based on this one, check if the same is true for the language you're working on.
546
- // Generally, formatted dates should look like they are in the middle of a sentence,
547
- // e.g. in Spanish language the weekdays and months should be in the lowercase.
548
-
549
- };
550
- var monthValues = {
551
- narrow: ['J', 'F', 'M', 'A', 'M', 'J', 'J', 'A', 'S', 'O', 'N', 'D'],
552
- abbreviated: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
553
- wide: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
554
- };
555
- var dayValues = {
556
- narrow: ['S', 'M', 'T', 'W', 'T', 'F', 'S'],
557
- short: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'],
558
- abbreviated: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
559
- wide: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
560
- };
561
- var dayPeriodValues = {
562
- narrow: {
563
- am: 'a',
564
- pm: 'p',
565
- midnight: 'mi',
566
- noon: 'n',
567
- morning: 'morning',
568
- afternoon: 'afternoon',
569
- evening: 'evening',
570
- night: 'night'
571
- },
572
- abbreviated: {
573
- am: 'AM',
574
- pm: 'PM',
575
- midnight: 'midnight',
576
- noon: 'noon',
577
- morning: 'morning',
578
- afternoon: 'afternoon',
579
- evening: 'evening',
580
- night: 'night'
581
- },
582
- wide: {
583
- am: 'a.m.',
584
- pm: 'p.m.',
585
- midnight: 'midnight',
586
- noon: 'noon',
587
- morning: 'morning',
588
- afternoon: 'afternoon',
589
- evening: 'evening',
590
- night: 'night'
591
- }
592
- };
593
- var formattingDayPeriodValues = {
594
- narrow: {
595
- am: 'a',
596
- pm: 'p',
597
- midnight: 'mi',
598
- noon: 'n',
599
- morning: 'in the morning',
600
- afternoon: 'in the afternoon',
601
- evening: 'in the evening',
602
- night: 'at night'
603
- },
604
- abbreviated: {
605
- am: 'AM',
606
- pm: 'PM',
607
- midnight: 'midnight',
608
- noon: 'noon',
609
- morning: 'in the morning',
610
- afternoon: 'in the afternoon',
611
- evening: 'in the evening',
612
- night: 'at night'
613
- },
614
- wide: {
615
- am: 'a.m.',
616
- pm: 'p.m.',
617
- midnight: 'midnight',
618
- noon: 'noon',
619
- morning: 'in the morning',
620
- afternoon: 'in the afternoon',
621
- evening: 'in the evening',
622
- night: 'at night'
623
- }
624
- };
625
-
626
- function ordinalNumber(dirtyNumber, _dirtyOptions) {
627
- var number = Number(dirtyNumber); // If ordinal numbers depend on context, for example,
628
- // if they are different for different grammatical genders,
629
- // use `options.unit`:
630
- //
631
- // var options = dirtyOptions || {}
632
- // var unit = String(options.unit)
633
- //
634
- // where `unit` can be 'year', 'quarter', 'month', 'week', 'date', 'dayOfYear',
635
- // 'day', 'hour', 'minute', 'second'
636
-
637
- var rem100 = number % 100;
638
-
639
- if (rem100 > 20 || rem100 < 10) {
640
- switch (rem100 % 10) {
641
- case 1:
642
- return number + 'st';
643
-
644
- case 2:
645
- return number + 'nd';
646
-
647
- case 3:
648
- return number + 'rd';
649
- }
650
- }
651
-
652
- return number + 'th';
653
- }
654
-
655
- var localize = {
656
- ordinalNumber: ordinalNumber,
657
- era: buildLocalizeFn({
658
- values: eraValues,
659
- defaultWidth: 'wide'
660
- }),
661
- quarter: buildLocalizeFn({
662
- values: quarterValues,
663
- defaultWidth: 'wide',
664
- argumentCallback: function (quarter) {
665
- return Number(quarter) - 1;
666
- }
667
- }),
668
- month: buildLocalizeFn({
669
- values: monthValues,
670
- defaultWidth: 'wide'
671
- }),
672
- day: buildLocalizeFn({
673
- values: dayValues,
674
- defaultWidth: 'wide'
675
- }),
676
- dayPeriod: buildLocalizeFn({
677
- values: dayPeriodValues,
678
- defaultWidth: 'wide',
679
- formattingValues: formattingDayPeriodValues,
680
- defaultFormattingWidth: 'wide'
681
- })
682
- };
683
-
684
- function buildMatchPatternFn(args) {
685
- return function (dirtyString, dirtyOptions) {
686
- var string = String(dirtyString);
687
- var options = dirtyOptions || {};
688
- var matchResult = string.match(args.matchPattern);
689
-
690
- if (!matchResult) {
691
- return null;
692
- }
693
-
694
- var matchedString = matchResult[0];
695
- var parseResult = string.match(args.parsePattern);
696
-
697
- if (!parseResult) {
698
- return null;
699
- }
700
-
701
- var value = args.valueCallback ? args.valueCallback(parseResult[0]) : parseResult[0];
702
- value = options.valueCallback ? options.valueCallback(value) : value;
703
- return {
704
- value: value,
705
- rest: string.slice(matchedString.length)
706
- };
707
- };
708
- }
709
-
710
- function buildMatchFn(args) {
711
- return function (dirtyString, dirtyOptions) {
712
- var string = String(dirtyString);
713
- var options = dirtyOptions || {};
714
- var width = options.width;
715
- var matchPattern = width && args.matchPatterns[width] || args.matchPatterns[args.defaultMatchWidth];
716
- var matchResult = string.match(matchPattern);
717
-
718
- if (!matchResult) {
719
- return null;
720
- }
721
-
722
- var matchedString = matchResult[0];
723
- var parsePatterns = width && args.parsePatterns[width] || args.parsePatterns[args.defaultParseWidth];
724
- var value;
725
-
726
- if (Object.prototype.toString.call(parsePatterns) === '[object Array]') {
727
- value = findIndex(parsePatterns, function (pattern) {
728
- return pattern.test(matchedString);
729
- });
730
- } else {
731
- value = findKey(parsePatterns, function (pattern) {
732
- return pattern.test(matchedString);
733
- });
734
- }
735
-
736
- value = args.valueCallback ? args.valueCallback(value) : value;
737
- value = options.valueCallback ? options.valueCallback(value) : value;
738
- return {
739
- value: value,
740
- rest: string.slice(matchedString.length)
741
- };
742
- };
743
- }
744
-
745
- function findKey(object, predicate) {
746
- for (var key in object) {
747
- if (object.hasOwnProperty(key) && predicate(object[key])) {
748
- return key;
749
- }
750
- }
751
- }
752
-
753
- function findIndex(array, predicate) {
754
- for (var key = 0; key < array.length; key++) {
755
- if (predicate(array[key])) {
756
- return key;
757
- }
758
- }
759
- }
760
-
761
- var matchOrdinalNumberPattern = /^(\d+)(th|st|nd|rd)?/i;
762
- var parseOrdinalNumberPattern = /\d+/i;
763
- var matchEraPatterns = {
764
- narrow: /^(b|a)/i,
765
- abbreviated: /^(b\.?\s?c\.?|b\.?\s?c\.?\s?e\.?|a\.?\s?d\.?|c\.?\s?e\.?)/i,
766
- wide: /^(before christ|before common era|anno domini|common era)/i
767
- };
768
- var parseEraPatterns = {
769
- any: [/^b/i, /^(a|c)/i]
770
- };
771
- var matchQuarterPatterns = {
772
- narrow: /^[1234]/i,
773
- abbreviated: /^q[1234]/i,
774
- wide: /^[1234](th|st|nd|rd)? quarter/i
775
- };
776
- var parseQuarterPatterns = {
777
- any: [/1/i, /2/i, /3/i, /4/i]
778
- };
779
- var matchMonthPatterns = {
780
- narrow: /^[jfmasond]/i,
781
- abbreviated: /^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/i,
782
- wide: /^(january|february|march|april|may|june|july|august|september|october|november|december)/i
783
- };
784
- var parseMonthPatterns = {
785
- narrow: [/^j/i, /^f/i, /^m/i, /^a/i, /^m/i, /^j/i, /^j/i, /^a/i, /^s/i, /^o/i, /^n/i, /^d/i],
786
- any: [/^ja/i, /^f/i, /^mar/i, /^ap/i, /^may/i, /^jun/i, /^jul/i, /^au/i, /^s/i, /^o/i, /^n/i, /^d/i]
787
- };
788
- var matchDayPatterns = {
789
- narrow: /^[smtwf]/i,
790
- short: /^(su|mo|tu|we|th|fr|sa)/i,
791
- abbreviated: /^(sun|mon|tue|wed|thu|fri|sat)/i,
792
- wide: /^(sunday|monday|tuesday|wednesday|thursday|friday|saturday)/i
793
- };
794
- var parseDayPatterns = {
795
- narrow: [/^s/i, /^m/i, /^t/i, /^w/i, /^t/i, /^f/i, /^s/i],
796
- any: [/^su/i, /^m/i, /^tu/i, /^w/i, /^th/i, /^f/i, /^sa/i]
797
- };
798
- var matchDayPeriodPatterns = {
799
- narrow: /^(a|p|mi|n|(in the|at) (morning|afternoon|evening|night))/i,
800
- any: /^([ap]\.?\s?m\.?|midnight|noon|(in the|at) (morning|afternoon|evening|night))/i
801
- };
802
- var parseDayPeriodPatterns = {
803
- any: {
804
- am: /^a/i,
805
- pm: /^p/i,
806
- midnight: /^mi/i,
807
- noon: /^no/i,
808
- morning: /morning/i,
809
- afternoon: /afternoon/i,
810
- evening: /evening/i,
811
- night: /night/i
812
- }
813
- };
814
- var match = {
815
- ordinalNumber: buildMatchPatternFn({
816
- matchPattern: matchOrdinalNumberPattern,
817
- parsePattern: parseOrdinalNumberPattern,
818
- valueCallback: function (value) {
819
- return parseInt(value, 10);
820
- }
821
- }),
822
- era: buildMatchFn({
823
- matchPatterns: matchEraPatterns,
824
- defaultMatchWidth: 'wide',
825
- parsePatterns: parseEraPatterns,
826
- defaultParseWidth: 'any'
827
- }),
828
- quarter: buildMatchFn({
829
- matchPatterns: matchQuarterPatterns,
830
- defaultMatchWidth: 'wide',
831
- parsePatterns: parseQuarterPatterns,
832
- defaultParseWidth: 'any',
833
- valueCallback: function (index) {
834
- return index + 1;
835
- }
836
- }),
837
- month: buildMatchFn({
838
- matchPatterns: matchMonthPatterns,
839
- defaultMatchWidth: 'wide',
840
- parsePatterns: parseMonthPatterns,
841
- defaultParseWidth: 'any'
842
- }),
843
- day: buildMatchFn({
844
- matchPatterns: matchDayPatterns,
845
- defaultMatchWidth: 'wide',
846
- parsePatterns: parseDayPatterns,
847
- defaultParseWidth: 'any'
848
- }),
849
- dayPeriod: buildMatchFn({
850
- matchPatterns: matchDayPeriodPatterns,
851
- defaultMatchWidth: 'any',
852
- parsePatterns: parseDayPeriodPatterns,
853
- defaultParseWidth: 'any'
854
- })
855
- };
856
-
857
- /**
858
- * @type {Locale}
859
- * @category Locales
860
- * @summary English locale (United States).
861
- * @language English
862
- * @iso-639-2 eng
863
- * @author Sasha Koss [@kossnocorp]{@link https://github.com/kossnocorp}
864
- * @author Lesha Koss [@leshakoss]{@link https://github.com/leshakoss}
865
- */
866
-
867
- var locale = {
868
- code: 'en-US',
869
- formatDistance: formatDistance,
870
- formatLong: formatLong,
871
- formatRelative: formatRelative,
872
- localize: localize,
873
- match: match,
874
- options: {
875
- weekStartsOn: 0
876
- /* Sunday */
877
- ,
878
- firstWeekContainsDate: 1
879
- }
880
- };
881
-
882
- /**
883
- * @name subMilliseconds
884
- * @category Millisecond Helpers
885
- * @summary Subtract the specified number of milliseconds from the given date.
886
- *
887
- * @description
888
- * Subtract the specified number of milliseconds from the given date.
889
- *
890
- * ### v2.0.0 breaking changes:
891
- *
892
- * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
893
- *
894
- * @param {Date|Number} date - the date to be changed
895
- * @param {Number} amount - the amount of milliseconds to be subtracted. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
896
- * @returns {Date} the new date with the milliseconds subtracted
897
- * @throws {TypeError} 2 arguments required
898
- *
899
- * @example
900
- * // Subtract 750 milliseconds from 10 July 2014 12:45:30.000:
901
- * var result = subMilliseconds(new Date(2014, 6, 10, 12, 45, 30, 0), 750)
902
- * //=> Thu Jul 10 2014 12:45:29.250
903
- */
904
-
905
- function subMilliseconds(dirtyDate, dirtyAmount) {
906
- requiredArgs(2, arguments);
907
- var amount = toInteger(dirtyAmount);
908
- return addMilliseconds(dirtyDate, -amount);
909
- }
910
-
911
- function addLeadingZeros(number, targetLength) {
912
- var sign = number < 0 ? '-' : '';
913
- var output = Math.abs(number).toString();
914
-
915
- while (output.length < targetLength) {
916
- output = '0' + output;
917
- }
918
-
919
- return sign + output;
920
- }
921
-
922
- /*
923
- * | | Unit | | Unit |
924
- * |-----|--------------------------------|-----|--------------------------------|
925
- * | a | AM, PM | A* | |
926
- * | d | Day of month | D | |
927
- * | h | Hour [1-12] | H | Hour [0-23] |
928
- * | m | Minute | M | Month |
929
- * | s | Second | S | Fraction of second |
930
- * | y | Year (abs) | Y | |
931
- *
932
- * Letters marked by * are not implemented but reserved by Unicode standard.
933
- */
934
-
935
- var formatters = {
936
- // Year
937
- y: function (date, token) {
938
- // From http://www.unicode.org/reports/tr35/tr35-31/tr35-dates.html#Date_Format_tokens
939
- // | Year | y | yy | yyy | yyyy | yyyyy |
940
- // |----------|-------|----|-------|-------|-------|
941
- // | AD 1 | 1 | 01 | 001 | 0001 | 00001 |
942
- // | AD 12 | 12 | 12 | 012 | 0012 | 00012 |
943
- // | AD 123 | 123 | 23 | 123 | 0123 | 00123 |
944
- // | AD 1234 | 1234 | 34 | 1234 | 1234 | 01234 |
945
- // | AD 12345 | 12345 | 45 | 12345 | 12345 | 12345 |
946
- var signedYear = date.getUTCFullYear(); // Returns 1 for 1 BC (which is year 0 in JavaScript)
947
-
948
- var year = signedYear > 0 ? signedYear : 1 - signedYear;
949
- return addLeadingZeros(token === 'yy' ? year % 100 : year, token.length);
950
- },
951
- // Month
952
- M: function (date, token) {
953
- var month = date.getUTCMonth();
954
- return token === 'M' ? String(month + 1) : addLeadingZeros(month + 1, 2);
955
- },
956
- // Day of the month
957
- d: function (date, token) {
958
- return addLeadingZeros(date.getUTCDate(), token.length);
959
- },
960
- // AM or PM
961
- a: function (date, token) {
962
- var dayPeriodEnumValue = date.getUTCHours() / 12 >= 1 ? 'pm' : 'am';
963
-
964
- switch (token) {
965
- case 'a':
966
- case 'aa':
967
- case 'aaa':
968
- return dayPeriodEnumValue.toUpperCase();
969
-
970
- case 'aaaaa':
971
- return dayPeriodEnumValue[0];
972
-
973
- case 'aaaa':
974
- default:
975
- return dayPeriodEnumValue === 'am' ? 'a.m.' : 'p.m.';
976
- }
977
- },
978
- // Hour [1-12]
979
- h: function (date, token) {
980
- return addLeadingZeros(date.getUTCHours() % 12 || 12, token.length);
981
- },
982
- // Hour [0-23]
983
- H: function (date, token) {
984
- return addLeadingZeros(date.getUTCHours(), token.length);
985
- },
986
- // Minute
987
- m: function (date, token) {
988
- return addLeadingZeros(date.getUTCMinutes(), token.length);
989
- },
990
- // Second
991
- s: function (date, token) {
992
- return addLeadingZeros(date.getUTCSeconds(), token.length);
993
- },
994
- // Fraction of second
995
- S: function (date, token) {
996
- var numberOfDigits = token.length;
997
- var milliseconds = date.getUTCMilliseconds();
998
- var fractionalSeconds = Math.floor(milliseconds * Math.pow(10, numberOfDigits - 3));
999
- return addLeadingZeros(fractionalSeconds, token.length);
1000
- }
1001
- };
1002
-
1003
- var MILLISECONDS_IN_DAY = 86400000; // This function will be a part of public API when UTC function will be implemented.
1004
- // See issue: https://github.com/date-fns/date-fns/issues/376
1005
-
1006
- function getUTCDayOfYear(dirtyDate) {
1007
- requiredArgs(1, arguments);
1008
- var date = toDate(dirtyDate);
1009
- var timestamp = date.getTime();
1010
- date.setUTCMonth(0, 1);
1011
- date.setUTCHours(0, 0, 0, 0);
1012
- var startOfYearTimestamp = date.getTime();
1013
- var difference = timestamp - startOfYearTimestamp;
1014
- return Math.floor(difference / MILLISECONDS_IN_DAY) + 1;
1015
- }
1016
-
1017
- // See issue: https://github.com/date-fns/date-fns/issues/376
1018
-
1019
- function startOfUTCISOWeek(dirtyDate) {
1020
- requiredArgs(1, arguments);
1021
- var weekStartsOn = 1;
1022
- var date = toDate(dirtyDate);
1023
- var day = date.getUTCDay();
1024
- var diff = (day < weekStartsOn ? 7 : 0) + day - weekStartsOn;
1025
- date.setUTCDate(date.getUTCDate() - diff);
1026
- date.setUTCHours(0, 0, 0, 0);
1027
- return date;
1028
- }
1029
-
1030
- // See issue: https://github.com/date-fns/date-fns/issues/376
1031
-
1032
- function getUTCISOWeekYear(dirtyDate) {
1033
- requiredArgs(1, arguments);
1034
- var date = toDate(dirtyDate);
1035
- var year = date.getUTCFullYear();
1036
- var fourthOfJanuaryOfNextYear = new Date(0);
1037
- fourthOfJanuaryOfNextYear.setUTCFullYear(year + 1, 0, 4);
1038
- fourthOfJanuaryOfNextYear.setUTCHours(0, 0, 0, 0);
1039
- var startOfNextYear = startOfUTCISOWeek(fourthOfJanuaryOfNextYear);
1040
- var fourthOfJanuaryOfThisYear = new Date(0);
1041
- fourthOfJanuaryOfThisYear.setUTCFullYear(year, 0, 4);
1042
- fourthOfJanuaryOfThisYear.setUTCHours(0, 0, 0, 0);
1043
- var startOfThisYear = startOfUTCISOWeek(fourthOfJanuaryOfThisYear);
1044
-
1045
- if (date.getTime() >= startOfNextYear.getTime()) {
1046
- return year + 1;
1047
- } else if (date.getTime() >= startOfThisYear.getTime()) {
1048
- return year;
1049
- } else {
1050
- return year - 1;
1051
- }
1052
- }
1053
-
1054
- // See issue: https://github.com/date-fns/date-fns/issues/376
1055
-
1056
- function startOfUTCISOWeekYear(dirtyDate) {
1057
- requiredArgs(1, arguments);
1058
- var year = getUTCISOWeekYear(dirtyDate);
1059
- var fourthOfJanuary = new Date(0);
1060
- fourthOfJanuary.setUTCFullYear(year, 0, 4);
1061
- fourthOfJanuary.setUTCHours(0, 0, 0, 0);
1062
- var date = startOfUTCISOWeek(fourthOfJanuary);
1063
- return date;
1064
- }
1065
-
1066
- var MILLISECONDS_IN_WEEK = 604800000; // This function will be a part of public API when UTC function will be implemented.
1067
- // See issue: https://github.com/date-fns/date-fns/issues/376
1068
-
1069
- function getUTCISOWeek(dirtyDate) {
1070
- requiredArgs(1, arguments);
1071
- var date = toDate(dirtyDate);
1072
- var diff = startOfUTCISOWeek(date).getTime() - startOfUTCISOWeekYear(date).getTime(); // Round the number of days to the nearest integer
1073
- // because the number of milliseconds in a week is not constant
1074
- // (e.g. it's different in the week of the daylight saving time clock shift)
1075
-
1076
- return Math.round(diff / MILLISECONDS_IN_WEEK) + 1;
1077
- }
1078
-
1079
- // See issue: https://github.com/date-fns/date-fns/issues/376
1080
-
1081
- function startOfUTCWeek(dirtyDate, dirtyOptions) {
1082
- requiredArgs(1, arguments);
1083
- var options = dirtyOptions || {};
1084
- var locale = options.locale;
1085
- var localeWeekStartsOn = locale && locale.options && locale.options.weekStartsOn;
1086
- var defaultWeekStartsOn = localeWeekStartsOn == null ? 0 : toInteger(localeWeekStartsOn);
1087
- var weekStartsOn = options.weekStartsOn == null ? defaultWeekStartsOn : toInteger(options.weekStartsOn); // Test if weekStartsOn is between 0 and 6 _and_ is not NaN
1088
-
1089
- if (!(weekStartsOn >= 0 && weekStartsOn <= 6)) {
1090
- throw new RangeError('weekStartsOn must be between 0 and 6 inclusively');
1091
- }
1092
-
1093
- var date = toDate(dirtyDate);
1094
- var day = date.getUTCDay();
1095
- var diff = (day < weekStartsOn ? 7 : 0) + day - weekStartsOn;
1096
- date.setUTCDate(date.getUTCDate() - diff);
1097
- date.setUTCHours(0, 0, 0, 0);
1098
- return date;
1099
- }
1100
-
1101
- // See issue: https://github.com/date-fns/date-fns/issues/376
1102
-
1103
- function getUTCWeekYear(dirtyDate, dirtyOptions) {
1104
- requiredArgs(1, arguments);
1105
- var date = toDate(dirtyDate, dirtyOptions);
1106
- var year = date.getUTCFullYear();
1107
- var options = dirtyOptions || {};
1108
- var locale = options.locale;
1109
- var localeFirstWeekContainsDate = locale && locale.options && locale.options.firstWeekContainsDate;
1110
- var defaultFirstWeekContainsDate = localeFirstWeekContainsDate == null ? 1 : toInteger(localeFirstWeekContainsDate);
1111
- var firstWeekContainsDate = options.firstWeekContainsDate == null ? defaultFirstWeekContainsDate : toInteger(options.firstWeekContainsDate); // Test if weekStartsOn is between 1 and 7 _and_ is not NaN
1112
-
1113
- if (!(firstWeekContainsDate >= 1 && firstWeekContainsDate <= 7)) {
1114
- throw new RangeError('firstWeekContainsDate must be between 1 and 7 inclusively');
1115
- }
1116
-
1117
- var firstWeekOfNextYear = new Date(0);
1118
- firstWeekOfNextYear.setUTCFullYear(year + 1, 0, firstWeekContainsDate);
1119
- firstWeekOfNextYear.setUTCHours(0, 0, 0, 0);
1120
- var startOfNextYear = startOfUTCWeek(firstWeekOfNextYear, dirtyOptions);
1121
- var firstWeekOfThisYear = new Date(0);
1122
- firstWeekOfThisYear.setUTCFullYear(year, 0, firstWeekContainsDate);
1123
- firstWeekOfThisYear.setUTCHours(0, 0, 0, 0);
1124
- var startOfThisYear = startOfUTCWeek(firstWeekOfThisYear, dirtyOptions);
1125
-
1126
- if (date.getTime() >= startOfNextYear.getTime()) {
1127
- return year + 1;
1128
- } else if (date.getTime() >= startOfThisYear.getTime()) {
1129
- return year;
1130
- } else {
1131
- return year - 1;
1132
- }
1133
- }
1134
-
1135
- // See issue: https://github.com/date-fns/date-fns/issues/376
1136
-
1137
- function startOfUTCWeekYear(dirtyDate, dirtyOptions) {
1138
- requiredArgs(1, arguments);
1139
- var options = dirtyOptions || {};
1140
- var locale = options.locale;
1141
- var localeFirstWeekContainsDate = locale && locale.options && locale.options.firstWeekContainsDate;
1142
- var defaultFirstWeekContainsDate = localeFirstWeekContainsDate == null ? 1 : toInteger(localeFirstWeekContainsDate);
1143
- var firstWeekContainsDate = options.firstWeekContainsDate == null ? defaultFirstWeekContainsDate : toInteger(options.firstWeekContainsDate);
1144
- var year = getUTCWeekYear(dirtyDate, dirtyOptions);
1145
- var firstWeek = new Date(0);
1146
- firstWeek.setUTCFullYear(year, 0, firstWeekContainsDate);
1147
- firstWeek.setUTCHours(0, 0, 0, 0);
1148
- var date = startOfUTCWeek(firstWeek, dirtyOptions);
1149
- return date;
1150
- }
1151
-
1152
- var MILLISECONDS_IN_WEEK$1 = 604800000; // This function will be a part of public API when UTC function will be implemented.
1153
- // See issue: https://github.com/date-fns/date-fns/issues/376
1154
-
1155
- function getUTCWeek(dirtyDate, options) {
1156
- requiredArgs(1, arguments);
1157
- var date = toDate(dirtyDate);
1158
- var diff = startOfUTCWeek(date, options).getTime() - startOfUTCWeekYear(date, options).getTime(); // Round the number of days to the nearest integer
1159
- // because the number of milliseconds in a week is not constant
1160
- // (e.g. it's different in the week of the daylight saving time clock shift)
1161
-
1162
- return Math.round(diff / MILLISECONDS_IN_WEEK$1) + 1;
1163
- }
1164
-
1165
- var dayPeriodEnum = {
1166
- am: 'am',
1167
- pm: 'pm',
1168
- midnight: 'midnight',
1169
- noon: 'noon',
1170
- morning: 'morning',
1171
- afternoon: 'afternoon',
1172
- evening: 'evening',
1173
- night: 'night'
1174
- /*
1175
- * | | Unit | | Unit |
1176
- * |-----|--------------------------------|-----|--------------------------------|
1177
- * | a | AM, PM | A* | Milliseconds in day |
1178
- * | b | AM, PM, noon, midnight | B | Flexible day period |
1179
- * | c | Stand-alone local day of week | C* | Localized hour w/ day period |
1180
- * | d | Day of month | D | Day of year |
1181
- * | e | Local day of week | E | Day of week |
1182
- * | f | | F* | Day of week in month |
1183
- * | g* | Modified Julian day | G | Era |
1184
- * | h | Hour [1-12] | H | Hour [0-23] |
1185
- * | i! | ISO day of week | I! | ISO week of year |
1186
- * | j* | Localized hour w/ day period | J* | Localized hour w/o day period |
1187
- * | k | Hour [1-24] | K | Hour [0-11] |
1188
- * | l* | (deprecated) | L | Stand-alone month |
1189
- * | m | Minute | M | Month |
1190
- * | n | | N | |
1191
- * | o! | Ordinal number modifier | O | Timezone (GMT) |
1192
- * | p! | Long localized time | P! | Long localized date |
1193
- * | q | Stand-alone quarter | Q | Quarter |
1194
- * | r* | Related Gregorian year | R! | ISO week-numbering year |
1195
- * | s | Second | S | Fraction of second |
1196
- * | t! | Seconds timestamp | T! | Milliseconds timestamp |
1197
- * | u | Extended year | U* | Cyclic year |
1198
- * | v* | Timezone (generic non-locat.) | V* | Timezone (location) |
1199
- * | w | Local week of year | W* | Week of month |
1200
- * | x | Timezone (ISO-8601 w/o Z) | X | Timezone (ISO-8601) |
1201
- * | y | Year (abs) | Y | Local week-numbering year |
1202
- * | z | Timezone (specific non-locat.) | Z* | Timezone (aliases) |
1203
- *
1204
- * Letters marked by * are not implemented but reserved by Unicode standard.
1205
- *
1206
- * Letters marked by ! are non-standard, but implemented by date-fns:
1207
- * - `o` modifies the previous token to turn it into an ordinal (see `format` docs)
1208
- * - `i` is ISO day of week. For `i` and `ii` is returns numeric ISO week days,
1209
- * i.e. 7 for Sunday, 1 for Monday, etc.
1210
- * - `I` is ISO week of year, as opposed to `w` which is local week of year.
1211
- * - `R` is ISO week-numbering year, as opposed to `Y` which is local week-numbering year.
1212
- * `R` is supposed to be used in conjunction with `I` and `i`
1213
- * for universal ISO week-numbering date, whereas
1214
- * `Y` is supposed to be used in conjunction with `w` and `e`
1215
- * for week-numbering date specific to the locale.
1216
- * - `P` is long localized date format
1217
- * - `p` is long localized time format
1218
- */
1219
-
1220
- };
1221
- var formatters$1 = {
1222
- // Era
1223
- G: function (date, token, localize) {
1224
- var era = date.getUTCFullYear() > 0 ? 1 : 0;
1225
-
1226
- switch (token) {
1227
- // AD, BC
1228
- case 'G':
1229
- case 'GG':
1230
- case 'GGG':
1231
- return localize.era(era, {
1232
- width: 'abbreviated'
1233
- });
1234
- // A, B
1235
-
1236
- case 'GGGGG':
1237
- return localize.era(era, {
1238
- width: 'narrow'
1239
- });
1240
- // Anno Domini, Before Christ
1241
-
1242
- case 'GGGG':
1243
- default:
1244
- return localize.era(era, {
1245
- width: 'wide'
1246
- });
1247
- }
1248
- },
1249
- // Year
1250
- y: function (date, token, localize) {
1251
- // Ordinal number
1252
- if (token === 'yo') {
1253
- var signedYear = date.getUTCFullYear(); // Returns 1 for 1 BC (which is year 0 in JavaScript)
1254
-
1255
- var year = signedYear > 0 ? signedYear : 1 - signedYear;
1256
- return localize.ordinalNumber(year, {
1257
- unit: 'year'
1258
- });
1259
- }
1260
-
1261
- return formatters.y(date, token);
1262
- },
1263
- // Local week-numbering year
1264
- Y: function (date, token, localize, options) {
1265
- var signedWeekYear = getUTCWeekYear(date, options); // Returns 1 for 1 BC (which is year 0 in JavaScript)
1266
-
1267
- var weekYear = signedWeekYear > 0 ? signedWeekYear : 1 - signedWeekYear; // Two digit year
1268
-
1269
- if (token === 'YY') {
1270
- var twoDigitYear = weekYear % 100;
1271
- return addLeadingZeros(twoDigitYear, 2);
1272
- } // Ordinal number
1273
-
1274
-
1275
- if (token === 'Yo') {
1276
- return localize.ordinalNumber(weekYear, {
1277
- unit: 'year'
1278
- });
1279
- } // Padding
1280
-
1281
-
1282
- return addLeadingZeros(weekYear, token.length);
1283
- },
1284
- // ISO week-numbering year
1285
- R: function (date, token) {
1286
- var isoWeekYear = getUTCISOWeekYear(date); // Padding
1287
-
1288
- return addLeadingZeros(isoWeekYear, token.length);
1289
- },
1290
- // Extended year. This is a single number designating the year of this calendar system.
1291
- // The main difference between `y` and `u` localizers are B.C. years:
1292
- // | Year | `y` | `u` |
1293
- // |------|-----|-----|
1294
- // | AC 1 | 1 | 1 |
1295
- // | BC 1 | 1 | 0 |
1296
- // | BC 2 | 2 | -1 |
1297
- // Also `yy` always returns the last two digits of a year,
1298
- // while `uu` pads single digit years to 2 characters and returns other years unchanged.
1299
- u: function (date, token) {
1300
- var year = date.getUTCFullYear();
1301
- return addLeadingZeros(year, token.length);
1302
- },
1303
- // Quarter
1304
- Q: function (date, token, localize) {
1305
- var quarter = Math.ceil((date.getUTCMonth() + 1) / 3);
1306
-
1307
- switch (token) {
1308
- // 1, 2, 3, 4
1309
- case 'Q':
1310
- return String(quarter);
1311
- // 01, 02, 03, 04
1312
-
1313
- case 'QQ':
1314
- return addLeadingZeros(quarter, 2);
1315
- // 1st, 2nd, 3rd, 4th
1316
-
1317
- case 'Qo':
1318
- return localize.ordinalNumber(quarter, {
1319
- unit: 'quarter'
1320
- });
1321
- // Q1, Q2, Q3, Q4
1322
-
1323
- case 'QQQ':
1324
- return localize.quarter(quarter, {
1325
- width: 'abbreviated',
1326
- context: 'formatting'
1327
- });
1328
- // 1, 2, 3, 4 (narrow quarter; could be not numerical)
1329
-
1330
- case 'QQQQQ':
1331
- return localize.quarter(quarter, {
1332
- width: 'narrow',
1333
- context: 'formatting'
1334
- });
1335
- // 1st quarter, 2nd quarter, ...
1336
-
1337
- case 'QQQQ':
1338
- default:
1339
- return localize.quarter(quarter, {
1340
- width: 'wide',
1341
- context: 'formatting'
1342
- });
1343
- }
1344
- },
1345
- // Stand-alone quarter
1346
- q: function (date, token, localize) {
1347
- var quarter = Math.ceil((date.getUTCMonth() + 1) / 3);
1348
-
1349
- switch (token) {
1350
- // 1, 2, 3, 4
1351
- case 'q':
1352
- return String(quarter);
1353
- // 01, 02, 03, 04
1354
-
1355
- case 'qq':
1356
- return addLeadingZeros(quarter, 2);
1357
- // 1st, 2nd, 3rd, 4th
1358
-
1359
- case 'qo':
1360
- return localize.ordinalNumber(quarter, {
1361
- unit: 'quarter'
1362
- });
1363
- // Q1, Q2, Q3, Q4
1364
-
1365
- case 'qqq':
1366
- return localize.quarter(quarter, {
1367
- width: 'abbreviated',
1368
- context: 'standalone'
1369
- });
1370
- // 1, 2, 3, 4 (narrow quarter; could be not numerical)
1371
-
1372
- case 'qqqqq':
1373
- return localize.quarter(quarter, {
1374
- width: 'narrow',
1375
- context: 'standalone'
1376
- });
1377
- // 1st quarter, 2nd quarter, ...
1378
-
1379
- case 'qqqq':
1380
- default:
1381
- return localize.quarter(quarter, {
1382
- width: 'wide',
1383
- context: 'standalone'
1384
- });
1385
- }
1386
- },
1387
- // Month
1388
- M: function (date, token, localize) {
1389
- var month = date.getUTCMonth();
1390
-
1391
- switch (token) {
1392
- case 'M':
1393
- case 'MM':
1394
- return formatters.M(date, token);
1395
- // 1st, 2nd, ..., 12th
1396
-
1397
- case 'Mo':
1398
- return localize.ordinalNumber(month + 1, {
1399
- unit: 'month'
1400
- });
1401
- // Jan, Feb, ..., Dec
1402
-
1403
- case 'MMM':
1404
- return localize.month(month, {
1405
- width: 'abbreviated',
1406
- context: 'formatting'
1407
- });
1408
- // J, F, ..., D
1409
-
1410
- case 'MMMMM':
1411
- return localize.month(month, {
1412
- width: 'narrow',
1413
- context: 'formatting'
1414
- });
1415
- // January, February, ..., December
1416
-
1417
- case 'MMMM':
1418
- default:
1419
- return localize.month(month, {
1420
- width: 'wide',
1421
- context: 'formatting'
1422
- });
1423
- }
1424
- },
1425
- // Stand-alone month
1426
- L: function (date, token, localize) {
1427
- var month = date.getUTCMonth();
1428
-
1429
- switch (token) {
1430
- // 1, 2, ..., 12
1431
- case 'L':
1432
- return String(month + 1);
1433
- // 01, 02, ..., 12
1434
-
1435
- case 'LL':
1436
- return addLeadingZeros(month + 1, 2);
1437
- // 1st, 2nd, ..., 12th
1438
-
1439
- case 'Lo':
1440
- return localize.ordinalNumber(month + 1, {
1441
- unit: 'month'
1442
- });
1443
- // Jan, Feb, ..., Dec
1444
-
1445
- case 'LLL':
1446
- return localize.month(month, {
1447
- width: 'abbreviated',
1448
- context: 'standalone'
1449
- });
1450
- // J, F, ..., D
1451
-
1452
- case 'LLLLL':
1453
- return localize.month(month, {
1454
- width: 'narrow',
1455
- context: 'standalone'
1456
- });
1457
- // January, February, ..., December
1458
-
1459
- case 'LLLL':
1460
- default:
1461
- return localize.month(month, {
1462
- width: 'wide',
1463
- context: 'standalone'
1464
- });
1465
- }
1466
- },
1467
- // Local week of year
1468
- w: function (date, token, localize, options) {
1469
- var week = getUTCWeek(date, options);
1470
-
1471
- if (token === 'wo') {
1472
- return localize.ordinalNumber(week, {
1473
- unit: 'week'
1474
- });
1475
- }
1476
-
1477
- return addLeadingZeros(week, token.length);
1478
- },
1479
- // ISO week of year
1480
- I: function (date, token, localize) {
1481
- var isoWeek = getUTCISOWeek(date);
1482
-
1483
- if (token === 'Io') {
1484
- return localize.ordinalNumber(isoWeek, {
1485
- unit: 'week'
1486
- });
1487
- }
1488
-
1489
- return addLeadingZeros(isoWeek, token.length);
1490
- },
1491
- // Day of the month
1492
- d: function (date, token, localize) {
1493
- if (token === 'do') {
1494
- return localize.ordinalNumber(date.getUTCDate(), {
1495
- unit: 'date'
1496
- });
1497
- }
1498
-
1499
- return formatters.d(date, token);
1500
- },
1501
- // Day of year
1502
- D: function (date, token, localize) {
1503
- var dayOfYear = getUTCDayOfYear(date);
1504
-
1505
- if (token === 'Do') {
1506
- return localize.ordinalNumber(dayOfYear, {
1507
- unit: 'dayOfYear'
1508
- });
1509
- }
1510
-
1511
- return addLeadingZeros(dayOfYear, token.length);
1512
- },
1513
- // Day of week
1514
- E: function (date, token, localize) {
1515
- var dayOfWeek = date.getUTCDay();
1516
-
1517
- switch (token) {
1518
- // Tue
1519
- case 'E':
1520
- case 'EE':
1521
- case 'EEE':
1522
- return localize.day(dayOfWeek, {
1523
- width: 'abbreviated',
1524
- context: 'formatting'
1525
- });
1526
- // T
1527
-
1528
- case 'EEEEE':
1529
- return localize.day(dayOfWeek, {
1530
- width: 'narrow',
1531
- context: 'formatting'
1532
- });
1533
- // Tu
1534
-
1535
- case 'EEEEEE':
1536
- return localize.day(dayOfWeek, {
1537
- width: 'short',
1538
- context: 'formatting'
1539
- });
1540
- // Tuesday
1541
-
1542
- case 'EEEE':
1543
- default:
1544
- return localize.day(dayOfWeek, {
1545
- width: 'wide',
1546
- context: 'formatting'
1547
- });
1548
- }
1549
- },
1550
- // Local day of week
1551
- e: function (date, token, localize, options) {
1552
- var dayOfWeek = date.getUTCDay();
1553
- var localDayOfWeek = (dayOfWeek - options.weekStartsOn + 8) % 7 || 7;
1554
-
1555
- switch (token) {
1556
- // Numerical value (Nth day of week with current locale or weekStartsOn)
1557
- case 'e':
1558
- return String(localDayOfWeek);
1559
- // Padded numerical value
1560
-
1561
- case 'ee':
1562
- return addLeadingZeros(localDayOfWeek, 2);
1563
- // 1st, 2nd, ..., 7th
1564
-
1565
- case 'eo':
1566
- return localize.ordinalNumber(localDayOfWeek, {
1567
- unit: 'day'
1568
- });
1569
-
1570
- case 'eee':
1571
- return localize.day(dayOfWeek, {
1572
- width: 'abbreviated',
1573
- context: 'formatting'
1574
- });
1575
- // T
1576
-
1577
- case 'eeeee':
1578
- return localize.day(dayOfWeek, {
1579
- width: 'narrow',
1580
- context: 'formatting'
1581
- });
1582
- // Tu
1583
-
1584
- case 'eeeeee':
1585
- return localize.day(dayOfWeek, {
1586
- width: 'short',
1587
- context: 'formatting'
1588
- });
1589
- // Tuesday
1590
-
1591
- case 'eeee':
1592
- default:
1593
- return localize.day(dayOfWeek, {
1594
- width: 'wide',
1595
- context: 'formatting'
1596
- });
1597
- }
1598
- },
1599
- // Stand-alone local day of week
1600
- c: function (date, token, localize, options) {
1601
- var dayOfWeek = date.getUTCDay();
1602
- var localDayOfWeek = (dayOfWeek - options.weekStartsOn + 8) % 7 || 7;
1603
-
1604
- switch (token) {
1605
- // Numerical value (same as in `e`)
1606
- case 'c':
1607
- return String(localDayOfWeek);
1608
- // Padded numerical value
1609
-
1610
- case 'cc':
1611
- return addLeadingZeros(localDayOfWeek, token.length);
1612
- // 1st, 2nd, ..., 7th
1613
-
1614
- case 'co':
1615
- return localize.ordinalNumber(localDayOfWeek, {
1616
- unit: 'day'
1617
- });
1618
-
1619
- case 'ccc':
1620
- return localize.day(dayOfWeek, {
1621
- width: 'abbreviated',
1622
- context: 'standalone'
1623
- });
1624
- // T
1625
-
1626
- case 'ccccc':
1627
- return localize.day(dayOfWeek, {
1628
- width: 'narrow',
1629
- context: 'standalone'
1630
- });
1631
- // Tu
1632
-
1633
- case 'cccccc':
1634
- return localize.day(dayOfWeek, {
1635
- width: 'short',
1636
- context: 'standalone'
1637
- });
1638
- // Tuesday
1639
-
1640
- case 'cccc':
1641
- default:
1642
- return localize.day(dayOfWeek, {
1643
- width: 'wide',
1644
- context: 'standalone'
1645
- });
1646
- }
1647
- },
1648
- // ISO day of week
1649
- i: function (date, token, localize) {
1650
- var dayOfWeek = date.getUTCDay();
1651
- var isoDayOfWeek = dayOfWeek === 0 ? 7 : dayOfWeek;
1652
-
1653
- switch (token) {
1654
- // 2
1655
- case 'i':
1656
- return String(isoDayOfWeek);
1657
- // 02
1658
-
1659
- case 'ii':
1660
- return addLeadingZeros(isoDayOfWeek, token.length);
1661
- // 2nd
1662
-
1663
- case 'io':
1664
- return localize.ordinalNumber(isoDayOfWeek, {
1665
- unit: 'day'
1666
- });
1667
- // Tue
1668
-
1669
- case 'iii':
1670
- return localize.day(dayOfWeek, {
1671
- width: 'abbreviated',
1672
- context: 'formatting'
1673
- });
1674
- // T
1675
-
1676
- case 'iiiii':
1677
- return localize.day(dayOfWeek, {
1678
- width: 'narrow',
1679
- context: 'formatting'
1680
- });
1681
- // Tu
1682
-
1683
- case 'iiiiii':
1684
- return localize.day(dayOfWeek, {
1685
- width: 'short',
1686
- context: 'formatting'
1687
- });
1688
- // Tuesday
1689
-
1690
- case 'iiii':
1691
- default:
1692
- return localize.day(dayOfWeek, {
1693
- width: 'wide',
1694
- context: 'formatting'
1695
- });
1696
- }
1697
- },
1698
- // AM or PM
1699
- a: function (date, token, localize) {
1700
- var hours = date.getUTCHours();
1701
- var dayPeriodEnumValue = hours / 12 >= 1 ? 'pm' : 'am';
1702
-
1703
- switch (token) {
1704
- case 'a':
1705
- case 'aa':
1706
- case 'aaa':
1707
- return localize.dayPeriod(dayPeriodEnumValue, {
1708
- width: 'abbreviated',
1709
- context: 'formatting'
1710
- });
1711
-
1712
- case 'aaaaa':
1713
- return localize.dayPeriod(dayPeriodEnumValue, {
1714
- width: 'narrow',
1715
- context: 'formatting'
1716
- });
1717
-
1718
- case 'aaaa':
1719
- default:
1720
- return localize.dayPeriod(dayPeriodEnumValue, {
1721
- width: 'wide',
1722
- context: 'formatting'
1723
- });
1724
- }
1725
- },
1726
- // AM, PM, midnight, noon
1727
- b: function (date, token, localize) {
1728
- var hours = date.getUTCHours();
1729
- var dayPeriodEnumValue;
1730
-
1731
- if (hours === 12) {
1732
- dayPeriodEnumValue = dayPeriodEnum.noon;
1733
- } else if (hours === 0) {
1734
- dayPeriodEnumValue = dayPeriodEnum.midnight;
1735
- } else {
1736
- dayPeriodEnumValue = hours / 12 >= 1 ? 'pm' : 'am';
1737
- }
1738
-
1739
- switch (token) {
1740
- case 'b':
1741
- case 'bb':
1742
- case 'bbb':
1743
- return localize.dayPeriod(dayPeriodEnumValue, {
1744
- width: 'abbreviated',
1745
- context: 'formatting'
1746
- });
1747
-
1748
- case 'bbbbb':
1749
- return localize.dayPeriod(dayPeriodEnumValue, {
1750
- width: 'narrow',
1751
- context: 'formatting'
1752
- });
1753
-
1754
- case 'bbbb':
1755
- default:
1756
- return localize.dayPeriod(dayPeriodEnumValue, {
1757
- width: 'wide',
1758
- context: 'formatting'
1759
- });
1760
- }
1761
- },
1762
- // in the morning, in the afternoon, in the evening, at night
1763
- B: function (date, token, localize) {
1764
- var hours = date.getUTCHours();
1765
- var dayPeriodEnumValue;
1766
-
1767
- if (hours >= 17) {
1768
- dayPeriodEnumValue = dayPeriodEnum.evening;
1769
- } else if (hours >= 12) {
1770
- dayPeriodEnumValue = dayPeriodEnum.afternoon;
1771
- } else if (hours >= 4) {
1772
- dayPeriodEnumValue = dayPeriodEnum.morning;
1773
- } else {
1774
- dayPeriodEnumValue = dayPeriodEnum.night;
1775
- }
1776
-
1777
- switch (token) {
1778
- case 'B':
1779
- case 'BB':
1780
- case 'BBB':
1781
- return localize.dayPeriod(dayPeriodEnumValue, {
1782
- width: 'abbreviated',
1783
- context: 'formatting'
1784
- });
1785
-
1786
- case 'BBBBB':
1787
- return localize.dayPeriod(dayPeriodEnumValue, {
1788
- width: 'narrow',
1789
- context: 'formatting'
1790
- });
1791
-
1792
- case 'BBBB':
1793
- default:
1794
- return localize.dayPeriod(dayPeriodEnumValue, {
1795
- width: 'wide',
1796
- context: 'formatting'
1797
- });
1798
- }
1799
- },
1800
- // Hour [1-12]
1801
- h: function (date, token, localize) {
1802
- if (token === 'ho') {
1803
- var hours = date.getUTCHours() % 12;
1804
- if (hours === 0) hours = 12;
1805
- return localize.ordinalNumber(hours, {
1806
- unit: 'hour'
1807
- });
1808
- }
1809
-
1810
- return formatters.h(date, token);
1811
- },
1812
- // Hour [0-23]
1813
- H: function (date, token, localize) {
1814
- if (token === 'Ho') {
1815
- return localize.ordinalNumber(date.getUTCHours(), {
1816
- unit: 'hour'
1817
- });
1818
- }
1819
-
1820
- return formatters.H(date, token);
1821
- },
1822
- // Hour [0-11]
1823
- K: function (date, token, localize) {
1824
- var hours = date.getUTCHours() % 12;
1825
-
1826
- if (token === 'Ko') {
1827
- return localize.ordinalNumber(hours, {
1828
- unit: 'hour'
1829
- });
1830
- }
1831
-
1832
- return addLeadingZeros(hours, token.length);
1833
- },
1834
- // Hour [1-24]
1835
- k: function (date, token, localize) {
1836
- var hours = date.getUTCHours();
1837
- if (hours === 0) hours = 24;
1838
-
1839
- if (token === 'ko') {
1840
- return localize.ordinalNumber(hours, {
1841
- unit: 'hour'
1842
- });
1843
- }
1844
-
1845
- return addLeadingZeros(hours, token.length);
1846
- },
1847
- // Minute
1848
- m: function (date, token, localize) {
1849
- if (token === 'mo') {
1850
- return localize.ordinalNumber(date.getUTCMinutes(), {
1851
- unit: 'minute'
1852
- });
1853
- }
1854
-
1855
- return formatters.m(date, token);
1856
- },
1857
- // Second
1858
- s: function (date, token, localize) {
1859
- if (token === 'so') {
1860
- return localize.ordinalNumber(date.getUTCSeconds(), {
1861
- unit: 'second'
1862
- });
1863
- }
1864
-
1865
- return formatters.s(date, token);
1866
- },
1867
- // Fraction of second
1868
- S: function (date, token) {
1869
- return formatters.S(date, token);
1870
- },
1871
- // Timezone (ISO-8601. If offset is 0, output is always `'Z'`)
1872
- X: function (date, token, _localize, options) {
1873
- var originalDate = options._originalDate || date;
1874
- var timezoneOffset = originalDate.getTimezoneOffset();
1875
-
1876
- if (timezoneOffset === 0) {
1877
- return 'Z';
1878
- }
1879
-
1880
- switch (token) {
1881
- // Hours and optional minutes
1882
- case 'X':
1883
- return formatTimezoneWithOptionalMinutes(timezoneOffset);
1884
- // Hours, minutes and optional seconds without `:` delimiter
1885
- // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
1886
- // so this token always has the same output as `XX`
1887
-
1888
- case 'XXXX':
1889
- case 'XX':
1890
- // Hours and minutes without `:` delimiter
1891
- return formatTimezone(timezoneOffset);
1892
- // Hours, minutes and optional seconds with `:` delimiter
1893
- // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
1894
- // so this token always has the same output as `XXX`
1895
-
1896
- case 'XXXXX':
1897
- case 'XXX': // Hours and minutes with `:` delimiter
1898
-
1899
- default:
1900
- return formatTimezone(timezoneOffset, ':');
1901
- }
1902
- },
1903
- // Timezone (ISO-8601. If offset is 0, output is `'+00:00'` or equivalent)
1904
- x: function (date, token, _localize, options) {
1905
- var originalDate = options._originalDate || date;
1906
- var timezoneOffset = originalDate.getTimezoneOffset();
1907
-
1908
- switch (token) {
1909
- // Hours and optional minutes
1910
- case 'x':
1911
- return formatTimezoneWithOptionalMinutes(timezoneOffset);
1912
- // Hours, minutes and optional seconds without `:` delimiter
1913
- // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
1914
- // so this token always has the same output as `xx`
1915
-
1916
- case 'xxxx':
1917
- case 'xx':
1918
- // Hours and minutes without `:` delimiter
1919
- return formatTimezone(timezoneOffset);
1920
- // Hours, minutes and optional seconds with `:` delimiter
1921
- // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
1922
- // so this token always has the same output as `xxx`
1923
-
1924
- case 'xxxxx':
1925
- case 'xxx': // Hours and minutes with `:` delimiter
1926
-
1927
- default:
1928
- return formatTimezone(timezoneOffset, ':');
1929
- }
1930
- },
1931
- // Timezone (GMT)
1932
- O: function (date, token, _localize, options) {
1933
- var originalDate = options._originalDate || date;
1934
- var timezoneOffset = originalDate.getTimezoneOffset();
1935
-
1936
- switch (token) {
1937
- // Short
1938
- case 'O':
1939
- case 'OO':
1940
- case 'OOO':
1941
- return 'GMT' + formatTimezoneShort(timezoneOffset, ':');
1942
- // Long
1943
-
1944
- case 'OOOO':
1945
- default:
1946
- return 'GMT' + formatTimezone(timezoneOffset, ':');
1947
- }
1948
- },
1949
- // Timezone (specific non-location)
1950
- z: function (date, token, _localize, options) {
1951
- var originalDate = options._originalDate || date;
1952
- var timezoneOffset = originalDate.getTimezoneOffset();
1953
-
1954
- switch (token) {
1955
- // Short
1956
- case 'z':
1957
- case 'zz':
1958
- case 'zzz':
1959
- return 'GMT' + formatTimezoneShort(timezoneOffset, ':');
1960
- // Long
1961
-
1962
- case 'zzzz':
1963
- default:
1964
- return 'GMT' + formatTimezone(timezoneOffset, ':');
1965
- }
1966
- },
1967
- // Seconds timestamp
1968
- t: function (date, token, _localize, options) {
1969
- var originalDate = options._originalDate || date;
1970
- var timestamp = Math.floor(originalDate.getTime() / 1000);
1971
- return addLeadingZeros(timestamp, token.length);
1972
- },
1973
- // Milliseconds timestamp
1974
- T: function (date, token, _localize, options) {
1975
- var originalDate = options._originalDate || date;
1976
- var timestamp = originalDate.getTime();
1977
- return addLeadingZeros(timestamp, token.length);
1978
- }
1979
- };
1980
-
1981
- function formatTimezoneShort(offset, dirtyDelimiter) {
1982
- var sign = offset > 0 ? '-' : '+';
1983
- var absOffset = Math.abs(offset);
1984
- var hours = Math.floor(absOffset / 60);
1985
- var minutes = absOffset % 60;
1986
-
1987
- if (minutes === 0) {
1988
- return sign + String(hours);
1989
- }
1990
-
1991
- var delimiter = dirtyDelimiter || '';
1992
- return sign + String(hours) + delimiter + addLeadingZeros(minutes, 2);
1993
- }
1994
-
1995
- function formatTimezoneWithOptionalMinutes(offset, dirtyDelimiter) {
1996
- if (offset % 60 === 0) {
1997
- var sign = offset > 0 ? '-' : '+';
1998
- return sign + addLeadingZeros(Math.abs(offset) / 60, 2);
1999
- }
2000
-
2001
- return formatTimezone(offset, dirtyDelimiter);
2002
- }
2003
-
2004
- function formatTimezone(offset, dirtyDelimiter) {
2005
- var delimiter = dirtyDelimiter || '';
2006
- var sign = offset > 0 ? '-' : '+';
2007
- var absOffset = Math.abs(offset);
2008
- var hours = addLeadingZeros(Math.floor(absOffset / 60), 2);
2009
- var minutes = addLeadingZeros(absOffset % 60, 2);
2010
- return sign + hours + delimiter + minutes;
2011
- }
2012
-
2013
- function dateLongFormatter(pattern, formatLong) {
2014
- switch (pattern) {
2015
- case 'P':
2016
- return formatLong.date({
2017
- width: 'short'
2018
- });
2019
-
2020
- case 'PP':
2021
- return formatLong.date({
2022
- width: 'medium'
2023
- });
2024
-
2025
- case 'PPP':
2026
- return formatLong.date({
2027
- width: 'long'
2028
- });
2029
-
2030
- case 'PPPP':
2031
- default:
2032
- return formatLong.date({
2033
- width: 'full'
2034
- });
2035
- }
2036
- }
2037
-
2038
- function timeLongFormatter(pattern, formatLong) {
2039
- switch (pattern) {
2040
- case 'p':
2041
- return formatLong.time({
2042
- width: 'short'
2043
- });
2044
-
2045
- case 'pp':
2046
- return formatLong.time({
2047
- width: 'medium'
2048
- });
2049
-
2050
- case 'ppp':
2051
- return formatLong.time({
2052
- width: 'long'
2053
- });
2054
-
2055
- case 'pppp':
2056
- default:
2057
- return formatLong.time({
2058
- width: 'full'
2059
- });
2060
- }
2061
- }
2062
-
2063
- function dateTimeLongFormatter(pattern, formatLong) {
2064
- var matchResult = pattern.match(/(P+)(p+)?/);
2065
- var datePattern = matchResult[1];
2066
- var timePattern = matchResult[2];
2067
-
2068
- if (!timePattern) {
2069
- return dateLongFormatter(pattern, formatLong);
2070
- }
2071
-
2072
- var dateTimeFormat;
2073
-
2074
- switch (datePattern) {
2075
- case 'P':
2076
- dateTimeFormat = formatLong.dateTime({
2077
- width: 'short'
2078
- });
2079
- break;
2080
-
2081
- case 'PP':
2082
- dateTimeFormat = formatLong.dateTime({
2083
- width: 'medium'
2084
- });
2085
- break;
2086
-
2087
- case 'PPP':
2088
- dateTimeFormat = formatLong.dateTime({
2089
- width: 'long'
2090
- });
2091
- break;
2092
-
2093
- case 'PPPP':
2094
- default:
2095
- dateTimeFormat = formatLong.dateTime({
2096
- width: 'full'
2097
- });
2098
- break;
2099
- }
2100
-
2101
- return dateTimeFormat.replace('{{date}}', dateLongFormatter(datePattern, formatLong)).replace('{{time}}', timeLongFormatter(timePattern, formatLong));
2102
- }
2103
-
2104
- var longFormatters = {
2105
- p: timeLongFormatter,
2106
- P: dateTimeLongFormatter
2107
- };
2108
-
2109
- var protectedDayOfYearTokens = ['D', 'DD'];
2110
- var protectedWeekYearTokens = ['YY', 'YYYY'];
2111
- function isProtectedDayOfYearToken(token) {
2112
- return protectedDayOfYearTokens.indexOf(token) !== -1;
2113
- }
2114
- function isProtectedWeekYearToken(token) {
2115
- return protectedWeekYearTokens.indexOf(token) !== -1;
2116
- }
2117
- function throwProtectedError(token, format, input) {
2118
- if (token === 'YYYY') {
2119
- throw new RangeError("Use `yyyy` instead of `YYYY` (in `".concat(format, "`) for formatting years to the input `").concat(input, "`; see: https://git.io/fxCyr"));
2120
- } else if (token === 'YY') {
2121
- throw new RangeError("Use `yy` instead of `YY` (in `".concat(format, "`) for formatting years to the input `").concat(input, "`; see: https://git.io/fxCyr"));
2122
- } else if (token === 'D') {
2123
- throw new RangeError("Use `d` instead of `D` (in `".concat(format, "`) for formatting days of the month to the input `").concat(input, "`; see: https://git.io/fxCyr"));
2124
- } else if (token === 'DD') {
2125
- throw new RangeError("Use `dd` instead of `DD` (in `".concat(format, "`) for formatting days of the month to the input `").concat(input, "`; see: https://git.io/fxCyr"));
2126
- }
2127
- }
2128
-
2129
- // - [yYQqMLwIdDecihHKkms]o matches any available ordinal number token
2130
- // (one of the certain letters followed by `o`)
2131
- // - (\w)\1* matches any sequences of the same letter
2132
- // - '' matches two quote characters in a row
2133
- // - '(''|[^'])+('|$) matches anything surrounded by two quote characters ('),
2134
- // except a single quote symbol, which ends the sequence.
2135
- // Two quote characters do not end the sequence.
2136
- // If there is no matching single quote
2137
- // then the sequence will continue until the end of the string.
2138
- // - . matches any single character unmatched by previous parts of the RegExps
2139
-
2140
- var formattingTokensRegExp = /[yYQqMLwIdDecihHKkms]o|(\w)\1*|''|'(''|[^'])+('|$)|./g; // This RegExp catches symbols escaped by quotes, and also
2141
- // sequences of symbols P, p, and the combinations like `PPPPPPPppppp`
2142
-
2143
- var longFormattingTokensRegExp = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g;
2144
- var escapedStringRegExp = /^'([^]*?)'?$/;
2145
- var doubleQuoteRegExp = /''/g;
2146
- var unescapedLatinCharacterRegExp = /[a-zA-Z]/;
2147
- /**
2148
- * @name format
2149
- * @category Common Helpers
2150
- * @summary Format the date.
2151
- *
2152
- * @description
2153
- * Return the formatted date string in the given format. The result may vary by locale.
2154
- *
2155
- * > ⚠️ Please note that the `format` tokens differ from Moment.js and other libraries.
2156
- * > See: https://git.io/fxCyr
2157
- *
2158
- * The characters wrapped between two single quotes characters (') are escaped.
2159
- * Two single quotes in a row, whether inside or outside a quoted sequence, represent a 'real' single quote.
2160
- * (see the last example)
2161
- *
2162
- * Format of the string is based on Unicode Technical Standard #35:
2163
- * https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
2164
- * with a few additions (see note 7 below the table).
2165
- *
2166
- * Accepted patterns:
2167
- * | Unit | Pattern | Result examples | Notes |
2168
- * |---------------------------------|---------|-----------------------------------|-------|
2169
- * | Era | G..GGG | AD, BC | |
2170
- * | | GGGG | Anno Domini, Before Christ | 2 |
2171
- * | | GGGGG | A, B | |
2172
- * | Calendar year | y | 44, 1, 1900, 2017 | 5 |
2173
- * | | yo | 44th, 1st, 0th, 17th | 5,7 |
2174
- * | | yy | 44, 01, 00, 17 | 5 |
2175
- * | | yyy | 044, 001, 1900, 2017 | 5 |
2176
- * | | yyyy | 0044, 0001, 1900, 2017 | 5 |
2177
- * | | yyyyy | ... | 3,5 |
2178
- * | Local week-numbering year | Y | 44, 1, 1900, 2017 | 5 |
2179
- * | | Yo | 44th, 1st, 1900th, 2017th | 5,7 |
2180
- * | | YY | 44, 01, 00, 17 | 5,8 |
2181
- * | | YYY | 044, 001, 1900, 2017 | 5 |
2182
- * | | YYYY | 0044, 0001, 1900, 2017 | 5,8 |
2183
- * | | YYYYY | ... | 3,5 |
2184
- * | ISO week-numbering year | R | -43, 0, 1, 1900, 2017 | 5,7 |
2185
- * | | RR | -43, 00, 01, 1900, 2017 | 5,7 |
2186
- * | | RRR | -043, 000, 001, 1900, 2017 | 5,7 |
2187
- * | | RRRR | -0043, 0000, 0001, 1900, 2017 | 5,7 |
2188
- * | | RRRRR | ... | 3,5,7 |
2189
- * | Extended year | u | -43, 0, 1, 1900, 2017 | 5 |
2190
- * | | uu | -43, 01, 1900, 2017 | 5 |
2191
- * | | uuu | -043, 001, 1900, 2017 | 5 |
2192
- * | | uuuu | -0043, 0001, 1900, 2017 | 5 |
2193
- * | | uuuuu | ... | 3,5 |
2194
- * | Quarter (formatting) | Q | 1, 2, 3, 4 | |
2195
- * | | Qo | 1st, 2nd, 3rd, 4th | 7 |
2196
- * | | QQ | 01, 02, 03, 04 | |
2197
- * | | QQQ | Q1, Q2, Q3, Q4 | |
2198
- * | | QQQQ | 1st quarter, 2nd quarter, ... | 2 |
2199
- * | | QQQQQ | 1, 2, 3, 4 | 4 |
2200
- * | Quarter (stand-alone) | q | 1, 2, 3, 4 | |
2201
- * | | qo | 1st, 2nd, 3rd, 4th | 7 |
2202
- * | | qq | 01, 02, 03, 04 | |
2203
- * | | qqq | Q1, Q2, Q3, Q4 | |
2204
- * | | qqqq | 1st quarter, 2nd quarter, ... | 2 |
2205
- * | | qqqqq | 1, 2, 3, 4 | 4 |
2206
- * | Month (formatting) | M | 1, 2, ..., 12 | |
2207
- * | | Mo | 1st, 2nd, ..., 12th | 7 |
2208
- * | | MM | 01, 02, ..., 12 | |
2209
- * | | MMM | Jan, Feb, ..., Dec | |
2210
- * | | MMMM | January, February, ..., December | 2 |
2211
- * | | MMMMM | J, F, ..., D | |
2212
- * | Month (stand-alone) | L | 1, 2, ..., 12 | |
2213
- * | | Lo | 1st, 2nd, ..., 12th | 7 |
2214
- * | | LL | 01, 02, ..., 12 | |
2215
- * | | LLL | Jan, Feb, ..., Dec | |
2216
- * | | LLLL | January, February, ..., December | 2 |
2217
- * | | LLLLL | J, F, ..., D | |
2218
- * | Local week of year | w | 1, 2, ..., 53 | |
2219
- * | | wo | 1st, 2nd, ..., 53th | 7 |
2220
- * | | ww | 01, 02, ..., 53 | |
2221
- * | ISO week of year | I | 1, 2, ..., 53 | 7 |
2222
- * | | Io | 1st, 2nd, ..., 53th | 7 |
2223
- * | | II | 01, 02, ..., 53 | 7 |
2224
- * | Day of month | d | 1, 2, ..., 31 | |
2225
- * | | do | 1st, 2nd, ..., 31st | 7 |
2226
- * | | dd | 01, 02, ..., 31 | |
2227
- * | Day of year | D | 1, 2, ..., 365, 366 | 9 |
2228
- * | | Do | 1st, 2nd, ..., 365th, 366th | 7 |
2229
- * | | DD | 01, 02, ..., 365, 366 | 9 |
2230
- * | | DDD | 001, 002, ..., 365, 366 | |
2231
- * | | DDDD | ... | 3 |
2232
- * | Day of week (formatting) | E..EEE | Mon, Tue, Wed, ..., Sun | |
2233
- * | | EEEE | Monday, Tuesday, ..., Sunday | 2 |
2234
- * | | EEEEE | M, T, W, T, F, S, S | |
2235
- * | | EEEEEE | Mo, Tu, We, Th, Fr, Su, Sa | |
2236
- * | ISO day of week (formatting) | i | 1, 2, 3, ..., 7 | 7 |
2237
- * | | io | 1st, 2nd, ..., 7th | 7 |
2238
- * | | ii | 01, 02, ..., 07 | 7 |
2239
- * | | iii | Mon, Tue, Wed, ..., Sun | 7 |
2240
- * | | iiii | Monday, Tuesday, ..., Sunday | 2,7 |
2241
- * | | iiiii | M, T, W, T, F, S, S | 7 |
2242
- * | | iiiiii | Mo, Tu, We, Th, Fr, Su, Sa | 7 |
2243
- * | Local day of week (formatting) | e | 2, 3, 4, ..., 1 | |
2244
- * | | eo | 2nd, 3rd, ..., 1st | 7 |
2245
- * | | ee | 02, 03, ..., 01 | |
2246
- * | | eee | Mon, Tue, Wed, ..., Sun | |
2247
- * | | eeee | Monday, Tuesday, ..., Sunday | 2 |
2248
- * | | eeeee | M, T, W, T, F, S, S | |
2249
- * | | eeeeee | Mo, Tu, We, Th, Fr, Su, Sa | |
2250
- * | Local day of week (stand-alone) | c | 2, 3, 4, ..., 1 | |
2251
- * | | co | 2nd, 3rd, ..., 1st | 7 |
2252
- * | | cc | 02, 03, ..., 01 | |
2253
- * | | ccc | Mon, Tue, Wed, ..., Sun | |
2254
- * | | cccc | Monday, Tuesday, ..., Sunday | 2 |
2255
- * | | ccccc | M, T, W, T, F, S, S | |
2256
- * | | cccccc | Mo, Tu, We, Th, Fr, Su, Sa | |
2257
- * | AM, PM | a..aaa | AM, PM | |
2258
- * | | aaaa | a.m., p.m. | 2 |
2259
- * | | aaaaa | a, p | |
2260
- * | AM, PM, noon, midnight | b..bbb | AM, PM, noon, midnight | |
2261
- * | | bbbb | a.m., p.m., noon, midnight | 2 |
2262
- * | | bbbbb | a, p, n, mi | |
2263
- * | Flexible day period | B..BBB | at night, in the morning, ... | |
2264
- * | | BBBB | at night, in the morning, ... | 2 |
2265
- * | | BBBBB | at night, in the morning, ... | |
2266
- * | Hour [1-12] | h | 1, 2, ..., 11, 12 | |
2267
- * | | ho | 1st, 2nd, ..., 11th, 12th | 7 |
2268
- * | | hh | 01, 02, ..., 11, 12 | |
2269
- * | Hour [0-23] | H | 0, 1, 2, ..., 23 | |
2270
- * | | Ho | 0th, 1st, 2nd, ..., 23rd | 7 |
2271
- * | | HH | 00, 01, 02, ..., 23 | |
2272
- * | Hour [0-11] | K | 1, 2, ..., 11, 0 | |
2273
- * | | Ko | 1st, 2nd, ..., 11th, 0th | 7 |
2274
- * | | KK | 01, 02, ..., 11, 00 | |
2275
- * | Hour [1-24] | k | 24, 1, 2, ..., 23 | |
2276
- * | | ko | 24th, 1st, 2nd, ..., 23rd | 7 |
2277
- * | | kk | 24, 01, 02, ..., 23 | |
2278
- * | Minute | m | 0, 1, ..., 59 | |
2279
- * | | mo | 0th, 1st, ..., 59th | 7 |
2280
- * | | mm | 00, 01, ..., 59 | |
2281
- * | Second | s | 0, 1, ..., 59 | |
2282
- * | | so | 0th, 1st, ..., 59th | 7 |
2283
- * | | ss | 00, 01, ..., 59 | |
2284
- * | Fraction of second | S | 0, 1, ..., 9 | |
2285
- * | | SS | 00, 01, ..., 99 | |
2286
- * | | SSS | 000, 0001, ..., 999 | |
2287
- * | | SSSS | ... | 3 |
2288
- * | Timezone (ISO-8601 w/ Z) | X | -08, +0530, Z | |
2289
- * | | XX | -0800, +0530, Z | |
2290
- * | | XXX | -08:00, +05:30, Z | |
2291
- * | | XXXX | -0800, +0530, Z, +123456 | 2 |
2292
- * | | XXXXX | -08:00, +05:30, Z, +12:34:56 | |
2293
- * | Timezone (ISO-8601 w/o Z) | x | -08, +0530, +00 | |
2294
- * | | xx | -0800, +0530, +0000 | |
2295
- * | | xxx | -08:00, +05:30, +00:00 | 2 |
2296
- * | | xxxx | -0800, +0530, +0000, +123456 | |
2297
- * | | xxxxx | -08:00, +05:30, +00:00, +12:34:56 | |
2298
- * | Timezone (GMT) | O...OOO | GMT-8, GMT+5:30, GMT+0 | |
2299
- * | | OOOO | GMT-08:00, GMT+05:30, GMT+00:00 | 2 |
2300
- * | Timezone (specific non-locat.) | z...zzz | GMT-8, GMT+5:30, GMT+0 | 6 |
2301
- * | | zzzz | GMT-08:00, GMT+05:30, GMT+00:00 | 2,6 |
2302
- * | Seconds timestamp | t | 512969520 | 7 |
2303
- * | | tt | ... | 3,7 |
2304
- * | Milliseconds timestamp | T | 512969520900 | 7 |
2305
- * | | TT | ... | 3,7 |
2306
- * | Long localized date | P | 05/29/1453 | 7 |
2307
- * | | PP | May 29, 1453 | 7 |
2308
- * | | PPP | May 29th, 1453 | 7 |
2309
- * | | PPPP | Sunday, May 29th, 1453 | 2,7 |
2310
- * | Long localized time | p | 12:00 AM | 7 |
2311
- * | | pp | 12:00:00 AM | 7 |
2312
- * | | ppp | 12:00:00 AM GMT+2 | 7 |
2313
- * | | pppp | 12:00:00 AM GMT+02:00 | 2,7 |
2314
- * | Combination of date and time | Pp | 05/29/1453, 12:00 AM | 7 |
2315
- * | | PPpp | May 29, 1453, 12:00:00 AM | 7 |
2316
- * | | PPPppp | May 29th, 1453 at ... | 7 |
2317
- * | | PPPPpppp| Sunday, May 29th, 1453 at ... | 2,7 |
2318
- * Notes:
2319
- * 1. "Formatting" units (e.g. formatting quarter) in the default en-US locale
2320
- * are the same as "stand-alone" units, but are different in some languages.
2321
- * "Formatting" units are declined according to the rules of the language
2322
- * in the context of a date. "Stand-alone" units are always nominative singular:
2323
- *
2324
- * `format(new Date(2017, 10, 6), 'do LLLL', {locale: cs}) //=> '6. listopad'`
2325
- *
2326
- * `format(new Date(2017, 10, 6), 'do MMMM', {locale: cs}) //=> '6. listopadu'`
2327
- *
2328
- * 2. Any sequence of the identical letters is a pattern, unless it is escaped by
2329
- * the single quote characters (see below).
2330
- * If the sequence is longer than listed in table (e.g. `EEEEEEEEEEE`)
2331
- * the output will be the same as default pattern for this unit, usually
2332
- * the longest one (in case of ISO weekdays, `EEEE`). Default patterns for units
2333
- * are marked with "2" in the last column of the table.
2334
- *
2335
- * `format(new Date(2017, 10, 6), 'MMM') //=> 'Nov'`
2336
- *
2337
- * `format(new Date(2017, 10, 6), 'MMMM') //=> 'November'`
2338
- *
2339
- * `format(new Date(2017, 10, 6), 'MMMMM') //=> 'N'`
2340
- *
2341
- * `format(new Date(2017, 10, 6), 'MMMMMM') //=> 'November'`
2342
- *
2343
- * `format(new Date(2017, 10, 6), 'MMMMMMM') //=> 'November'`
2344
- *
2345
- * 3. Some patterns could be unlimited length (such as `yyyyyyyy`).
2346
- * The output will be padded with zeros to match the length of the pattern.
2347
- *
2348
- * `format(new Date(2017, 10, 6), 'yyyyyyyy') //=> '00002017'`
2349
- *
2350
- * 4. `QQQQQ` and `qqqqq` could be not strictly numerical in some locales.
2351
- * These tokens represent the shortest form of the quarter.
2352
- *
2353
- * 5. The main difference between `y` and `u` patterns are B.C. years:
2354
- *
2355
- * | Year | `y` | `u` |
2356
- * |------|-----|-----|
2357
- * | AC 1 | 1 | 1 |
2358
- * | BC 1 | 1 | 0 |
2359
- * | BC 2 | 2 | -1 |
2360
- *
2361
- * Also `yy` always returns the last two digits of a year,
2362
- * while `uu` pads single digit years to 2 characters and returns other years unchanged:
2363
- *
2364
- * | Year | `yy` | `uu` |
2365
- * |------|------|------|
2366
- * | 1 | 01 | 01 |
2367
- * | 14 | 14 | 14 |
2368
- * | 376 | 76 | 376 |
2369
- * | 1453 | 53 | 1453 |
2370
- *
2371
- * The same difference is true for local and ISO week-numbering years (`Y` and `R`),
2372
- * except local week-numbering years are dependent on `options.weekStartsOn`
2373
- * and `options.firstWeekContainsDate` (compare [getISOWeekYear]{@link https://date-fns.org/docs/getISOWeekYear}
2374
- * and [getWeekYear]{@link https://date-fns.org/docs/getWeekYear}).
2375
- *
2376
- * 6. Specific non-location timezones are currently unavailable in `date-fns`,
2377
- * so right now these tokens fall back to GMT timezones.
2378
- *
2379
- * 7. These patterns are not in the Unicode Technical Standard #35:
2380
- * - `i`: ISO day of week
2381
- * - `I`: ISO week of year
2382
- * - `R`: ISO week-numbering year
2383
- * - `t`: seconds timestamp
2384
- * - `T`: milliseconds timestamp
2385
- * - `o`: ordinal number modifier
2386
- * - `P`: long localized date
2387
- * - `p`: long localized time
2388
- *
2389
- * 8. `YY` and `YYYY` tokens represent week-numbering years but they are often confused with years.
2390
- * You should enable `options.useAdditionalWeekYearTokens` to use them. See: https://git.io/fxCyr
2391
- *
2392
- * 9. `D` and `DD` tokens represent days of the year but they are ofthen confused with days of the month.
2393
- * You should enable `options.useAdditionalDayOfYearTokens` to use them. See: https://git.io/fxCyr
2394
- *
2395
- * ### v2.0.0 breaking changes:
2396
- *
2397
- * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
2398
- *
2399
- * - The second argument is now required for the sake of explicitness.
2400
- *
2401
- * ```javascript
2402
- * // Before v2.0.0
2403
- * format(new Date(2016, 0, 1))
2404
- *
2405
- * // v2.0.0 onward
2406
- * format(new Date(2016, 0, 1), "yyyy-MM-dd'T'HH:mm:ss.SSSxxx")
2407
- * ```
2408
- *
2409
- * - New format string API for `format` function
2410
- * which is based on [Unicode Technical Standard #35](https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table).
2411
- * See [this post](https://blog.date-fns.org/post/unicode-tokens-in-date-fns-v2-sreatyki91jg) for more details.
2412
- *
2413
- * - Characters are now escaped using single quote symbols (`'`) instead of square brackets.
2414
- *
2415
- * @param {Date|Number} date - the original date
2416
- * @param {String} format - the string of tokens
2417
- * @param {Object} [options] - an object with options.
2418
- * @param {Locale} [options.locale=defaultLocale] - the locale object. See [Locale]{@link https://date-fns.org/docs/Locale}
2419
- * @param {0|1|2|3|4|5|6} [options.weekStartsOn=0] - the index of the first day of the week (0 - Sunday)
2420
- * @param {Number} [options.firstWeekContainsDate=1] - the day of January, which is
2421
- * @param {Boolean} [options.useAdditionalWeekYearTokens=false] - if true, allows usage of the week-numbering year tokens `YY` and `YYYY`;
2422
- * see: https://git.io/fxCyr
2423
- * @param {Boolean} [options.useAdditionalDayOfYearTokens=false] - if true, allows usage of the day of year tokens `D` and `DD`;
2424
- * see: https://git.io/fxCyr
2425
- * @returns {String} the formatted date string
2426
- * @throws {TypeError} 2 arguments required
2427
- * @throws {RangeError} `date` must not be Invalid Date
2428
- * @throws {RangeError} `options.locale` must contain `localize` property
2429
- * @throws {RangeError} `options.locale` must contain `formatLong` property
2430
- * @throws {RangeError} `options.weekStartsOn` must be between 0 and 6
2431
- * @throws {RangeError} `options.firstWeekContainsDate` must be between 1 and 7
2432
- * @throws {RangeError} use `yyyy` instead of `YYYY` for formatting years using [format provided] to the input [input provided]; see: https://git.io/fxCyr
2433
- * @throws {RangeError} use `yy` instead of `YY` for formatting years using [format provided] to the input [input provided]; see: https://git.io/fxCyr
2434
- * @throws {RangeError} use `d` instead of `D` for formatting days of the month using [format provided] to the input [input provided]; see: https://git.io/fxCyr
2435
- * @throws {RangeError} use `dd` instead of `DD` for formatting days of the month using [format provided] to the input [input provided]; see: https://git.io/fxCyr
2436
- * @throws {RangeError} format string contains an unescaped latin alphabet character
2437
- *
2438
- * @example
2439
- * // Represent 11 February 2014 in middle-endian format:
2440
- * var result = format(new Date(2014, 1, 11), 'MM/dd/yyyy')
2441
- * //=> '02/11/2014'
2442
- *
2443
- * @example
2444
- * // Represent 2 July 2014 in Esperanto:
2445
- * import { eoLocale } from 'date-fns/locale/eo'
2446
- * var result = format(new Date(2014, 6, 2), "do 'de' MMMM yyyy", {
2447
- * locale: eoLocale
2448
- * })
2449
- * //=> '2-a de julio 2014'
2450
- *
2451
- * @example
2452
- * // Escape string by single quote characters:
2453
- * var result = format(new Date(2014, 6, 2, 15), "h 'o''clock'")
2454
- * //=> "3 o'clock"
2455
- */
2456
-
2457
- function format(dirtyDate, dirtyFormatStr, dirtyOptions) {
2458
- requiredArgs(2, arguments);
2459
- var formatStr = String(dirtyFormatStr);
2460
- var options = dirtyOptions || {};
2461
- var locale$1 = options.locale || locale;
2462
- var localeFirstWeekContainsDate = locale$1.options && locale$1.options.firstWeekContainsDate;
2463
- var defaultFirstWeekContainsDate = localeFirstWeekContainsDate == null ? 1 : toInteger(localeFirstWeekContainsDate);
2464
- var firstWeekContainsDate = options.firstWeekContainsDate == null ? defaultFirstWeekContainsDate : toInteger(options.firstWeekContainsDate); // Test if weekStartsOn is between 1 and 7 _and_ is not NaN
2465
-
2466
- if (!(firstWeekContainsDate >= 1 && firstWeekContainsDate <= 7)) {
2467
- throw new RangeError('firstWeekContainsDate must be between 1 and 7 inclusively');
2468
- }
2469
-
2470
- var localeWeekStartsOn = locale$1.options && locale$1.options.weekStartsOn;
2471
- var defaultWeekStartsOn = localeWeekStartsOn == null ? 0 : toInteger(localeWeekStartsOn);
2472
- var weekStartsOn = options.weekStartsOn == null ? defaultWeekStartsOn : toInteger(options.weekStartsOn); // Test if weekStartsOn is between 0 and 6 _and_ is not NaN
2473
-
2474
- if (!(weekStartsOn >= 0 && weekStartsOn <= 6)) {
2475
- throw new RangeError('weekStartsOn must be between 0 and 6 inclusively');
2476
- }
2477
-
2478
- if (!locale$1.localize) {
2479
- throw new RangeError('locale must contain localize property');
2480
- }
2481
-
2482
- if (!locale$1.formatLong) {
2483
- throw new RangeError('locale must contain formatLong property');
2484
- }
2485
-
2486
- var originalDate = toDate(dirtyDate);
2487
-
2488
- if (!isValid(originalDate)) {
2489
- throw new RangeError('Invalid time value');
2490
- } // Convert the date in system timezone to the same date in UTC+00:00 timezone.
2491
- // This ensures that when UTC functions will be implemented, locales will be compatible with them.
2492
- // See an issue about UTC functions: https://github.com/date-fns/date-fns/issues/376
2493
-
2494
-
2495
- var timezoneOffset = getTimezoneOffsetInMilliseconds(originalDate);
2496
- var utcDate = subMilliseconds(originalDate, timezoneOffset);
2497
- var formatterOptions = {
2498
- firstWeekContainsDate: firstWeekContainsDate,
2499
- weekStartsOn: weekStartsOn,
2500
- locale: locale$1,
2501
- _originalDate: originalDate
2502
- };
2503
- var result = formatStr.match(longFormattingTokensRegExp).map(function (substring) {
2504
- var firstCharacter = substring[0];
2505
-
2506
- if (firstCharacter === 'p' || firstCharacter === 'P') {
2507
- var longFormatter = longFormatters[firstCharacter];
2508
- return longFormatter(substring, locale$1.formatLong, formatterOptions);
2509
- }
2510
-
2511
- return substring;
2512
- }).join('').match(formattingTokensRegExp).map(function (substring) {
2513
- // Replace two single quote characters with one single quote character
2514
- if (substring === "''") {
2515
- return "'";
2516
- }
2517
-
2518
- var firstCharacter = substring[0];
2519
-
2520
- if (firstCharacter === "'") {
2521
- return cleanEscapedString(substring);
2522
- }
2523
-
2524
- var formatter = formatters$1[firstCharacter];
2525
-
2526
- if (formatter) {
2527
- if (!options.useAdditionalWeekYearTokens && isProtectedWeekYearToken(substring)) {
2528
- throwProtectedError(substring, dirtyFormatStr, dirtyDate);
2529
- }
2530
-
2531
- if (!options.useAdditionalDayOfYearTokens && isProtectedDayOfYearToken(substring)) {
2532
- throwProtectedError(substring, dirtyFormatStr, dirtyDate);
2533
- }
2534
-
2535
- return formatter(utcDate, substring, locale$1.localize, formatterOptions);
2536
- }
2537
-
2538
- if (firstCharacter.match(unescapedLatinCharacterRegExp)) {
2539
- throw new RangeError('Format string contains an unescaped latin alphabet character `' + firstCharacter + '`');
2540
- }
2541
-
2542
- return substring;
2543
- }).join('');
2544
- return result;
2545
- }
2546
-
2547
- function cleanEscapedString(input) {
2548
- return input.match(escapedStringRegExp)[1].replace(doubleQuoteRegExp, "'");
2549
- }
2550
-
2551
- const modelVariantsSectionComponentCss = ".abe-car-icon{max-width:120px;height:80px;object-fit:contain}.abe-fade-in-bottom{-webkit-animation:fade-in-bottom 0.3s cubic-bezier(0.39, 0.575, 0.565, 1) both;animation:fade-in-bottom 0.3s cubic-bezier(0.39, 0.575, 0.565, 1) both}@-webkit-keyframes fade-in-bottom{0%{-webkit-transform:translateY(50px);transform:translateY(50px);opacity:0}100%{-webkit-transform:translateY(0);transform:translateY(0);opacity:1}}@keyframes fade-in-bottom{0%{-webkit-transform:translateY(50px);transform:translateY(50px);opacity:0}100%{-webkit-transform:translateY(0);transform:translateY(0);opacity:1}}";
2552
-
2553
- const ModelVariantsSection = class {
2554
- constructor(hostRef) {
2555
- index.registerInstance(this, hostRef);
2556
- this.selectedVariant = session_query.none;
2557
- this.placeholderImage = index.getAssetPath('./assets/car-placeholder.svg');
2558
- }
2559
- componentWillLoad() {
2560
- session_query.sessionQuery.selectedVariant$.subscribe((state) => {
2561
- this.selectedVariant = state;
2562
- });
2563
- session_query.sessionQuery.modelVariantsList$.subscribe((state) => {
2564
- this.variantsList = carsCalculator_service.getOrDefault(state, []);
2565
- });
2566
- }
2567
- render() {
2568
- return (index.h(index.Host, { class: "d-flex flex-column justify-content-start abe-fade-in-bottom" }, session_query.isNone(this.selectedVariant)
2569
- ? this.variantsList.map((variant) => this.variantCard(variant, false))
2570
- : this.variantCard(this.selectedVariant.value, true)));
2571
- }
2572
- variantCard(variant, isSelected) {
2573
- const imgSrc = carsCalculator_service.getOrDefault(variant.photoUri, this.placeholderImage);
2574
- return (index.h("div", { class: "card d-flex w-100 flex-row justify-content-between align-items-center mt-3" }, index.h("img", { class: "abe-car-icon mx-4 d-none d-md-flex", src: imgSrc, alt: "", onError: (e) => this.handleImgError(e) }), index.h("div", { class: "d-flex flex-column align-items-start flex-grow-1 px-3 py-2 p-md-0" }, index.h("h5", { class: "card-title text-capitalize mb-0" }, variant.description.toLowerCase()), index.h("p", { class: "card-text text-muted" }, "Built from ", this.toMonthName(variant.modelMonth), " ", variant.buildYear)), isSelected ? (index.h("fl-button", { class: "ml-3 mr-4", variant: "secondary", onClick: () => this.resetVariant() }, index.h("span", { class: "px-3" }, "Change"))) : (index.h("fl-button", { class: "ml-3 mr-4", onClick: () => this.chooseVariant(variant) }, index.h("span", { class: "px-3" }, "Select")))));
2575
- }
2576
- toMonthName(monthNumber) {
2577
- return format(new Date().setMonth(monthNumber), 'MMMM');
2578
- }
2579
- resetVariant() {
2580
- carsCalculator_service.carsCalculatorService.selectVariant(session_query.none);
2581
- }
2582
- chooseVariant(variant) {
2583
- carsCalculator_service.carsCalculatorService.selectVariant(session_query.some(variant));
2584
- }
2585
- handleImgError(event) {
2586
- event.target.src = this.placeholderImage;
2587
- }
2588
- static get assetsDirs() { return ["assets"]; }
2589
- };
2590
- ModelVariantsSection.style = modelVariantsSectionComponentCss;
2591
-
2592
- const generateTermsOptionsArray = (years) => [...Array(years).keys()]
2593
- .map((n) => n + 1)
2594
- .map((n) => ({
2595
- label: `${n} Year${n > 1 ? 's' : ''}`,
2596
- value: n
2597
- }));
2598
- const PersonalInfoSection = class {
2599
- constructor(hostRef) {
2600
- index.registerInstance(this, hostRef);
2601
- this.terms = generateTermsOptionsArray(5);
2602
- this.states = ['ACT', 'NSW', 'NT', 'QLD', 'SA', 'TAS', 'VIC', 'WA'];
2603
- this.paymentPeriods = ['Monthly', 'Fortnightly', 'Weekly'];
2604
- session_query.sessionQuery.user$.subscribe((state) => (this.userInfo = state));
2605
- }
2606
- render() {
2607
- return (index.h(index.Host, { class: "d-flex flex-column align-items-start justify-content-between" }, index.h("div", { class: "d-flex flex-column flex-lg-row align-items-start align-items-lg-center justify-content-center mt-2 h4" }, index.h("span", { class: "pr-0 pr-sm-2 d-flex text-center" }, "My annual salary before tax is"), index.h("input", { placeholder: "50000", type: "text", class: "form-control d-flex w-auto mt-2 mt-lg-0", value: '$' + this.getUserInfo('annualSalary'), onInput: e => {
2608
- const el = e.target;
2609
- el.value = el.value.replace(/\D/g, '');
2610
- }, onFocus: e => {
2611
- const el = e.target;
2612
- el.value = el.value.replace('$', '');
2613
- }, onBlur: e => {
2614
- const el = e.target;
2615
- el.value = '$' + el.value;
2616
- }, onChange: (e) => this.updateUserInfo('annualSalary', parseFloat(e.target.value.trim())) })), index.h("div", { class: "d-flex flex-column flex-lg-row align-items-start align-items-lg-center justify-content-center mt-4 h4" }, index.h("span", { class: "pr-0 pr-sm-2 d-flex text-center" }, "I get paid"), index.h("fl-dropdown", { class: "d-flex my-2 my-lg-0", options: carsCalculator_service.toSelectInputOptionsArray(this.paymentPeriods), requiredValidationMessage: "Select an option", placeholder: "Select...", value: this.getUserInfo('paymentPeriod'), onValueChanged: (e) => this.updateUserInfo('paymentPeriod', e.detail.value) })), index.h("div", { class: "d-flex flex-column flex-lg-row align-items-start align-items-lg-center justify-content-center mt-4 h4" }, index.h("span", { class: "pr-0 pr-sm-2 d-flex text-center" }, "Every year I expect to drive"), index.h("input", { placeholder: "10000", type: "text", class: "form-control d-flex w-auto mt-2 mt-lg-0", value: this.getUserInfo('annualKms') + ' km', onInput: e => {
2617
- const el = e.target;
2618
- el.value = el.value.replace(/\D/g, '');
2619
- }, onFocus: e => {
2620
- const el = e.target;
2621
- el.value = el.value.replace(' km', '');
2622
- }, onBlur: e => {
2623
- const el = e.target;
2624
- el.value += ' km';
2625
- }, onChange: (ev) => this.updateUserInfo('annualKms', parseInt(ev.target.value.trim())) })), index.h("div", { class: "d-flex flex-column flex-lg-row align-items-start align-items-lg-center justify-content-center mt-4 h4" }, index.h("span", { class: "pr-0 pr-sm-2 d-flex text-center" }, "I live in"), index.h("fl-dropdown", { class: "d-flex my-2 my-lg-0", options: carsCalculator_service.toSelectInputOptionsArray(this.states), requiredValidationMessage: "Select an option", placeholder: "select state", value: this.getUserInfo('state'), onValueChanged: (e) => this.updateUserInfo('state', e.detail.value) })), index.h("div", { class: "d-flex flex-column flex-lg-row align-items-start align-items-lg-center justify-content-center mt-4 h4" }, index.h("span", { class: "pr-0 pr-sm-2 d-flex text-center" }, "I want my lease term to be"), index.h("fl-dropdown", { class: "d-flex my-2 my-lg-0", options: this.terms, requiredValidationMessage: "Select an option", placeholder: "Select...", value: this.getUserInfo('term'), onValueChanged: (e) => this.updateUserInfo('term', e.detail.value) }))));
2626
- }
2627
- updateUserInfo(key, value) {
2628
- session_query.sessionStore.update({ user: Object.assign(Object.assign({}, this.userInfo), { [key]: session_query.some(value) }) });
2629
- }
2630
- getUserInfo(key) {
2631
- return carsCalculator_service.pipe(this.userInfo[key], session_query.getOrElseW(() => ''));
2632
- }
2633
- };
2634
-
2635
- const QuoteResultSection = class {
2636
- constructor(hostRef) {
2637
- index.registerInstance(this, hostRef);
2638
- this.showRequestQuoteModal = false;
2639
- this.showBreakdownModal = false;
2640
- this.showCompletePage = false;
2641
- this.getRenderedPaymentPeriod = () => {
2642
- const selectedPaymentPeriod = session_query.getOrElse(() => 'Monthly')(session_query.sessionQuery.user.paymentPeriod);
2643
- let renderedPaymentPeriod = 'month';
2644
- switch (selectedPaymentPeriod) {
2645
- case 'Monthly':
2646
- renderedPaymentPeriod = 'month';
2647
- break;
2648
- case 'Fortnightly':
2649
- renderedPaymentPeriod = 'fortnight';
2650
- break;
2651
- case 'Weekly':
2652
- renderedPaymentPeriod = 'week';
2653
- }
2654
- return `Cost per ${renderedPaymentPeriod}`;
2655
- };
2656
- this.renderQuoteField = (quoteField) => (index.h("span", null, "$", this.quote.quoteState === 'Calculation pending' ? (index.h("fl-loading-indicator", { class: "ml-2" })) : (carsCalculator_service.getOrDefault(quoteField, null))));
2657
- this.leaseInclusion = (props) => (index.h("p", { class: "font-weight-light d-inline-flex align-items-center" }, index.h("img", { class: "pr-1", src: index.getAssetPath('./assets/check.svg') }), props.inclusionName));
2658
- }
2659
- componentWillLoad() {
2660
- this.subscription = session_query.sessionQuery.result$.subscribe((_state) => {
2661
- this.quote = session_query.sessionQuery.result;
2662
- });
2663
- }
2664
- disconnectedCallback() {
2665
- this.subscription.unsubscribe();
2666
- }
2667
- render() {
2668
- return (index.h(index.Host, { class: "card d-flex flex-column justify-content-between w-100 h-100" }, index.h("div", { class: "d-flex flex-column flex-grow-1 justify-content-between p-4" }, index.h("span", { class: "mb-3 text-left" }, index.h("p", { class: "h1 text-muted font-weight-bold mb-0" }, this.renderQuoteField(this.quote.afterTaxEffectPerPayCycle)), index.h("p", { class: "mb-0" }, this.getRenderedPaymentPeriod())), index.h("span", { class: "mb-3 text-left" }, index.h("p", { class: "h1 text-info font-weight-bold mb-0" }, this.renderQuoteField(this.quote.taxSaving)), index.h("p", { class: "mb-0" }, "Total tax savings")), index.h("span", { class: "mb-3 text-left" }, index.h("p", { class: "h1 text-muted font-weight-bold mb-0" }, this.renderQuoteField(this.quote.residualValue)), index.h("p", { class: "mb-0" }, "Residual value")), index.h("fl-button", { class: "mt-2", isBlockElement: true, onClick: () => (this.showRequestQuoteModal = true) }, "Request a quote")), index.h("div", { class: "bg-light px-4 py-3" }, index.h("p", { class: "font-weight-bold text-center" }, "Your lease includes"), index.h("div", { class: "d-flex flex-row align-items-center justify-content-between" }, index.h("span", { class: "d-flex flex-column" }, index.h(this.leaseInclusion, { inclusionName: "Finance" }), index.h(this.leaseInclusion, { inclusionName: "Servicing" })), index.h("span", { class: "d-flex flex-column" }, index.h(this.leaseInclusion, { inclusionName: "Insurance" }), index.h(this.leaseInclusion, { inclusionName: "Registration" })), index.h("span", { class: "d-flex flex-column" }, index.h(this.leaseInclusion, { inclusionName: "Fuel" }), index.h(this.leaseInclusion, { inclusionName: "Tyres" }))), index.h("fl-button", { class: "mt-2", isBlockElement: true, variant: "secondary", onClick: () => (this.showBreakdownModal = true) }, "View running cost breakdown")), index.h("ap-ben-modal-section", { show: this.showRequestQuoteModal, showHeader: true, onModalClosed: () => {
2669
- this.showRequestQuoteModal = false;
2670
- this.showCompletePage = false;
2671
- } }, this.showCompletePage ? (index.h("ap-ben-complete-section", { onClosed: () => {
2672
- this.showRequestQuoteModal = false;
2673
- this.showCompletePage = false;
2674
- } })) : (index.h("ap-ben-submit-quote-section", { onEnquirySubmitted: () => {
2675
- this.showCompletePage = true;
2676
- } }))), index.h("ap-ben-modal-section", { show: this.showBreakdownModal, modalTitle: "Running cost breakdown", onModalClosed: () => (this.showBreakdownModal = false), showHeader: true, showFooter: true }, index.h("ap-ben-cost-breakdown-section", { quote: this.quote }))));
2677
- }
2678
- static get assetsDirs() { return ["assets"]; }
2679
- };
2680
-
2681
- exports.ap_ben_choose_vehicle_section = ChooseVehicleSection;
2682
- exports.ap_ben_model_variants_section = ModelVariantsSection;
2683
- exports.ap_ben_personal_info_section = PersonalInfoSection;
2684
- exports.ap_ben_quote_result_section = QuoteResultSection;