@attocash/cli 0.1.0

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 (400) hide show
  1. package/LICENSE +28 -0
  2. package/README.md +707 -0
  3. package/dist/application/app.d.ts +138 -0
  4. package/dist/application/app.js +654 -0
  5. package/dist/application/operations.d.ts +9 -0
  6. package/dist/application/operations.js +96 -0
  7. package/dist/cli/cli.d.ts +1 -0
  8. package/dist/cli/cli.js +460 -0
  9. package/dist/cli/help.d.ts +4 -0
  10. package/dist/cli/help.js +49 -0
  11. package/dist/cli/main.d.ts +2 -0
  12. package/dist/cli/main.js +13 -0
  13. package/dist/cli/onboarding.d.ts +14 -0
  14. package/dist/cli/onboarding.js +144 -0
  15. package/dist/cli/output.d.ts +2 -0
  16. package/dist/cli/output.js +231 -0
  17. package/dist/cli/terminal.d.ts +6 -0
  18. package/dist/cli/terminal.js +92 -0
  19. package/dist/cli/update-check.d.ts +1 -0
  20. package/dist/cli/update-check.js +12 -0
  21. package/dist/cli/updates.d.ts +2 -0
  22. package/dist/cli/updates.js +98 -0
  23. package/dist/core.d.ts +14 -0
  24. package/dist/core.js +14 -0
  25. package/dist/doctor/credential-probe.d.ts +7 -0
  26. package/dist/doctor/credential-probe.js +49 -0
  27. package/dist/doctor/doctor.d.ts +4 -0
  28. package/dist/doctor/doctor.js +213 -0
  29. package/dist/doctor/keyring.d.ts +7 -0
  30. package/dist/doctor/keyring.js +150 -0
  31. package/dist/doctor/profile.d.ts +19 -0
  32. package/dist/doctor/profile.js +73 -0
  33. package/dist/doctor/types.d.ts +40 -0
  34. package/dist/doctor/types.js +1 -0
  35. package/dist/domain/amount.d.ts +6 -0
  36. package/dist/domain/amount.js +27 -0
  37. package/dist/domain/errors.d.ts +10 -0
  38. package/dist/domain/errors.js +16 -0
  39. package/dist/labels/directory.d.ts +87 -0
  40. package/dist/labels/directory.js +140 -0
  41. package/dist/labels/personal.d.ts +17 -0
  42. package/dist/labels/personal.js +56 -0
  43. package/dist/labels/presentation.d.ts +154 -0
  44. package/dist/labels/presentation.js +90 -0
  45. package/dist/network/reader.d.ts +31 -0
  46. package/dist/network/reader.js +370 -0
  47. package/dist/network/retry.d.ts +7 -0
  48. package/dist/network/retry.js +53 -0
  49. package/dist/network/work.d.ts +3 -0
  50. package/dist/network/work.js +66 -0
  51. package/dist/pricing/market.d.ts +29 -0
  52. package/dist/pricing/market.js +150 -0
  53. package/dist/pricing/terms.d.ts +6 -0
  54. package/dist/pricing/terms.js +12 -0
  55. package/dist/spending/destination.d.ts +16 -0
  56. package/dist/spending/destination.js +42 -0
  57. package/dist/spending/journal.d.ts +28 -0
  58. package/dist/spending/journal.js +69 -0
  59. package/dist/spending/ledger.d.ts +118 -0
  60. package/dist/spending/ledger.js +444 -0
  61. package/dist/spending/payments.d.ts +67 -0
  62. package/dist/spending/payments.js +424 -0
  63. package/dist/spending/pool.d.ts +13 -0
  64. package/dist/spending/pool.js +38 -0
  65. package/dist/spending/reconcile.d.ts +18 -0
  66. package/dist/spending/reconcile.js +64 -0
  67. package/dist/storage/profiles.d.ts +13 -0
  68. package/dist/storage/profiles.js +86 -0
  69. package/dist/storage/secrets.d.ts +16 -0
  70. package/dist/storage/secrets.js +104 -0
  71. package/dist/storage/state.d.ts +32 -0
  72. package/dist/storage/state.js +255 -0
  73. package/dist/wallet/auto-receive.d.ts +57 -0
  74. package/dist/wallet/auto-receive.js +140 -0
  75. package/dist/wallet/defaults.d.ts +3 -0
  76. package/dist/wallet/defaults.js +26 -0
  77. package/dist/wallet/signing.d.ts +17 -0
  78. package/dist/wallet/signing.js +128 -0
  79. package/dist/wallet/types.d.ts +65 -0
  80. package/dist/wallet/types.js +1 -0
  81. package/dist/wallet/work.d.ts +29 -0
  82. package/dist/wallet/work.js +154 -0
  83. package/dist/watches/manager.d.ts +75 -0
  84. package/dist/watches/manager.js +197 -0
  85. package/node_modules/@attocash/commons-core/Kotlin-DateTime-library-kotlinx-datetime.mjs +6678 -0
  86. package/node_modules/@attocash/commons-core/Kotlin-DateTime-library-kotlinx-datetime.mjs.map +1 -0
  87. package/node_modules/@attocash/commons-core/LICENSE +28 -0
  88. package/node_modules/@attocash/commons-core/README.md +118 -0
  89. package/node_modules/@attocash/commons-core/commons-commons-core.d.mts +1036 -0
  90. package/node_modules/@attocash/commons-core/commons-commons-core.mjs +7701 -0
  91. package/node_modules/@attocash/commons-core/commons-commons-core.mjs.map +1 -0
  92. package/node_modules/@attocash/commons-core/kotlin-kotlin-stdlib.mjs +17681 -0
  93. package/node_modules/@attocash/commons-core/kotlin-kotlin-stdlib.mjs.map +1 -0
  94. package/node_modules/@attocash/commons-core/kotlin_org_jetbrains_kotlin_kotlin_dom_api_compat.mjs +4 -0
  95. package/node_modules/@attocash/commons-core/kotlin_org_jetbrains_kotlin_kotlin_dom_api_compat.mjs.map +1 -0
  96. package/node_modules/@attocash/commons-core/kotlinx-io-kotlinx-io-bytestring.mjs +209 -0
  97. package/node_modules/@attocash/commons-core/kotlinx-io-kotlinx-io-bytestring.mjs.map +1 -0
  98. package/node_modules/@attocash/commons-core/kotlinx-io-kotlinx-io-core.mjs +2284 -0
  99. package/node_modules/@attocash/commons-core/kotlinx-io-kotlinx-io-core.mjs.map +1 -0
  100. package/node_modules/@attocash/commons-core/kotlinx-serialization-kotlinx-serialization-core.mjs +6042 -0
  101. package/node_modules/@attocash/commons-core/kotlinx-serialization-kotlinx-serialization-core.mjs.map +1 -0
  102. package/node_modules/@attocash/commons-core/kotlinx-serialization-kotlinx-serialization-json.mjs +5294 -0
  103. package/node_modules/@attocash/commons-core/kotlinx-serialization-kotlinx-serialization-json.mjs.map +1 -0
  104. package/node_modules/@attocash/commons-core/package.json +27 -0
  105. package/node_modules/@attocash/commons-node/LICENSE +28 -0
  106. package/node_modules/@attocash/commons-node/README.md +92 -0
  107. package/node_modules/@attocash/commons-node/commons-commons-node.d.mts +255 -0
  108. package/node_modules/@attocash/commons-node/commons-commons-node.mjs +2977 -0
  109. package/node_modules/@attocash/commons-node/commons-commons-node.mjs.map +1 -0
  110. package/node_modules/@attocash/commons-node/kotlin-logging.mjs +432 -0
  111. package/node_modules/@attocash/commons-node/kotlin-logging.mjs.map +1 -0
  112. package/node_modules/@attocash/commons-node/kotlinx-serialization-kotlinx-serialization-json.mjs +5294 -0
  113. package/node_modules/@attocash/commons-node/kotlinx-serialization-kotlinx-serialization-json.mjs.map +1 -0
  114. package/node_modules/@attocash/commons-node/package.json +29 -0
  115. package/node_modules/@attocash/commons-node-remote/LICENSE +28 -0
  116. package/node_modules/@attocash/commons-node-remote/README.md +61 -0
  117. package/node_modules/@attocash/commons-node-remote/commons-commons-node-remote.d.mts +122 -0
  118. package/node_modules/@attocash/commons-node-remote/commons-commons-node-remote.mjs +1810 -0
  119. package/node_modules/@attocash/commons-node-remote/commons-commons-node-remote.mjs.map +1 -0
  120. package/node_modules/@attocash/commons-node-remote/kotlin-logging.mjs +432 -0
  121. package/node_modules/@attocash/commons-node-remote/kotlin-logging.mjs.map +1 -0
  122. package/node_modules/@attocash/commons-node-remote/kotlinx-browser.mjs +8 -0
  123. package/node_modules/@attocash/commons-node-remote/kotlinx-browser.mjs.map +1 -0
  124. package/node_modules/@attocash/commons-node-remote/kotlinx-serialization-kotlinx-serialization-json-io.mjs +4 -0
  125. package/node_modules/@attocash/commons-node-remote/kotlinx-serialization-kotlinx-serialization-json-io.mjs.map +1 -0
  126. package/node_modules/@attocash/commons-node-remote/kotlinx-serialization-kotlinx-serialization-json.mjs +5294 -0
  127. package/node_modules/@attocash/commons-node-remote/kotlinx-serialization-kotlinx-serialization-json.mjs.map +1 -0
  128. package/node_modules/@attocash/commons-node-remote/package.json +31 -0
  129. package/node_modules/@attocash/commons-transport/LICENSE +28 -0
  130. package/node_modules/@attocash/commons-transport/README.md +5 -0
  131. package/node_modules/@attocash/commons-transport/commons-commons-transport.d.mts +64 -0
  132. package/node_modules/@attocash/commons-transport/commons-commons-transport.mjs +249 -0
  133. package/node_modules/@attocash/commons-transport/commons-commons-transport.mjs.map +1 -0
  134. package/node_modules/@attocash/commons-transport/kotlinx-atomicfu.mjs +263 -0
  135. package/node_modules/@attocash/commons-transport/kotlinx-atomicfu.mjs.map +1 -0
  136. package/node_modules/@attocash/commons-transport/kotlinx-browser.mjs +8 -0
  137. package/node_modules/@attocash/commons-transport/kotlinx-browser.mjs.map +1 -0
  138. package/node_modules/@attocash/commons-transport/kotlinx-coroutines-core.mjs +11604 -0
  139. package/node_modules/@attocash/commons-transport/kotlinx-coroutines-core.mjs.map +1 -0
  140. package/node_modules/@attocash/commons-transport/kotlinx-serialization-kotlinx-serialization-json-io.mjs +4 -0
  141. package/node_modules/@attocash/commons-transport/kotlinx-serialization-kotlinx-serialization-json-io.mjs.map +1 -0
  142. package/node_modules/@attocash/commons-transport/kotlinx-serialization-kotlinx-serialization-json.mjs +5294 -0
  143. package/node_modules/@attocash/commons-transport/kotlinx-serialization-kotlinx-serialization-json.mjs.map +1 -0
  144. package/node_modules/@attocash/commons-transport/ktor-ktor-client-content-negotiation.mjs +499 -0
  145. package/node_modules/@attocash/commons-transport/ktor-ktor-client-content-negotiation.mjs.map +1 -0
  146. package/node_modules/@attocash/commons-transport/ktor-ktor-client-core.mjs +6456 -0
  147. package/node_modules/@attocash/commons-transport/ktor-ktor-client-core.mjs.map +1 -0
  148. package/node_modules/@attocash/commons-transport/ktor-ktor-events.mjs +83 -0
  149. package/node_modules/@attocash/commons-transport/ktor-ktor-events.mjs.map +1 -0
  150. package/node_modules/@attocash/commons-transport/ktor-ktor-http-cio.mjs +1714 -0
  151. package/node_modules/@attocash/commons-transport/ktor-ktor-http-cio.mjs.map +1 -0
  152. package/node_modules/@attocash/commons-transport/ktor-ktor-http.mjs +3197 -0
  153. package/node_modules/@attocash/commons-transport/ktor-ktor-http.mjs.map +1 -0
  154. package/node_modules/@attocash/commons-transport/ktor-ktor-io.mjs +2290 -0
  155. package/node_modules/@attocash/commons-transport/ktor-ktor-io.mjs.map +1 -0
  156. package/node_modules/@attocash/commons-transport/ktor-ktor-serialization-kotlinx-json.mjs +46 -0
  157. package/node_modules/@attocash/commons-transport/ktor-ktor-serialization-kotlinx-json.mjs.map +1 -0
  158. package/node_modules/@attocash/commons-transport/ktor-ktor-serialization-kotlinx.mjs +482 -0
  159. package/node_modules/@attocash/commons-transport/ktor-ktor-serialization-kotlinx.mjs.map +1 -0
  160. package/node_modules/@attocash/commons-transport/ktor-ktor-serialization.mjs +165 -0
  161. package/node_modules/@attocash/commons-transport/ktor-ktor-serialization.mjs.map +1 -0
  162. package/node_modules/@attocash/commons-transport/ktor-ktor-sse.mjs +4 -0
  163. package/node_modules/@attocash/commons-transport/ktor-ktor-sse.mjs.map +1 -0
  164. package/node_modules/@attocash/commons-transport/ktor-ktor-utils.mjs +3222 -0
  165. package/node_modules/@attocash/commons-transport/ktor-ktor-utils.mjs.map +1 -0
  166. package/node_modules/@attocash/commons-transport/ktor-ktor-websocket-serialization.mjs +4 -0
  167. package/node_modules/@attocash/commons-transport/ktor-ktor-websocket-serialization.mjs.map +1 -0
  168. package/node_modules/@attocash/commons-transport/ktor-ktor-websockets.mjs +1485 -0
  169. package/node_modules/@attocash/commons-transport/ktor-ktor-websockets.mjs.map +1 -0
  170. package/node_modules/@attocash/commons-transport/package.json +29 -0
  171. package/node_modules/@attocash/commons-worker/LICENSE +28 -0
  172. package/node_modules/@attocash/commons-worker/README.md +48 -0
  173. package/node_modules/@attocash/commons-worker/commons-commons-worker.d.mts +73 -0
  174. package/node_modules/@attocash/commons-worker/commons-commons-worker.mjs +702 -0
  175. package/node_modules/@attocash/commons-worker/commons-commons-worker.mjs.map +1 -0
  176. package/node_modules/@attocash/commons-worker/kotlin-logging.mjs +432 -0
  177. package/node_modules/@attocash/commons-worker/kotlin-logging.mjs.map +1 -0
  178. package/node_modules/@attocash/commons-worker/kotlinx-serialization-kotlinx-serialization-json.mjs +5294 -0
  179. package/node_modules/@attocash/commons-worker/kotlinx-serialization-kotlinx-serialization-json.mjs.map +1 -0
  180. package/node_modules/@attocash/commons-worker/package.json +29 -0
  181. package/node_modules/@attocash/commons-worker-remote/LICENSE +28 -0
  182. package/node_modules/@attocash/commons-worker-remote/README.md +60 -0
  183. package/node_modules/@attocash/commons-worker-remote/commons-commons-worker-remote.d.mts +93 -0
  184. package/node_modules/@attocash/commons-worker-remote/commons-commons-worker-remote.mjs +289 -0
  185. package/node_modules/@attocash/commons-worker-remote/commons-commons-worker-remote.mjs.map +1 -0
  186. package/node_modules/@attocash/commons-worker-remote/kotlin-logging.mjs +432 -0
  187. package/node_modules/@attocash/commons-worker-remote/kotlin-logging.mjs.map +1 -0
  188. package/node_modules/@attocash/commons-worker-remote/kotlinx-browser.mjs +8 -0
  189. package/node_modules/@attocash/commons-worker-remote/kotlinx-browser.mjs.map +1 -0
  190. package/node_modules/@attocash/commons-worker-remote/kotlinx-serialization-kotlinx-serialization-json-io.mjs +4 -0
  191. package/node_modules/@attocash/commons-worker-remote/kotlinx-serialization-kotlinx-serialization-json-io.mjs.map +1 -0
  192. package/node_modules/@attocash/commons-worker-remote/kotlinx-serialization-kotlinx-serialization-json.mjs +5294 -0
  193. package/node_modules/@attocash/commons-worker-remote/kotlinx-serialization-kotlinx-serialization-json.mjs.map +1 -0
  194. package/node_modules/@attocash/commons-worker-remote/package.json +31 -0
  195. package/node_modules/@js-joda/core/CHANGELOG.md +363 -0
  196. package/node_modules/@js-joda/core/CheatSheet.md +947 -0
  197. package/node_modules/@js-joda/core/LICENSE +34 -0
  198. package/node_modules/@js-joda/core/README.md +155 -0
  199. package/node_modules/@js-joda/core/bower.json +21 -0
  200. package/node_modules/@js-joda/core/dist/js-joda.d.ts +2452 -0
  201. package/node_modules/@js-joda/core/dist/js-joda.esm.js +13564 -0
  202. package/node_modules/@js-joda/core/dist/js-joda.flow.js +949 -0
  203. package/node_modules/@js-joda/core/dist/js-joda.js +13630 -0
  204. package/node_modules/@js-joda/core/dist/js-joda.js.map +1 -0
  205. package/node_modules/@js-joda/core/dist/js-joda.min.js +5 -0
  206. package/node_modules/@js-joda/core/package.json +76 -0
  207. package/node_modules/@js-joda/core/src/Clock.js +330 -0
  208. package/node_modules/@js-joda/core/src/DayOfWeek.js +451 -0
  209. package/node_modules/@js-joda/core/src/Duration.js +1205 -0
  210. package/node_modules/@js-joda/core/src/Enum.js +30 -0
  211. package/node_modules/@js-joda/core/src/Instant.js +1012 -0
  212. package/node_modules/@js-joda/core/src/LocalDate.js +1703 -0
  213. package/node_modules/@js-joda/core/src/LocalDateTime.js +1686 -0
  214. package/node_modules/@js-joda/core/src/LocalTime.js +1415 -0
  215. package/node_modules/@js-joda/core/src/MathUtil.js +236 -0
  216. package/node_modules/@js-joda/core/src/Month.js +600 -0
  217. package/node_modules/@js-joda/core/src/MonthDay.js +730 -0
  218. package/node_modules/@js-joda/core/src/OffsetDateTime.js +757 -0
  219. package/node_modules/@js-joda/core/src/OffsetTime.js +621 -0
  220. package/node_modules/@js-joda/core/src/Period.js +933 -0
  221. package/node_modules/@js-joda/core/src/StringUtil.js +43 -0
  222. package/node_modules/@js-joda/core/src/Year.js +1015 -0
  223. package/node_modules/@js-joda/core/src/YearConstants.js +21 -0
  224. package/node_modules/@js-joda/core/src/YearMonth.js +1096 -0
  225. package/node_modules/@js-joda/core/src/ZoneId.js +236 -0
  226. package/node_modules/@js-joda/core/src/ZoneIdFactory.js +201 -0
  227. package/node_modules/@js-joda/core/src/ZoneOffset.js +486 -0
  228. package/node_modules/@js-joda/core/src/ZoneRegion.js +72 -0
  229. package/node_modules/@js-joda/core/src/ZonedDateTime.js +2007 -0
  230. package/node_modules/@js-joda/core/src/_init.js +68 -0
  231. package/node_modules/@js-joda/core/src/assert.js +33 -0
  232. package/node_modules/@js-joda/core/src/chrono/ChronoLocalDate.js +230 -0
  233. package/node_modules/@js-joda/core/src/chrono/ChronoLocalDateTime.js +130 -0
  234. package/node_modules/@js-joda/core/src/chrono/ChronoZonedDateTime.js +194 -0
  235. package/node_modules/@js-joda/core/src/chrono/IsoChronology.js +235 -0
  236. package/node_modules/@js-joda/core/src/convert.js +83 -0
  237. package/node_modules/@js-joda/core/src/errors.js +54 -0
  238. package/node_modules/@js-joda/core/src/format/DateTimeBuilder.js +535 -0
  239. package/node_modules/@js-joda/core/src/format/DateTimeFormatter.js +728 -0
  240. package/node_modules/@js-joda/core/src/format/DateTimeFormatterBuilder.js +1545 -0
  241. package/node_modules/@js-joda/core/src/format/DateTimeParseContext.js +297 -0
  242. package/node_modules/@js-joda/core/src/format/DateTimePrintContext.js +138 -0
  243. package/node_modules/@js-joda/core/src/format/DecimalStyle.js +113 -0
  244. package/node_modules/@js-joda/core/src/format/EnumMap.js +70 -0
  245. package/node_modules/@js-joda/core/src/format/ParsePosition.js +31 -0
  246. package/node_modules/@js-joda/core/src/format/ResolverStyle.js +93 -0
  247. package/node_modules/@js-joda/core/src/format/SignStyle.js +38 -0
  248. package/node_modules/@js-joda/core/src/format/StringBuilder.js +47 -0
  249. package/node_modules/@js-joda/core/src/format/TextStyle.js +114 -0
  250. package/node_modules/@js-joda/core/src/format/parser/CharLiteralPrinterParser.js +46 -0
  251. package/node_modules/@js-joda/core/src/format/parser/CompositePrinterParser.js +89 -0
  252. package/node_modules/@js-joda/core/src/format/parser/FractionPrinterParser.js +162 -0
  253. package/node_modules/@js-joda/core/src/format/parser/NumberPrinterParser.js +367 -0
  254. package/node_modules/@js-joda/core/src/format/parser/OffsetIdPrinterParser.js +177 -0
  255. package/node_modules/@js-joda/core/src/format/parser/PadPrinterParserDecorator.js +81 -0
  256. package/node_modules/@js-joda/core/src/format/parser/SettingsParser.js +44 -0
  257. package/node_modules/@js-joda/core/src/format/parser/StringLiteralPrinterParser.js +39 -0
  258. package/node_modules/@js-joda/core/src/format/parser/ZoneIdPrinterParser.js +218 -0
  259. package/node_modules/@js-joda/core/src/js-joda.js +210 -0
  260. package/node_modules/@js-joda/core/src/license-preamble.js +3 -0
  261. package/node_modules/@js-joda/core/src/temporal/ChronoField.js +470 -0
  262. package/node_modules/@js-joda/core/src/temporal/ChronoUnit.js +310 -0
  263. package/node_modules/@js-joda/core/src/temporal/DefaultInterfaceTemporal.js +118 -0
  264. package/node_modules/@js-joda/core/src/temporal/IsoFields.js +859 -0
  265. package/node_modules/@js-joda/core/src/temporal/NativeJsTemporal.js +105 -0
  266. package/node_modules/@js-joda/core/src/temporal/Temporal.js +346 -0
  267. package/node_modules/@js-joda/core/src/temporal/TemporalAccessor.js +125 -0
  268. package/node_modules/@js-joda/core/src/temporal/TemporalAdjuster.js +92 -0
  269. package/node_modules/@js-joda/core/src/temporal/TemporalAdjusters.js +464 -0
  270. package/node_modules/@js-joda/core/src/temporal/TemporalAmount.js +166 -0
  271. package/node_modules/@js-joda/core/src/temporal/TemporalField.js +248 -0
  272. package/node_modules/@js-joda/core/src/temporal/TemporalQueries.js +223 -0
  273. package/node_modules/@js-joda/core/src/temporal/TemporalQueriesFactory.js +77 -0
  274. package/node_modules/@js-joda/core/src/temporal/TemporalQuery.js +107 -0
  275. package/node_modules/@js-joda/core/src/temporal/TemporalUnit.js +179 -0
  276. package/node_modules/@js-joda/core/src/temporal/ValueRange.js +257 -0
  277. package/node_modules/@js-joda/core/src/use.js +20 -0
  278. package/node_modules/@js-joda/core/src/zone/SystemDefaultZoneId.js +31 -0
  279. package/node_modules/@js-joda/core/src/zone/SystemDefaultZoneRules.js +162 -0
  280. package/node_modules/@js-joda/core/src/zone/ZoneOffsetTransition.js +289 -0
  281. package/node_modules/@js-joda/core/src/zone/ZoneRules.js +464 -0
  282. package/node_modules/@js-joda/core/src/zone/ZoneRulesProvider.js +36 -0
  283. package/node_modules/@noble/hashes/LICENSE +21 -0
  284. package/node_modules/@noble/hashes/README.md +563 -0
  285. package/node_modules/@noble/hashes/_blake.d.ts +21 -0
  286. package/node_modules/@noble/hashes/_blake.d.ts.map +1 -0
  287. package/node_modules/@noble/hashes/_blake.js +52 -0
  288. package/node_modules/@noble/hashes/_blake.js.map +1 -0
  289. package/node_modules/@noble/hashes/_md.d.ts +99 -0
  290. package/node_modules/@noble/hashes/_md.d.ts.map +1 -0
  291. package/node_modules/@noble/hashes/_md.js +202 -0
  292. package/node_modules/@noble/hashes/_md.js.map +1 -0
  293. package/node_modules/@noble/hashes/_u64.d.ts +63 -0
  294. package/node_modules/@noble/hashes/_u64.d.ts.map +1 -0
  295. package/node_modules/@noble/hashes/_u64.js +84 -0
  296. package/node_modules/@noble/hashes/_u64.js.map +1 -0
  297. package/node_modules/@noble/hashes/argon2.d.ts +112 -0
  298. package/node_modules/@noble/hashes/argon2.d.ts.map +1 -0
  299. package/node_modules/@noble/hashes/argon2.js +517 -0
  300. package/node_modules/@noble/hashes/argon2.js.map +1 -0
  301. package/node_modules/@noble/hashes/blake1.d.ts +156 -0
  302. package/node_modules/@noble/hashes/blake1.d.ts.map +1 -0
  303. package/node_modules/@noble/hashes/blake1.js +560 -0
  304. package/node_modules/@noble/hashes/blake1.js.map +1 -0
  305. package/node_modules/@noble/hashes/blake2.d.ts +184 -0
  306. package/node_modules/@noble/hashes/blake2.d.ts.map +1 -0
  307. package/node_modules/@noble/hashes/blake2.js +501 -0
  308. package/node_modules/@noble/hashes/blake2.js.map +1 -0
  309. package/node_modules/@noble/hashes/blake3.d.ts +68 -0
  310. package/node_modules/@noble/hashes/blake3.d.ts.map +1 -0
  311. package/node_modules/@noble/hashes/blake3.js +284 -0
  312. package/node_modules/@noble/hashes/blake3.js.map +1 -0
  313. package/node_modules/@noble/hashes/eskdf.d.ts +92 -0
  314. package/node_modules/@noble/hashes/eskdf.d.ts.map +1 -0
  315. package/node_modules/@noble/hashes/eskdf.js +218 -0
  316. package/node_modules/@noble/hashes/eskdf.js.map +1 -0
  317. package/node_modules/@noble/hashes/hkdf.d.ts +64 -0
  318. package/node_modules/@noble/hashes/hkdf.d.ts.map +1 -0
  319. package/node_modules/@noble/hashes/hkdf.js +120 -0
  320. package/node_modules/@noble/hashes/hkdf.js.map +1 -0
  321. package/node_modules/@noble/hashes/hmac.d.ts +47 -0
  322. package/node_modules/@noble/hashes/hmac.d.ts.map +1 -0
  323. package/node_modules/@noble/hashes/hmac.js +93 -0
  324. package/node_modules/@noble/hashes/hmac.js.map +1 -0
  325. package/node_modules/@noble/hashes/index.d.ts +2 -0
  326. package/node_modules/@noble/hashes/index.d.ts.map +1 -0
  327. package/node_modules/@noble/hashes/index.js +35 -0
  328. package/node_modules/@noble/hashes/index.js.map +1 -0
  329. package/node_modules/@noble/hashes/legacy.d.ts +102 -0
  330. package/node_modules/@noble/hashes/legacy.d.ts.map +1 -0
  331. package/node_modules/@noble/hashes/legacy.js +327 -0
  332. package/node_modules/@noble/hashes/legacy.js.map +1 -0
  333. package/node_modules/@noble/hashes/package.json +97 -0
  334. package/node_modules/@noble/hashes/pbkdf2.d.ts +56 -0
  335. package/node_modules/@noble/hashes/pbkdf2.d.ts.map +1 -0
  336. package/node_modules/@noble/hashes/pbkdf2.js +135 -0
  337. package/node_modules/@noble/hashes/pbkdf2.js.map +1 -0
  338. package/node_modules/@noble/hashes/scrypt.d.ts +65 -0
  339. package/node_modules/@noble/hashes/scrypt.d.ts.map +1 -0
  340. package/node_modules/@noble/hashes/scrypt.js +257 -0
  341. package/node_modules/@noble/hashes/scrypt.js.map +1 -0
  342. package/node_modules/@noble/hashes/sha2.d.ts +249 -0
  343. package/node_modules/@noble/hashes/sha2.d.ts.map +1 -0
  344. package/node_modules/@noble/hashes/sha2.js +458 -0
  345. package/node_modules/@noble/hashes/sha2.js.map +1 -0
  346. package/node_modules/@noble/hashes/sha3-addons.d.ts +461 -0
  347. package/node_modules/@noble/hashes/sha3-addons.d.ts.map +1 -0
  348. package/node_modules/@noble/hashes/sha3-addons.js +783 -0
  349. package/node_modules/@noble/hashes/sha3-addons.js.map +1 -0
  350. package/node_modules/@noble/hashes/sha3.d.ts +199 -0
  351. package/node_modules/@noble/hashes/sha3.d.ts.map +1 -0
  352. package/node_modules/@noble/hashes/sha3.js +431 -0
  353. package/node_modules/@noble/hashes/sha3.js.map +1 -0
  354. package/node_modules/@noble/hashes/src/_blake.ts +57 -0
  355. package/node_modules/@noble/hashes/src/_md.ts +222 -0
  356. package/node_modules/@noble/hashes/src/_u64.ts +117 -0
  357. package/node_modules/@noble/hashes/src/argon2.ts +667 -0
  358. package/node_modules/@noble/hashes/src/blake1.ts +614 -0
  359. package/node_modules/@noble/hashes/src/blake2.ts +582 -0
  360. package/node_modules/@noble/hashes/src/blake3.ts +317 -0
  361. package/node_modules/@noble/hashes/src/eskdf.ts +259 -0
  362. package/node_modules/@noble/hashes/src/hkdf.ts +133 -0
  363. package/node_modules/@noble/hashes/src/hmac.ts +126 -0
  364. package/node_modules/@noble/hashes/src/index.ts +33 -0
  365. package/node_modules/@noble/hashes/src/legacy.ts +339 -0
  366. package/node_modules/@noble/hashes/src/pbkdf2.ts +175 -0
  367. package/node_modules/@noble/hashes/src/scrypt.ts +315 -0
  368. package/node_modules/@noble/hashes/src/sha2.ts +530 -0
  369. package/node_modules/@noble/hashes/src/sha3-addons.ts +983 -0
  370. package/node_modules/@noble/hashes/src/sha3.ts +485 -0
  371. package/node_modules/@noble/hashes/src/utils.ts +848 -0
  372. package/node_modules/@noble/hashes/src/webcrypto.ts +239 -0
  373. package/node_modules/@noble/hashes/utils.d.ts +519 -0
  374. package/node_modules/@noble/hashes/utils.d.ts.map +1 -0
  375. package/node_modules/@noble/hashes/utils.js +578 -0
  376. package/node_modules/@noble/hashes/utils.js.map +1 -0
  377. package/node_modules/@noble/hashes/webcrypto.d.ts +120 -0
  378. package/node_modules/@noble/hashes/webcrypto.d.ts.map +1 -0
  379. package/node_modules/@noble/hashes/webcrypto.js +165 -0
  380. package/node_modules/@noble/hashes/webcrypto.js.map +1 -0
  381. package/node_modules/ws/LICENSE +20 -0
  382. package/node_modules/ws/README.md +548 -0
  383. package/node_modules/ws/browser.js +8 -0
  384. package/node_modules/ws/index.js +22 -0
  385. package/node_modules/ws/lib/buffer-util.js +131 -0
  386. package/node_modules/ws/lib/constants.js +19 -0
  387. package/node_modules/ws/lib/event-target.js +292 -0
  388. package/node_modules/ws/lib/extension.js +203 -0
  389. package/node_modules/ws/lib/limiter.js +55 -0
  390. package/node_modules/ws/lib/permessage-deflate.js +530 -0
  391. package/node_modules/ws/lib/receiver.js +743 -0
  392. package/node_modules/ws/lib/sender.js +607 -0
  393. package/node_modules/ws/lib/stream.js +161 -0
  394. package/node_modules/ws/lib/subprotocol.js +62 -0
  395. package/node_modules/ws/lib/validation.js +152 -0
  396. package/node_modules/ws/lib/websocket-server.js +562 -0
  397. package/node_modules/ws/lib/websocket.js +1407 -0
  398. package/node_modules/ws/package.json +74 -0
  399. package/node_modules/ws/wrapper.mjs +21 -0
  400. package/package.json +53 -0
@@ -0,0 +1,1205 @@
1
+ /**
2
+ * @copyright (c) 2016, Philipp Thürwächter & Pattrick Hüper
3
+ * @copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
4
+ * @license BSD-3-Clause (see LICENSE in the root directory of this source tree)
5
+ */
6
+ import {requireNonNull, requireInstance} from './assert';
7
+ import {ArithmeticException, DateTimeParseException, UnsupportedTemporalTypeException} from './errors';
8
+ import {MathUtil, MAX_SAFE_INTEGER, MIN_SAFE_INTEGER} from './MathUtil';
9
+
10
+ import {ChronoField} from './temporal/ChronoField';
11
+ import {ChronoUnit} from './temporal/ChronoUnit';
12
+ import {TemporalAmount} from './temporal/TemporalAmount';
13
+ import {TemporalUnit} from './temporal/TemporalUnit';
14
+
15
+ import {LocalTime} from './LocalTime';
16
+
17
+ /**
18
+ * A time-based amount of time, such as '34.5 seconds'.
19
+ *
20
+ * This class models a quantity or amount of time in terms of seconds and nanoseconds.
21
+ * It can be accessed using other duration-based units, such as minutes and hours.
22
+ * In addition, the {@link ChronoUnit#DAYS} unit can be used and is treated as
23
+ * exactly equal to 24 hours, thus ignoring daylight savings effects.
24
+ * See {@link Period} for the date-based equivalent to this class.
25
+ *
26
+ * A physical duration could be of infinite length.
27
+ * For practicality, the duration is stored with constraints similar to {@link Instant}.
28
+ * The duration uses nanosecond resolution with a maximum value of the seconds that can
29
+ * be held in a `long`. This is greater than the current estimated age of the universe.
30
+ *
31
+ * The range of a duration requires the storage of a number larger than a `long`.
32
+ * To achieve this, the class stores a `long` representing seconds and an `int`
33
+ * representing nanosecond-of-second, which will always be between 0 and 999,999,999.
34
+ *
35
+ * The duration is measured in "seconds", but these are not necessarily identical to
36
+ * the scientific "SI second" definition based on atomic clocks.
37
+ * This difference only impacts durations measured near a leap-second and should not affect
38
+ * most applications.
39
+ * See {@link Instant} for a discussion as to the meaning of the second and time-scales.
40
+ *
41
+ * ### Static properties of Class {@link Duration}
42
+ *
43
+ * Duration.ZERO
44
+ *
45
+ * Constant for a duration of zero.
46
+ *
47
+ */
48
+ export class Duration extends TemporalAmount /*implements TemporalAmount, Comparable<Duration>, Serializable */ {
49
+
50
+ /**
51
+ * Constructs an instance of {@link Duration} using seconds and nanoseconds.
52
+ *
53
+ * @param {Number} seconds - the length of the duration in seconds, positive or negative
54
+ * @param {Number} nanos - the nanoseconds within the second, from 0 to 999,999,999
55
+ * @private
56
+ */
57
+ constructor(seconds, nanos) {
58
+ super();
59
+ this._seconds = MathUtil.safeToInt(seconds);
60
+ this._nanos = MathUtil.safeToInt(nanos);
61
+ }
62
+
63
+ //-----------------------------------------------------------------------
64
+ /**
65
+ * Obtains an instance of {@link Duration} from a number of standard 24 hour days.
66
+ *
67
+ * The seconds are calculated based on the standard definition of a day,
68
+ * where each day is 86400 seconds which implies a 24 hour day.
69
+ * The nanosecond in second field is set to zero.
70
+ *
71
+ * @param {Number} days - the number of days, positive or negative
72
+ * @return {!Duration}
73
+ * @throws ArithmeticException if the input days exceeds the capacity of {@link Duration}
74
+ */
75
+ static ofDays(days) {
76
+ return Duration._create(MathUtil.safeMultiply(days, LocalTime.SECONDS_PER_DAY), 0);
77
+ }
78
+
79
+ /**
80
+ * Obtains an instance of {@link Duration} from a number of standard hours.
81
+ *
82
+ * The seconds are calculated based on the standard definition of an hour,
83
+ * where each hour is 3600 seconds.
84
+ * The nanosecond in second field is set to zero.
85
+ *
86
+ * @param {Number} hours - the number of hours, positive or negative
87
+ * @return {!Duration}
88
+ * @throws ArithmeticException if the input hours exceeds the capacity of {@link Duration}
89
+ */
90
+ static ofHours(hours) {
91
+ return Duration._create(MathUtil.safeMultiply(hours, LocalTime.SECONDS_PER_HOUR), 0);
92
+ }
93
+
94
+ /**
95
+ * Obtains an instance of {@link Duration} from a number of standard minutes.
96
+ *
97
+ * The seconds are calculated based on the standard definition of a minute,
98
+ * where each minute is 60 seconds.
99
+ * The nanosecond in second field is set to zero.
100
+ *
101
+ * @param {Number} minutes - the number of minutes, positive or negative
102
+ * @return {!Duration}
103
+ * @throws ArithmeticException if the input minutes exceeds the capacity of {@link Duration}
104
+ */
105
+ static ofMinutes(minutes) {
106
+ return Duration._create(MathUtil.safeMultiply(minutes, LocalTime.SECONDS_PER_MINUTE), 0);
107
+ }
108
+
109
+ //-----------------------------------------------------------------------
110
+ /**
111
+ * Obtains an instance of {@link Duration} from a number of seconds
112
+ * and an adjustment in nanoseconds.
113
+ *
114
+ * This method allows an arbitrary number of nanoseconds to be passed in.
115
+ * The factory will alter the values of the second and nanosecond in order
116
+ * to ensure that the stored nanosecond is in the range 0 to 999,999,999.
117
+ * For example, the following will result in the exactly the same duration:
118
+ * <pre>
119
+ * Duration.ofSeconds(3, 1);
120
+ * Duration.ofSeconds(4, -999_999_999);
121
+ * Duration.ofSeconds(2, 1000_000_001);
122
+ * </pre>
123
+ *
124
+ * @param {Number} seconds - the number of seconds, positive or negative
125
+ * @param {Number} nanoAdjustment the nanosecond adjustment to the number of seconds, positive or negative
126
+ * @return {!Duration}
127
+ * @throws ArithmeticException if the adjustment causes the seconds to exceed the capacity of {@link Duration}
128
+ */
129
+ static ofSeconds(seconds, nanoAdjustment = 0) {
130
+ const secs = MathUtil.safeAdd(seconds, MathUtil.floorDiv(nanoAdjustment, LocalTime.NANOS_PER_SECOND));
131
+ const nos = MathUtil.floorMod(nanoAdjustment, LocalTime.NANOS_PER_SECOND);
132
+ return Duration._create(secs, nos);
133
+ }
134
+
135
+ //-----------------------------------------------------------------------
136
+ /**
137
+ * Obtains an instance of {@link Duration} from a number of milliseconds.
138
+ *
139
+ * The seconds and nanoseconds are extracted from the specified milliseconds.
140
+ *
141
+ * @param {Number} millis - the number of milliseconds, positive or negative
142
+ * @return {!Duration}
143
+ */
144
+ static ofMillis(millis) {
145
+ let secs = MathUtil.intDiv(millis, 1000);
146
+ let mos = MathUtil.intMod(millis, 1000);
147
+ if (mos < 0) {
148
+ mos += 1000;
149
+ secs--;
150
+ }
151
+ return Duration._create(secs, mos * 1000000);
152
+ }
153
+
154
+ //-----------------------------------------------------------------------
155
+ /**
156
+ * Obtains an instance of {@link Duration} from a number of nanoseconds.
157
+ *
158
+ * The seconds and nanoseconds are extracted from the specified nanoseconds.
159
+ *
160
+ * @param {Number} nanos - the number of nanoseconds, positive or negative
161
+ * @return {!Duration}
162
+ */
163
+ static ofNanos(nanos) {
164
+ let secs = MathUtil.intDiv(nanos, LocalTime.NANOS_PER_SECOND);
165
+ let nos = MathUtil.intMod(nanos, LocalTime.NANOS_PER_SECOND);
166
+ if (nos < 0) {
167
+ nos += LocalTime.NANOS_PER_SECOND;
168
+ secs--;
169
+ }
170
+ return this._create(secs, nos);
171
+ }
172
+
173
+ //-----------------------------------------------------------------------
174
+ /**
175
+ * Obtains an instance of {@link Duration} from a duration in the specified unit.
176
+ *
177
+ * The parameters represent the two parts of a phrase like '6 Hours'. For example:
178
+ * <pre>
179
+ * Duration.of(3, SECONDS);
180
+ * Duration.of(465, HOURS);
181
+ * </pre>
182
+ * Only a subset of units are accepted by this method.
183
+ * The unit must either have an exact duration (see {@link TemporalUnit#isDurationEstimated}) or
184
+ * be {@link ChronoUnit#DAYS} which is treated as 24 hours. Other units throw an exception.
185
+ *
186
+ * @param {Number} amount - the amount of the duration, measured in terms of the unit, positive or negative
187
+ * @param {TemporalUnit} unit - the unit that the duration is measured in, must have an exact duration, not null
188
+ * @return {!Duration}
189
+ * @throws DateTimeException if the period unit has an estimated duration
190
+ * @throws ArithmeticException if a numeric overflow occurs
191
+ */
192
+ static of(amount, unit) {
193
+ return Duration.ZERO.plus(amount, unit);
194
+ }
195
+
196
+ //-----------------------------------------------------------------------
197
+ /**
198
+ * Obtains an instance of {@link Duration} from an amount.
199
+ *
200
+ * This obtains a duration based on the specified amount.
201
+ * A TemporalAmount represents an amount of time, which may be date-based
202
+ * or time-based, which this factory extracts to a duration.
203
+ *
204
+ * The conversion loops around the set of units from the amount and uses
205
+ * the duration of the unit to calculate the total Duration.
206
+ * Only a subset of units are accepted by this method.
207
+ * The unit must either have an exact duration or be ChronoUnit.DAYS which
208
+ * is treated as 24 hours. If any other units are found then an exception is thrown.
209
+ *
210
+ * @param {TemporalAmount} amount - the temporal amount to convert, not null
211
+ * @return {Duration} the resulting duration, not null
212
+ * @throws DateTimeException if the amount cannot be converted
213
+ * @throws ArithmeticException if a numeric overflow occurs
214
+ */
215
+ static from(amount) {
216
+ requireNonNull(amount, 'amount');
217
+ requireInstance(amount, TemporalAmount);
218
+ let duration = Duration.ZERO;
219
+ amount.units().forEach((unit) => {
220
+ duration = duration.plus(amount.get(unit), unit);
221
+ });
222
+ return duration;
223
+ }
224
+
225
+ /**
226
+ * Obtains an instance of {@link Duration} representing the duration between two instants.
227
+ *
228
+ * Obtains a {@link Duration} representing the duration between two instants.
229
+ * This calculates the duration between two temporal objects of the same type.
230
+ * The difference in seconds is calculated using {@link Temporal#until}.
231
+ * The difference in nanoseconds is calculated using by querying the
232
+ * {@link ChronoField#NANO_OF_SECOND} field.
233
+ *
234
+ * The result of this method can be a negative period if the end is before the start.
235
+ * To guarantee to obtain a positive duration call abs() on the result.
236
+ *
237
+ * @param {Temporal} startInclusive - the start instant, inclusive, not null
238
+ * @param {Temporal} endExclusive - the end instant, exclusive, not null
239
+ * @return {!Duration}
240
+ * @throws DateTimeException if the seconds between the temporals cannot be obtained
241
+ * @throws ArithmeticException if the calculation exceeds the capacity of {@link Duration}
242
+ */
243
+ static between(startInclusive, endExclusive) {
244
+ requireNonNull(startInclusive, 'startInclusive');
245
+ requireNonNull(endExclusive, 'endExclusive');
246
+ let secs = startInclusive.until(endExclusive, ChronoUnit.SECONDS);
247
+ let nanos = 0;
248
+ if (startInclusive.isSupported(ChronoField.NANO_OF_SECOND) && endExclusive.isSupported(ChronoField.NANO_OF_SECOND)) {
249
+ try {
250
+ const startNos = startInclusive.getLong(ChronoField.NANO_OF_SECOND);
251
+ nanos = endExclusive.getLong(ChronoField.NANO_OF_SECOND) - startNos;
252
+ if (secs > 0 && nanos < 0) {
253
+ nanos += LocalTime.NANOS_PER_SECOND;
254
+ } else if (secs < 0 && nanos > 0) {
255
+ nanos -= LocalTime.NANOS_PER_SECOND;
256
+ } else if (secs === 0 && nanos !== 0) {
257
+ // two possible meanings for result, so recalculate secs
258
+ const adjustedEnd = endExclusive.with(ChronoField.NANO_OF_SECOND, startNos);
259
+ secs = startInclusive.until(adjustedEnd, ChronoUnit.SECONDS);
260
+ }
261
+ } catch (e) {
262
+ // ignore and only use seconds
263
+ }
264
+ }
265
+ return this.ofSeconds(secs, nanos);
266
+ }
267
+
268
+ //-----------------------------------------------------------------------
269
+ /**
270
+ * Obtains a {@link Duration} from a text string such as {@link PnDTnHnMn.nS}.
271
+ *
272
+ * This will parse a textual representation of a duration, including the
273
+ * string produced by {@link toString}. The formats accepted are based
274
+ * on the ISO-8601 duration format {@link PnDTnHnMn.nS} with days
275
+ * considered to be exactly 24 hours.
276
+ *
277
+ * The string starts with an optional sign, denoted by the ASCII negative
278
+ * or positive symbol. If negative, the whole period is negated.
279
+ * The ASCII letter "P" is next in upper or lower case.
280
+ * There are then four sections, each consisting of a number and a suffix.
281
+ * The sections have suffixes in ASCII of "D", "H", "M" and "S" for
282
+ * days, hours, minutes and seconds, accepted in upper or lower case.
283
+ * The suffixes must occur in order. The ASCII letter "T" must occur before
284
+ * the first occurrence, if any, of an hour, minute or second section.
285
+ * At least one of the four sections must be present, and if "T" is present
286
+ * there must be at least one section after the "T".
287
+ * The number part of each section must consist of one or more ASCII digits.
288
+ * The number may be prefixed by the ASCII negative or positive symbol.
289
+ * The number of days, hours and minutes must parse to a `long`.
290
+ * The number of seconds must parse to a `long` with optional fraction.
291
+ * The decimal point may be either a dot or a comma.
292
+ * The fractional part may have from zero to 9 digits.
293
+ *
294
+ * The leading plus/minus sign, and negative values for other units are
295
+ * not part of the ISO-8601 standard.
296
+ *
297
+ * Examples:
298
+ * <pre>
299
+ * "PT20.345S" -> parses as "20.345 seconds"
300
+ * "PT15M" -> parses as "15 minutes" (where a minute is 60 seconds)
301
+ * "PT10H" -> parses as "10 hours" (where an hour is 3600 seconds)
302
+ * "P2D" -> parses as "2 days" (where a day is 24 hours or 86400 seconds)
303
+ * "P2DT3H4M" -> parses as "2 days, 3 hours and 4 minutes"
304
+ * "P-6H3M" -> parses as "-6 hours and +3 minutes"
305
+ * "-P6H3M" -> parses as "-6 hours and -3 minutes"
306
+ * "-P-6H+3M" -> parses as "+6 hours and -3 minutes"
307
+ * </pre>
308
+ *
309
+ * @param {String} text - the text to parse, not null
310
+ * @return {Duration} the parsed duration, not null
311
+ * @throws DateTimeParseException if the text cannot be parsed to a duration
312
+ */
313
+ static parse(text) {
314
+ requireNonNull(text, 'text');
315
+ /**
316
+ * The pattern for parsing.
317
+ */
318
+ const PATTERN = new RegExp('([-+]?)P(?:([-+]?[0-9]+)D)?(T(?:([-+]?[0-9]+)H)?(?:([-+]?[0-9]+)M)?(?:([-+]?[0-9]+)(?:[.,]([0-9]{0,9}))?S)?)?', 'i');
319
+ const matches = PATTERN.exec(text);
320
+ if (matches !== null) {
321
+ // check for letter T but no time sections
322
+ if ('T' === matches[3] === false) {
323
+ const negate = '-' === matches[1];
324
+ const dayMatch = matches[2];
325
+ const hourMatch = matches[4];
326
+ const minuteMatch = matches[5];
327
+ const secondMatch = matches[6];
328
+ const fractionMatch = matches[7];
329
+ if (dayMatch != null || hourMatch != null || minuteMatch != null || secondMatch != null) {
330
+ const daysAsSecs = Duration._parseNumber(text, dayMatch, LocalTime.SECONDS_PER_DAY, 'days');
331
+ const hoursAsSecs = Duration._parseNumber(text, hourMatch, LocalTime.SECONDS_PER_HOUR, 'hours');
332
+ const minsAsSecs = Duration._parseNumber(text, minuteMatch, LocalTime.SECONDS_PER_MINUTE, 'minutes');
333
+ const seconds = Duration._parseNumber(text, secondMatch, 1, 'seconds');
334
+ const negativeSecs = secondMatch != null && secondMatch.charAt(0) === '-';
335
+ const nanos = Duration._parseFraction(text, fractionMatch, negativeSecs ? -1 : 1);
336
+ try {
337
+ return Duration._create(negate, daysAsSecs, hoursAsSecs, minsAsSecs, seconds, nanos);
338
+ } catch (ex) {
339
+ throw new DateTimeParseException('Text cannot be parsed to a Duration: overflow', text, 0, ex);
340
+ }
341
+ }
342
+ }
343
+ }
344
+ throw new DateTimeParseException('Text cannot be parsed to a Duration', text, 0);
345
+ }
346
+
347
+ static _parseNumber(text, parsed, multiplier, errorText) {
348
+ // regex limits to [-+]?[0-9]+
349
+ if (parsed == null) {
350
+ return 0;
351
+ }
352
+ try {
353
+ if (parsed[0] === '+') {
354
+ parsed = parsed.substring(1);
355
+ }
356
+ return MathUtil.safeMultiply(parseFloat(parsed), multiplier);
357
+ } catch (ex) {
358
+ throw new DateTimeParseException('Text cannot be parsed to a Duration: ' + errorText, text, 0, ex);
359
+ }
360
+ }
361
+
362
+ static _parseFraction(text, parsed, negate) {
363
+ // regex limits to [0-9]{0,9}
364
+ if (parsed == null || parsed.length === 0) {
365
+ return 0;
366
+ }
367
+ parsed = (parsed + '000000000').substring(0, 9);
368
+ return parseFloat(parsed) * negate;
369
+ }
370
+
371
+ //-----------------------------------------------------------------------
372
+ /**
373
+ * to handle function overriding this function accepts any number of arguments, checks their type and delegates to the appropriate
374
+ * function
375
+ *
376
+ * @return {Duration}
377
+ */
378
+ static _create() {
379
+ if (arguments.length <= 2) {
380
+ return Duration._createSecondsNanos(arguments[0], arguments[1]);
381
+ } else {
382
+ return Duration._createNegateDaysHoursMinutesSecondsNanos(arguments[0], arguments[1], arguments[2], arguments[3], arguments[4], arguments[5]);
383
+ }
384
+ }
385
+
386
+ static _createNegateDaysHoursMinutesSecondsNanos(negate, daysAsSecs, hoursAsSecs, minsAsSecs, secs, nanos) {
387
+ const seconds = MathUtil.safeAdd(daysAsSecs, MathUtil.safeAdd(hoursAsSecs, MathUtil.safeAdd(minsAsSecs, secs)));
388
+ if (negate) {
389
+ return Duration.ofSeconds(seconds, nanos).negated();
390
+ }
391
+ return Duration.ofSeconds(seconds, nanos);
392
+ }
393
+
394
+ /**
395
+ * Obtains an instance of {@link Duration} using seconds and nanoseconds.
396
+ *
397
+ * @param {Number} seconds - the length of the duration in seconds, positive or negative
398
+ * @param {Number} nanoAdjustment - the nanosecond adjustment within the second, from 0 to 999,999,999
399
+ */
400
+ static _createSecondsNanos(seconds = 0, nanoAdjustment = 0) {
401
+ if (seconds === 0 && nanoAdjustment === 0) {
402
+ return Duration.ZERO;
403
+ }
404
+ return new Duration(seconds, nanoAdjustment);
405
+ }
406
+
407
+ //-----------------------------------------------------------------------
408
+ /**
409
+ * Gets the value of the requested unit.
410
+ *
411
+ * This returns a value for each of the two supported units,
412
+ * {@link ChronoUnit#SECONDS} and {@link ChronoUnit#NANOS}.
413
+ * All other units throw an exception.
414
+ *
415
+ * @param {TemporalUnit} unit the {@link TemporalUnit} for which to return the value
416
+ * @return {number} the const value of the unit
417
+ * @throws DateTimeException if the unit is not supported
418
+ * @throws UnsupportedTemporalTypeException if the unit is not supported
419
+ */
420
+ get(unit) {
421
+ if (unit === ChronoUnit.SECONDS) {
422
+ return this._seconds;
423
+ } else if (unit === ChronoUnit.NANOS) {
424
+ return this._nanos;
425
+ } else {
426
+ throw new UnsupportedTemporalTypeException('Unsupported unit: ' + unit);
427
+ }
428
+ }
429
+
430
+ units() {
431
+ return [ChronoUnit.SECONDS, ChronoUnit.NANOS];
432
+ }
433
+
434
+ //-----------------------------------------------------------------------
435
+ /**
436
+ * Checks if this duration is zero length.
437
+ *
438
+ * A {@link Duration} represents a directed distance between two points on
439
+ * the time-line and can therefore be positive, zero or negative.
440
+ * This method checks whether the length is zero.
441
+ *
442
+ * @return {boolean} true if this duration has a total length equal to zero
443
+ */
444
+ isZero() {
445
+ return this._seconds === 0 && this._nanos === 0;
446
+ }
447
+
448
+ /**
449
+ * Checks if this duration is negative, excluding zero.
450
+ *
451
+ * A {@link Duration} represents a directed distance between two points on
452
+ * the time-line and can therefore be positive, zero or negative.
453
+ * This method checks whether the length is less than zero.
454
+ *
455
+ * @return {boolean} true if this duration has a total length less than zero
456
+ */
457
+ isNegative() {
458
+ return this._seconds < 0;
459
+ }
460
+
461
+ //-----------------------------------------------------------------------
462
+ /**
463
+ * Gets the number of seconds in this duration.
464
+ *
465
+ * The length of the duration is stored using two fields - seconds and nanoseconds.
466
+ * The nanoseconds part is a value from 0 to 999,999,999 that is an adjustment to
467
+ * the length in seconds.
468
+ * The total duration is defined by calling this method and {@link getNano}.
469
+ *
470
+ * A {@link Duration} represents a directed distance between two points on the time-line.
471
+ * A negative duration is expressed by the negative sign of the seconds part.
472
+ * A duration of -1 nanosecond is stored as -1 seconds plus 999,999,999 nanoseconds.
473
+ *
474
+ * @return {number} the whole seconds part of the length of the duration, positive or negative
475
+ */
476
+ seconds() {
477
+ return this._seconds;
478
+ }
479
+
480
+ /**
481
+ * Gets the number of nanoseconds within the second in this duration.
482
+ *
483
+ * The length of the duration is stored using two fields - seconds and nanoseconds.
484
+ * The nanoseconds part is a value from 0 to 999,999,999 that is an adjustment to
485
+ * the length in seconds.
486
+ * The total duration is defined by calling this method and {@link getSeconds}.
487
+ *
488
+ * A {@link Duration} represents a directed distance between two points on the time-line.
489
+ * A negative duration is expressed by the negative sign of the seconds part.
490
+ * A duration of -1 nanosecond is stored as -1 seconds plus 999,999,999 nanoseconds.
491
+ *
492
+ * @return {number} the nanoseconds within the second part of the length of the duration, from 0 to 999,999,999
493
+ */
494
+ nano() {
495
+ return this._nanos;
496
+ }
497
+
498
+ //-----------------------------------------------------------------------
499
+ /**
500
+ * Returns a copy of this duration with the specified amount of seconds.
501
+ *
502
+ * This returns a duration with the specified seconds, retaining the
503
+ * nano-of-second part of this duration.
504
+ *
505
+ * This instance is immutable and unaffected by this method call.
506
+ *
507
+ * @param {Number} seconds - the seconds to represent, may be negative
508
+ * @return {Duration} based on this period with the requested seconds, not null
509
+ */
510
+ withSeconds(seconds) {
511
+ return Duration._create(seconds, this._nanos);
512
+ }
513
+
514
+ /**
515
+ * Returns a copy of this duration with the specified nano-of-second.
516
+ *
517
+ * This returns a duration with the specified nano-of-second, retaining the
518
+ * seconds part of this duration.
519
+ *
520
+ * This instance is immutable and unaffected by this method call.
521
+ *
522
+ * @param {Number} nanoOfSecond - the nano-of-second to represent, from 0 to 999,999,999
523
+ * @return {Duration} based on this period with the requested nano-of-second, not null
524
+ * @throws DateTimeException if the nano-of-second is invalid
525
+ */
526
+ withNanos(nanoOfSecond) {
527
+ ChronoField.NANO_OF_SECOND.checkValidIntValue(nanoOfSecond);
528
+ return Duration._create(this._seconds, nanoOfSecond);
529
+ }
530
+
531
+ //-----------------------------------------------------------------------
532
+ /**
533
+ * Returns a copy of this duration with the specified duration added.
534
+ *
535
+ * This instance is immutable and unaffected by this method call.
536
+ *
537
+ * @param {Duration} duration - the duration to add, positive or negative, not null
538
+ * @return {Duration} based on this duration with the specified duration added, not null
539
+ * @throws ArithmeticException if numeric overflow occurs
540
+ */
541
+ plusDuration(duration) {
542
+ requireNonNull(duration, 'duration');
543
+ return this.plus(duration.seconds(), duration.nano());
544
+ }
545
+
546
+
547
+ /**
548
+ * function overloading for {@link Duration.plus}
549
+ *
550
+ * if called with 1 arguments, then {@link Duration.plusDuration} is executed.
551
+ *
552
+ * if called with 2 arguments and second argument is an instance of TemporalUnit, then {@link Duration.plusAmountUnit} is executed.
553
+ *
554
+ * Otherwise {@link Duration.plusSecondsNanos} is executed.
555
+ *
556
+ * @param {!(Duration|number)} durationOrNumber
557
+ * @param {!TemporalUnit|number} unitOrNumber
558
+ * @returns {Duration}
559
+ */
560
+ plus(durationOrNumber, unitOrNumber) {
561
+ if (arguments.length === 1) {
562
+ return this.plusDuration(durationOrNumber);
563
+ }
564
+ else if (arguments.length === 2 && unitOrNumber instanceof TemporalUnit) {
565
+ return this.plusAmountUnit(durationOrNumber, unitOrNumber);
566
+ } else {
567
+ return this.plusSecondsNanos(durationOrNumber, unitOrNumber);
568
+ }
569
+ }
570
+
571
+ /**
572
+ * Returns a copy of this duration with the specified duration added.
573
+ *
574
+ * The duration amount is measured in terms of the specified unit.
575
+ * Only a subset of units are accepted by this method.
576
+ * The unit must either have an exact duration (see {@link TemporalUnit#isDurationEstimated}) or
577
+ * be {@link ChronoUnit#DAYS} which is treated as 24 hours. Other units throw an exception.
578
+ *
579
+ * This instance is immutable and unaffected by this method call.
580
+ *
581
+ * @param {Number} amountToAdd - the amount to add, measured in terms of the unit, positive or negative
582
+ * @param {TemporalUnit} unit - the unit that the amount is measured in, must have an exact duration, not null
583
+ * @return {Duration} based on this duration with the specified duration added, not null
584
+ * @throws UnsupportedTemporalTypeException if the unit is not supported
585
+ * @throws ArithmeticException if numeric overflow occurs
586
+ */
587
+ plusAmountUnit(amountToAdd, unit) {
588
+ requireNonNull(amountToAdd, 'amountToAdd');
589
+ requireNonNull(unit, 'unit');
590
+ if (unit === ChronoUnit.DAYS) {
591
+ return this.plusSecondsNanos(MathUtil.safeMultiply(amountToAdd, LocalTime.SECONDS_PER_DAY), 0);
592
+ }
593
+ if (unit.isDurationEstimated()) {
594
+ throw new UnsupportedTemporalTypeException('Unit must not have an estimated duration');
595
+ }
596
+ if (amountToAdd === 0) {
597
+ return this;
598
+ }
599
+ if (unit instanceof ChronoUnit) {
600
+ switch (unit) {
601
+ case ChronoUnit.NANOS: return this.plusNanos(amountToAdd);
602
+ case ChronoUnit.MICROS: return this.plusSecondsNanos(MathUtil.intDiv(amountToAdd, (1000000 * 1000)) * 1000, MathUtil.intMod(amountToAdd, (1000000 * 1000)) * 1000);
603
+ case ChronoUnit.MILLIS: return this.plusMillis(amountToAdd);
604
+ case ChronoUnit.SECONDS: return this.plusSeconds(amountToAdd);
605
+ }
606
+ return this.plusSecondsNanos(MathUtil.safeMultiply(unit.duration().seconds(), amountToAdd), 0);
607
+ }
608
+ const duration = unit.duration().multipliedBy(amountToAdd);
609
+ return this.plusSecondsNanos(duration.seconds(), duration.nano());
610
+ }
611
+
612
+ //-----------------------------------------------------------------------
613
+ /**
614
+ * Returns a copy of this duration with the specified duration in 24 hour days added.
615
+ *
616
+ * This instance is immutable and unaffected by this method call.
617
+ *
618
+ * @param {Number} daysToAdd - the days to add, positive or negative
619
+ * @return {Duration} based on this duration with the specified days added, not null
620
+ * @throws ArithmeticException if numeric overflow occurs
621
+ */
622
+ plusDays(daysToAdd) {
623
+ return this.plusSecondsNanos(MathUtil.safeMultiply(daysToAdd, LocalTime.SECONDS_PER_DAY), 0);
624
+ }
625
+
626
+ /**
627
+ * Returns a copy of this duration with the specified duration in hours added.
628
+ *
629
+ * This instance is immutable and unaffected by this method call.
630
+ *
631
+ * @param {Number} hoursToAdd - the hours to add, positive or negative
632
+ * @return {Duration} based on this duration with the specified hours added, not null
633
+ * @throws ArithmeticException if numeric overflow occurs
634
+ */
635
+ plusHours(hoursToAdd) {
636
+ return this.plusSecondsNanos(MathUtil.safeMultiply(hoursToAdd, LocalTime.SECONDS_PER_HOUR), 0);
637
+ }
638
+
639
+ /**
640
+ * Returns a copy of this duration with the specified duration in minutes added.
641
+ *
642
+ * This instance is immutable and unaffected by this method call.
643
+ *
644
+ * @param {Number} minutesToAdd - the minutes to add, positive or negative
645
+ * @return {Duration} based on this duration with the specified minutes added, not null
646
+ * @throws ArithmeticException if numeric overflow occurs
647
+ */
648
+ plusMinutes(minutesToAdd) {
649
+ return this.plusSecondsNanos(MathUtil.safeMultiply(minutesToAdd, LocalTime.SECONDS_PER_MINUTE), 0);
650
+ }
651
+
652
+ /**
653
+ * Returns a copy of this duration with the specified duration in seconds added.
654
+ *
655
+ * This instance is immutable and unaffected by this method call.
656
+ *
657
+ * @param {Number} secondsToAdd - the seconds to add, positive or negative
658
+ * @return {Duration} based on this duration with the specified seconds added, not null
659
+ * @throws ArithmeticException if numeric overflow occurs
660
+ */
661
+ plusSeconds(secondsToAdd) {
662
+ return this.plusSecondsNanos(secondsToAdd, 0);
663
+ }
664
+
665
+ /**
666
+ * Returns a copy of this duration with the specified duration in milliseconds added.
667
+ *
668
+ * This instance is immutable and unaffected by this method call.
669
+ *
670
+ * @param {Number} millisToAdd - the milliseconds to add, positive or negative
671
+ * @return {Duration} based on this duration with the specified milliseconds added, not null
672
+ * @throws ArithmeticException if numeric overflow occurs
673
+ */
674
+ plusMillis(millisToAdd) {
675
+ return this.plusSecondsNanos(MathUtil.intDiv(millisToAdd, 1000), MathUtil.intMod(millisToAdd, 1000) * 1000000);
676
+ }
677
+
678
+ /**
679
+ * Returns a copy of this duration with the specified duration in nanoseconds added.
680
+ *
681
+ * This instance is immutable and unaffected by this method call.
682
+ *
683
+ * @param {Number} nanosToAdd - the nanoseconds to add, positive or negative
684
+ * @return {Duration} based on this duration with the specified nanoseconds added, not null
685
+ * @throws ArithmeticException if numeric overflow occurs
686
+ */
687
+ plusNanos(nanosToAdd) {
688
+ return this.plusSecondsNanos(0, nanosToAdd);
689
+ }
690
+
691
+ /**
692
+ * Returns a copy of this duration with the specified duration added.
693
+ *
694
+ * This instance is immutable and unaffected by this method call.
695
+ *
696
+ * @param {Number} secondsToAdd - the seconds to add, positive or negative
697
+ * @param {Number} nanosToAdd - the nanos to add, positive or negative
698
+ * @return {Duration} based on this duration with the specified seconds added, not null
699
+ * @throws ArithmeticException if numeric overflow occurs
700
+ */
701
+ plusSecondsNanos(secondsToAdd, nanosToAdd) {
702
+ requireNonNull(secondsToAdd, 'secondsToAdd');
703
+ requireNonNull(nanosToAdd, 'nanosToAdd');
704
+ if (secondsToAdd === 0 && nanosToAdd === 0) {
705
+ return this;
706
+ }
707
+ let epochSec = MathUtil.safeAdd(this._seconds, secondsToAdd);
708
+ epochSec = MathUtil.safeAdd(epochSec, MathUtil.intDiv(nanosToAdd, LocalTime.NANOS_PER_SECOND));
709
+ nanosToAdd = MathUtil.intMod(nanosToAdd, LocalTime.NANOS_PER_SECOND);
710
+ const nanoAdjustment = MathUtil.safeAdd(this._nanos, nanosToAdd); // safe int+LocalTime.NANOS_PER_SECOND
711
+ return Duration.ofSeconds(epochSec, nanoAdjustment);
712
+ }
713
+
714
+ //-----------------------------------------------------------------------
715
+ /**
716
+ * function overloading for {@link Duration.minus}
717
+ *
718
+ * if called with 1 arguments and first argument is an instance of Duration, then {@link Duration.minusDuration} is executed.
719
+ *
720
+ * Otherwise {@link Duration.minusAmountUnit} is executed.
721
+ *
722
+ * @param {!(Duration|number)} durationOrNumber
723
+ * @param {?TemporalUnit} unit
724
+ * @return {Duration}
725
+ */
726
+ minus(durationOrNumber, unit) {
727
+ if (arguments.length === 1) {
728
+ return this.minusDuration(durationOrNumber);
729
+ } else {
730
+ return this.minusAmountUnit(durationOrNumber, unit);
731
+ }
732
+ }
733
+
734
+ /**
735
+ * Returns a copy of this duration with the specified duration subtracted.
736
+ *
737
+ * This instance is immutable and unaffected by this method call.
738
+ *
739
+ * @param {Duration} duration - the duration to subtract, positive or negative, not null
740
+ * @return {Duration} based on this duration with the specified duration subtracted, not null
741
+ * @throws ArithmeticException if numeric overflow occurs
742
+ */
743
+ minusDuration(duration) {
744
+ requireNonNull(duration, 'duration');
745
+ const secsToSubtract = duration.seconds();
746
+ const nanosToSubtract = duration.nano();
747
+ if (secsToSubtract === MIN_SAFE_INTEGER) {
748
+ return this.plus(MAX_SAFE_INTEGER, -nanosToSubtract);
749
+ }
750
+ return this.plus(-secsToSubtract, -nanosToSubtract);
751
+ }
752
+
753
+ /**
754
+ * Returns a copy of this duration with the specified duration subtracted.
755
+ *
756
+ * The duration amount is measured in terms of the specified unit.
757
+ * Only a subset of units are accepted by this method.
758
+ * The unit must either have an exact duration (see {@link TemporalUnit#isDurationEstimated}) or
759
+ * be {@link ChronoUnit#DAYS} which is treated as 24 hours. Other units throw an exception.
760
+ *
761
+ * This instance is immutable and unaffected by this method call.
762
+ *
763
+ * @param {Number} amountToSubtract - the amount to subtract, measured in terms of the unit, positive or negative
764
+ * @param {TemporalUnit} unit - the unit that the amount is measured in, must have an exact duration, not null
765
+ * @return {Duration} based on this duration with the specified duration subtracted, not null
766
+ * @throws ArithmeticException if numeric overflow occurs
767
+ */
768
+ minusAmountUnit(amountToSubtract, unit) {
769
+ requireNonNull(amountToSubtract, 'amountToSubtract');
770
+ requireNonNull(unit, 'unit');
771
+ return (amountToSubtract === MIN_SAFE_INTEGER ? this.plusAmountUnit(MAX_SAFE_INTEGER, unit) : this.plusAmountUnit(-amountToSubtract, unit));
772
+ }
773
+
774
+ //-----------------------------------------------------------------------
775
+ /**
776
+ * Returns a copy of this duration with the specified duration in 24 hour days subtracted.
777
+ *
778
+ * This instance is immutable and unaffected by this method call.
779
+ *
780
+ * @param {Number} daysToSubtract - the days to subtract, positive or negative
781
+ * @return {Duration} based on this duration with the specified days subtracted, not null
782
+ * @throws ArithmeticException if numeric overflow occurs
783
+ */
784
+ minusDays(daysToSubtract) {
785
+ return (daysToSubtract === MIN_SAFE_INTEGER ? this.plusDays(MAX_SAFE_INTEGER) : this.plusDays(-daysToSubtract));
786
+ }
787
+
788
+ /**
789
+ * Returns a copy of this duration with the specified duration in hours subtracted.
790
+ *
791
+ * This instance is immutable and unaffected by this method call.
792
+ *
793
+ * @param {Number} hoursToSubtract - the hours to subtract, positive or negative
794
+ * @return {Duration} based on this duration with the specified hours subtracted, not null
795
+ * @throws ArithmeticException if numeric overflow occurs
796
+ */
797
+ minusHours(hoursToSubtract) {
798
+ return (hoursToSubtract === MIN_SAFE_INTEGER ? this.plusHours(MAX_SAFE_INTEGER) : this.plusHours(-hoursToSubtract));
799
+ }
800
+
801
+ /**
802
+ * Returns a copy of this duration with the specified duration in minutes subtracted.
803
+ *
804
+ * The number of hours is multiplied by 60 to obtain the number of seconds to subtract.
805
+ *
806
+ * This instance is immutable and unaffected by this method call.
807
+ *
808
+ * @param {Number} minutesToSubtract - the minutes to subtract, positive or negative
809
+ * @return {Duration} based on this duration with the specified minutes subtracted, not null
810
+ * @throws ArithmeticException if numeric overflow occurs
811
+ */
812
+ minusMinutes(minutesToSubtract) {
813
+ return (minutesToSubtract === MIN_SAFE_INTEGER ? this.plusMinutes(MAX_SAFE_INTEGER) : this.plusMinutes(-minutesToSubtract));
814
+ }
815
+
816
+ /**
817
+ * Returns a copy of this duration with the specified duration in seconds subtracted.
818
+ *
819
+ * This instance is immutable and unaffected by this method call.
820
+ *
821
+ * @param {Number} secondsToSubtract - the seconds to subtract, positive or negative
822
+ * @return {Duration} based on this duration with the specified seconds subtracted, not null
823
+ * @throws ArithmeticException if numeric overflow occurs
824
+ */
825
+ minusSeconds(secondsToSubtract) {
826
+ return (secondsToSubtract === MIN_SAFE_INTEGER ? this.plusSeconds(MAX_SAFE_INTEGER) : this.plusSeconds(-secondsToSubtract));
827
+ }
828
+
829
+ /**
830
+ * Returns a copy of this duration with the specified duration in milliseconds subtracted.
831
+ *
832
+ * This instance is immutable and unaffected by this method call.
833
+ *
834
+ * @param {Number} millisToSubtract - the milliseconds to subtract, positive or negative
835
+ * @return {Duration} based on this duration with the specified milliseconds subtracted, not null
836
+ * @throws ArithmeticException if numeric overflow occurs
837
+ */
838
+ minusMillis(millisToSubtract) {
839
+ return (millisToSubtract === MIN_SAFE_INTEGER ? this.plusMillis(MAX_SAFE_INTEGER) : this.plusMillis(-millisToSubtract));
840
+ }
841
+
842
+ /**
843
+ * Returns a copy of this duration with the specified duration in nanoseconds subtracted.
844
+ *
845
+ * This instance is immutable and unaffected by this method call.
846
+ *
847
+ * @param {Number} nanosToSubtract - the nanoseconds to subtract, positive or negative
848
+ * @return {Duration} based on this duration with the specified nanoseconds subtracted, not null
849
+ * @throws ArithmeticException if numeric overflow occurs
850
+ */
851
+ minusNanos(nanosToSubtract) {
852
+ return (nanosToSubtract === MIN_SAFE_INTEGER ? this.plusNanos(MAX_SAFE_INTEGER) : this.plusNanos(-nanosToSubtract));
853
+ }
854
+
855
+ //-----------------------------------------------------------------------
856
+ /**
857
+ * Returns a copy of this duration multiplied by the scalar.
858
+ *
859
+ * This instance is immutable and unaffected by this method call.
860
+ *
861
+ * @param {Number} multiplicand - the value to multiply the duration by, positive or negative
862
+ * @return {Duration} based on this duration multiplied by the specified scalar, not null
863
+ * @throws ArithmeticException if numeric overflow occurs
864
+ */
865
+ multipliedBy(multiplicand) {
866
+ if (multiplicand === 0) {
867
+ return Duration.ZERO;
868
+ }
869
+ if (multiplicand === 1) {
870
+ return this;
871
+ }
872
+ let secs = MathUtil.safeMultiply(this._seconds, multiplicand);
873
+ let nos = MathUtil.safeMultiply(this._nanos, multiplicand);
874
+ secs = secs + MathUtil.intDiv(nos, LocalTime.NANOS_PER_SECOND);
875
+ nos = MathUtil.intMod(nos, LocalTime.NANOS_PER_SECOND);
876
+ return Duration.ofSeconds(secs, nos);
877
+ }
878
+
879
+ /**
880
+ * Returns a copy of this duration divided by the specified value.
881
+ *
882
+ * In opposite to the threeten implementation the division is realized by floating point not by
883
+ * fixed point arithmetic. Expect floating point rounding errors for {@link Duration.dividedBy}.
884
+ *
885
+ * @param {Number} divisor - the value to divide the duration by, positive or negative, not zero
886
+ * @return {Duration} based on this duration divided by the specified divisor, not null
887
+ * @throws ArithmeticException if the divisor is zero or if numeric overflow occurs
888
+ */
889
+ dividedBy(divisor) {
890
+ if (divisor === 0) {
891
+ throw new ArithmeticException('Cannot divide by zero');
892
+ }
893
+ if (divisor === 1) {
894
+ return this;
895
+ }
896
+ const secs = MathUtil.intDiv(this._seconds, divisor);
897
+ const secsMod = MathUtil.roundDown(((this._seconds/ divisor) - secs) * LocalTime.NANOS_PER_SECOND);
898
+ let nos = MathUtil.intDiv(this._nanos, divisor);
899
+ nos = secsMod + nos;
900
+ return Duration.ofSeconds(secs, nos);
901
+ }
902
+
903
+ //-----------------------------------------------------------------------
904
+ /**
905
+ * Returns a copy of this duration with the length negated.
906
+ *
907
+ * This method swaps the sign of the total length of this duration.
908
+ * For example, {@link PT1.3S} will be returned as {@link PT-1.3S}.
909
+ *
910
+ * This instance is immutable and unaffected by this method call.
911
+ *
912
+ * @return {Duration} based on this duration with the amount negated, not null
913
+ * @throws ArithmeticException if numeric overflow occurs
914
+ */
915
+ negated() {
916
+ return this.multipliedBy(-1);
917
+ }
918
+
919
+ /**
920
+ * Returns a copy of this duration with a positive length.
921
+ *
922
+ * This method returns a positive duration by effectively removing the sign from any negative total length.
923
+ * For example, {@link PT-1.3S} will be returned as {@link PT1.3S}.
924
+ *
925
+ * This instance is immutable and unaffected by this method call.
926
+ *
927
+ * @return {Duration} based on this duration with an absolute length, not null
928
+ * @throws ArithmeticException if numeric overflow occurs
929
+ */
930
+ abs() {
931
+ return this.isNegative() ? this.negated() : this;
932
+ }
933
+
934
+ //-------------------------------------------------------------------------
935
+ /**
936
+ * Adds this duration to the specified temporal object.
937
+ *
938
+ * This returns a temporal object of the same observable type as the input
939
+ * with this duration added.
940
+ *
941
+ * In most cases, it is clearer to reverse the calling pattern by using
942
+ * {@link Temporal#plus}.
943
+ * <pre>
944
+ * // these two lines are equivalent, but the second approach is recommended
945
+ * dateTime = thisDuration.addTo(dateTime);
946
+ * dateTime = dateTime.plus(thisDuration);
947
+ * </pre>
948
+ *
949
+ * The calculation will add the seconds, then nanos.
950
+ * Only non-zero amounts will be added.
951
+ *
952
+ * This instance is immutable and unaffected by this method call.
953
+ *
954
+ * @param {Temporal} temporal - the temporal object to adjust, not null
955
+ * @return {Temporal} an object of the same type with the adjustment made, not null
956
+ * @throws DateTimeException if unable to add
957
+ * @throws ArithmeticException if numeric overflow occurs
958
+ */
959
+ addTo(temporal) {
960
+ requireNonNull(temporal, 'temporal');
961
+ if (this._seconds !== 0) {
962
+ temporal = temporal.plus(this._seconds, ChronoUnit.SECONDS);
963
+ }
964
+ if (this._nanos !== 0) {
965
+ temporal = temporal.plus(this._nanos, ChronoUnit.NANOS);
966
+ }
967
+ return temporal;
968
+ }
969
+
970
+ /**
971
+ * Subtracts this duration from the specified temporal object.
972
+ *
973
+ * This returns a temporal object of the same observable type as the input
974
+ * with this duration subtracted.
975
+ *
976
+ * In most cases, it is clearer to reverse the calling pattern by using
977
+ * {@link Temporal#minus}.
978
+ * <pre>
979
+ * // these two lines are equivalent, but the second approach is recommended
980
+ * dateTime = thisDuration.subtractFrom(dateTime);
981
+ * dateTime = dateTime.minus(thisDuration);
982
+ * </pre>
983
+ *
984
+ * The calculation will subtract the seconds, then nanos.
985
+ * Only non-zero amounts will be added.
986
+ *
987
+ * This instance is immutable and unaffected by this method call.
988
+ *
989
+ * @param {Temporal} temporal - the temporal object to adjust, not null
990
+ * @return {Temporal} an object of the same type with the adjustment made, not null
991
+ * @throws DateTimeException if unable to subtract
992
+ * @throws ArithmeticException if numeric overflow occurs
993
+ */
994
+ subtractFrom(temporal) {
995
+ requireNonNull(temporal, 'temporal');
996
+ if (this._seconds !== 0) {
997
+ temporal = temporal.minus(this._seconds, ChronoUnit.SECONDS);
998
+ }
999
+ if (this._nanos !== 0) {
1000
+ temporal = temporal.minus(this._nanos, ChronoUnit.NANOS);
1001
+ }
1002
+ return temporal;
1003
+ }
1004
+
1005
+ //-----------------------------------------------------------------------
1006
+ /**
1007
+ * Gets the number of days in this duration.
1008
+ *
1009
+ * This returns the total number of days in the duration by dividing the
1010
+ * number of seconds by 86400.
1011
+ * This is based on the standard definition of a day as 24 hours.
1012
+ *
1013
+ * This instance is immutable and unaffected by this method call.
1014
+ *
1015
+ * @return {number} the number of days in the duration, may be negative
1016
+ */
1017
+ toDays() {
1018
+ return MathUtil.intDiv(this._seconds, LocalTime.SECONDS_PER_DAY);
1019
+ }
1020
+
1021
+ /**
1022
+ * Gets the number of hours in this duration.
1023
+ *
1024
+ * This returns the total number of hours in the duration by dividing the
1025
+ * number of seconds by 3600.
1026
+ *
1027
+ * This instance is immutable and unaffected by this method call.
1028
+ *
1029
+ * @return {number} the number of hours in the duration, may be negative
1030
+ */
1031
+ toHours() {
1032
+ return MathUtil.intDiv(this._seconds, LocalTime.SECONDS_PER_HOUR);
1033
+ }
1034
+
1035
+ /**
1036
+ * Gets the number of minutes in this duration.
1037
+ *
1038
+ * This returns the total number of minutes in the duration by dividing the
1039
+ * number of seconds by 60.
1040
+ *
1041
+ * This instance is immutable and unaffected by this method call.
1042
+ *
1043
+ * @return {number} the number of minutes in the duration, may be negative
1044
+ */
1045
+ toMinutes() {
1046
+ return MathUtil.intDiv(this._seconds, LocalTime.SECONDS_PER_MINUTE);
1047
+ }
1048
+
1049
+ /**
1050
+ * Converts this duration to the total length in milliseconds.
1051
+ *
1052
+ * If this duration is too large to fit in a `long` milliseconds, then an
1053
+ * exception is thrown.
1054
+ *
1055
+ * If this duration has greater than millisecond precision, then the conversion
1056
+ * will drop any excess precision information as though the amount in nanoseconds
1057
+ * was subject to integer division by one million.
1058
+ *
1059
+ * @return {number} the total length of the duration in milliseconds
1060
+ * @throws ArithmeticException if numeric overflow occurs
1061
+ */
1062
+ toMillis() {
1063
+ let millis = Math.round(MathUtil.safeMultiply(this._seconds, 1000));
1064
+ millis = MathUtil.safeAdd(millis, MathUtil.intDiv(this._nanos, 1000000));
1065
+ return millis;
1066
+ }
1067
+
1068
+ /**
1069
+ * Converts this duration to the total length in nanoseconds expressed as a `long`.
1070
+ *
1071
+ * If this duration is too large to fit in a `long` nanoseconds, then an
1072
+ * exception is thrown.
1073
+ *
1074
+ * @return {number} the total length of the duration in nanoseconds
1075
+ * @throws ArithmeticException if numeric overflow occurs
1076
+ */
1077
+ toNanos() {
1078
+ let totalNanos = MathUtil.safeMultiply(this._seconds, LocalTime.NANOS_PER_SECOND);
1079
+ totalNanos = MathUtil.safeAdd(totalNanos, this._nanos);
1080
+ return totalNanos;
1081
+ }
1082
+
1083
+ //-----------------------------------------------------------------------
1084
+ /**
1085
+ * Compares this duration to the specified {@link Duration}.
1086
+ *
1087
+ * The comparison is based on the total length of the durations.
1088
+ *
1089
+ * @param {Duration} otherDuration - the other duration to compare to, not null
1090
+ * @return {number} the comparator value, negative if less, positive if greater
1091
+ */
1092
+ compareTo(otherDuration) {
1093
+ requireNonNull(otherDuration, 'otherDuration');
1094
+ requireInstance(otherDuration, Duration, 'otherDuration');
1095
+ const cmp = MathUtil.compareNumbers(this._seconds, otherDuration.seconds());
1096
+ if (cmp !== 0) {
1097
+ return cmp;
1098
+ }
1099
+ return this._nanos - otherDuration.nano();
1100
+ }
1101
+
1102
+ //-----------------------------------------------------------------------
1103
+ /**
1104
+ * Checks if this duration is equal to the specified {@link Duration}.
1105
+ *
1106
+ * The comparison is based on the total length of the durations.
1107
+ *
1108
+ * @param {*} otherDuration - the other duration, null returns false
1109
+ * @return {boolean} true if the other duration is equal to this one
1110
+ */
1111
+ equals(otherDuration) {
1112
+ if (this === otherDuration) {
1113
+ return true;
1114
+ }
1115
+ if (otherDuration instanceof Duration) {
1116
+ return this.seconds() === otherDuration.seconds() &&
1117
+ this.nano() === otherDuration.nano();
1118
+ }
1119
+ return false;
1120
+ }
1121
+
1122
+ //-----------------------------------------------------------------------
1123
+ /**
1124
+ * A string representation of this duration using ISO-8601 seconds
1125
+ * based representation, such as {@link PT8H6M12.345S}.
1126
+ *
1127
+ * The format of the returned string will be {@link PTnHnMnS}, where n is
1128
+ * the relevant hours, minutes or seconds part of the duration.
1129
+ * Any fractional seconds are placed after a decimal point in the seconds section.
1130
+ * If a section has a zero value, it is omitted.
1131
+ * The hours, minutes and seconds will all have the same sign.
1132
+ *
1133
+ * Examples:
1134
+ * <pre>
1135
+ * "20.345 seconds" -> "PT20.345S
1136
+ * "15 minutes" (15 * 60 seconds) -> "PT15M"
1137
+ * "10 hours" (10 * 3600 seconds) -> "PT10H"
1138
+ * "2 days" (2 * 86400 seconds) -> "PT48H"
1139
+ * </pre>
1140
+ * Note that multiples of 24 hours are not output as days to avoid confusion
1141
+ * with {@link Period}.
1142
+ *
1143
+ * @return {string} an ISO-8601 representation of this duration, not null
1144
+ */
1145
+ toString() {
1146
+ if (this === Duration.ZERO) {
1147
+ return 'PT0S';
1148
+ }
1149
+ const hours = MathUtil.intDiv(this._seconds, LocalTime.SECONDS_PER_HOUR);
1150
+ const minutes = MathUtil.intDiv(MathUtil.intMod(this._seconds, LocalTime.SECONDS_PER_HOUR), LocalTime.SECONDS_PER_MINUTE);
1151
+ const secs = MathUtil.intMod(this._seconds, LocalTime.SECONDS_PER_MINUTE);
1152
+ let rval = 'PT';
1153
+ if (hours !== 0) {
1154
+ rval += hours + 'H';
1155
+ }
1156
+ if (minutes !== 0) {
1157
+ rval += minutes + 'M';
1158
+ }
1159
+ if (secs === 0 && this._nanos === 0 && rval.length > 2) {
1160
+ return rval;
1161
+ }
1162
+ if (secs < 0 && this._nanos > 0) {
1163
+ if (secs === -1) {
1164
+ rval += '-0';
1165
+ } else {
1166
+ rval += secs + 1;
1167
+ }
1168
+ } else {
1169
+ rval += secs;
1170
+ }
1171
+ if (this._nanos > 0) {
1172
+ rval += '.';
1173
+ let nanoString;
1174
+ if (secs < 0) {
1175
+ nanoString = '' + (2 * LocalTime.NANOS_PER_SECOND - this._nanos);
1176
+ } else {
1177
+ nanoString = '' + (LocalTime.NANOS_PER_SECOND + this._nanos);
1178
+ }
1179
+ // remove the leading '1'
1180
+ nanoString = nanoString.slice(1, nanoString.length);
1181
+ rval += nanoString;
1182
+ while (rval.charAt(rval.length - 1) === '0') {
1183
+ rval = rval.slice(0, rval.length - 1);
1184
+ }
1185
+ }
1186
+ rval += 'S';
1187
+ return rval;
1188
+ }
1189
+
1190
+ /**
1191
+ *
1192
+ * @return {string} same as {@link Duration.toString}
1193
+ */
1194
+ toJSON() {
1195
+ return this.toString();
1196
+ }
1197
+
1198
+ }
1199
+
1200
+ export function _init() {
1201
+ /**
1202
+ * Constant for a duration of zero.
1203
+ */
1204
+ Duration.ZERO = new Duration(0, 0);
1205
+ }