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