@flarehr/apollo-benefits 0.1.106 → 0.3.53396

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