@nocobase/plugin-workflow 0.11.1-alpha.5 → 0.12.0-alpha.2

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 (537) hide show
  1. package/client.d.ts +2 -3
  2. package/client.js +1 -1
  3. package/dist/client/index.js +7802 -0
  4. package/{lib → dist}/client/nodes/aggregate.d.ts +1 -5
  5. package/{lib → dist}/client/nodes/create.d.ts +1 -2
  6. package/{lib → dist}/client/nodes/destroy.d.ts +1 -1
  7. package/{lib → dist}/client/nodes/query.d.ts +1 -2
  8. package/{lib → dist}/client/nodes/request.d.ts +1 -2
  9. package/{lib → dist}/client/nodes/update.d.ts +1 -1
  10. package/{lib → dist}/client/schemas/collection.d.ts +1 -2
  11. package/{lib → dist}/client/triggers/collection.d.ts +6 -7
  12. package/{lib → dist}/index.d.ts +1 -0
  13. package/dist/index.js +18 -0
  14. package/dist/locale/en-US.js +133 -0
  15. package/{lib → dist}/locale/es-ES.js +51 -54
  16. package/dist/locale/fr-FR.js +133 -0
  17. package/dist/locale/ja-JP.js +91 -0
  18. package/dist/locale/pt-BR.js +133 -0
  19. package/dist/locale/ru-RU.js +91 -0
  20. package/dist/locale/tr-TR.js +91 -0
  21. package/dist/locale/zh-CN.js +216 -0
  22. package/dist/node_modules/cron-parser/.eslintrc.json +15 -0
  23. package/dist/node_modules/cron-parser/.travis.yml +7 -0
  24. package/dist/node_modules/cron-parser/LICENSE +21 -0
  25. package/dist/node_modules/cron-parser/component.json +11 -0
  26. package/dist/node_modules/cron-parser/index.d.ts +1 -0
  27. package/dist/node_modules/cron-parser/lib/date.js +252 -0
  28. package/dist/node_modules/cron-parser/lib/expression.js +983 -0
  29. package/dist/node_modules/cron-parser/lib/field_compactor.js +70 -0
  30. package/dist/node_modules/cron-parser/lib/field_stringify.js +38 -0
  31. package/dist/node_modules/cron-parser/lib/parser.js +1 -0
  32. package/dist/node_modules/cron-parser/node_modules/luxon/build/amd/luxon.js +8489 -0
  33. package/dist/node_modules/cron-parser/node_modules/luxon/build/cjs-browser/luxon.js +8487 -0
  34. package/dist/node_modules/cron-parser/node_modules/luxon/build/global/luxon.js +8490 -0
  35. package/dist/node_modules/cron-parser/node_modules/luxon/build/global/luxon.min.js +1 -0
  36. package/dist/node_modules/cron-parser/node_modules/luxon/build/node/luxon.js +7522 -0
  37. package/dist/node_modules/cron-parser/node_modules/luxon/package.json +96 -0
  38. package/dist/node_modules/cron-parser/node_modules/luxon/src/datetime.js +2169 -0
  39. package/dist/node_modules/cron-parser/node_modules/luxon/src/duration.js +880 -0
  40. package/dist/node_modules/cron-parser/node_modules/luxon/src/errors.js +61 -0
  41. package/dist/node_modules/cron-parser/node_modules/luxon/src/impl/conversions.js +157 -0
  42. package/dist/node_modules/cron-parser/node_modules/luxon/src/impl/diff.js +80 -0
  43. package/dist/node_modules/cron-parser/node_modules/luxon/src/impl/digits.js +76 -0
  44. package/dist/node_modules/cron-parser/node_modules/luxon/src/impl/english.js +233 -0
  45. package/dist/node_modules/cron-parser/node_modules/luxon/src/impl/formats.js +191 -0
  46. package/dist/node_modules/cron-parser/node_modules/luxon/src/impl/formatter.js +386 -0
  47. package/dist/node_modules/cron-parser/node_modules/luxon/src/impl/invalid.js +14 -0
  48. package/dist/node_modules/cron-parser/node_modules/luxon/src/impl/locale.js +482 -0
  49. package/dist/node_modules/cron-parser/node_modules/luxon/src/impl/regexParser.js +335 -0
  50. package/dist/node_modules/cron-parser/node_modules/luxon/src/impl/tokenParser.js +424 -0
  51. package/dist/node_modules/cron-parser/node_modules/luxon/src/impl/util.js +292 -0
  52. package/dist/node_modules/cron-parser/node_modules/luxon/src/impl/zoneUtil.js +36 -0
  53. package/dist/node_modules/cron-parser/node_modules/luxon/src/info.js +193 -0
  54. package/dist/node_modules/cron-parser/node_modules/luxon/src/interval.js +602 -0
  55. package/dist/node_modules/cron-parser/node_modules/luxon/src/luxon.js +26 -0
  56. package/dist/node_modules/cron-parser/node_modules/luxon/src/luxonFilled.js +13 -0
  57. package/dist/node_modules/cron-parser/node_modules/luxon/src/settings.js +137 -0
  58. package/dist/node_modules/cron-parser/node_modules/luxon/src/zone.js +88 -0
  59. package/dist/node_modules/cron-parser/node_modules/luxon/src/zones/IANAZone.js +191 -0
  60. package/dist/node_modules/cron-parser/node_modules/luxon/src/zones/fixedOffsetZone.js +94 -0
  61. package/dist/node_modules/cron-parser/node_modules/luxon/src/zones/invalidZone.js +53 -0
  62. package/dist/node_modules/cron-parser/node_modules/luxon/src/zones/localZone.js +63 -0
  63. package/dist/node_modules/cron-parser/package.json +1 -0
  64. package/dist/node_modules/cron-parser/test/31_of_month.js +17 -0
  65. package/dist/node_modules/cron-parser/test/bug.js +29 -0
  66. package/dist/node_modules/cron-parser/test/crondate.js +16 -0
  67. package/dist/node_modules/cron-parser/test/crontab.example +7 -0
  68. package/dist/node_modules/cron-parser/test/empty_around_comma.js +22 -0
  69. package/dist/node_modules/cron-parser/test/expression.js +1489 -0
  70. package/dist/node_modules/cron-parser/test/field_compactor.js +250 -0
  71. package/dist/node_modules/cron-parser/test/field_stringify.js +84 -0
  72. package/dist/node_modules/cron-parser/test/fields.js +32 -0
  73. package/dist/node_modules/cron-parser/test/increment_on_first_iteration.js +22 -0
  74. package/dist/node_modules/cron-parser/test/index-ts3.test-d.ts +133 -0
  75. package/dist/node_modules/cron-parser/test/index.test-d.ts +138 -0
  76. package/dist/node_modules/cron-parser/test/leap_year.js +17 -0
  77. package/dist/node_modules/cron-parser/test/parser.js +46 -0
  78. package/dist/node_modules/cron-parser/test/parser_crondate_formats.js +145 -0
  79. package/dist/node_modules/cron-parser/test/parser_day_of_month.js +169 -0
  80. package/dist/node_modules/cron-parser/test/prev_date.js +32 -0
  81. package/dist/node_modules/cron-parser/test/stringify.js +402 -0
  82. package/dist/node_modules/cron-parser/test/timezone.js +422 -0
  83. package/dist/node_modules/cron-parser/types/common.d.ts +131 -0
  84. package/dist/node_modules/cron-parser/types/index.d.ts +45 -0
  85. package/dist/node_modules/cron-parser/types/ts3/index.d.ts +28 -0
  86. package/dist/node_modules/lru-cache/index-cjs.d.ts +7 -0
  87. package/dist/node_modules/lru-cache/index-cjs.js +1 -0
  88. package/dist/node_modules/lru-cache/index.d.ts +807 -0
  89. package/dist/node_modules/lru-cache/index.js +1334 -0
  90. package/dist/node_modules/lru-cache/index.min.js +2 -0
  91. package/dist/node_modules/lru-cache/package.json +1 -0
  92. package/dist/server/Plugin.js +297 -0
  93. package/{src/server/Processor.ts → dist/server/Processor.js} +80 -147
  94. package/dist/server/actions/index.js +49 -0
  95. package/{src/server/actions/nodes.ts → dist/server/actions/nodes.js} +55 -81
  96. package/{src/server/actions/workflows.ts → dist/server/actions/workflows.js} +60 -72
  97. package/dist/server/collections/executions.js +37 -0
  98. package/dist/server/collections/flow_nodes.js +56 -0
  99. package/dist/server/collections/jobs.js +33 -0
  100. package/dist/server/collections/workflows.js +90 -0
  101. package/{lib → dist}/server/constants.js +5 -8
  102. package/dist/server/fields/expression-field.js +11 -0
  103. package/dist/server/fields/index.js +11 -0
  104. package/dist/server/functions/index.js +13 -0
  105. package/dist/server/index.js +41 -0
  106. package/dist/server/instructions/aggregate.js +37 -0
  107. package/dist/server/instructions/calculation.js +34 -0
  108. package/dist/server/instructions/condition.js +123 -0
  109. package/{src/server/instructions/create.ts → dist/server/instructions/create.js} +17 -17
  110. package/dist/server/instructions/delay.js +87 -0
  111. package/dist/server/instructions/destroy.js +24 -0
  112. package/dist/server/instructions/index.js +40 -0
  113. package/{src/server/instructions/loop.ts → dist/server/instructions/loop.js} +21 -43
  114. package/{src/server/instructions/manual/actions.ts → dist/server/instructions/manual/actions.js} +18 -44
  115. package/dist/server/instructions/manual/collecions/jobs.js +21 -0
  116. package/dist/server/instructions/manual/collecions/users.js +19 -0
  117. package/dist/server/instructions/manual/collecions/users_jobs.js +52 -0
  118. package/{src/server/instructions/manual/forms/create.ts → dist/server/instructions/manual/forms/create.js} +8 -8
  119. package/dist/server/instructions/manual/forms/index.js +16 -0
  120. package/{src/server/instructions/manual/forms/update.ts → dist/server/instructions/manual/forms/update.js} +8 -8
  121. package/dist/server/instructions/manual/index.js +160 -0
  122. package/dist/server/instructions/parallel.js +105 -0
  123. package/dist/server/instructions/query.js +36 -0
  124. package/dist/server/instructions/request.js +69 -0
  125. package/dist/server/instructions/sql.js +26 -0
  126. package/dist/server/instructions/update.js +24 -0
  127. package/{src/server/migrations/20221129153547-calculation-variables.ts → dist/server/migrations/20221129153547-calculation-variables.js} +20 -19
  128. package/dist/server/migrations/20230221032941-change-request-body-type.js +71 -0
  129. package/dist/server/migrations/20230221071831-calculation-expression.js +94 -0
  130. package/dist/server/migrations/20230221121203-condition-calculation.js +41 -0
  131. package/dist/server/migrations/20230221162902-jsonb-to-json.js +52 -0
  132. package/dist/server/migrations/20230411034722-manual-multi-form.js +252 -0
  133. package/dist/server/migrations/20230612021134-manual-collection-block.js +126 -0
  134. package/dist/server/migrations/20230710115902-manual-action-values.js +74 -0
  135. package/{src/server/triggers/collection.ts → dist/server/triggers/collection.js} +34 -64
  136. package/dist/server/triggers/index.js +27 -0
  137. package/{src/server/triggers/schedule.ts → dist/server/triggers/schedule.js} +108 -220
  138. package/dist/server/types/Execution.js +8 -0
  139. package/dist/server/types/FlowNode.js +8 -0
  140. package/dist/server/types/Job.js +8 -0
  141. package/dist/server/types/Workflow.js +8 -0
  142. package/dist/server/types/index.js +2 -0
  143. package/{lib → dist}/server/utils.js +6 -8
  144. package/package.json +26 -37
  145. package/server.d.ts +2 -3
  146. package/server.js +1 -1
  147. package/lib/client/AddButton.js +0 -161
  148. package/lib/client/Branch.js +0 -50
  149. package/lib/client/CanvasContent.js +0 -51
  150. package/lib/client/ExecutionCanvas.js +0 -218
  151. package/lib/client/ExecutionLink.js +0 -48
  152. package/lib/client/ExecutionPage.js +0 -68
  153. package/lib/client/ExecutionResourceProvider.js +0 -48
  154. package/lib/client/FlowContext.js +0 -21
  155. package/lib/client/WorkflowCanvas.js +0 -300
  156. package/lib/client/WorkflowLink.js +0 -48
  157. package/lib/client/WorkflowPage.js +0 -70
  158. package/lib/client/WorkflowProvider.js +0 -100
  159. package/lib/client/components/CollectionBlockInitializer.js +0 -103
  160. package/lib/client/components/CollectionFieldset.js +0 -198
  161. package/lib/client/components/Duration.js +0 -72
  162. package/lib/client/components/DynamicExpression.js +0 -117
  163. package/lib/client/components/FieldsSelect.js +0 -72
  164. package/lib/client/components/FilterDynamicComponent.js +0 -34
  165. package/lib/client/components/NodeDescription.js +0 -73
  166. package/lib/client/components/NullRender.js +0 -9
  167. package/lib/client/components/OpenDrawer.js +0 -68
  168. package/lib/client/components/RadioWithTooltip.js +0 -65
  169. package/lib/client/components/ValueBlock.js +0 -103
  170. package/lib/client/components/renderEngineReference.js +0 -49
  171. package/lib/client/constants.js +0 -126
  172. package/lib/client/index.js +0 -121
  173. package/lib/client/interfaces/expression.js +0 -38
  174. package/lib/client/locale/index.js +0 -42
  175. package/lib/client/nodes/aggregate.js +0 -353
  176. package/lib/client/nodes/calculation.js +0 -292
  177. package/lib/client/nodes/condition.js +0 -531
  178. package/lib/client/nodes/create.js +0 -110
  179. package/lib/client/nodes/delay.js +0 -47
  180. package/lib/client/nodes/destroy.js +0 -49
  181. package/lib/client/nodes/index.js +0 -550
  182. package/lib/client/nodes/loop.js +0 -171
  183. package/lib/client/nodes/manual/AssigneesSelect.js +0 -56
  184. package/lib/client/nodes/manual/DetailsBlockProvider.js +0 -106
  185. package/lib/client/nodes/manual/FormBlockInitializer.js +0 -107
  186. package/lib/client/nodes/manual/FormBlockProvider.js +0 -113
  187. package/lib/client/nodes/manual/ModeConfig.js +0 -126
  188. package/lib/client/nodes/manual/SchemaConfig.js +0 -468
  189. package/lib/client/nodes/manual/WorkflowTodo.js +0 -642
  190. package/lib/client/nodes/manual/WorkflowTodoBlockInitializer.js +0 -60
  191. package/lib/client/nodes/manual/forms/create.js +0 -111
  192. package/lib/client/nodes/manual/forms/custom.js +0 -428
  193. package/lib/client/nodes/manual/forms/update.js +0 -168
  194. package/lib/client/nodes/manual/index.js +0 -168
  195. package/lib/client/nodes/manual/utils.js +0 -31
  196. package/lib/client/nodes/parallel.js +0 -162
  197. package/lib/client/nodes/query.js +0 -112
  198. package/lib/client/nodes/request.js +0 -225
  199. package/lib/client/nodes/sql.js +0 -61
  200. package/lib/client/nodes/update.js +0 -127
  201. package/lib/client/schemas/collection.js +0 -93
  202. package/lib/client/schemas/executions.js +0 -190
  203. package/lib/client/schemas/workflows.js +0 -397
  204. package/lib/client/style.js +0 -350
  205. package/lib/client/triggers/collection.js +0 -188
  206. package/lib/client/triggers/index.js +0 -356
  207. package/lib/client/triggers/schedule/EndsByField.js +0 -71
  208. package/lib/client/triggers/schedule/OnField.js +0 -117
  209. package/lib/client/triggers/schedule/RepeatField.js +0 -155
  210. package/lib/client/triggers/schedule/ScheduleConfig.js +0 -251
  211. package/lib/client/triggers/schedule/constants.js +0 -11
  212. package/lib/client/triggers/schedule/index.js +0 -101
  213. package/lib/client/triggers/schedule/locale/Cron.zh-CN.js +0 -48
  214. package/lib/client/utils.js +0 -59
  215. package/lib/client/variable.js +0 -319
  216. package/lib/index.js +0 -13
  217. package/lib/locale/en-US.js +0 -136
  218. package/lib/locale/fr-FR.js +0 -136
  219. package/lib/locale/ja-JP.js +0 -94
  220. package/lib/locale/pt-BR.js +0 -136
  221. package/lib/locale/ru-RU.js +0 -94
  222. package/lib/locale/tr-TR.js +0 -94
  223. package/lib/locale/zh-CN.js +0 -219
  224. package/lib/server/Plugin.js +0 -382
  225. package/lib/server/Processor.js +0 -394
  226. package/lib/server/actions/index.js +0 -30
  227. package/lib/server/actions/nodes.js +0 -269
  228. package/lib/server/actions/workflows.js +0 -273
  229. package/lib/server/collections/executions.js +0 -33
  230. package/lib/server/collections/flow_nodes.js +0 -53
  231. package/lib/server/collections/jobs.js +0 -30
  232. package/lib/server/collections/workflows.js +0 -76
  233. package/lib/server/fields/expression-field.js +0 -19
  234. package/lib/server/fields/index.js +0 -12
  235. package/lib/server/functions/index.js +0 -26
  236. package/lib/server/index.js +0 -55
  237. package/lib/server/instructions/aggregate.js +0 -57
  238. package/lib/server/instructions/calculation.js +0 -59
  239. package/lib/server/instructions/condition.js +0 -150
  240. package/lib/server/instructions/create.js +0 -60
  241. package/lib/server/instructions/delay.js +0 -118
  242. package/lib/server/instructions/destroy.js +0 -37
  243. package/lib/server/instructions/index.js +0 -44
  244. package/lib/server/instructions/loop.js +0 -107
  245. package/lib/server/instructions/manual/actions.js +0 -99
  246. package/lib/server/instructions/manual/collecions/jobs.js +0 -21
  247. package/lib/server/instructions/manual/collecions/users.js +0 -19
  248. package/lib/server/instructions/manual/collecions/users_jobs.js +0 -46
  249. package/lib/server/instructions/manual/forms/create.js +0 -52
  250. package/lib/server/instructions/manual/forms/index.js +0 -15
  251. package/lib/server/instructions/manual/forms/update.js +0 -53
  252. package/lib/server/instructions/manual/index.js +0 -174
  253. package/lib/server/instructions/parallel.js +0 -128
  254. package/lib/server/instructions/query.js +0 -53
  255. package/lib/server/instructions/request.js +0 -99
  256. package/lib/server/instructions/sql.js +0 -34
  257. package/lib/server/instructions/update.js +0 -38
  258. package/lib/server/migrations/20221129153547-calculation-variables.js +0 -92
  259. package/lib/server/migrations/20230221032941-change-request-body-type.js +0 -90
  260. package/lib/server/migrations/20230221071831-calculation-expression.js +0 -111
  261. package/lib/server/migrations/20230221121203-condition-calculation.js +0 -103
  262. package/lib/server/migrations/20230221162902-jsonb-to-json.js +0 -64
  263. package/lib/server/migrations/20230411034722-manual-multi-form.js +0 -297
  264. package/lib/server/migrations/20230612021134-manual-collection-block.js +0 -155
  265. package/lib/server/migrations/20230710115902-manual-action-values.js +0 -97
  266. package/lib/server/triggers/collection.js +0 -175
  267. package/lib/server/triggers/index.js +0 -46
  268. package/lib/server/triggers/schedule.js +0 -582
  269. package/lib/server/types/Execution.js +0 -15
  270. package/lib/server/types/FlowNode.js +0 -15
  271. package/lib/server/types/Job.js +0 -15
  272. package/lib/server/types/Workflow.js +0 -15
  273. package/lib/server/types/index.js +0 -5
  274. package/src/client/AddButton.tsx +0 -111
  275. package/src/client/Branch.tsx +0 -37
  276. package/src/client/CanvasContent.tsx +0 -25
  277. package/src/client/ExecutionCanvas.tsx +0 -166
  278. package/src/client/ExecutionLink.tsx +0 -16
  279. package/src/client/ExecutionPage.tsx +0 -45
  280. package/src/client/ExecutionResourceProvider.tsx +0 -21
  281. package/src/client/FlowContext.ts +0 -7
  282. package/src/client/WorkflowCanvas.tsx +0 -221
  283. package/src/client/WorkflowLink.tsx +0 -16
  284. package/src/client/WorkflowPage.tsx +0 -52
  285. package/src/client/WorkflowProvider.tsx +0 -84
  286. package/src/client/components/CollectionBlockInitializer.tsx +0 -71
  287. package/src/client/components/CollectionFieldset.tsx +0 -152
  288. package/src/client/components/Duration.tsx +0 -45
  289. package/src/client/components/DynamicExpression.tsx +0 -57
  290. package/src/client/components/FieldsSelect.tsx +0 -32
  291. package/src/client/components/FilterDynamicComponent.tsx +0 -15
  292. package/src/client/components/NodeDescription.tsx +0 -51
  293. package/src/client/components/NullRender.tsx +0 -3
  294. package/src/client/components/OpenDrawer.tsx +0 -24
  295. package/src/client/components/RadioWithTooltip.tsx +0 -38
  296. package/src/client/components/ValueBlock.tsx +0 -67
  297. package/src/client/components/renderEngineReference.tsx +0 -30
  298. package/src/client/constants.tsx +0 -91
  299. package/src/client/index.tsx +0 -51
  300. package/src/client/interfaces/expression.tsx +0 -25
  301. package/src/client/locale/index.ts +0 -18
  302. package/src/client/nodes/aggregate.tsx +0 -327
  303. package/src/client/nodes/calculation.tsx +0 -216
  304. package/src/client/nodes/condition.tsx +0 -463
  305. package/src/client/nodes/create.tsx +0 -85
  306. package/src/client/nodes/delay.tsx +0 -37
  307. package/src/client/nodes/destroy.tsx +0 -34
  308. package/src/client/nodes/index.tsx +0 -500
  309. package/src/client/nodes/loop.tsx +0 -144
  310. package/src/client/nodes/manual/AssigneesSelect.tsx +0 -33
  311. package/src/client/nodes/manual/DetailsBlockProvider.tsx +0 -80
  312. package/src/client/nodes/manual/FormBlockInitializer.tsx +0 -69
  313. package/src/client/nodes/manual/FormBlockProvider.tsx +0 -75
  314. package/src/client/nodes/manual/ModeConfig.tsx +0 -84
  315. package/src/client/nodes/manual/SchemaConfig.tsx +0 -509
  316. package/src/client/nodes/manual/WorkflowTodo.tsx +0 -607
  317. package/src/client/nodes/manual/WorkflowTodoBlockInitializer.tsx +0 -28
  318. package/src/client/nodes/manual/forms/create.tsx +0 -92
  319. package/src/client/nodes/manual/forms/custom.tsx +0 -392
  320. package/src/client/nodes/manual/forms/update.tsx +0 -134
  321. package/src/client/nodes/manual/index.tsx +0 -162
  322. package/src/client/nodes/manual/utils.ts +0 -28
  323. package/src/client/nodes/parallel.tsx +0 -138
  324. package/src/client/nodes/query.tsx +0 -88
  325. package/src/client/nodes/request.tsx +0 -185
  326. package/src/client/nodes/sql.tsx +0 -37
  327. package/src/client/nodes/update.tsx +0 -100
  328. package/src/client/schemas/collection.ts +0 -75
  329. package/src/client/schemas/executions.tsx +0 -169
  330. package/src/client/schemas/workflows.ts +0 -364
  331. package/src/client/style.tsx +0 -350
  332. package/src/client/triggers/collection.tsx +0 -190
  333. package/src/client/triggers/index.tsx +0 -311
  334. package/src/client/triggers/schedule/EndsByField.tsx +0 -40
  335. package/src/client/triggers/schedule/OnField.tsx +0 -64
  336. package/src/client/triggers/schedule/RepeatField.tsx +0 -116
  337. package/src/client/triggers/schedule/ScheduleConfig.tsx +0 -227
  338. package/src/client/triggers/schedule/constants.ts +0 -4
  339. package/src/client/triggers/schedule/index.tsx +0 -78
  340. package/src/client/triggers/schedule/locale/Cron.zh-CN.ts +0 -79
  341. package/src/client/utils.ts +0 -36
  342. package/src/client/variable.tsx +0 -318
  343. package/src/index.ts +0 -1
  344. package/src/locale/en-US.ts +0 -136
  345. package/src/locale/es-ES.ts +0 -129
  346. package/src/locale/fr-FR.ts +0 -137
  347. package/src/locale/ja-JP.ts +0 -90
  348. package/src/locale/pt-BR.ts +0 -136
  349. package/src/locale/ru-RU.ts +0 -90
  350. package/src/locale/tr-TR.ts +0 -90
  351. package/src/locale/zh-CN.ts +0 -248
  352. package/src/server/Plugin.ts +0 -355
  353. package/src/server/__tests__/Plugin.test.ts +0 -398
  354. package/src/server/__tests__/Processor.test.ts +0 -474
  355. package/src/server/__tests__/actions/workflows.test.ts +0 -419
  356. package/src/server/__tests__/collections/categories.ts +0 -27
  357. package/src/server/__tests__/collections/comments.ts +0 -24
  358. package/src/server/__tests__/collections/posts.ts +0 -42
  359. package/src/server/__tests__/collections/replies.ts +0 -9
  360. package/src/server/__tests__/collections/tags.ts +0 -15
  361. package/src/server/__tests__/index.ts +0 -89
  362. package/src/server/__tests__/instructions/aggregate.test.ts +0 -294
  363. package/src/server/__tests__/instructions/calculation.test.ts +0 -265
  364. package/src/server/__tests__/instructions/condition.test.ts +0 -434
  365. package/src/server/__tests__/instructions/create.test.ts +0 -129
  366. package/src/server/__tests__/instructions/delay.test.ts +0 -182
  367. package/src/server/__tests__/instructions/destroy.test.ts +0 -58
  368. package/src/server/__tests__/instructions/loop.test.ts +0 -331
  369. package/src/server/__tests__/instructions/manual.test.ts +0 -1173
  370. package/src/server/__tests__/instructions/parallel.test.ts +0 -445
  371. package/src/server/__tests__/instructions/query.test.ts +0 -359
  372. package/src/server/__tests__/instructions/request.test.ts +0 -247
  373. package/src/server/__tests__/instructions/sql.test.ts +0 -162
  374. package/src/server/__tests__/instructions/update.test.ts +0 -189
  375. package/src/server/__tests__/triggers/collection.test.ts +0 -333
  376. package/src/server/__tests__/triggers/schedule.test.ts +0 -369
  377. package/src/server/actions/index.ts +0 -25
  378. package/src/server/collections/executions.ts +0 -35
  379. package/src/server/collections/flow_nodes.ts +0 -54
  380. package/src/server/collections/jobs.ts +0 -31
  381. package/src/server/collections/workflows.ts +0 -88
  382. package/src/server/constants.ts +0 -26
  383. package/src/server/fields/expression-field.ts +0 -11
  384. package/src/server/fields/index.ts +0 -7
  385. package/src/server/functions/index.ts +0 -16
  386. package/src/server/index.ts +0 -6
  387. package/src/server/instructions/aggregate.ts +0 -42
  388. package/src/server/instructions/calculation.ts +0 -41
  389. package/src/server/instructions/condition.ts +0 -172
  390. package/src/server/instructions/delay.ts +0 -105
  391. package/src/server/instructions/destroy.ts +0 -23
  392. package/src/server/instructions/index.ts +0 -64
  393. package/src/server/instructions/manual/collecions/jobs.ts +0 -17
  394. package/src/server/instructions/manual/collecions/users.ts +0 -15
  395. package/src/server/instructions/manual/collecions/users_jobs.ts +0 -50
  396. package/src/server/instructions/manual/forms/index.ts +0 -12
  397. package/src/server/instructions/manual/index.ts +0 -184
  398. package/src/server/instructions/parallel.ts +0 -121
  399. package/src/server/instructions/query.ts +0 -42
  400. package/src/server/instructions/request.ts +0 -88
  401. package/src/server/instructions/sql.ts +0 -25
  402. package/src/server/instructions/update.ts +0 -24
  403. package/src/server/migrations/20230221032941-change-request-body-type.ts +0 -76
  404. package/src/server/migrations/20230221071831-calculation-expression.ts +0 -102
  405. package/src/server/migrations/20230221121203-condition-calculation.ts +0 -82
  406. package/src/server/migrations/20230221162902-jsonb-to-json.ts +0 -51
  407. package/src/server/migrations/20230411034722-manual-multi-form.ts +0 -282
  408. package/src/server/migrations/20230612021134-manual-collection-block.ts +0 -138
  409. package/src/server/migrations/20230710115902-manual-action-values.ts +0 -78
  410. package/src/server/triggers/index.ts +0 -22
  411. package/src/server/types/Execution.ts +0 -26
  412. package/src/server/types/FlowNode.ts +0 -21
  413. package/src/server/types/Job.ts +0 -18
  414. package/src/server/types/Workflow.ts +0 -36
  415. package/src/server/types/index.ts +0 -4
  416. package/src/server/utils.ts +0 -17
  417. /package/{lib → dist}/client/AddButton.d.ts +0 -0
  418. /package/{lib → dist}/client/Branch.d.ts +0 -0
  419. /package/{lib → dist}/client/CanvasContent.d.ts +0 -0
  420. /package/{lib → dist}/client/ExecutionCanvas.d.ts +0 -0
  421. /package/{lib → dist}/client/ExecutionLink.d.ts +0 -0
  422. /package/{lib → dist}/client/ExecutionPage.d.ts +0 -0
  423. /package/{lib → dist}/client/ExecutionResourceProvider.d.ts +0 -0
  424. /package/{lib → dist}/client/FlowContext.d.ts +0 -0
  425. /package/{lib → dist}/client/WorkflowCanvas.d.ts +0 -0
  426. /package/{lib → dist}/client/WorkflowLink.d.ts +0 -0
  427. /package/{lib → dist}/client/WorkflowPage.d.ts +0 -0
  428. /package/{lib → dist}/client/WorkflowProvider.d.ts +0 -0
  429. /package/{lib → dist}/client/components/CollectionBlockInitializer.d.ts +0 -0
  430. /package/{lib → dist}/client/components/CollectionFieldset.d.ts +0 -0
  431. /package/{lib → dist}/client/components/Duration.d.ts +0 -0
  432. /package/{lib → dist}/client/components/DynamicExpression.d.ts +0 -0
  433. /package/{lib → dist}/client/components/FieldsSelect.d.ts +0 -0
  434. /package/{lib → dist}/client/components/FilterDynamicComponent.d.ts +0 -0
  435. /package/{lib → dist}/client/components/NodeDescription.d.ts +0 -0
  436. /package/{lib → dist}/client/components/NullRender.d.ts +0 -0
  437. /package/{lib → dist}/client/components/OpenDrawer.d.ts +0 -0
  438. /package/{lib → dist}/client/components/RadioWithTooltip.d.ts +0 -0
  439. /package/{lib → dist}/client/components/ValueBlock.d.ts +0 -0
  440. /package/{lib → dist}/client/components/renderEngineReference.d.ts +0 -0
  441. /package/{lib → dist}/client/constants.d.ts +0 -0
  442. /package/{lib → dist}/client/index.d.ts +0 -0
  443. /package/{lib → dist}/client/interfaces/expression.d.ts +0 -0
  444. /package/{lib → dist}/client/locale/index.d.ts +0 -0
  445. /package/{lib → dist}/client/nodes/calculation.d.ts +0 -0
  446. /package/{lib → dist}/client/nodes/condition.d.ts +0 -0
  447. /package/{lib → dist}/client/nodes/delay.d.ts +0 -0
  448. /package/{lib → dist}/client/nodes/index.d.ts +0 -0
  449. /package/{lib → dist}/client/nodes/loop.d.ts +0 -0
  450. /package/{lib → dist}/client/nodes/manual/AssigneesSelect.d.ts +0 -0
  451. /package/{lib → dist}/client/nodes/manual/DetailsBlockProvider.d.ts +0 -0
  452. /package/{lib → dist}/client/nodes/manual/FormBlockInitializer.d.ts +0 -0
  453. /package/{lib → dist}/client/nodes/manual/FormBlockProvider.d.ts +0 -0
  454. /package/{lib → dist}/client/nodes/manual/ModeConfig.d.ts +0 -0
  455. /package/{lib → dist}/client/nodes/manual/SchemaConfig.d.ts +0 -0
  456. /package/{lib → dist}/client/nodes/manual/WorkflowTodo.d.ts +0 -0
  457. /package/{lib → dist}/client/nodes/manual/WorkflowTodoBlockInitializer.d.ts +0 -0
  458. /package/{lib → dist}/client/nodes/manual/forms/create.d.ts +0 -0
  459. /package/{lib → dist}/client/nodes/manual/forms/custom.d.ts +0 -0
  460. /package/{lib → dist}/client/nodes/manual/forms/update.d.ts +0 -0
  461. /package/{lib → dist}/client/nodes/manual/index.d.ts +0 -0
  462. /package/{lib → dist}/client/nodes/manual/utils.d.ts +0 -0
  463. /package/{lib → dist}/client/nodes/parallel.d.ts +0 -0
  464. /package/{lib → dist}/client/nodes/sql.d.ts +0 -0
  465. /package/{lib → dist}/client/schemas/executions.d.ts +0 -0
  466. /package/{lib → dist}/client/schemas/workflows.d.ts +0 -0
  467. /package/{lib → dist}/client/style.d.ts +0 -0
  468. /package/{lib → dist}/client/triggers/index.d.ts +0 -0
  469. /package/{lib → dist}/client/triggers/schedule/EndsByField.d.ts +0 -0
  470. /package/{lib → dist}/client/triggers/schedule/OnField.d.ts +0 -0
  471. /package/{lib → dist}/client/triggers/schedule/RepeatField.d.ts +0 -0
  472. /package/{lib → dist}/client/triggers/schedule/ScheduleConfig.d.ts +0 -0
  473. /package/{lib → dist}/client/triggers/schedule/constants.d.ts +0 -0
  474. /package/{lib → dist}/client/triggers/schedule/index.d.ts +0 -0
  475. /package/{lib → dist}/client/triggers/schedule/locale/Cron.zh-CN.d.ts +0 -0
  476. /package/{lib → dist}/client/utils.d.ts +0 -0
  477. /package/{lib → dist}/client/variable.d.ts +0 -0
  478. /package/{lib → dist}/locale/en-US.d.ts +0 -0
  479. /package/{lib → dist}/locale/es-ES.d.ts +0 -0
  480. /package/{lib → dist}/locale/fr-FR.d.ts +0 -0
  481. /package/{lib → dist}/locale/ja-JP.d.ts +0 -0
  482. /package/{lib → dist}/locale/pt-BR.d.ts +0 -0
  483. /package/{lib → dist}/locale/ru-RU.d.ts +0 -0
  484. /package/{lib → dist}/locale/tr-TR.d.ts +0 -0
  485. /package/{lib → dist}/locale/zh-CN.d.ts +0 -0
  486. /package/{lib → dist}/server/Plugin.d.ts +0 -0
  487. /package/{lib → dist}/server/Processor.d.ts +0 -0
  488. /package/{lib → dist}/server/actions/index.d.ts +0 -0
  489. /package/{lib → dist}/server/actions/nodes.d.ts +0 -0
  490. /package/{lib → dist}/server/actions/workflows.d.ts +0 -0
  491. /package/{lib → dist}/server/collections/executions.d.ts +0 -0
  492. /package/{lib → dist}/server/collections/flow_nodes.d.ts +0 -0
  493. /package/{lib → dist}/server/collections/jobs.d.ts +0 -0
  494. /package/{lib → dist}/server/collections/workflows.d.ts +0 -0
  495. /package/{lib → dist}/server/constants.d.ts +0 -0
  496. /package/{lib → dist}/server/fields/expression-field.d.ts +0 -0
  497. /package/{lib → dist}/server/fields/index.d.ts +0 -0
  498. /package/{lib → dist}/server/functions/index.d.ts +0 -0
  499. /package/{lib → dist}/server/index.d.ts +0 -0
  500. /package/{lib → dist}/server/instructions/aggregate.d.ts +0 -0
  501. /package/{lib → dist}/server/instructions/calculation.d.ts +0 -0
  502. /package/{lib → dist}/server/instructions/condition.d.ts +0 -0
  503. /package/{lib → dist}/server/instructions/create.d.ts +0 -0
  504. /package/{lib → dist}/server/instructions/delay.d.ts +0 -0
  505. /package/{lib → dist}/server/instructions/destroy.d.ts +0 -0
  506. /package/{lib → dist}/server/instructions/index.d.ts +0 -0
  507. /package/{lib → dist}/server/instructions/loop.d.ts +0 -0
  508. /package/{lib → dist}/server/instructions/manual/actions.d.ts +0 -0
  509. /package/{lib → dist}/server/instructions/manual/collecions/jobs.d.ts +0 -0
  510. /package/{lib → dist}/server/instructions/manual/collecions/users.d.ts +0 -0
  511. /package/{lib → dist}/server/instructions/manual/collecions/users_jobs.d.ts +0 -0
  512. /package/{lib → dist}/server/instructions/manual/forms/create.d.ts +0 -0
  513. /package/{lib → dist}/server/instructions/manual/forms/index.d.ts +0 -0
  514. /package/{lib → dist}/server/instructions/manual/forms/update.d.ts +0 -0
  515. /package/{lib → dist}/server/instructions/manual/index.d.ts +0 -0
  516. /package/{lib → dist}/server/instructions/parallel.d.ts +0 -0
  517. /package/{lib → dist}/server/instructions/query.d.ts +0 -0
  518. /package/{lib → dist}/server/instructions/request.d.ts +0 -0
  519. /package/{lib → dist}/server/instructions/sql.d.ts +0 -0
  520. /package/{lib → dist}/server/instructions/update.d.ts +0 -0
  521. /package/{lib → dist}/server/migrations/20221129153547-calculation-variables.d.ts +0 -0
  522. /package/{lib → dist}/server/migrations/20230221032941-change-request-body-type.d.ts +0 -0
  523. /package/{lib → dist}/server/migrations/20230221071831-calculation-expression.d.ts +0 -0
  524. /package/{lib → dist}/server/migrations/20230221121203-condition-calculation.d.ts +0 -0
  525. /package/{lib → dist}/server/migrations/20230221162902-jsonb-to-json.d.ts +0 -0
  526. /package/{lib → dist}/server/migrations/20230411034722-manual-multi-form.d.ts +0 -0
  527. /package/{lib → dist}/server/migrations/20230612021134-manual-collection-block.d.ts +0 -0
  528. /package/{lib → dist}/server/migrations/20230710115902-manual-action-values.d.ts +0 -0
  529. /package/{lib → dist}/server/triggers/collection.d.ts +0 -0
  530. /package/{lib → dist}/server/triggers/index.d.ts +0 -0
  531. /package/{lib → dist}/server/triggers/schedule.d.ts +0 -0
  532. /package/{lib → dist}/server/types/Execution.d.ts +0 -0
  533. /package/{lib → dist}/server/types/FlowNode.d.ts +0 -0
  534. /package/{lib → dist}/server/types/Job.d.ts +0 -0
  535. /package/{lib → dist}/server/types/Workflow.d.ts +0 -0
  536. /package/{lib → dist}/server/types/index.d.ts +0 -0
  537. /package/{lib → dist}/server/utils.d.ts +0 -0
@@ -0,0 +1,2169 @@
1
+ import Duration, { friendlyDuration } from "./duration.js";
2
+ import Interval from "./interval.js";
3
+ import Settings from "./settings.js";
4
+ import Info from "./info.js";
5
+ import Formatter from "./impl/formatter.js";
6
+ import FixedOffsetZone from "./zones/fixedOffsetZone.js";
7
+ import Locale from "./impl/locale.js";
8
+ import {
9
+ isUndefined,
10
+ maybeArray,
11
+ isDate,
12
+ isNumber,
13
+ bestBy,
14
+ daysInMonth,
15
+ daysInYear,
16
+ isLeapYear,
17
+ weeksInWeekYear,
18
+ normalizeObject,
19
+ roundTo,
20
+ objToLocalTS
21
+ } from "./impl/util.js";
22
+ import { normalizeZone } from "./impl/zoneUtil.js";
23
+ import diff from "./impl/diff.js";
24
+ import { parseRFC2822Date, parseISODate, parseHTTPDate, parseSQL } from "./impl/regexParser.js";
25
+ import { parseFromTokens, explainFromTokens } from "./impl/tokenParser.js";
26
+ import {
27
+ gregorianToWeek,
28
+ weekToGregorian,
29
+ gregorianToOrdinal,
30
+ ordinalToGregorian,
31
+ hasInvalidGregorianData,
32
+ hasInvalidWeekData,
33
+ hasInvalidOrdinalData,
34
+ hasInvalidTimeData
35
+ } from "./impl/conversions.js";
36
+ import * as Formats from "./impl/formats.js";
37
+ import {
38
+ InvalidArgumentError,
39
+ ConflictingSpecificationError,
40
+ InvalidUnitError,
41
+ InvalidDateTimeError
42
+ } from "./errors.js";
43
+ import Invalid from "./impl/invalid.js";
44
+
45
+ const INVALID = "Invalid DateTime";
46
+ const MAX_DATE = 8.64e15;
47
+
48
+ function unsupportedZone(zone) {
49
+ return new Invalid("unsupported zone", `the zone "${zone.name}" is not supported`);
50
+ }
51
+
52
+ // we cache week data on the DT object and this intermediates the cache
53
+ function possiblyCachedWeekData(dt) {
54
+ if (dt.weekData === null) {
55
+ dt.weekData = gregorianToWeek(dt.c);
56
+ }
57
+ return dt.weekData;
58
+ }
59
+
60
+ // clone really means, "make a new object with these modifications". all "setters" really use this
61
+ // to create a new object while only changing some of the properties
62
+ function clone(inst, alts) {
63
+ const current = {
64
+ ts: inst.ts,
65
+ zone: inst.zone,
66
+ c: inst.c,
67
+ o: inst.o,
68
+ loc: inst.loc,
69
+ invalid: inst.invalid
70
+ };
71
+ return new DateTime(Object.assign({}, current, alts, { old: current }));
72
+ }
73
+
74
+ // find the right offset a given local time. The o input is our guess, which determines which
75
+ // offset we'll pick in ambiguous cases (e.g. there are two 3 AMs b/c Fallback DST)
76
+ function fixOffset(localTS, o, tz) {
77
+ // Our UTC time is just a guess because our offset is just a guess
78
+ let utcGuess = localTS - o * 60 * 1000;
79
+
80
+ // Test whether the zone matches the offset for this ts
81
+ const o2 = tz.offset(utcGuess);
82
+
83
+ // If so, offset didn't change and we're done
84
+ if (o === o2) {
85
+ return [utcGuess, o];
86
+ }
87
+
88
+ // If not, change the ts by the difference in the offset
89
+ utcGuess -= (o2 - o) * 60 * 1000;
90
+
91
+ // If that gives us the local time we want, we're done
92
+ const o3 = tz.offset(utcGuess);
93
+ if (o2 === o3) {
94
+ return [utcGuess, o2];
95
+ }
96
+
97
+ // If it's different, we're in a hole time. The offset has changed, but the we don't adjust the time
98
+ return [localTS - Math.min(o2, o3) * 60 * 1000, Math.max(o2, o3)];
99
+ }
100
+
101
+ // convert an epoch timestamp into a calendar object with the given offset
102
+ function tsToObj(ts, offset) {
103
+ ts += offset * 60 * 1000;
104
+
105
+ const d = new Date(ts);
106
+
107
+ return {
108
+ year: d.getUTCFullYear(),
109
+ month: d.getUTCMonth() + 1,
110
+ day: d.getUTCDate(),
111
+ hour: d.getUTCHours(),
112
+ minute: d.getUTCMinutes(),
113
+ second: d.getUTCSeconds(),
114
+ millisecond: d.getUTCMilliseconds()
115
+ };
116
+ }
117
+
118
+ // convert a calendar object to a epoch timestamp
119
+ function objToTS(obj, offset, zone) {
120
+ return fixOffset(objToLocalTS(obj), offset, zone);
121
+ }
122
+
123
+ // create a new DT instance by adding a duration, adjusting for DSTs
124
+ function adjustTime(inst, dur) {
125
+ const oPre = inst.o,
126
+ year = inst.c.year + Math.trunc(dur.years),
127
+ month = inst.c.month + Math.trunc(dur.months) + Math.trunc(dur.quarters) * 3,
128
+ c = Object.assign({}, inst.c, {
129
+ year,
130
+ month,
131
+ day:
132
+ Math.min(inst.c.day, daysInMonth(year, month)) +
133
+ Math.trunc(dur.days) +
134
+ Math.trunc(dur.weeks) * 7
135
+ }),
136
+ millisToAdd = Duration.fromObject({
137
+ years: dur.years - Math.trunc(dur.years),
138
+ quarters: dur.quarters - Math.trunc(dur.quarters),
139
+ months: dur.months - Math.trunc(dur.months),
140
+ weeks: dur.weeks - Math.trunc(dur.weeks),
141
+ days: dur.days - Math.trunc(dur.days),
142
+ hours: dur.hours,
143
+ minutes: dur.minutes,
144
+ seconds: dur.seconds,
145
+ milliseconds: dur.milliseconds
146
+ }).as("milliseconds"),
147
+ localTS = objToLocalTS(c);
148
+
149
+ let [ts, o] = fixOffset(localTS, oPre, inst.zone);
150
+
151
+ if (millisToAdd !== 0) {
152
+ ts += millisToAdd;
153
+ // that could have changed the offset by going over a DST, but we want to keep the ts the same
154
+ o = inst.zone.offset(ts);
155
+ }
156
+
157
+ return { ts, o };
158
+ }
159
+
160
+ // helper useful in turning the results of parsing into real dates
161
+ // by handling the zone options
162
+ function parseDataToDateTime(parsed, parsedZone, opts, format, text) {
163
+ const { setZone, zone } = opts;
164
+ if (parsed && Object.keys(parsed).length !== 0) {
165
+ const interpretationZone = parsedZone || zone,
166
+ inst = DateTime.fromObject(
167
+ Object.assign(parsed, opts, {
168
+ zone: interpretationZone,
169
+ // setZone is a valid option in the calling methods, but not in fromObject
170
+ setZone: undefined
171
+ })
172
+ );
173
+ return setZone ? inst : inst.setZone(zone);
174
+ } else {
175
+ return DateTime.invalid(
176
+ new Invalid("unparsable", `the input "${text}" can't be parsed as ${format}`)
177
+ );
178
+ }
179
+ }
180
+
181
+ // if you want to output a technical format (e.g. RFC 2822), this helper
182
+ // helps handle the details
183
+ function toTechFormat(dt, format, allowZ = true) {
184
+ return dt.isValid
185
+ ? Formatter.create(Locale.create("en-US"), {
186
+ allowZ,
187
+ forceSimple: true
188
+ }).formatDateTimeFromString(dt, format)
189
+ : null;
190
+ }
191
+
192
+ // technical time formats (e.g. the time part of ISO 8601), take some options
193
+ // and this commonizes their handling
194
+ function toTechTimeFormat(
195
+ dt,
196
+ {
197
+ suppressSeconds = false,
198
+ suppressMilliseconds = false,
199
+ includeOffset,
200
+ includePrefix = false,
201
+ includeZone = false,
202
+ spaceZone = false,
203
+ format = "extended"
204
+ }
205
+ ) {
206
+ let fmt = format === "basic" ? "HHmm" : "HH:mm";
207
+
208
+ if (!suppressSeconds || dt.second !== 0 || dt.millisecond !== 0) {
209
+ fmt += format === "basic" ? "ss" : ":ss";
210
+ if (!suppressMilliseconds || dt.millisecond !== 0) {
211
+ fmt += ".SSS";
212
+ }
213
+ }
214
+
215
+ if ((includeZone || includeOffset) && spaceZone) {
216
+ fmt += " ";
217
+ }
218
+
219
+ if (includeZone) {
220
+ fmt += "z";
221
+ } else if (includeOffset) {
222
+ fmt += format === "basic" ? "ZZZ" : "ZZ";
223
+ }
224
+
225
+ let str = toTechFormat(dt, fmt);
226
+
227
+ if (includePrefix) {
228
+ str = "T" + str;
229
+ }
230
+
231
+ return str;
232
+ }
233
+
234
+ // defaults for unspecified units in the supported calendars
235
+ const defaultUnitValues = {
236
+ month: 1,
237
+ day: 1,
238
+ hour: 0,
239
+ minute: 0,
240
+ second: 0,
241
+ millisecond: 0
242
+ },
243
+ defaultWeekUnitValues = {
244
+ weekNumber: 1,
245
+ weekday: 1,
246
+ hour: 0,
247
+ minute: 0,
248
+ second: 0,
249
+ millisecond: 0
250
+ },
251
+ defaultOrdinalUnitValues = {
252
+ ordinal: 1,
253
+ hour: 0,
254
+ minute: 0,
255
+ second: 0,
256
+ millisecond: 0
257
+ };
258
+
259
+ // Units in the supported calendars, sorted by bigness
260
+ const orderedUnits = ["year", "month", "day", "hour", "minute", "second", "millisecond"],
261
+ orderedWeekUnits = [
262
+ "weekYear",
263
+ "weekNumber",
264
+ "weekday",
265
+ "hour",
266
+ "minute",
267
+ "second",
268
+ "millisecond"
269
+ ],
270
+ orderedOrdinalUnits = ["year", "ordinal", "hour", "minute", "second", "millisecond"];
271
+
272
+ // standardize case and plurality in units
273
+ function normalizeUnit(unit) {
274
+ const normalized = {
275
+ year: "year",
276
+ years: "year",
277
+ month: "month",
278
+ months: "month",
279
+ day: "day",
280
+ days: "day",
281
+ hour: "hour",
282
+ hours: "hour",
283
+ minute: "minute",
284
+ minutes: "minute",
285
+ quarter: "quarter",
286
+ quarters: "quarter",
287
+ second: "second",
288
+ seconds: "second",
289
+ millisecond: "millisecond",
290
+ milliseconds: "millisecond",
291
+ weekday: "weekday",
292
+ weekdays: "weekday",
293
+ weeknumber: "weekNumber",
294
+ weeksnumber: "weekNumber",
295
+ weeknumbers: "weekNumber",
296
+ weekyear: "weekYear",
297
+ weekyears: "weekYear",
298
+ ordinal: "ordinal"
299
+ }[unit.toLowerCase()];
300
+
301
+ if (!normalized) throw new InvalidUnitError(unit);
302
+
303
+ return normalized;
304
+ }
305
+
306
+ // this is a dumbed down version of fromObject() that runs about 60% faster
307
+ // but doesn't do any validation, makes a bunch of assumptions about what units
308
+ // are present, and so on.
309
+ function quickDT(obj, zone) {
310
+ // assume we have the higher-order units
311
+ for (const u of orderedUnits) {
312
+ if (isUndefined(obj[u])) {
313
+ obj[u] = defaultUnitValues[u];
314
+ }
315
+ }
316
+
317
+ const invalid = hasInvalidGregorianData(obj) || hasInvalidTimeData(obj);
318
+ if (invalid) {
319
+ return DateTime.invalid(invalid);
320
+ }
321
+
322
+ const tsNow = Settings.now(),
323
+ offsetProvis = zone.offset(tsNow),
324
+ [ts, o] = objToTS(obj, offsetProvis, zone);
325
+
326
+ return new DateTime({
327
+ ts,
328
+ zone,
329
+ o
330
+ });
331
+ }
332
+
333
+ function diffRelative(start, end, opts) {
334
+ const round = isUndefined(opts.round) ? true : opts.round,
335
+ format = (c, unit) => {
336
+ c = roundTo(c, round || opts.calendary ? 0 : 2, true);
337
+ const formatter = end.loc.clone(opts).relFormatter(opts);
338
+ return formatter.format(c, unit);
339
+ },
340
+ differ = unit => {
341
+ if (opts.calendary) {
342
+ if (!end.hasSame(start, unit)) {
343
+ return end
344
+ .startOf(unit)
345
+ .diff(start.startOf(unit), unit)
346
+ .get(unit);
347
+ } else return 0;
348
+ } else {
349
+ return end.diff(start, unit).get(unit);
350
+ }
351
+ };
352
+
353
+ if (opts.unit) {
354
+ return format(differ(opts.unit), opts.unit);
355
+ }
356
+
357
+ for (const unit of opts.units) {
358
+ const count = differ(unit);
359
+ if (Math.abs(count) >= 1) {
360
+ return format(count, unit);
361
+ }
362
+ }
363
+ return format(start > end ? -0 : 0, opts.units[opts.units.length - 1]);
364
+ }
365
+
366
+ /**
367
+ * A DateTime is an immutable data structure representing a specific date and time and accompanying methods. It contains class and instance methods for creating, parsing, interrogating, transforming, and formatting them.
368
+ *
369
+ * A DateTime comprises of:
370
+ * * A timestamp. Each DateTime instance refers to a specific millisecond of the Unix epoch.
371
+ * * A time zone. Each instance is considered in the context of a specific zone (by default the local system's zone).
372
+ * * Configuration properties that effect how output strings are formatted, such as `locale`, `numberingSystem`, and `outputCalendar`.
373
+ *
374
+ * Here is a brief overview of the most commonly used functionality it provides:
375
+ *
376
+ * * **Creation**: To create a DateTime from its components, use one of its factory class methods: {@link local}, {@link utc}, and (most flexibly) {@link fromObject}. To create one from a standard string format, use {@link fromISO}, {@link fromHTTP}, and {@link fromRFC2822}. To create one from a custom string format, use {@link fromFormat}. To create one from a native JS date, use {@link fromJSDate}.
377
+ * * **Gregorian calendar and time**: To examine the Gregorian properties of a DateTime individually (i.e as opposed to collectively through {@link toObject}), use the {@link year}, {@link month},
378
+ * {@link day}, {@link hour}, {@link minute}, {@link second}, {@link millisecond} accessors.
379
+ * * **Week calendar**: For ISO week calendar attributes, see the {@link weekYear}, {@link weekNumber}, and {@link weekday} accessors.
380
+ * * **Configuration** See the {@link locale} and {@link numberingSystem} accessors.
381
+ * * **Transformation**: To transform the DateTime into other DateTimes, use {@link set}, {@link reconfigure}, {@link setZone}, {@link setLocale}, {@link plus}, {@link minus}, {@link endOf}, {@link startOf}, {@link toUTC}, and {@link toLocal}.
382
+ * * **Output**: To convert the DateTime to other representations, use the {@link toRelative}, {@link toRelativeCalendar}, {@link toJSON}, {@link toISO}, {@link toHTTP}, {@link toObject}, {@link toRFC2822}, {@link toString}, {@link toLocaleString}, {@link toFormat}, {@link toMillis} and {@link toJSDate}.
383
+ *
384
+ * There's plenty others documented below. In addition, for more information on subtler topics like internationalization, time zones, alternative calendars, validity, and so on, see the external documentation.
385
+ */
386
+ export default class DateTime {
387
+ /**
388
+ * @access private
389
+ */
390
+ constructor(config) {
391
+ const zone = config.zone || Settings.defaultZone;
392
+
393
+ let invalid =
394
+ config.invalid ||
395
+ (Number.isNaN(config.ts) ? new Invalid("invalid input") : null) ||
396
+ (!zone.isValid ? unsupportedZone(zone) : null);
397
+ /**
398
+ * @access private
399
+ */
400
+ this.ts = isUndefined(config.ts) ? Settings.now() : config.ts;
401
+
402
+ let c = null,
403
+ o = null;
404
+ if (!invalid) {
405
+ const unchanged = config.old && config.old.ts === this.ts && config.old.zone.equals(zone);
406
+
407
+ if (unchanged) {
408
+ [c, o] = [config.old.c, config.old.o];
409
+ } else {
410
+ const ot = zone.offset(this.ts);
411
+ c = tsToObj(this.ts, ot);
412
+ invalid = Number.isNaN(c.year) ? new Invalid("invalid input") : null;
413
+ c = invalid ? null : c;
414
+ o = invalid ? null : ot;
415
+ }
416
+ }
417
+
418
+ /**
419
+ * @access private
420
+ */
421
+ this._zone = zone;
422
+ /**
423
+ * @access private
424
+ */
425
+ this.loc = config.loc || Locale.create();
426
+ /**
427
+ * @access private
428
+ */
429
+ this.invalid = invalid;
430
+ /**
431
+ * @access private
432
+ */
433
+ this.weekData = null;
434
+ /**
435
+ * @access private
436
+ */
437
+ this.c = c;
438
+ /**
439
+ * @access private
440
+ */
441
+ this.o = o;
442
+ /**
443
+ * @access private
444
+ */
445
+ this.isLuxonDateTime = true;
446
+ }
447
+
448
+ // CONSTRUCT
449
+
450
+ /**
451
+ * Create a DateTime for the current instant, in the system's time zone.
452
+ *
453
+ * Use Settings to override these default values if needed.
454
+ * @example DateTime.now().toISO() //~> now in the ISO format
455
+ * @return {DateTime}
456
+ */
457
+ static now() {
458
+ return new DateTime({});
459
+ }
460
+
461
+ /**
462
+ * Create a local DateTime
463
+ * @param {number} [year] - The calendar year. If omitted (as in, call `local()` with no arguments), the current time will be used
464
+ * @param {number} [month=1] - The month, 1-indexed
465
+ * @param {number} [day=1] - The day of the month, 1-indexed
466
+ * @param {number} [hour=0] - The hour of the day, in 24-hour time
467
+ * @param {number} [minute=0] - The minute of the hour, meaning a number between 0 and 59
468
+ * @param {number} [second=0] - The second of the minute, meaning a number between 0 and 59
469
+ * @param {number} [millisecond=0] - The millisecond of the second, meaning a number between 0 and 999
470
+ * @example DateTime.local() //~> now
471
+ * @example DateTime.local(2017) //~> 2017-01-01T00:00:00
472
+ * @example DateTime.local(2017, 3) //~> 2017-03-01T00:00:00
473
+ * @example DateTime.local(2017, 3, 12) //~> 2017-03-12T00:00:00
474
+ * @example DateTime.local(2017, 3, 12, 5) //~> 2017-03-12T05:00:00
475
+ * @example DateTime.local(2017, 3, 12, 5, 45) //~> 2017-03-12T05:45:00
476
+ * @example DateTime.local(2017, 3, 12, 5, 45, 10) //~> 2017-03-12T05:45:10
477
+ * @example DateTime.local(2017, 3, 12, 5, 45, 10, 765) //~> 2017-03-12T05:45:10.765
478
+ * @return {DateTime}
479
+ */
480
+ static local(year, month, day, hour, minute, second, millisecond) {
481
+ if (isUndefined(year)) {
482
+ return DateTime.now();
483
+ } else {
484
+ return quickDT(
485
+ {
486
+ year,
487
+ month,
488
+ day,
489
+ hour,
490
+ minute,
491
+ second,
492
+ millisecond
493
+ },
494
+ Settings.defaultZone
495
+ );
496
+ }
497
+ }
498
+
499
+ /**
500
+ * Create a DateTime in UTC
501
+ * @param {number} [year] - The calendar year. If omitted (as in, call `utc()` with no arguments), the current time will be used
502
+ * @param {number} [month=1] - The month, 1-indexed
503
+ * @param {number} [day=1] - The day of the month
504
+ * @param {number} [hour=0] - The hour of the day, in 24-hour time
505
+ * @param {number} [minute=0] - The minute of the hour, meaning a number between 0 and 59
506
+ * @param {number} [second=0] - The second of the minute, meaning a number between 0 and 59
507
+ * @param {number} [millisecond=0] - The millisecond of the second, meaning a number between 0 and 999
508
+ * @example DateTime.utc() //~> now
509
+ * @example DateTime.utc(2017) //~> 2017-01-01T00:00:00Z
510
+ * @example DateTime.utc(2017, 3) //~> 2017-03-01T00:00:00Z
511
+ * @example DateTime.utc(2017, 3, 12) //~> 2017-03-12T00:00:00Z
512
+ * @example DateTime.utc(2017, 3, 12, 5) //~> 2017-03-12T05:00:00Z
513
+ * @example DateTime.utc(2017, 3, 12, 5, 45) //~> 2017-03-12T05:45:00Z
514
+ * @example DateTime.utc(2017, 3, 12, 5, 45, 10) //~> 2017-03-12T05:45:10Z
515
+ * @example DateTime.utc(2017, 3, 12, 5, 45, 10, 765) //~> 2017-03-12T05:45:10.765Z
516
+ * @return {DateTime}
517
+ */
518
+ static utc(year, month, day, hour, minute, second, millisecond) {
519
+ if (isUndefined(year)) {
520
+ return new DateTime({
521
+ ts: Settings.now(),
522
+ zone: FixedOffsetZone.utcInstance
523
+ });
524
+ } else {
525
+ return quickDT(
526
+ {
527
+ year,
528
+ month,
529
+ day,
530
+ hour,
531
+ minute,
532
+ second,
533
+ millisecond
534
+ },
535
+ FixedOffsetZone.utcInstance
536
+ );
537
+ }
538
+ }
539
+
540
+ /**
541
+ * Create a DateTime from a JavaScript Date object. Uses the default zone.
542
+ * @param {Date} date - a JavaScript Date object
543
+ * @param {Object} options - configuration options for the DateTime
544
+ * @param {string|Zone} [options.zone='local'] - the zone to place the DateTime into
545
+ * @return {DateTime}
546
+ */
547
+ static fromJSDate(date, options = {}) {
548
+ const ts = isDate(date) ? date.valueOf() : NaN;
549
+ if (Number.isNaN(ts)) {
550
+ return DateTime.invalid("invalid input");
551
+ }
552
+
553
+ const zoneToUse = normalizeZone(options.zone, Settings.defaultZone);
554
+ if (!zoneToUse.isValid) {
555
+ return DateTime.invalid(unsupportedZone(zoneToUse));
556
+ }
557
+
558
+ return new DateTime({
559
+ ts: ts,
560
+ zone: zoneToUse,
561
+ loc: Locale.fromObject(options)
562
+ });
563
+ }
564
+
565
+ /**
566
+ * Create a DateTime from a number of milliseconds since the epoch (meaning since 1 January 1970 00:00:00 UTC). Uses the default zone.
567
+ * @param {number} milliseconds - a number of milliseconds since 1970 UTC
568
+ * @param {Object} options - configuration options for the DateTime
569
+ * @param {string|Zone} [options.zone='local'] - the zone to place the DateTime into
570
+ * @param {string} [options.locale] - a locale to set on the resulting DateTime instance
571
+ * @param {string} options.outputCalendar - the output calendar to set on the resulting DateTime instance
572
+ * @param {string} options.numberingSystem - the numbering system to set on the resulting DateTime instance
573
+ * @return {DateTime}
574
+ */
575
+ static fromMillis(milliseconds, options = {}) {
576
+ if (!isNumber(milliseconds)) {
577
+ throw new InvalidArgumentError(
578
+ `fromMillis requires a numerical input, but received a ${typeof milliseconds} with value ${milliseconds}`
579
+ );
580
+ } else if (milliseconds < -MAX_DATE || milliseconds > MAX_DATE) {
581
+ // this isn't perfect because because we can still end up out of range because of additional shifting, but it's a start
582
+ return DateTime.invalid("Timestamp out of range");
583
+ } else {
584
+ return new DateTime({
585
+ ts: milliseconds,
586
+ zone: normalizeZone(options.zone, Settings.defaultZone),
587
+ loc: Locale.fromObject(options)
588
+ });
589
+ }
590
+ }
591
+
592
+ /**
593
+ * Create a DateTime from a number of seconds since the epoch (meaning since 1 January 1970 00:00:00 UTC). Uses the default zone.
594
+ * @param {number} seconds - a number of seconds since 1970 UTC
595
+ * @param {Object} options - configuration options for the DateTime
596
+ * @param {string|Zone} [options.zone='local'] - the zone to place the DateTime into
597
+ * @param {string} [options.locale] - a locale to set on the resulting DateTime instance
598
+ * @param {string} options.outputCalendar - the output calendar to set on the resulting DateTime instance
599
+ * @param {string} options.numberingSystem - the numbering system to set on the resulting DateTime instance
600
+ * @return {DateTime}
601
+ */
602
+ static fromSeconds(seconds, options = {}) {
603
+ if (!isNumber(seconds)) {
604
+ throw new InvalidArgumentError("fromSeconds requires a numerical input");
605
+ } else {
606
+ return new DateTime({
607
+ ts: seconds * 1000,
608
+ zone: normalizeZone(options.zone, Settings.defaultZone),
609
+ loc: Locale.fromObject(options)
610
+ });
611
+ }
612
+ }
613
+
614
+ /**
615
+ * Create a DateTime from a JavaScript object with keys like 'year' and 'hour' with reasonable defaults.
616
+ * @param {Object} obj - the object to create the DateTime from
617
+ * @param {number} obj.year - a year, such as 1987
618
+ * @param {number} obj.month - a month, 1-12
619
+ * @param {number} obj.day - a day of the month, 1-31, depending on the month
620
+ * @param {number} obj.ordinal - day of the year, 1-365 or 366
621
+ * @param {number} obj.weekYear - an ISO week year
622
+ * @param {number} obj.weekNumber - an ISO week number, between 1 and 52 or 53, depending on the year
623
+ * @param {number} obj.weekday - an ISO weekday, 1-7, where 1 is Monday and 7 is Sunday
624
+ * @param {number} obj.hour - hour of the day, 0-23
625
+ * @param {number} obj.minute - minute of the hour, 0-59
626
+ * @param {number} obj.second - second of the minute, 0-59
627
+ * @param {number} obj.millisecond - millisecond of the second, 0-999
628
+ * @param {string|Zone} [obj.zone='local'] - interpret the numbers in the context of a particular zone. Can take any value taken as the first argument to setZone()
629
+ * @param {string} [obj.locale='system's locale'] - a locale to set on the resulting DateTime instance
630
+ * @param {string} obj.outputCalendar - the output calendar to set on the resulting DateTime instance
631
+ * @param {string} obj.numberingSystem - the numbering system to set on the resulting DateTime instance
632
+ * @example DateTime.fromObject({ year: 1982, month: 5, day: 25}).toISODate() //=> '1982-05-25'
633
+ * @example DateTime.fromObject({ year: 1982 }).toISODate() //=> '1982-01-01'
634
+ * @example DateTime.fromObject({ hour: 10, minute: 26, second: 6 }) //~> today at 10:26:06
635
+ * @example DateTime.fromObject({ hour: 10, minute: 26, second: 6, zone: 'utc' }),
636
+ * @example DateTime.fromObject({ hour: 10, minute: 26, second: 6, zone: 'local' })
637
+ * @example DateTime.fromObject({ hour: 10, minute: 26, second: 6, zone: 'America/New_York' })
638
+ * @example DateTime.fromObject({ weekYear: 2016, weekNumber: 2, weekday: 3 }).toISODate() //=> '2016-01-13'
639
+ * @return {DateTime}
640
+ */
641
+ static fromObject(obj) {
642
+ const zoneToUse = normalizeZone(obj.zone, Settings.defaultZone);
643
+ if (!zoneToUse.isValid) {
644
+ return DateTime.invalid(unsupportedZone(zoneToUse));
645
+ }
646
+
647
+ const tsNow = Settings.now(),
648
+ offsetProvis = zoneToUse.offset(tsNow),
649
+ normalized = normalizeObject(obj, normalizeUnit, [
650
+ "zone",
651
+ "locale",
652
+ "outputCalendar",
653
+ "numberingSystem"
654
+ ]),
655
+ containsOrdinal = !isUndefined(normalized.ordinal),
656
+ containsGregorYear = !isUndefined(normalized.year),
657
+ containsGregorMD = !isUndefined(normalized.month) || !isUndefined(normalized.day),
658
+ containsGregor = containsGregorYear || containsGregorMD,
659
+ definiteWeekDef = normalized.weekYear || normalized.weekNumber,
660
+ loc = Locale.fromObject(obj);
661
+
662
+ // cases:
663
+ // just a weekday -> this week's instance of that weekday, no worries
664
+ // (gregorian data or ordinal) + (weekYear or weekNumber) -> error
665
+ // (gregorian month or day) + ordinal -> error
666
+ // otherwise just use weeks or ordinals or gregorian, depending on what's specified
667
+
668
+ if ((containsGregor || containsOrdinal) && definiteWeekDef) {
669
+ throw new ConflictingSpecificationError(
670
+ "Can't mix weekYear/weekNumber units with year/month/day or ordinals"
671
+ );
672
+ }
673
+
674
+ if (containsGregorMD && containsOrdinal) {
675
+ throw new ConflictingSpecificationError("Can't mix ordinal dates with month/day");
676
+ }
677
+
678
+ const useWeekData = definiteWeekDef || (normalized.weekday && !containsGregor);
679
+
680
+ // configure ourselves to deal with gregorian dates or week stuff
681
+ let units,
682
+ defaultValues,
683
+ objNow = tsToObj(tsNow, offsetProvis);
684
+ if (useWeekData) {
685
+ units = orderedWeekUnits;
686
+ defaultValues = defaultWeekUnitValues;
687
+ objNow = gregorianToWeek(objNow);
688
+ } else if (containsOrdinal) {
689
+ units = orderedOrdinalUnits;
690
+ defaultValues = defaultOrdinalUnitValues;
691
+ objNow = gregorianToOrdinal(objNow);
692
+ } else {
693
+ units = orderedUnits;
694
+ defaultValues = defaultUnitValues;
695
+ }
696
+
697
+ // set default values for missing stuff
698
+ let foundFirst = false;
699
+ for (const u of units) {
700
+ const v = normalized[u];
701
+ if (!isUndefined(v)) {
702
+ foundFirst = true;
703
+ } else if (foundFirst) {
704
+ normalized[u] = defaultValues[u];
705
+ } else {
706
+ normalized[u] = objNow[u];
707
+ }
708
+ }
709
+
710
+ // make sure the values we have are in range
711
+ const higherOrderInvalid = useWeekData
712
+ ? hasInvalidWeekData(normalized)
713
+ : containsOrdinal
714
+ ? hasInvalidOrdinalData(normalized)
715
+ : hasInvalidGregorianData(normalized),
716
+ invalid = higherOrderInvalid || hasInvalidTimeData(normalized);
717
+
718
+ if (invalid) {
719
+ return DateTime.invalid(invalid);
720
+ }
721
+
722
+ // compute the actual time
723
+ const gregorian = useWeekData
724
+ ? weekToGregorian(normalized)
725
+ : containsOrdinal
726
+ ? ordinalToGregorian(normalized)
727
+ : normalized,
728
+ [tsFinal, offsetFinal] = objToTS(gregorian, offsetProvis, zoneToUse),
729
+ inst = new DateTime({
730
+ ts: tsFinal,
731
+ zone: zoneToUse,
732
+ o: offsetFinal,
733
+ loc
734
+ });
735
+
736
+ // gregorian data + weekday serves only to validate
737
+ if (normalized.weekday && containsGregor && obj.weekday !== inst.weekday) {
738
+ return DateTime.invalid(
739
+ "mismatched weekday",
740
+ `you can't specify both a weekday of ${normalized.weekday} and a date of ${inst.toISO()}`
741
+ );
742
+ }
743
+
744
+ return inst;
745
+ }
746
+
747
+ /**
748
+ * Create a DateTime from an ISO 8601 string
749
+ * @param {string} text - the ISO string
750
+ * @param {Object} opts - options to affect the creation
751
+ * @param {string|Zone} [opts.zone='local'] - use this zone if no offset is specified in the input string itself. Will also convert the time to this zone
752
+ * @param {boolean} [opts.setZone=false] - override the zone with a fixed-offset zone specified in the string itself, if it specifies one
753
+ * @param {string} [opts.locale='system's locale'] - a locale to set on the resulting DateTime instance
754
+ * @param {string} [opts.outputCalendar] - the output calendar to set on the resulting DateTime instance
755
+ * @param {string} [opts.numberingSystem] - the numbering system to set on the resulting DateTime instance
756
+ * @example DateTime.fromISO('2016-05-25T09:08:34.123')
757
+ * @example DateTime.fromISO('2016-05-25T09:08:34.123+06:00')
758
+ * @example DateTime.fromISO('2016-05-25T09:08:34.123+06:00', {setZone: true})
759
+ * @example DateTime.fromISO('2016-05-25T09:08:34.123', {zone: 'utc'})
760
+ * @example DateTime.fromISO('2016-W05-4')
761
+ * @return {DateTime}
762
+ */
763
+ static fromISO(text, opts = {}) {
764
+ const [vals, parsedZone] = parseISODate(text);
765
+ return parseDataToDateTime(vals, parsedZone, opts, "ISO 8601", text);
766
+ }
767
+
768
+ /**
769
+ * Create a DateTime from an RFC 2822 string
770
+ * @param {string} text - the RFC 2822 string
771
+ * @param {Object} opts - options to affect the creation
772
+ * @param {string|Zone} [opts.zone='local'] - convert the time to this zone. Since the offset is always specified in the string itself, this has no effect on the interpretation of string, merely the zone the resulting DateTime is expressed in.
773
+ * @param {boolean} [opts.setZone=false] - override the zone with a fixed-offset zone specified in the string itself, if it specifies one
774
+ * @param {string} [opts.locale='system's locale'] - a locale to set on the resulting DateTime instance
775
+ * @param {string} opts.outputCalendar - the output calendar to set on the resulting DateTime instance
776
+ * @param {string} opts.numberingSystem - the numbering system to set on the resulting DateTime instance
777
+ * @example DateTime.fromRFC2822('25 Nov 2016 13:23:12 GMT')
778
+ * @example DateTime.fromRFC2822('Fri, 25 Nov 2016 13:23:12 +0600')
779
+ * @example DateTime.fromRFC2822('25 Nov 2016 13:23 Z')
780
+ * @return {DateTime}
781
+ */
782
+ static fromRFC2822(text, opts = {}) {
783
+ const [vals, parsedZone] = parseRFC2822Date(text);
784
+ return parseDataToDateTime(vals, parsedZone, opts, "RFC 2822", text);
785
+ }
786
+
787
+ /**
788
+ * Create a DateTime from an HTTP header date
789
+ * @see https://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1
790
+ * @param {string} text - the HTTP header date
791
+ * @param {Object} opts - options to affect the creation
792
+ * @param {string|Zone} [opts.zone='local'] - convert the time to this zone. Since HTTP dates are always in UTC, this has no effect on the interpretation of string, merely the zone the resulting DateTime is expressed in.
793
+ * @param {boolean} [opts.setZone=false] - override the zone with the fixed-offset zone specified in the string. For HTTP dates, this is always UTC, so this option is equivalent to setting the `zone` option to 'utc', but this option is included for consistency with similar methods.
794
+ * @param {string} [opts.locale='system's locale'] - a locale to set on the resulting DateTime instance
795
+ * @param {string} opts.outputCalendar - the output calendar to set on the resulting DateTime instance
796
+ * @param {string} opts.numberingSystem - the numbering system to set on the resulting DateTime instance
797
+ * @example DateTime.fromHTTP('Sun, 06 Nov 1994 08:49:37 GMT')
798
+ * @example DateTime.fromHTTP('Sunday, 06-Nov-94 08:49:37 GMT')
799
+ * @example DateTime.fromHTTP('Sun Nov 6 08:49:37 1994')
800
+ * @return {DateTime}
801
+ */
802
+ static fromHTTP(text, opts = {}) {
803
+ const [vals, parsedZone] = parseHTTPDate(text);
804
+ return parseDataToDateTime(vals, parsedZone, opts, "HTTP", opts);
805
+ }
806
+
807
+ /**
808
+ * Create a DateTime from an input string and format string.
809
+ * Defaults to en-US if no locale has been specified, regardless of the system's locale.
810
+ * @see https://moment.github.io/luxon/docs/manual/parsing.html#table-of-tokens
811
+ * @param {string} text - the string to parse
812
+ * @param {string} fmt - the format the string is expected to be in (see the link below for the formats)
813
+ * @param {Object} opts - options to affect the creation
814
+ * @param {string|Zone} [opts.zone='local'] - use this zone if no offset is specified in the input string itself. Will also convert the DateTime to this zone
815
+ * @param {boolean} [opts.setZone=false] - override the zone with a zone specified in the string itself, if it specifies one
816
+ * @param {string} [opts.locale='en-US'] - a locale string to use when parsing. Will also set the DateTime to this locale
817
+ * @param {string} opts.numberingSystem - the numbering system to use when parsing. Will also set the resulting DateTime to this numbering system
818
+ * @param {string} opts.outputCalendar - the output calendar to set on the resulting DateTime instance
819
+ * @return {DateTime}
820
+ */
821
+ static fromFormat(text, fmt, opts = {}) {
822
+ if (isUndefined(text) || isUndefined(fmt)) {
823
+ throw new InvalidArgumentError("fromFormat requires an input string and a format");
824
+ }
825
+
826
+ const { locale = null, numberingSystem = null } = opts,
827
+ localeToUse = Locale.fromOpts({
828
+ locale,
829
+ numberingSystem,
830
+ defaultToEN: true
831
+ }),
832
+ [vals, parsedZone, invalid] = parseFromTokens(localeToUse, text, fmt);
833
+ if (invalid) {
834
+ return DateTime.invalid(invalid);
835
+ } else {
836
+ return parseDataToDateTime(vals, parsedZone, opts, `format ${fmt}`, text);
837
+ }
838
+ }
839
+
840
+ /**
841
+ * @deprecated use fromFormat instead
842
+ */
843
+ static fromString(text, fmt, opts = {}) {
844
+ return DateTime.fromFormat(text, fmt, opts);
845
+ }
846
+
847
+ /**
848
+ * Create a DateTime from a SQL date, time, or datetime
849
+ * Defaults to en-US if no locale has been specified, regardless of the system's locale
850
+ * @param {string} text - the string to parse
851
+ * @param {Object} opts - options to affect the creation
852
+ * @param {string|Zone} [opts.zone='local'] - use this zone if no offset is specified in the input string itself. Will also convert the DateTime to this zone
853
+ * @param {boolean} [opts.setZone=false] - override the zone with a zone specified in the string itself, if it specifies one
854
+ * @param {string} [opts.locale='en-US'] - a locale string to use when parsing. Will also set the DateTime to this locale
855
+ * @param {string} opts.numberingSystem - the numbering system to use when parsing. Will also set the resulting DateTime to this numbering system
856
+ * @param {string} opts.outputCalendar - the output calendar to set on the resulting DateTime instance
857
+ * @example DateTime.fromSQL('2017-05-15')
858
+ * @example DateTime.fromSQL('2017-05-15 09:12:34')
859
+ * @example DateTime.fromSQL('2017-05-15 09:12:34.342')
860
+ * @example DateTime.fromSQL('2017-05-15 09:12:34.342+06:00')
861
+ * @example DateTime.fromSQL('2017-05-15 09:12:34.342 America/Los_Angeles')
862
+ * @example DateTime.fromSQL('2017-05-15 09:12:34.342 America/Los_Angeles', { setZone: true })
863
+ * @example DateTime.fromSQL('2017-05-15 09:12:34.342', { zone: 'America/Los_Angeles' })
864
+ * @example DateTime.fromSQL('09:12:34.342')
865
+ * @return {DateTime}
866
+ */
867
+ static fromSQL(text, opts = {}) {
868
+ const [vals, parsedZone] = parseSQL(text);
869
+ return parseDataToDateTime(vals, parsedZone, opts, "SQL", text);
870
+ }
871
+
872
+ /**
873
+ * Create an invalid DateTime.
874
+ * @param {string} reason - simple string of why this DateTime is invalid. Should not contain parameters or anything else data-dependent
875
+ * @param {string} [explanation=null] - longer explanation, may include parameters and other useful debugging information
876
+ * @return {DateTime}
877
+ */
878
+ static invalid(reason, explanation = null) {
879
+ if (!reason) {
880
+ throw new InvalidArgumentError("need to specify a reason the DateTime is invalid");
881
+ }
882
+
883
+ const invalid = reason instanceof Invalid ? reason : new Invalid(reason, explanation);
884
+
885
+ if (Settings.throwOnInvalid) {
886
+ throw new InvalidDateTimeError(invalid);
887
+ } else {
888
+ return new DateTime({ invalid });
889
+ }
890
+ }
891
+
892
+ /**
893
+ * Check if an object is a DateTime. Works across context boundaries
894
+ * @param {object} o
895
+ * @return {boolean}
896
+ */
897
+ static isDateTime(o) {
898
+ return (o && o.isLuxonDateTime) || false;
899
+ }
900
+
901
+ // INFO
902
+
903
+ /**
904
+ * Get the value of unit.
905
+ * @param {string} unit - a unit such as 'minute' or 'day'
906
+ * @example DateTime.local(2017, 7, 4).get('month'); //=> 7
907
+ * @example DateTime.local(2017, 7, 4).get('day'); //=> 4
908
+ * @return {number}
909
+ */
910
+ get(unit) {
911
+ return this[unit];
912
+ }
913
+
914
+ /**
915
+ * Returns whether the DateTime is valid. Invalid DateTimes occur when:
916
+ * * The DateTime was created from invalid calendar information, such as the 13th month or February 30
917
+ * * The DateTime was created by an operation on another invalid date
918
+ * @type {boolean}
919
+ */
920
+ get isValid() {
921
+ return this.invalid === null;
922
+ }
923
+
924
+ /**
925
+ * Returns an error code if this DateTime is invalid, or null if the DateTime is valid
926
+ * @type {string}
927
+ */
928
+ get invalidReason() {
929
+ return this.invalid ? this.invalid.reason : null;
930
+ }
931
+
932
+ /**
933
+ * Returns an explanation of why this DateTime became invalid, or null if the DateTime is valid
934
+ * @type {string}
935
+ */
936
+ get invalidExplanation() {
937
+ return this.invalid ? this.invalid.explanation : null;
938
+ }
939
+
940
+ /**
941
+ * Get the locale of a DateTime, such 'en-GB'. The locale is used when formatting the DateTime
942
+ *
943
+ * @type {string}
944
+ */
945
+ get locale() {
946
+ return this.isValid ? this.loc.locale : null;
947
+ }
948
+
949
+ /**
950
+ * Get the numbering system of a DateTime, such 'beng'. The numbering system is used when formatting the DateTime
951
+ *
952
+ * @type {string}
953
+ */
954
+ get numberingSystem() {
955
+ return this.isValid ? this.loc.numberingSystem : null;
956
+ }
957
+
958
+ /**
959
+ * Get the output calendar of a DateTime, such 'islamic'. The output calendar is used when formatting the DateTime
960
+ *
961
+ * @type {string}
962
+ */
963
+ get outputCalendar() {
964
+ return this.isValid ? this.loc.outputCalendar : null;
965
+ }
966
+
967
+ /**
968
+ * Get the time zone associated with this DateTime.
969
+ * @type {Zone}
970
+ */
971
+ get zone() {
972
+ return this._zone;
973
+ }
974
+
975
+ /**
976
+ * Get the name of the time zone.
977
+ * @type {string}
978
+ */
979
+ get zoneName() {
980
+ return this.isValid ? this.zone.name : null;
981
+ }
982
+
983
+ /**
984
+ * Get the year
985
+ * @example DateTime.local(2017, 5, 25).year //=> 2017
986
+ * @type {number}
987
+ */
988
+ get year() {
989
+ return this.isValid ? this.c.year : NaN;
990
+ }
991
+
992
+ /**
993
+ * Get the quarter
994
+ * @example DateTime.local(2017, 5, 25).quarter //=> 2
995
+ * @type {number}
996
+ */
997
+ get quarter() {
998
+ return this.isValid ? Math.ceil(this.c.month / 3) : NaN;
999
+ }
1000
+
1001
+ /**
1002
+ * Get the month (1-12).
1003
+ * @example DateTime.local(2017, 5, 25).month //=> 5
1004
+ * @type {number}
1005
+ */
1006
+ get month() {
1007
+ return this.isValid ? this.c.month : NaN;
1008
+ }
1009
+
1010
+ /**
1011
+ * Get the day of the month (1-30ish).
1012
+ * @example DateTime.local(2017, 5, 25).day //=> 25
1013
+ * @type {number}
1014
+ */
1015
+ get day() {
1016
+ return this.isValid ? this.c.day : NaN;
1017
+ }
1018
+
1019
+ /**
1020
+ * Get the hour of the day (0-23).
1021
+ * @example DateTime.local(2017, 5, 25, 9).hour //=> 9
1022
+ * @type {number}
1023
+ */
1024
+ get hour() {
1025
+ return this.isValid ? this.c.hour : NaN;
1026
+ }
1027
+
1028
+ /**
1029
+ * Get the minute of the hour (0-59).
1030
+ * @example DateTime.local(2017, 5, 25, 9, 30).minute //=> 30
1031
+ * @type {number}
1032
+ */
1033
+ get minute() {
1034
+ return this.isValid ? this.c.minute : NaN;
1035
+ }
1036
+
1037
+ /**
1038
+ * Get the second of the minute (0-59).
1039
+ * @example DateTime.local(2017, 5, 25, 9, 30, 52).second //=> 52
1040
+ * @type {number}
1041
+ */
1042
+ get second() {
1043
+ return this.isValid ? this.c.second : NaN;
1044
+ }
1045
+
1046
+ /**
1047
+ * Get the millisecond of the second (0-999).
1048
+ * @example DateTime.local(2017, 5, 25, 9, 30, 52, 654).millisecond //=> 654
1049
+ * @type {number}
1050
+ */
1051
+ get millisecond() {
1052
+ return this.isValid ? this.c.millisecond : NaN;
1053
+ }
1054
+
1055
+ /**
1056
+ * Get the week year
1057
+ * @see https://en.wikipedia.org/wiki/ISO_week_date
1058
+ * @example DateTime.local(2014, 12, 31).weekYear //=> 2015
1059
+ * @type {number}
1060
+ */
1061
+ get weekYear() {
1062
+ return this.isValid ? possiblyCachedWeekData(this).weekYear : NaN;
1063
+ }
1064
+
1065
+ /**
1066
+ * Get the week number of the week year (1-52ish).
1067
+ * @see https://en.wikipedia.org/wiki/ISO_week_date
1068
+ * @example DateTime.local(2017, 5, 25).weekNumber //=> 21
1069
+ * @type {number}
1070
+ */
1071
+ get weekNumber() {
1072
+ return this.isValid ? possiblyCachedWeekData(this).weekNumber : NaN;
1073
+ }
1074
+
1075
+ /**
1076
+ * Get the day of the week.
1077
+ * 1 is Monday and 7 is Sunday
1078
+ * @see https://en.wikipedia.org/wiki/ISO_week_date
1079
+ * @example DateTime.local(2014, 11, 31).weekday //=> 4
1080
+ * @type {number}
1081
+ */
1082
+ get weekday() {
1083
+ return this.isValid ? possiblyCachedWeekData(this).weekday : NaN;
1084
+ }
1085
+
1086
+ /**
1087
+ * Get the ordinal (meaning the day of the year)
1088
+ * @example DateTime.local(2017, 5, 25).ordinal //=> 145
1089
+ * @type {number|DateTime}
1090
+ */
1091
+ get ordinal() {
1092
+ return this.isValid ? gregorianToOrdinal(this.c).ordinal : NaN;
1093
+ }
1094
+
1095
+ /**
1096
+ * Get the human readable short month name, such as 'Oct'.
1097
+ * Defaults to the system's locale if no locale has been specified
1098
+ * @example DateTime.local(2017, 10, 30).monthShort //=> Oct
1099
+ * @type {string}
1100
+ */
1101
+ get monthShort() {
1102
+ return this.isValid ? Info.months("short", { locObj: this.loc })[this.month - 1] : null;
1103
+ }
1104
+
1105
+ /**
1106
+ * Get the human readable long month name, such as 'October'.
1107
+ * Defaults to the system's locale if no locale has been specified
1108
+ * @example DateTime.local(2017, 10, 30).monthLong //=> October
1109
+ * @type {string}
1110
+ */
1111
+ get monthLong() {
1112
+ return this.isValid ? Info.months("long", { locObj: this.loc })[this.month - 1] : null;
1113
+ }
1114
+
1115
+ /**
1116
+ * Get the human readable short weekday, such as 'Mon'.
1117
+ * Defaults to the system's locale if no locale has been specified
1118
+ * @example DateTime.local(2017, 10, 30).weekdayShort //=> Mon
1119
+ * @type {string}
1120
+ */
1121
+ get weekdayShort() {
1122
+ return this.isValid ? Info.weekdays("short", { locObj: this.loc })[this.weekday - 1] : null;
1123
+ }
1124
+
1125
+ /**
1126
+ * Get the human readable long weekday, such as 'Monday'.
1127
+ * Defaults to the system's locale if no locale has been specified
1128
+ * @example DateTime.local(2017, 10, 30).weekdayLong //=> Monday
1129
+ * @type {string}
1130
+ */
1131
+ get weekdayLong() {
1132
+ return this.isValid ? Info.weekdays("long", { locObj: this.loc })[this.weekday - 1] : null;
1133
+ }
1134
+
1135
+ /**
1136
+ * Get the UTC offset of this DateTime in minutes
1137
+ * @example DateTime.now().offset //=> -240
1138
+ * @example DateTime.utc().offset //=> 0
1139
+ * @type {number}
1140
+ */
1141
+ get offset() {
1142
+ return this.isValid ? +this.o : NaN;
1143
+ }
1144
+
1145
+ /**
1146
+ * Get the short human name for the zone's current offset, for example "EST" or "EDT".
1147
+ * Defaults to the system's locale if no locale has been specified
1148
+ * @type {string}
1149
+ */
1150
+ get offsetNameShort() {
1151
+ if (this.isValid) {
1152
+ return this.zone.offsetName(this.ts, {
1153
+ format: "short",
1154
+ locale: this.locale
1155
+ });
1156
+ } else {
1157
+ return null;
1158
+ }
1159
+ }
1160
+
1161
+ /**
1162
+ * Get the long human name for the zone's current offset, for example "Eastern Standard Time" or "Eastern Daylight Time".
1163
+ * Defaults to the system's locale if no locale has been specified
1164
+ * @type {string}
1165
+ */
1166
+ get offsetNameLong() {
1167
+ if (this.isValid) {
1168
+ return this.zone.offsetName(this.ts, {
1169
+ format: "long",
1170
+ locale: this.locale
1171
+ });
1172
+ } else {
1173
+ return null;
1174
+ }
1175
+ }
1176
+
1177
+ /**
1178
+ * Get whether this zone's offset ever changes, as in a DST.
1179
+ * @type {boolean}
1180
+ */
1181
+ get isOffsetFixed() {
1182
+ return this.isValid ? this.zone.universal : null;
1183
+ }
1184
+
1185
+ /**
1186
+ * Get whether the DateTime is in a DST.
1187
+ * @type {boolean}
1188
+ */
1189
+ get isInDST() {
1190
+ if (this.isOffsetFixed) {
1191
+ return false;
1192
+ } else {
1193
+ return (
1194
+ this.offset > this.set({ month: 1 }).offset || this.offset > this.set({ month: 5 }).offset
1195
+ );
1196
+ }
1197
+ }
1198
+
1199
+ /**
1200
+ * Returns true if this DateTime is in a leap year, false otherwise
1201
+ * @example DateTime.local(2016).isInLeapYear //=> true
1202
+ * @example DateTime.local(2013).isInLeapYear //=> false
1203
+ * @type {boolean}
1204
+ */
1205
+ get isInLeapYear() {
1206
+ return isLeapYear(this.year);
1207
+ }
1208
+
1209
+ /**
1210
+ * Returns the number of days in this DateTime's month
1211
+ * @example DateTime.local(2016, 2).daysInMonth //=> 29
1212
+ * @example DateTime.local(2016, 3).daysInMonth //=> 31
1213
+ * @type {number}
1214
+ */
1215
+ get daysInMonth() {
1216
+ return daysInMonth(this.year, this.month);
1217
+ }
1218
+
1219
+ /**
1220
+ * Returns the number of days in this DateTime's year
1221
+ * @example DateTime.local(2016).daysInYear //=> 366
1222
+ * @example DateTime.local(2013).daysInYear //=> 365
1223
+ * @type {number}
1224
+ */
1225
+ get daysInYear() {
1226
+ return this.isValid ? daysInYear(this.year) : NaN;
1227
+ }
1228
+
1229
+ /**
1230
+ * Returns the number of weeks in this DateTime's year
1231
+ * @see https://en.wikipedia.org/wiki/ISO_week_date
1232
+ * @example DateTime.local(2004).weeksInWeekYear //=> 53
1233
+ * @example DateTime.local(2013).weeksInWeekYear //=> 52
1234
+ * @type {number}
1235
+ */
1236
+ get weeksInWeekYear() {
1237
+ return this.isValid ? weeksInWeekYear(this.weekYear) : NaN;
1238
+ }
1239
+
1240
+ /**
1241
+ * Returns the resolved Intl options for this DateTime.
1242
+ * This is useful in understanding the behavior of formatting methods
1243
+ * @param {Object} opts - the same options as toLocaleString
1244
+ * @return {Object}
1245
+ */
1246
+ resolvedLocaleOpts(opts = {}) {
1247
+ const { locale, numberingSystem, calendar } = Formatter.create(
1248
+ this.loc.clone(opts),
1249
+ opts
1250
+ ).resolvedOptions(this);
1251
+ return { locale, numberingSystem, outputCalendar: calendar };
1252
+ }
1253
+
1254
+ // TRANSFORM
1255
+
1256
+ /**
1257
+ * "Set" the DateTime's zone to UTC. Returns a newly-constructed DateTime.
1258
+ *
1259
+ * Equivalent to {@link setZone}('utc')
1260
+ * @param {number} [offset=0] - optionally, an offset from UTC in minutes
1261
+ * @param {Object} [opts={}] - options to pass to `setZone()`
1262
+ * @return {DateTime}
1263
+ */
1264
+ toUTC(offset = 0, opts = {}) {
1265
+ return this.setZone(FixedOffsetZone.instance(offset), opts);
1266
+ }
1267
+
1268
+ /**
1269
+ * "Set" the DateTime's zone to the host's local zone. Returns a newly-constructed DateTime.
1270
+ *
1271
+ * Equivalent to `setZone('local')`
1272
+ * @return {DateTime}
1273
+ */
1274
+ toLocal() {
1275
+ return this.setZone(Settings.defaultZone);
1276
+ }
1277
+
1278
+ /**
1279
+ * "Set" the DateTime's zone to specified zone. Returns a newly-constructed DateTime.
1280
+ *
1281
+ * By default, the setter keeps the underlying time the same (as in, the same timestamp), but the new instance will report different local times and consider DSTs when making computations, as with {@link plus}. You may wish to use {@link toLocal} and {@link toUTC} which provide simple convenience wrappers for commonly used zones.
1282
+ * @param {string|Zone} [zone='local'] - a zone identifier. As a string, that can be any IANA zone supported by the host environment, or a fixed-offset name of the form 'UTC+3', or the strings 'local' or 'utc'. You may also supply an instance of a {@link Zone} class.
1283
+ * @param {Object} opts - options
1284
+ * @param {boolean} [opts.keepLocalTime=false] - If true, adjust the underlying time so that the local time stays the same, but in the target zone. You should rarely need this.
1285
+ * @return {DateTime}
1286
+ */
1287
+ setZone(zone, { keepLocalTime = false, keepCalendarTime = false } = {}) {
1288
+ zone = normalizeZone(zone, Settings.defaultZone);
1289
+ if (zone.equals(this.zone)) {
1290
+ return this;
1291
+ } else if (!zone.isValid) {
1292
+ return DateTime.invalid(unsupportedZone(zone));
1293
+ } else {
1294
+ let newTS = this.ts;
1295
+ if (keepLocalTime || keepCalendarTime) {
1296
+ const offsetGuess = zone.offset(this.ts);
1297
+ const asObj = this.toObject();
1298
+ [newTS] = objToTS(asObj, offsetGuess, zone);
1299
+ }
1300
+ return clone(this, { ts: newTS, zone });
1301
+ }
1302
+ }
1303
+
1304
+ /**
1305
+ * "Set" the locale, numberingSystem, or outputCalendar. Returns a newly-constructed DateTime.
1306
+ * @param {Object} properties - the properties to set
1307
+ * @example DateTime.local(2017, 5, 25).reconfigure({ locale: 'en-GB' })
1308
+ * @return {DateTime}
1309
+ */
1310
+ reconfigure({ locale, numberingSystem, outputCalendar } = {}) {
1311
+ const loc = this.loc.clone({ locale, numberingSystem, outputCalendar });
1312
+ return clone(this, { loc });
1313
+ }
1314
+
1315
+ /**
1316
+ * "Set" the locale. Returns a newly-constructed DateTime.
1317
+ * Just a convenient alias for reconfigure({ locale })
1318
+ * @example DateTime.local(2017, 5, 25).setLocale('en-GB')
1319
+ * @return {DateTime}
1320
+ */
1321
+ setLocale(locale) {
1322
+ return this.reconfigure({ locale });
1323
+ }
1324
+
1325
+ /**
1326
+ * "Set" the values of specified units. Returns a newly-constructed DateTime.
1327
+ * You can only set units with this method; for "setting" metadata, see {@link reconfigure} and {@link setZone}.
1328
+ * @param {Object} values - a mapping of units to numbers
1329
+ * @example dt.set({ year: 2017 })
1330
+ * @example dt.set({ hour: 8, minute: 30 })
1331
+ * @example dt.set({ weekday: 5 })
1332
+ * @example dt.set({ year: 2005, ordinal: 234 })
1333
+ * @return {DateTime}
1334
+ */
1335
+ set(values) {
1336
+ if (!this.isValid) return this;
1337
+
1338
+ const normalized = normalizeObject(values, normalizeUnit, []),
1339
+ settingWeekStuff =
1340
+ !isUndefined(normalized.weekYear) ||
1341
+ !isUndefined(normalized.weekNumber) ||
1342
+ !isUndefined(normalized.weekday),
1343
+ containsOrdinal = !isUndefined(normalized.ordinal),
1344
+ containsGregorYear = !isUndefined(normalized.year),
1345
+ containsGregorMD = !isUndefined(normalized.month) || !isUndefined(normalized.day),
1346
+ containsGregor = containsGregorYear || containsGregorMD,
1347
+ definiteWeekDef = normalized.weekYear || normalized.weekNumber;
1348
+
1349
+ if ((containsGregor || containsOrdinal) && definiteWeekDef) {
1350
+ throw new ConflictingSpecificationError(
1351
+ "Can't mix weekYear/weekNumber units with year/month/day or ordinals"
1352
+ );
1353
+ }
1354
+
1355
+ if (containsGregorMD && containsOrdinal) {
1356
+ throw new ConflictingSpecificationError("Can't mix ordinal dates with month/day");
1357
+ }
1358
+
1359
+ let mixed;
1360
+ if (settingWeekStuff) {
1361
+ mixed = weekToGregorian(Object.assign(gregorianToWeek(this.c), normalized));
1362
+ } else if (!isUndefined(normalized.ordinal)) {
1363
+ mixed = ordinalToGregorian(Object.assign(gregorianToOrdinal(this.c), normalized));
1364
+ } else {
1365
+ mixed = Object.assign(this.toObject(), normalized);
1366
+
1367
+ // if we didn't set the day but we ended up on an overflow date,
1368
+ // use the last day of the right month
1369
+ if (isUndefined(normalized.day)) {
1370
+ mixed.day = Math.min(daysInMonth(mixed.year, mixed.month), mixed.day);
1371
+ }
1372
+ }
1373
+
1374
+ const [ts, o] = objToTS(mixed, this.o, this.zone);
1375
+ return clone(this, { ts, o });
1376
+ }
1377
+
1378
+ /**
1379
+ * Add a period of time to this DateTime and return the resulting DateTime
1380
+ *
1381
+ * Adding hours, minutes, seconds, or milliseconds increases the timestamp by the right number of milliseconds. Adding days, months, or years shifts the calendar, accounting for DSTs and leap years along the way. Thus, `dt.plus({ hours: 24 })` may result in a different time than `dt.plus({ days: 1 })` if there's a DST shift in between.
1382
+ * @param {Duration|Object|number} duration - The amount to add. Either a Luxon Duration, a number of milliseconds, the object argument to Duration.fromObject()
1383
+ * @example DateTime.now().plus(123) //~> in 123 milliseconds
1384
+ * @example DateTime.now().plus({ minutes: 15 }) //~> in 15 minutes
1385
+ * @example DateTime.now().plus({ days: 1 }) //~> this time tomorrow
1386
+ * @example DateTime.now().plus({ days: -1 }) //~> this time yesterday
1387
+ * @example DateTime.now().plus({ hours: 3, minutes: 13 }) //~> in 3 hr, 13 min
1388
+ * @example DateTime.now().plus(Duration.fromObject({ hours: 3, minutes: 13 })) //~> in 3 hr, 13 min
1389
+ * @return {DateTime}
1390
+ */
1391
+ plus(duration) {
1392
+ if (!this.isValid) return this;
1393
+ const dur = friendlyDuration(duration);
1394
+ return clone(this, adjustTime(this, dur));
1395
+ }
1396
+
1397
+ /**
1398
+ * Subtract a period of time to this DateTime and return the resulting DateTime
1399
+ * See {@link plus}
1400
+ * @param {Duration|Object|number} duration - The amount to subtract. Either a Luxon Duration, a number of milliseconds, the object argument to Duration.fromObject()
1401
+ @return {DateTime}
1402
+ */
1403
+ minus(duration) {
1404
+ if (!this.isValid) return this;
1405
+ const dur = friendlyDuration(duration).negate();
1406
+ return clone(this, adjustTime(this, dur));
1407
+ }
1408
+
1409
+ /**
1410
+ * "Set" this DateTime to the beginning of a unit of time.
1411
+ * @param {string} unit - The unit to go to the beginning of. Can be 'year', 'quarter', 'month', 'week', 'day', 'hour', 'minute', 'second', or 'millisecond'.
1412
+ * @example DateTime.local(2014, 3, 3).startOf('month').toISODate(); //=> '2014-03-01'
1413
+ * @example DateTime.local(2014, 3, 3).startOf('year').toISODate(); //=> '2014-01-01'
1414
+ * @example DateTime.local(2014, 3, 3).startOf('week').toISODate(); //=> '2014-03-03', weeks always start on Mondays
1415
+ * @example DateTime.local(2014, 3, 3, 5, 30).startOf('day').toISOTime(); //=> '00:00.000-05:00'
1416
+ * @example DateTime.local(2014, 3, 3, 5, 30).startOf('hour').toISOTime(); //=> '05:00:00.000-05:00'
1417
+ * @return {DateTime}
1418
+ */
1419
+ startOf(unit) {
1420
+ if (!this.isValid) return this;
1421
+ const o = {},
1422
+ normalizedUnit = Duration.normalizeUnit(unit);
1423
+ switch (normalizedUnit) {
1424
+ case "years":
1425
+ o.month = 1;
1426
+ // falls through
1427
+ case "quarters":
1428
+ case "months":
1429
+ o.day = 1;
1430
+ // falls through
1431
+ case "weeks":
1432
+ case "days":
1433
+ o.hour = 0;
1434
+ // falls through
1435
+ case "hours":
1436
+ o.minute = 0;
1437
+ // falls through
1438
+ case "minutes":
1439
+ o.second = 0;
1440
+ // falls through
1441
+ case "seconds":
1442
+ o.millisecond = 0;
1443
+ break;
1444
+ case "milliseconds":
1445
+ break;
1446
+ // no default, invalid units throw in normalizeUnit()
1447
+ }
1448
+
1449
+ if (normalizedUnit === "weeks") {
1450
+ o.weekday = 1;
1451
+ }
1452
+
1453
+ if (normalizedUnit === "quarters") {
1454
+ const q = Math.ceil(this.month / 3);
1455
+ o.month = (q - 1) * 3 + 1;
1456
+ }
1457
+
1458
+ return this.set(o);
1459
+ }
1460
+
1461
+ /**
1462
+ * "Set" this DateTime to the end (meaning the last millisecond) of a unit of time
1463
+ * @param {string} unit - The unit to go to the end of. Can be 'year', 'quarter', 'month', 'week', 'day', 'hour', 'minute', 'second', or 'millisecond'.
1464
+ * @example DateTime.local(2014, 3, 3).endOf('month').toISO(); //=> '2014-03-31T23:59:59.999-05:00'
1465
+ * @example DateTime.local(2014, 3, 3).endOf('year').toISO(); //=> '2014-12-31T23:59:59.999-05:00'
1466
+ * @example DateTime.local(2014, 3, 3).endOf('week').toISO(); // => '2014-03-09T23:59:59.999-05:00', weeks start on Mondays
1467
+ * @example DateTime.local(2014, 3, 3, 5, 30).endOf('day').toISO(); //=> '2014-03-03T23:59:59.999-05:00'
1468
+ * @example DateTime.local(2014, 3, 3, 5, 30).endOf('hour').toISO(); //=> '2014-03-03T05:59:59.999-05:00'
1469
+ * @return {DateTime}
1470
+ */
1471
+ endOf(unit) {
1472
+ return this.isValid
1473
+ ? this.plus({ [unit]: 1 })
1474
+ .startOf(unit)
1475
+ .minus(1)
1476
+ : this;
1477
+ }
1478
+
1479
+ // OUTPUT
1480
+
1481
+ /**
1482
+ * Returns a string representation of this DateTime formatted according to the specified format string.
1483
+ * **You may not want this.** See {@link toLocaleString} for a more flexible formatting tool. For a table of tokens and their interpretations, see [here](https://moment.github.io/luxon/docs/manual/formatting.html#table-of-tokens).
1484
+ * Defaults to en-US if no locale has been specified, regardless of the system's locale.
1485
+ * @see https://moment.github.io/luxon/docs/manual/formatting.html#table-of-tokens
1486
+ * @param {string} fmt - the format string
1487
+ * @param {Object} opts - opts to override the configuration options
1488
+ * @example DateTime.now().toFormat('yyyy LLL dd') //=> '2017 Apr 22'
1489
+ * @example DateTime.now().setLocale('fr').toFormat('yyyy LLL dd') //=> '2017 avr. 22'
1490
+ * @example DateTime.now().toFormat('yyyy LLL dd', { locale: "fr" }) //=> '2017 avr. 22'
1491
+ * @example DateTime.now().toFormat("HH 'hours and' mm 'minutes'") //=> '20 hours and 55 minutes'
1492
+ * @return {string}
1493
+ */
1494
+ toFormat(fmt, opts = {}) {
1495
+ return this.isValid
1496
+ ? Formatter.create(this.loc.redefaultToEN(opts)).formatDateTimeFromString(this, fmt)
1497
+ : INVALID;
1498
+ }
1499
+
1500
+ /**
1501
+ * Returns a localized string representing this date. Accepts the same options as the Intl.DateTimeFormat constructor and any presets defined by Luxon, such as `DateTime.DATE_FULL` or `DateTime.TIME_SIMPLE`.
1502
+ * The exact behavior of this method is browser-specific, but in general it will return an appropriate representation
1503
+ * of the DateTime in the assigned locale.
1504
+ * Defaults to the system's locale if no locale has been specified
1505
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat
1506
+ * @param opts {Object} - Intl.DateTimeFormat constructor options and configuration options
1507
+ * @example DateTime.now().toLocaleString(); //=> 4/20/2017
1508
+ * @example DateTime.now().setLocale('en-gb').toLocaleString(); //=> '20/04/2017'
1509
+ * @example DateTime.now().toLocaleString({ locale: 'en-gb' }); //=> '20/04/2017'
1510
+ * @example DateTime.now().toLocaleString(DateTime.DATE_FULL); //=> 'April 20, 2017'
1511
+ * @example DateTime.now().toLocaleString(DateTime.TIME_SIMPLE); //=> '11:32 AM'
1512
+ * @example DateTime.now().toLocaleString(DateTime.DATETIME_SHORT); //=> '4/20/2017, 11:32 AM'
1513
+ * @example DateTime.now().toLocaleString({ weekday: 'long', month: 'long', day: '2-digit' }); //=> 'Thursday, April 20'
1514
+ * @example DateTime.now().toLocaleString({ weekday: 'short', month: 'short', day: '2-digit', hour: '2-digit', minute: '2-digit' }); //=> 'Thu, Apr 20, 11:27 AM'
1515
+ * @example DateTime.now().toLocaleString({ hour: '2-digit', minute: '2-digit', hour12: false }); //=> '11:32'
1516
+ * @return {string}
1517
+ */
1518
+ toLocaleString(opts = Formats.DATE_SHORT) {
1519
+ return this.isValid
1520
+ ? Formatter.create(this.loc.clone(opts), opts).formatDateTime(this)
1521
+ : INVALID;
1522
+ }
1523
+
1524
+ /**
1525
+ * Returns an array of format "parts", meaning individual tokens along with metadata. This is allows callers to post-process individual sections of the formatted output.
1526
+ * Defaults to the system's locale if no locale has been specified
1527
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/formatToParts
1528
+ * @param opts {Object} - Intl.DateTimeFormat constructor options, same as `toLocaleString`.
1529
+ * @example DateTime.now().toLocaleParts(); //=> [
1530
+ * //=> { type: 'day', value: '25' },
1531
+ * //=> { type: 'literal', value: '/' },
1532
+ * //=> { type: 'month', value: '05' },
1533
+ * //=> { type: 'literal', value: '/' },
1534
+ * //=> { type: 'year', value: '1982' }
1535
+ * //=> ]
1536
+ */
1537
+ toLocaleParts(opts = {}) {
1538
+ return this.isValid
1539
+ ? Formatter.create(this.loc.clone(opts), opts).formatDateTimeParts(this)
1540
+ : [];
1541
+ }
1542
+
1543
+ /**
1544
+ * Returns an ISO 8601-compliant string representation of this DateTime
1545
+ * @param {Object} opts - options
1546
+ * @param {boolean} [opts.suppressMilliseconds=false] - exclude milliseconds from the format if they're 0
1547
+ * @param {boolean} [opts.suppressSeconds=false] - exclude seconds from the format if they're 0
1548
+ * @param {boolean} [opts.includeOffset=true] - include the offset, such as 'Z' or '-04:00'
1549
+ * @param {string} [opts.format='extended'] - choose between the basic and extended format
1550
+ * @example DateTime.utc(1982, 5, 25).toISO() //=> '1982-05-25T00:00:00.000Z'
1551
+ * @example DateTime.now().toISO() //=> '2017-04-22T20:47:05.335-04:00'
1552
+ * @example DateTime.now().toISO({ includeOffset: false }) //=> '2017-04-22T20:47:05.335'
1553
+ * @example DateTime.now().toISO({ format: 'basic' }) //=> '20170422T204705.335-0400'
1554
+ * @return {string}
1555
+ */
1556
+ toISO(opts = {}) {
1557
+ if (!this.isValid) {
1558
+ return null;
1559
+ }
1560
+
1561
+ return `${this.toISODate(opts)}T${this.toISOTime(opts)}`;
1562
+ }
1563
+
1564
+ /**
1565
+ * Returns an ISO 8601-compliant string representation of this DateTime's date component
1566
+ * @param {Object} opts - options
1567
+ * @param {string} [opts.format='extended'] - choose between the basic and extended format
1568
+ * @example DateTime.utc(1982, 5, 25).toISODate() //=> '1982-05-25'
1569
+ * @example DateTime.utc(1982, 5, 25).toISODate({ format: 'basic' }) //=> '19820525'
1570
+ * @return {string}
1571
+ */
1572
+ toISODate({ format = "extended" } = {}) {
1573
+ let fmt = format === "basic" ? "yyyyMMdd" : "yyyy-MM-dd";
1574
+ if (this.year > 9999) {
1575
+ fmt = "+" + fmt;
1576
+ }
1577
+
1578
+ return toTechFormat(this, fmt);
1579
+ }
1580
+
1581
+ /**
1582
+ * Returns an ISO 8601-compliant string representation of this DateTime's week date
1583
+ * @example DateTime.utc(1982, 5, 25).toISOWeekDate() //=> '1982-W21-2'
1584
+ * @return {string}
1585
+ */
1586
+ toISOWeekDate() {
1587
+ return toTechFormat(this, "kkkk-'W'WW-c");
1588
+ }
1589
+
1590
+ /**
1591
+ * Returns an ISO 8601-compliant string representation of this DateTime's time component
1592
+ * @param {Object} opts - options
1593
+ * @param {boolean} [opts.suppressMilliseconds=false] - exclude milliseconds from the format if they're 0
1594
+ * @param {boolean} [opts.suppressSeconds=false] - exclude seconds from the format if they're 0
1595
+ * @param {boolean} [opts.includeOffset=true] - include the offset, such as 'Z' or '-04:00'
1596
+ * @param {boolean} [opts.includePrefix=false] - include the `T` prefix
1597
+ * @param {string} [opts.format='extended'] - choose between the basic and extended format
1598
+ * @example DateTime.utc().set({ hour: 7, minute: 34 }).toISOTime() //=> '07:34:19.361Z'
1599
+ * @example DateTime.utc().set({ hour: 7, minute: 34, seconds: 0, milliseconds: 0 }).toISOTime({ suppressSeconds: true }) //=> '07:34Z'
1600
+ * @example DateTime.utc().set({ hour: 7, minute: 34 }).toISOTime({ format: 'basic' }) //=> '073419.361Z'
1601
+ * @example DateTime.utc().set({ hour: 7, minute: 34 }).toISOTime({ includePrefix: true }) //=> 'T07:34:19.361Z'
1602
+ * @return {string}
1603
+ */
1604
+ toISOTime({
1605
+ suppressMilliseconds = false,
1606
+ suppressSeconds = false,
1607
+ includeOffset = true,
1608
+ includePrefix = false,
1609
+ format = "extended"
1610
+ } = {}) {
1611
+ return toTechTimeFormat(this, {
1612
+ suppressSeconds,
1613
+ suppressMilliseconds,
1614
+ includeOffset,
1615
+ includePrefix,
1616
+ format
1617
+ });
1618
+ }
1619
+
1620
+ /**
1621
+ * Returns an RFC 2822-compatible string representation of this DateTime, always in UTC
1622
+ * @example DateTime.utc(2014, 7, 13).toRFC2822() //=> 'Sun, 13 Jul 2014 00:00:00 +0000'
1623
+ * @example DateTime.local(2014, 7, 13).toRFC2822() //=> 'Sun, 13 Jul 2014 00:00:00 -0400'
1624
+ * @return {string}
1625
+ */
1626
+ toRFC2822() {
1627
+ return toTechFormat(this, "EEE, dd LLL yyyy HH:mm:ss ZZZ", false);
1628
+ }
1629
+
1630
+ /**
1631
+ * Returns a string representation of this DateTime appropriate for use in HTTP headers.
1632
+ * Specifically, the string conforms to RFC 1123.
1633
+ * @see https://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1
1634
+ * @example DateTime.utc(2014, 7, 13).toHTTP() //=> 'Sun, 13 Jul 2014 00:00:00 GMT'
1635
+ * @example DateTime.utc(2014, 7, 13, 19).toHTTP() //=> 'Sun, 13 Jul 2014 19:00:00 GMT'
1636
+ * @return {string}
1637
+ */
1638
+ toHTTP() {
1639
+ return toTechFormat(this.toUTC(), "EEE, dd LLL yyyy HH:mm:ss 'GMT'");
1640
+ }
1641
+
1642
+ /**
1643
+ * Returns a string representation of this DateTime appropriate for use in SQL Date
1644
+ * @example DateTime.utc(2014, 7, 13).toSQLDate() //=> '2014-07-13'
1645
+ * @return {string}
1646
+ */
1647
+ toSQLDate() {
1648
+ return toTechFormat(this, "yyyy-MM-dd");
1649
+ }
1650
+
1651
+ /**
1652
+ * Returns a string representation of this DateTime appropriate for use in SQL Time
1653
+ * @param {Object} opts - options
1654
+ * @param {boolean} [opts.includeZone=false] - include the zone, such as 'America/New_York'. Overrides includeOffset.
1655
+ * @param {boolean} [opts.includeOffset=true] - include the offset, such as 'Z' or '-04:00'
1656
+ * @example DateTime.utc().toSQL() //=> '05:15:16.345'
1657
+ * @example DateTime.now().toSQL() //=> '05:15:16.345 -04:00'
1658
+ * @example DateTime.now().toSQL({ includeOffset: false }) //=> '05:15:16.345'
1659
+ * @example DateTime.now().toSQL({ includeZone: false }) //=> '05:15:16.345 America/New_York'
1660
+ * @return {string}
1661
+ */
1662
+ toSQLTime({ includeOffset = true, includeZone = false } = {}) {
1663
+ return toTechTimeFormat(this, {
1664
+ includeOffset,
1665
+ includeZone,
1666
+ spaceZone: true
1667
+ });
1668
+ }
1669
+
1670
+ /**
1671
+ * Returns a string representation of this DateTime appropriate for use in SQL DateTime
1672
+ * @param {Object} opts - options
1673
+ * @param {boolean} [opts.includeZone=false] - include the zone, such as 'America/New_York'. Overrides includeOffset.
1674
+ * @param {boolean} [opts.includeOffset=true] - include the offset, such as 'Z' or '-04:00'
1675
+ * @example DateTime.utc(2014, 7, 13).toSQL() //=> '2014-07-13 00:00:00.000 Z'
1676
+ * @example DateTime.local(2014, 7, 13).toSQL() //=> '2014-07-13 00:00:00.000 -04:00'
1677
+ * @example DateTime.local(2014, 7, 13).toSQL({ includeOffset: false }) //=> '2014-07-13 00:00:00.000'
1678
+ * @example DateTime.local(2014, 7, 13).toSQL({ includeZone: true }) //=> '2014-07-13 00:00:00.000 America/New_York'
1679
+ * @return {string}
1680
+ */
1681
+ toSQL(opts = {}) {
1682
+ if (!this.isValid) {
1683
+ return null;
1684
+ }
1685
+
1686
+ return `${this.toSQLDate()} ${this.toSQLTime(opts)}`;
1687
+ }
1688
+
1689
+ /**
1690
+ * Returns a string representation of this DateTime appropriate for debugging
1691
+ * @return {string}
1692
+ */
1693
+ toString() {
1694
+ return this.isValid ? this.toISO() : INVALID;
1695
+ }
1696
+
1697
+ /**
1698
+ * Returns the epoch milliseconds of this DateTime. Alias of {@link toMillis}
1699
+ * @return {number}
1700
+ */
1701
+ valueOf() {
1702
+ return this.toMillis();
1703
+ }
1704
+
1705
+ /**
1706
+ * Returns the epoch milliseconds of this DateTime.
1707
+ * @return {number}
1708
+ */
1709
+ toMillis() {
1710
+ return this.isValid ? this.ts : NaN;
1711
+ }
1712
+
1713
+ /**
1714
+ * Returns the epoch seconds of this DateTime.
1715
+ * @return {number}
1716
+ */
1717
+ toSeconds() {
1718
+ return this.isValid ? this.ts / 1000 : NaN;
1719
+ }
1720
+
1721
+ /**
1722
+ * Returns an ISO 8601 representation of this DateTime appropriate for use in JSON.
1723
+ * @return {string}
1724
+ */
1725
+ toJSON() {
1726
+ return this.toISO();
1727
+ }
1728
+
1729
+ /**
1730
+ * Returns a BSON serializable equivalent to this DateTime.
1731
+ * @return {Date}
1732
+ */
1733
+ toBSON() {
1734
+ return this.toJSDate();
1735
+ }
1736
+
1737
+ /**
1738
+ * Returns a JavaScript object with this DateTime's year, month, day, and so on.
1739
+ * @param opts - options for generating the object
1740
+ * @param {boolean} [opts.includeConfig=false] - include configuration attributes in the output
1741
+ * @example DateTime.now().toObject() //=> { year: 2017, month: 4, day: 22, hour: 20, minute: 49, second: 42, millisecond: 268 }
1742
+ * @return {Object}
1743
+ */
1744
+ toObject(opts = {}) {
1745
+ if (!this.isValid) return {};
1746
+
1747
+ const base = Object.assign({}, this.c);
1748
+
1749
+ if (opts.includeConfig) {
1750
+ base.outputCalendar = this.outputCalendar;
1751
+ base.numberingSystem = this.loc.numberingSystem;
1752
+ base.locale = this.loc.locale;
1753
+ }
1754
+ return base;
1755
+ }
1756
+
1757
+ /**
1758
+ * Returns a JavaScript Date equivalent to this DateTime.
1759
+ * @return {Date}
1760
+ */
1761
+ toJSDate() {
1762
+ return new Date(this.isValid ? this.ts : NaN);
1763
+ }
1764
+
1765
+ // COMPARE
1766
+
1767
+ /**
1768
+ * Return the difference between two DateTimes as a Duration.
1769
+ * @param {DateTime} otherDateTime - the DateTime to compare this one to
1770
+ * @param {string|string[]} [unit=['milliseconds']] - the unit or array of units (such as 'hours' or 'days') to include in the duration.
1771
+ * @param {Object} opts - options that affect the creation of the Duration
1772
+ * @param {string} [opts.conversionAccuracy='casual'] - the conversion system to use
1773
+ * @example
1774
+ * var i1 = DateTime.fromISO('1982-05-25T09:45'),
1775
+ * i2 = DateTime.fromISO('1983-10-14T10:30');
1776
+ * i2.diff(i1).toObject() //=> { milliseconds: 43807500000 }
1777
+ * i2.diff(i1, 'hours').toObject() //=> { hours: 12168.75 }
1778
+ * i2.diff(i1, ['months', 'days']).toObject() //=> { months: 16, days: 19.03125 }
1779
+ * i2.diff(i1, ['months', 'days', 'hours']).toObject() //=> { months: 16, days: 19, hours: 0.75 }
1780
+ * @return {Duration}
1781
+ */
1782
+ diff(otherDateTime, unit = "milliseconds", opts = {}) {
1783
+ if (!this.isValid || !otherDateTime.isValid) {
1784
+ return Duration.invalid(
1785
+ this.invalid || otherDateTime.invalid,
1786
+ "created by diffing an invalid DateTime"
1787
+ );
1788
+ }
1789
+
1790
+ const durOpts = Object.assign(
1791
+ { locale: this.locale, numberingSystem: this.numberingSystem },
1792
+ opts
1793
+ );
1794
+
1795
+ const units = maybeArray(unit).map(Duration.normalizeUnit),
1796
+ otherIsLater = otherDateTime.valueOf() > this.valueOf(),
1797
+ earlier = otherIsLater ? this : otherDateTime,
1798
+ later = otherIsLater ? otherDateTime : this,
1799
+ diffed = diff(earlier, later, units, durOpts);
1800
+
1801
+ return otherIsLater ? diffed.negate() : diffed;
1802
+ }
1803
+
1804
+ /**
1805
+ * Return the difference between this DateTime and right now.
1806
+ * See {@link diff}
1807
+ * @param {string|string[]} [unit=['milliseconds']] - the unit or units units (such as 'hours' or 'days') to include in the duration
1808
+ * @param {Object} opts - options that affect the creation of the Duration
1809
+ * @param {string} [opts.conversionAccuracy='casual'] - the conversion system to use
1810
+ * @return {Duration}
1811
+ */
1812
+ diffNow(unit = "milliseconds", opts = {}) {
1813
+ return this.diff(DateTime.now(), unit, opts);
1814
+ }
1815
+
1816
+ /**
1817
+ * Return an Interval spanning between this DateTime and another DateTime
1818
+ * @param {DateTime} otherDateTime - the other end point of the Interval
1819
+ * @return {Interval}
1820
+ */
1821
+ until(otherDateTime) {
1822
+ return this.isValid ? Interval.fromDateTimes(this, otherDateTime) : this;
1823
+ }
1824
+
1825
+ /**
1826
+ * Return whether this DateTime is in the same unit of time as another DateTime.
1827
+ * Higher-order units must also be identical for this function to return `true`.
1828
+ * Note that time zones are **ignored** in this comparison, which compares the **local** calendar time. Use {@link setZone} to convert one of the dates if needed.
1829
+ * @param {DateTime} otherDateTime - the other DateTime
1830
+ * @param {string} unit - the unit of time to check sameness on
1831
+ * @example DateTime.now().hasSame(otherDT, 'day'); //~> true if otherDT is in the same current calendar day
1832
+ * @return {boolean}
1833
+ */
1834
+ hasSame(otherDateTime, unit) {
1835
+ if (!this.isValid) return false;
1836
+
1837
+ const inputMs = otherDateTime.valueOf();
1838
+ const otherZoneDateTime = this.setZone(otherDateTime.zone, { keepLocalTime: true });
1839
+ return otherZoneDateTime.startOf(unit) <= inputMs && inputMs <= otherZoneDateTime.endOf(unit);
1840
+ }
1841
+
1842
+ /**
1843
+ * Equality check
1844
+ * Two DateTimes are equal iff they represent the same millisecond, have the same zone and location, and are both valid.
1845
+ * To compare just the millisecond values, use `+dt1 === +dt2`.
1846
+ * @param {DateTime} other - the other DateTime
1847
+ * @return {boolean}
1848
+ */
1849
+ equals(other) {
1850
+ return (
1851
+ this.isValid &&
1852
+ other.isValid &&
1853
+ this.valueOf() === other.valueOf() &&
1854
+ this.zone.equals(other.zone) &&
1855
+ this.loc.equals(other.loc)
1856
+ );
1857
+ }
1858
+
1859
+ /**
1860
+ * Returns a string representation of a this time relative to now, such as "in two days". Can only internationalize if your
1861
+ * platform supports Intl.RelativeTimeFormat. Rounds down by default.
1862
+ * @param {Object} options - options that affect the output
1863
+ * @param {DateTime} [options.base=DateTime.now()] - the DateTime to use as the basis to which this time is compared. Defaults to now.
1864
+ * @param {string} [options.style="long"] - the style of units, must be "long", "short", or "narrow"
1865
+ * @param {string|string[]} options.unit - use a specific unit or array of units; if omitted, or an array, the method will pick the best unit. Use an array or one of "years", "quarters", "months", "weeks", "days", "hours", "minutes", or "seconds"
1866
+ * @param {boolean} [options.round=true] - whether to round the numbers in the output.
1867
+ * @param {number} [options.padding=0] - padding in milliseconds. This allows you to round up the result if it fits inside the threshold. Don't use in combination with {round: false} because the decimal output will include the padding.
1868
+ * @param {string} options.locale - override the locale of this DateTime
1869
+ * @param {string} options.numberingSystem - override the numberingSystem of this DateTime. The Intl system may choose not to honor this
1870
+ * @example DateTime.now().plus({ days: 1 }).toRelative() //=> "in 1 day"
1871
+ * @example DateTime.now().setLocale("es").toRelative({ days: 1 }) //=> "dentro de 1 día"
1872
+ * @example DateTime.now().plus({ days: 1 }).toRelative({ locale: "fr" }) //=> "dans 23 heures"
1873
+ * @example DateTime.now().minus({ days: 2 }).toRelative() //=> "2 days ago"
1874
+ * @example DateTime.now().minus({ days: 2 }).toRelative({ unit: "hours" }) //=> "48 hours ago"
1875
+ * @example DateTime.now().minus({ hours: 36 }).toRelative({ round: false }) //=> "1.5 days ago"
1876
+ */
1877
+ toRelative(options = {}) {
1878
+ if (!this.isValid) return null;
1879
+ const base = options.base || DateTime.fromObject({ zone: this.zone }),
1880
+ padding = options.padding ? (this < base ? -options.padding : options.padding) : 0;
1881
+ let units = ["years", "months", "days", "hours", "minutes", "seconds"];
1882
+ let unit = options.unit;
1883
+ if (Array.isArray(options.unit)) {
1884
+ units = options.unit;
1885
+ unit = undefined;
1886
+ }
1887
+ return diffRelative(
1888
+ base,
1889
+ this.plus(padding),
1890
+ Object.assign(options, {
1891
+ numeric: "always",
1892
+ units,
1893
+ unit
1894
+ })
1895
+ );
1896
+ }
1897
+
1898
+ /**
1899
+ * Returns a string representation of this date relative to today, such as "yesterday" or "next month".
1900
+ * Only internationalizes on platforms that supports Intl.RelativeTimeFormat.
1901
+ * @param {Object} options - options that affect the output
1902
+ * @param {DateTime} [options.base=DateTime.now()] - the DateTime to use as the basis to which this time is compared. Defaults to now.
1903
+ * @param {string} options.locale - override the locale of this DateTime
1904
+ * @param {string} options.unit - use a specific unit; if omitted, the method will pick the unit. Use one of "years", "quarters", "months", "weeks", or "days"
1905
+ * @param {string} options.numberingSystem - override the numberingSystem of this DateTime. The Intl system may choose not to honor this
1906
+ * @example DateTime.now().plus({ days: 1 }).toRelativeCalendar() //=> "tomorrow"
1907
+ * @example DateTime.now().setLocale("es").plus({ days: 1 }).toRelative() //=> ""mañana"
1908
+ * @example DateTime.now().plus({ days: 1 }).toRelativeCalendar({ locale: "fr" }) //=> "demain"
1909
+ * @example DateTime.now().minus({ days: 2 }).toRelativeCalendar() //=> "2 days ago"
1910
+ */
1911
+ toRelativeCalendar(options = {}) {
1912
+ if (!this.isValid) return null;
1913
+
1914
+ return diffRelative(
1915
+ options.base || DateTime.fromObject({ zone: this.zone }),
1916
+ this,
1917
+ Object.assign(options, {
1918
+ numeric: "auto",
1919
+ units: ["years", "months", "days"],
1920
+ calendary: true
1921
+ })
1922
+ );
1923
+ }
1924
+
1925
+ /**
1926
+ * Return the min of several date times
1927
+ * @param {...DateTime} dateTimes - the DateTimes from which to choose the minimum
1928
+ * @return {DateTime} the min DateTime, or undefined if called with no argument
1929
+ */
1930
+ static min(...dateTimes) {
1931
+ if (!dateTimes.every(DateTime.isDateTime)) {
1932
+ throw new InvalidArgumentError("min requires all arguments be DateTimes");
1933
+ }
1934
+ return bestBy(dateTimes, i => i.valueOf(), Math.min);
1935
+ }
1936
+
1937
+ /**
1938
+ * Return the max of several date times
1939
+ * @param {...DateTime} dateTimes - the DateTimes from which to choose the maximum
1940
+ * @return {DateTime} the max DateTime, or undefined if called with no argument
1941
+ */
1942
+ static max(...dateTimes) {
1943
+ if (!dateTimes.every(DateTime.isDateTime)) {
1944
+ throw new InvalidArgumentError("max requires all arguments be DateTimes");
1945
+ }
1946
+ return bestBy(dateTimes, i => i.valueOf(), Math.max);
1947
+ }
1948
+
1949
+ // MISC
1950
+
1951
+ /**
1952
+ * Explain how a string would be parsed by fromFormat()
1953
+ * @param {string} text - the string to parse
1954
+ * @param {string} fmt - the format the string is expected to be in (see description)
1955
+ * @param {Object} options - options taken by fromFormat()
1956
+ * @return {Object}
1957
+ */
1958
+ static fromFormatExplain(text, fmt, options = {}) {
1959
+ const { locale = null, numberingSystem = null } = options,
1960
+ localeToUse = Locale.fromOpts({
1961
+ locale,
1962
+ numberingSystem,
1963
+ defaultToEN: true
1964
+ });
1965
+ return explainFromTokens(localeToUse, text, fmt);
1966
+ }
1967
+
1968
+ /**
1969
+ * @deprecated use fromFormatExplain instead
1970
+ */
1971
+ static fromStringExplain(text, fmt, options = {}) {
1972
+ return DateTime.fromFormatExplain(text, fmt, options);
1973
+ }
1974
+
1975
+ // FORMAT PRESETS
1976
+
1977
+ /**
1978
+ * {@link toLocaleString} format like 10/14/1983
1979
+ * @type {Object}
1980
+ */
1981
+ static get DATE_SHORT() {
1982
+ return Formats.DATE_SHORT;
1983
+ }
1984
+
1985
+ /**
1986
+ * {@link toLocaleString} format like 'Oct 14, 1983'
1987
+ * @type {Object}
1988
+ */
1989
+ static get DATE_MED() {
1990
+ return Formats.DATE_MED;
1991
+ }
1992
+
1993
+ /**
1994
+ * {@link toLocaleString} format like 'Fri, Oct 14, 1983'
1995
+ * @type {Object}
1996
+ */
1997
+ static get DATE_MED_WITH_WEEKDAY() {
1998
+ return Formats.DATE_MED_WITH_WEEKDAY;
1999
+ }
2000
+
2001
+ /**
2002
+ * {@link toLocaleString} format like 'October 14, 1983'
2003
+ * @type {Object}
2004
+ */
2005
+ static get DATE_FULL() {
2006
+ return Formats.DATE_FULL;
2007
+ }
2008
+
2009
+ /**
2010
+ * {@link toLocaleString} format like 'Tuesday, October 14, 1983'
2011
+ * @type {Object}
2012
+ */
2013
+ static get DATE_HUGE() {
2014
+ return Formats.DATE_HUGE;
2015
+ }
2016
+
2017
+ /**
2018
+ * {@link toLocaleString} format like '09:30 AM'. Only 12-hour if the locale is.
2019
+ * @type {Object}
2020
+ */
2021
+ static get TIME_SIMPLE() {
2022
+ return Formats.TIME_SIMPLE;
2023
+ }
2024
+
2025
+ /**
2026
+ * {@link toLocaleString} format like '09:30:23 AM'. Only 12-hour if the locale is.
2027
+ * @type {Object}
2028
+ */
2029
+ static get TIME_WITH_SECONDS() {
2030
+ return Formats.TIME_WITH_SECONDS;
2031
+ }
2032
+
2033
+ /**
2034
+ * {@link toLocaleString} format like '09:30:23 AM EDT'. Only 12-hour if the locale is.
2035
+ * @type {Object}
2036
+ */
2037
+ static get TIME_WITH_SHORT_OFFSET() {
2038
+ return Formats.TIME_WITH_SHORT_OFFSET;
2039
+ }
2040
+
2041
+ /**
2042
+ * {@link toLocaleString} format like '09:30:23 AM Eastern Daylight Time'. Only 12-hour if the locale is.
2043
+ * @type {Object}
2044
+ */
2045
+ static get TIME_WITH_LONG_OFFSET() {
2046
+ return Formats.TIME_WITH_LONG_OFFSET;
2047
+ }
2048
+
2049
+ /**
2050
+ * {@link toLocaleString} format like '09:30', always 24-hour.
2051
+ * @type {Object}
2052
+ */
2053
+ static get TIME_24_SIMPLE() {
2054
+ return Formats.TIME_24_SIMPLE;
2055
+ }
2056
+
2057
+ /**
2058
+ * {@link toLocaleString} format like '09:30:23', always 24-hour.
2059
+ * @type {Object}
2060
+ */
2061
+ static get TIME_24_WITH_SECONDS() {
2062
+ return Formats.TIME_24_WITH_SECONDS;
2063
+ }
2064
+
2065
+ /**
2066
+ * {@link toLocaleString} format like '09:30:23 EDT', always 24-hour.
2067
+ * @type {Object}
2068
+ */
2069
+ static get TIME_24_WITH_SHORT_OFFSET() {
2070
+ return Formats.TIME_24_WITH_SHORT_OFFSET;
2071
+ }
2072
+
2073
+ /**
2074
+ * {@link toLocaleString} format like '09:30:23 Eastern Daylight Time', always 24-hour.
2075
+ * @type {Object}
2076
+ */
2077
+ static get TIME_24_WITH_LONG_OFFSET() {
2078
+ return Formats.TIME_24_WITH_LONG_OFFSET;
2079
+ }
2080
+
2081
+ /**
2082
+ * {@link toLocaleString} format like '10/14/1983, 9:30 AM'. Only 12-hour if the locale is.
2083
+ * @type {Object}
2084
+ */
2085
+ static get DATETIME_SHORT() {
2086
+ return Formats.DATETIME_SHORT;
2087
+ }
2088
+
2089
+ /**
2090
+ * {@link toLocaleString} format like '10/14/1983, 9:30:33 AM'. Only 12-hour if the locale is.
2091
+ * @type {Object}
2092
+ */
2093
+ static get DATETIME_SHORT_WITH_SECONDS() {
2094
+ return Formats.DATETIME_SHORT_WITH_SECONDS;
2095
+ }
2096
+
2097
+ /**
2098
+ * {@link toLocaleString} format like 'Oct 14, 1983, 9:30 AM'. Only 12-hour if the locale is.
2099
+ * @type {Object}
2100
+ */
2101
+ static get DATETIME_MED() {
2102
+ return Formats.DATETIME_MED;
2103
+ }
2104
+
2105
+ /**
2106
+ * {@link toLocaleString} format like 'Oct 14, 1983, 9:30:33 AM'. Only 12-hour if the locale is.
2107
+ * @type {Object}
2108
+ */
2109
+ static get DATETIME_MED_WITH_SECONDS() {
2110
+ return Formats.DATETIME_MED_WITH_SECONDS;
2111
+ }
2112
+
2113
+ /**
2114
+ * {@link toLocaleString} format like 'Fri, 14 Oct 1983, 9:30 AM'. Only 12-hour if the locale is.
2115
+ * @type {Object}
2116
+ */
2117
+ static get DATETIME_MED_WITH_WEEKDAY() {
2118
+ return Formats.DATETIME_MED_WITH_WEEKDAY;
2119
+ }
2120
+
2121
+ /**
2122
+ * {@link toLocaleString} format like 'October 14, 1983, 9:30 AM EDT'. Only 12-hour if the locale is.
2123
+ * @type {Object}
2124
+ */
2125
+ static get DATETIME_FULL() {
2126
+ return Formats.DATETIME_FULL;
2127
+ }
2128
+
2129
+ /**
2130
+ * {@link toLocaleString} format like 'October 14, 1983, 9:30:33 AM EDT'. Only 12-hour if the locale is.
2131
+ * @type {Object}
2132
+ */
2133
+ static get DATETIME_FULL_WITH_SECONDS() {
2134
+ return Formats.DATETIME_FULL_WITH_SECONDS;
2135
+ }
2136
+
2137
+ /**
2138
+ * {@link toLocaleString} format like 'Friday, October 14, 1983, 9:30 AM Eastern Daylight Time'. Only 12-hour if the locale is.
2139
+ * @type {Object}
2140
+ */
2141
+ static get DATETIME_HUGE() {
2142
+ return Formats.DATETIME_HUGE;
2143
+ }
2144
+
2145
+ /**
2146
+ * {@link toLocaleString} format like 'Friday, October 14, 1983, 9:30:33 AM Eastern Daylight Time'. Only 12-hour if the locale is.
2147
+ * @type {Object}
2148
+ */
2149
+ static get DATETIME_HUGE_WITH_SECONDS() {
2150
+ return Formats.DATETIME_HUGE_WITH_SECONDS;
2151
+ }
2152
+ }
2153
+
2154
+ /**
2155
+ * @private
2156
+ */
2157
+ export function friendlyDateTime(dateTimeish) {
2158
+ if (DateTime.isDateTime(dateTimeish)) {
2159
+ return dateTimeish;
2160
+ } else if (dateTimeish && dateTimeish.valueOf && isNumber(dateTimeish.valueOf())) {
2161
+ return DateTime.fromJSDate(dateTimeish);
2162
+ } else if (dateTimeish && typeof dateTimeish === "object") {
2163
+ return DateTime.fromObject(dateTimeish);
2164
+ } else {
2165
+ throw new InvalidArgumentError(
2166
+ `Unknown datetime argument: ${dateTimeish}, of type ${typeof dateTimeish}`
2167
+ );
2168
+ }
2169
+ }