track-cli 3.0.0-rc

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 (224) hide show
  1. package/LICENSE +7 -0
  2. package/README.md +3 -0
  3. package/esm/_dnt.polyfills.d.ts +6 -0
  4. package/esm/_dnt.polyfills.js +1 -0
  5. package/esm/_dnt.shims.d.ts +19 -0
  6. package/esm/_dnt.shims.js +78 -0
  7. package/esm/deps/deno.land/std@0.170.0/fmt/colors.d.ts +270 -0
  8. package/esm/deps/deno.land/std@0.170.0/fmt/colors.js +473 -0
  9. package/esm/deps/deno.land/std@0.195.0/_util/os.d.ts +4 -0
  10. package/esm/deps/deno.land/std@0.195.0/_util/os.js +18 -0
  11. package/esm/deps/deno.land/std@0.195.0/assert/assert.d.ts +2 -0
  12. package/esm/deps/deno.land/std@0.195.0/assert/assert.js +8 -0
  13. package/esm/deps/deno.land/std@0.195.0/assert/assertion_error.d.ts +4 -0
  14. package/esm/deps/deno.land/std@0.195.0/assert/assertion_error.js +12 -0
  15. package/esm/deps/deno.land/std@0.195.0/datetime/_common.d.ts +50 -0
  16. package/esm/deps/deno.land/std@0.195.0/datetime/_common.js +545 -0
  17. package/esm/deps/deno.land/std@0.195.0/datetime/constants.d.ts +55 -0
  18. package/esm/deps/deno.land/std@0.195.0/datetime/constants.js +57 -0
  19. package/esm/deps/deno.land/std@0.195.0/datetime/day_of_year.d.ts +26 -0
  20. package/esm/deps/deno.land/std@0.195.0/datetime/day_of_year.js +45 -0
  21. package/esm/deps/deno.land/std@0.195.0/datetime/difference.d.ts +38 -0
  22. package/esm/deps/deno.land/std@0.195.0/datetime/difference.js +93 -0
  23. package/esm/deps/deno.land/std@0.195.0/datetime/format.d.ts +22 -0
  24. package/esm/deps/deno.land/std@0.195.0/datetime/format.js +28 -0
  25. package/esm/deps/deno.land/std@0.195.0/datetime/is_leap.d.ts +49 -0
  26. package/esm/deps/deno.land/std@0.195.0/datetime/is_leap.js +60 -0
  27. package/esm/deps/deno.land/std@0.195.0/datetime/mod.d.ts +43 -0
  28. package/esm/deps/deno.land/std@0.195.0/datetime/mod.js +45 -0
  29. package/esm/deps/deno.land/std@0.195.0/datetime/parse.d.ts +21 -0
  30. package/esm/deps/deno.land/std@0.195.0/datetime/parse.js +29 -0
  31. package/esm/deps/deno.land/std@0.195.0/datetime/to_imf.d.ts +17 -0
  32. package/esm/deps/deno.land/std@0.195.0/datetime/to_imf.js +44 -0
  33. package/esm/deps/deno.land/std@0.195.0/datetime/week_of_year.d.ts +13 -0
  34. package/esm/deps/deno.land/std@0.195.0/datetime/week_of_year.js +38 -0
  35. package/esm/deps/deno.land/std@0.195.0/fmt/colors.d.ts +270 -0
  36. package/esm/deps/deno.land/std@0.195.0/fmt/colors.js +474 -0
  37. package/esm/deps/deno.land/std@0.195.0/fmt/duration.d.ts +15 -0
  38. package/esm/deps/deno.land/std@0.195.0/fmt/duration.js +96 -0
  39. package/esm/deps/deno.land/std@0.195.0/fs/_util.d.ts +35 -0
  40. package/esm/deps/deno.land/std@0.195.0/fs/_util.js +80 -0
  41. package/esm/deps/deno.land/std@0.195.0/fs/copy.d.ts +51 -0
  42. package/esm/deps/deno.land/std@0.195.0/fs/copy.js +244 -0
  43. package/esm/deps/deno.land/std@0.195.0/fs/empty_dir.d.ts +31 -0
  44. package/esm/deps/deno.land/std@0.195.0/fs/empty_dir.js +74 -0
  45. package/esm/deps/deno.land/std@0.195.0/fs/ensure_dir.d.ts +27 -0
  46. package/esm/deps/deno.land/std@0.195.0/fs/ensure_dir.js +55 -0
  47. package/esm/deps/deno.land/std@0.195.0/fs/ensure_file.d.ts +33 -0
  48. package/esm/deps/deno.land/std@0.195.0/fs/ensure_file.js +75 -0
  49. package/esm/deps/deno.land/std@0.195.0/fs/ensure_link.d.ts +31 -0
  50. package/esm/deps/deno.land/std@0.195.0/fs/ensure_link.js +43 -0
  51. package/esm/deps/deno.land/std@0.195.0/fs/ensure_symlink.d.ts +17 -0
  52. package/esm/deps/deno.land/std@0.195.0/fs/ensure_symlink.js +68 -0
  53. package/esm/deps/deno.land/std@0.195.0/fs/eol.d.ts +40 -0
  54. package/esm/deps/deno.land/std@0.195.0/fs/eol.js +53 -0
  55. package/esm/deps/deno.land/std@0.195.0/fs/exists.d.ts +102 -0
  56. package/esm/deps/deno.land/std@0.195.0/fs/exists.js +163 -0
  57. package/esm/deps/deno.land/std@0.195.0/fs/expand_glob.d.ts +37 -0
  58. package/esm/deps/deno.land/std@0.195.0/fs/expand_glob.js +216 -0
  59. package/esm/deps/deno.land/std@0.195.0/fs/mod.d.ts +16 -0
  60. package/esm/deps/deno.land/std@0.195.0/fs/mod.js +17 -0
  61. package/esm/deps/deno.land/std@0.195.0/fs/move.d.ts +29 -0
  62. package/esm/deps/deno.land/std@0.195.0/fs/move.js +88 -0
  63. package/esm/deps/deno.land/std@0.195.0/fs/walk.d.ts +40 -0
  64. package/esm/deps/deno.land/std@0.195.0/fs/walk.js +158 -0
  65. package/esm/deps/deno.land/std@0.195.0/path/_constants.d.ts +39 -0
  66. package/esm/deps/deno.land/std@0.195.0/path/_constants.js +46 -0
  67. package/esm/deps/deno.land/std@0.195.0/path/_interface.d.ts +26 -0
  68. package/esm/deps/deno.land/std@0.195.0/path/_interface.js +3 -0
  69. package/esm/deps/deno.land/std@0.195.0/path/_util.d.ts +11 -0
  70. package/esm/deps/deno.land/std@0.195.0/path/_util.js +161 -0
  71. package/esm/deps/deno.land/std@0.195.0/path/common.d.ts +13 -0
  72. package/esm/deps/deno.land/std@0.195.0/path/common.js +36 -0
  73. package/esm/deps/deno.land/std@0.195.0/path/glob.d.ts +83 -0
  74. package/esm/deps/deno.land/std@0.195.0/path/glob.js +361 -0
  75. package/esm/deps/deno.land/std@0.195.0/path/mod.d.ts +9 -0
  76. package/esm/deps/deno.land/std@0.195.0/path/mod.js +33 -0
  77. package/esm/deps/deno.land/std@0.195.0/path/posix.d.ts +86 -0
  78. package/esm/deps/deno.land/std@0.195.0/path/posix.js +442 -0
  79. package/esm/deps/deno.land/std@0.195.0/path/separator.d.ts +2 -0
  80. package/esm/deps/deno.land/std@0.195.0/path/separator.js +5 -0
  81. package/esm/deps/deno.land/std@0.195.0/path/win32.d.ts +91 -0
  82. package/esm/deps/deno.land/std@0.195.0/path/win32.js +909 -0
  83. package/esm/deps/deno.land/x/cliffy@v0.25.7/_utils/distance.d.ts +1 -0
  84. package/esm/deps/deno.land/x/cliffy@v0.25.7/_utils/distance.js +26 -0
  85. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/_errors.d.ts +76 -0
  86. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/_errors.js +154 -0
  87. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/_utils.d.ts +32 -0
  88. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/_utils.js +105 -0
  89. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/command.d.ts +831 -0
  90. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/command.js +1701 -0
  91. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/_bash_completions_generator.d.ts +17 -0
  92. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/_bash_completions_generator.js +201 -0
  93. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/_fish_completions_generator.d.ts +14 -0
  94. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/_fish_completions_generator.js +141 -0
  95. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/_zsh_completions_generator.d.ts +21 -0
  96. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/_zsh_completions_generator.js +285 -0
  97. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/bash.d.ts +6 -0
  98. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/bash.js +38 -0
  99. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/complete.d.ts +8 -0
  100. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/complete.js +32 -0
  101. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/fish.d.ts +6 -0
  102. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/fish.js +38 -0
  103. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/mod.d.ts +6 -0
  104. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/mod.js +46 -0
  105. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/zsh.d.ts +6 -0
  106. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/zsh.js +38 -0
  107. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/deprecated.d.ts +45 -0
  108. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/deprecated.js +2 -0
  109. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/deps.d.ts +1 -0
  110. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/deps.js +1 -0
  111. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/help/_help_generator.d.ts +27 -0
  112. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/help/_help_generator.js +323 -0
  113. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/help/mod.d.ts +6 -0
  114. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/help/mod.js +34 -0
  115. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/mod.d.ts +18 -0
  116. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/mod.js +17 -0
  117. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/type.d.ts +41 -0
  118. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/type.js +24 -0
  119. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/action_list.d.ts +9 -0
  120. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/action_list.js +20 -0
  121. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/boolean.d.ts +9 -0
  122. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/boolean.js +13 -0
  123. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/child_command.d.ts +9 -0
  124. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/child_command.js +27 -0
  125. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/command.d.ts +7 -0
  126. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/command.js +9 -0
  127. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/enum.d.ts +10 -0
  128. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/enum.js +29 -0
  129. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/file.d.ts +5 -0
  130. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/file.js +12 -0
  131. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/integer.d.ts +7 -0
  132. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/integer.js +9 -0
  133. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/number.d.ts +7 -0
  134. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/number.js +9 -0
  135. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/string.d.ts +7 -0
  136. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/string.js +9 -0
  137. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types.d.ts +118 -0
  138. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types.js +2 -0
  139. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/mod.d.ts +5 -0
  140. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/mod.js +5 -0
  141. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/provider/deno_land.d.ts +14 -0
  142. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/provider/deno_land.js +46 -0
  143. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/provider/github.d.ts +26 -0
  144. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/provider/github.js +118 -0
  145. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/provider/nest_land.d.ts +14 -0
  146. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/provider/nest_land.js +55 -0
  147. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/provider.d.ts +27 -0
  148. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/provider.js +102 -0
  149. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/upgrade_command.d.ts +17 -0
  150. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/upgrade_command.js +75 -0
  151. package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/_errors.d.ts +60 -0
  152. package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/_errors.js +117 -0
  153. package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/_utils.d.ts +18 -0
  154. package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/_utils.js +106 -0
  155. package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/_validate_flags.d.ts +10 -0
  156. package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/_validate_flags.js +157 -0
  157. package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/deprecated.d.ts +24 -0
  158. package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/deprecated.js +9 -0
  159. package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/flags.d.ts +33 -0
  160. package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/flags.js +402 -0
  161. package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types/boolean.d.ts +3 -0
  162. package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types/boolean.js +11 -0
  163. package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types/integer.d.ts +3 -0
  164. package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types/integer.js +9 -0
  165. package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types/number.d.ts +3 -0
  166. package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types/number.js +9 -0
  167. package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types/string.d.ts +3 -0
  168. package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types/string.js +4 -0
  169. package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types.d.ts +59 -0
  170. package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types.js +1 -0
  171. package/esm/deps/deno.land/x/cliffy@v0.25.7/table/border.d.ts +20 -0
  172. package/esm/deps/deno.land/x/cliffy@v0.25.7/table/border.js +18 -0
  173. package/esm/deps/deno.land/x/cliffy@v0.25.7/table/cell.d.ts +78 -0
  174. package/esm/deps/deno.land/x/cliffy@v0.25.7/table/cell.js +128 -0
  175. package/esm/deps/deno.land/x/cliffy@v0.25.7/table/deps.d.ts +1 -0
  176. package/esm/deps/deno.land/x/cliffy@v0.25.7/table/deps.js +1 -0
  177. package/esm/deps/deno.land/x/cliffy@v0.25.7/table/layout.d.ts +99 -0
  178. package/esm/deps/deno.land/x/cliffy@v0.25.7/table/layout.js +529 -0
  179. package/esm/deps/deno.land/x/cliffy@v0.25.7/table/row.d.ts +49 -0
  180. package/esm/deps/deno.land/x/cliffy@v0.25.7/table/row.js +74 -0
  181. package/esm/deps/deno.land/x/cliffy@v0.25.7/table/table.d.ts +135 -0
  182. package/esm/deps/deno.land/x/cliffy@v0.25.7/table/table.js +237 -0
  183. package/esm/deps/deno.land/x/cliffy@v0.25.7/table/utils.d.ts +13 -0
  184. package/esm/deps/deno.land/x/cliffy@v0.25.7/table/utils.js +60 -0
  185. package/esm/package.json +3 -0
  186. package/esm/src/action/add.d.ts +1 -0
  187. package/esm/src/action/add.js +57 -0
  188. package/esm/src/action/clone.d.ts +6 -0
  189. package/esm/src/action/clone.js +108 -0
  190. package/esm/src/action/lang.d.ts +1 -0
  191. package/esm/src/action/lang.js +40 -0
  192. package/esm/src/action/pull.d.ts +1 -0
  193. package/esm/src/action/pull.js +22 -0
  194. package/esm/src/action/remove.d.ts +4 -0
  195. package/esm/src/action/remove.js +67 -0
  196. package/esm/src/action/reset.d.ts +1 -0
  197. package/esm/src/action/reset.js +21 -0
  198. package/esm/src/action/run.d.ts +4 -0
  199. package/esm/src/action/run.js +163 -0
  200. package/esm/src/action/status.d.ts +1 -0
  201. package/esm/src/action/status.js +5 -0
  202. package/esm/src/main.d.ts +2 -0
  203. package/esm/src/main.js +96 -0
  204. package/esm/src/meta.d.ts +3 -0
  205. package/esm/src/meta.js +51 -0
  206. package/esm/src/orca/client.d.ts +20 -0
  207. package/esm/src/orca/client.js +152 -0
  208. package/esm/src/orca/types.d.ts +54 -0
  209. package/esm/src/orca/types.js +12 -0
  210. package/esm/src/shared/config.d.ts +24 -0
  211. package/esm/src/shared/config.js +24 -0
  212. package/esm/src/shared/errors.d.ts +82 -0
  213. package/esm/src/shared/errors.js +228 -0
  214. package/esm/src/shared/file.d.ts +30 -0
  215. package/esm/src/shared/file.js +110 -0
  216. package/esm/src/shared/mod.d.ts +40 -0
  217. package/esm/src/shared/mod.js +383 -0
  218. package/esm/src/shared/types.d.ts +12 -0
  219. package/esm/src/shared/types.js +1 -0
  220. package/esm/src/track/client.d.ts +60 -0
  221. package/esm/src/track/client.js +268 -0
  222. package/esm/src/track/types.d.ts +210 -0
  223. package/esm/src/track/types.js +40 -0
  224. package/package.json +35 -0
@@ -0,0 +1,45 @@
1
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
2
+ // This module is browser compatible.
3
+ import { DAY } from "./constants.js";
4
+ /**
5
+ * Returns the number of the day in the year in the local time zone.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * import { dayOfYear } from "https://deno.land/std@$STD_VERSION/datetime/mod.ts";
10
+ *
11
+ * dayOfYear(new Date("2019-03-11T03:24:00")); // output: 70
12
+ * ```
13
+ *
14
+ * @return Number of the day in the year in the local time zone
15
+ */
16
+ export function dayOfYear(date) {
17
+ // Values from 0 to 99 map to the years 1900 to 1999. All other values are the actual year. (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date)
18
+ // Using setFullYear as a workaround
19
+ const yearStart = new Date(date);
20
+ yearStart.setFullYear(date.getFullYear(), 0, 0);
21
+ const diff = date.getTime() -
22
+ yearStart.getTime();
23
+ return Math.floor(diff / DAY);
24
+ }
25
+ /**
26
+ * Returns the number of the day in the year in UTC time.
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * import { dayOfYearUtc } from "https://deno.land/std@$STD_VERSION/datetime/mod.ts";
31
+ *
32
+ * dayOfYearUtc(new Date("2019-03-11T03:24:00.000Z")) // output 70
33
+ * ```
34
+ *
35
+ * @return Number of the day in the year in UTC time
36
+ */
37
+ export function dayOfYearUtc(date) {
38
+ // Values from 0 to 99 map to the years 1900 to 1999. All other values are the actual year. (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date)
39
+ // Using setUTCFullYear as a workaround
40
+ const yearStart = new Date(date);
41
+ yearStart.setUTCFullYear(date.getUTCFullYear(), 0, 0);
42
+ const diff = date.getTime() -
43
+ yearStart.getTime();
44
+ return Math.floor(diff / DAY);
45
+ }
@@ -0,0 +1,38 @@
1
+ export type Unit = "milliseconds" | "seconds" | "minutes" | "hours" | "days" | "weeks" | "months" | "quarters" | "years";
2
+ export type DifferenceFormat = Partial<Record<Unit, number>>;
3
+ export type DifferenceOptions = {
4
+ units?: Unit[];
5
+ };
6
+ /**
7
+ * Returns the difference of the 2 given dates in the given units. If the units
8
+ * are omitted, it returns the difference in the all available units.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * import { difference } from "https://deno.land/std@$STD_VERSION/datetime/difference.ts";
13
+ *
14
+ * const date0 = new Date("2018-05-14");
15
+ * const date1 = new Date("2020-05-13");
16
+ *
17
+ * difference(date0, date1, { units: ["days", "months", "years"] });
18
+ * // => returns { days: 730, months: 23, years: 1 }
19
+ *
20
+ * difference(date0, date1);
21
+ * // => returns {
22
+ * // milliseconds: 63072000000,
23
+ * // seconds: 63072000,
24
+ * // minutes: 1051200,
25
+ * // hours: 17520,
26
+ * // days: 730,
27
+ * // weeks: 104,
28
+ * // months: 23,
29
+ * // quarters: 7,
30
+ * // years: 1
31
+ * // }
32
+ * ```
33
+ *
34
+ * @param from Year to calculate difference
35
+ * @param to Year to calculate difference with
36
+ * @param options Options for determining how to respond
37
+ */
38
+ export declare function difference(from: Date, to: Date, options?: DifferenceOptions): DifferenceFormat;
@@ -0,0 +1,93 @@
1
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
2
+ // This module is browser compatible.
3
+ import { DAY, HOUR, MINUTE, SECOND, WEEK } from "./constants.js";
4
+ function calculateMonthsDifference(from, to) {
5
+ let months = (to.getFullYear() - from.getFullYear()) * 12 +
6
+ (to.getMonth() - from.getMonth());
7
+ if (to.getDate() < from.getDate()) {
8
+ months--;
9
+ }
10
+ return months;
11
+ }
12
+ /**
13
+ * Returns the difference of the 2 given dates in the given units. If the units
14
+ * are omitted, it returns the difference in the all available units.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * import { difference } from "https://deno.land/std@$STD_VERSION/datetime/difference.ts";
19
+ *
20
+ * const date0 = new Date("2018-05-14");
21
+ * const date1 = new Date("2020-05-13");
22
+ *
23
+ * difference(date0, date1, { units: ["days", "months", "years"] });
24
+ * // => returns { days: 730, months: 23, years: 1 }
25
+ *
26
+ * difference(date0, date1);
27
+ * // => returns {
28
+ * // milliseconds: 63072000000,
29
+ * // seconds: 63072000,
30
+ * // minutes: 1051200,
31
+ * // hours: 17520,
32
+ * // days: 730,
33
+ * // weeks: 104,
34
+ * // months: 23,
35
+ * // quarters: 7,
36
+ * // years: 1
37
+ * // }
38
+ * ```
39
+ *
40
+ * @param from Year to calculate difference
41
+ * @param to Year to calculate difference with
42
+ * @param options Options for determining how to respond
43
+ */
44
+ export function difference(from, to, options) {
45
+ [from, to] = from < to ? [from, to] : [to, from];
46
+ const uniqueUnits = options?.units ? [...new Set(options?.units)] : [
47
+ "milliseconds",
48
+ "seconds",
49
+ "minutes",
50
+ "hours",
51
+ "days",
52
+ "weeks",
53
+ "months",
54
+ "quarters",
55
+ "years",
56
+ ];
57
+ const differenceInMs = Math.abs(from.getTime() - to.getTime());
58
+ const differences = {};
59
+ for (const uniqueUnit of uniqueUnits) {
60
+ switch (uniqueUnit) {
61
+ case "milliseconds":
62
+ differences.milliseconds = differenceInMs;
63
+ break;
64
+ case "seconds":
65
+ differences.seconds = Math.floor(differenceInMs / SECOND);
66
+ break;
67
+ case "minutes":
68
+ differences.minutes = Math.floor(differenceInMs / MINUTE);
69
+ break;
70
+ case "hours":
71
+ differences.hours = Math.floor(differenceInMs / HOUR);
72
+ break;
73
+ case "days":
74
+ differences.days = Math.floor(differenceInMs / DAY);
75
+ break;
76
+ case "weeks":
77
+ differences.weeks = Math.floor(differenceInMs / WEEK);
78
+ break;
79
+ case "months":
80
+ differences.months = calculateMonthsDifference(from, to);
81
+ break;
82
+ case "quarters":
83
+ differences.quarters = Math.floor((differences.months !== undefined && differences.months / 3) ||
84
+ calculateMonthsDifference(from, to) / 3);
85
+ break;
86
+ case "years":
87
+ differences.years = Math.floor((differences.months !== undefined && differences.months / 12) ||
88
+ calculateMonthsDifference(from, to) / 12);
89
+ break;
90
+ }
91
+ }
92
+ return differences;
93
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Takes an input `date` and a `formatString` to format to a `string`.
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * import { format } from "https://deno.land/std@$STD_VERSION/datetime/format.ts";
7
+ *
8
+ * format(new Date(2019, 0, 20), "dd-MM-yyyy"); // output : "20-01-2019"
9
+ * format(new Date(2019, 0, 20), "yyyy-MM-dd"); // output : "2019-01-20"
10
+ * format(new Date(2019, 0, 20), "dd.MM.yyyy"); // output : "20.01.2019"
11
+ * format(new Date(2019, 0, 20, 16, 34), "MM-dd-yyyy HH:mm"); // output : "01-20-2019 16:34"
12
+ * format(new Date(2019, 0, 20, 16, 34), "MM-dd-yyyy hh:mm a"); // output : "01-20-2019 04:34 PM"
13
+ * format(new Date(2019, 0, 20, 16, 34), "HH:mm MM-dd-yyyy"); // output : "16:34 01-20-2019"
14
+ * format(new Date(2019, 0, 20, 16, 34, 23, 123), "MM-dd-yyyy HH:mm:ss.SSS"); // output : "01-20-2019 16:34:23.123"
15
+ * format(new Date(2019, 0, 20), "'today:' yyyy-MM-dd"); // output : "today: 2019-01-20"
16
+ * ```
17
+ *
18
+ * @param date Date
19
+ * @param formatString Format string
20
+ * @return formatted date string
21
+ */
22
+ export declare function format(date: Date, formatString: string): string;
@@ -0,0 +1,28 @@
1
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
2
+ // This module is browser compatible.
3
+ import { DateTimeFormatter } from "./_common.js";
4
+ /**
5
+ * Takes an input `date` and a `formatString` to format to a `string`.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * import { format } from "https://deno.land/std@$STD_VERSION/datetime/format.ts";
10
+ *
11
+ * format(new Date(2019, 0, 20), "dd-MM-yyyy"); // output : "20-01-2019"
12
+ * format(new Date(2019, 0, 20), "yyyy-MM-dd"); // output : "2019-01-20"
13
+ * format(new Date(2019, 0, 20), "dd.MM.yyyy"); // output : "20.01.2019"
14
+ * format(new Date(2019, 0, 20, 16, 34), "MM-dd-yyyy HH:mm"); // output : "01-20-2019 16:34"
15
+ * format(new Date(2019, 0, 20, 16, 34), "MM-dd-yyyy hh:mm a"); // output : "01-20-2019 04:34 PM"
16
+ * format(new Date(2019, 0, 20, 16, 34), "HH:mm MM-dd-yyyy"); // output : "16:34 01-20-2019"
17
+ * format(new Date(2019, 0, 20, 16, 34, 23, 123), "MM-dd-yyyy HH:mm:ss.SSS"); // output : "01-20-2019 16:34:23.123"
18
+ * format(new Date(2019, 0, 20), "'today:' yyyy-MM-dd"); // output : "today: 2019-01-20"
19
+ * ```
20
+ *
21
+ * @param date Date
22
+ * @param formatString Format string
23
+ * @return formatted date string
24
+ */
25
+ export function format(date, formatString) {
26
+ const formatter = new DateTimeFormatter(formatString);
27
+ return formatter.format(date);
28
+ }
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Returns whether the given date or year (in number) is a leap year or not in the local time zone.
3
+ * based on: https://docs.microsoft.com/en-us/office/troubleshoot/excel/determine-a-leap-year
4
+ *
5
+ * @example
6
+ * ```ts
7
+ * import { isLeap } from "https://deno.land/std@$STD_VERSION/datetime/is_leap.ts";
8
+ *
9
+ * isLeap(new Date("1970-01-02")); // => returns false
10
+ * isLeap(new Date("1972-01-02")); // => returns true
11
+ * isLeap(new Date("2000-01-02")); // => returns true
12
+ * isLeap(new Date("2100-01-02")); // => returns false
13
+ * isLeap(1972); // => returns true
14
+ * ```
15
+ *
16
+ * Some dates may return different values depending on your timezone.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * import { isLeap } from "https://deno.land/std@$STD_VERSION/datetime/is_leap.ts";
21
+ *
22
+ * isLeap(new Date("2000-01-01")); // => returns true if the local timezone is GMT+0, returns false if the local timezone is GMT-1
23
+ * isLeap(2000); // => returns true regardless of the local timezone
24
+ * ```
25
+ *
26
+ * @param year year in number or Date format
27
+ */
28
+ export declare function isLeap(year: Date | number): boolean;
29
+ /**
30
+ * Returns whether the given date or year (in number) is a leap year or not in UTC time. This always returns the same value regardless of the local timezone.
31
+ * based on: https://docs.microsoft.com/en-us/office/troubleshoot/excel/determine-a-leap-year
32
+ *
33
+ * @example
34
+ * ```ts
35
+ * import { isUtcLeap } from "https://deno.land/std@$STD_VERSION/datetime/is_leap.ts";
36
+ *
37
+ * isUtcLeap(2000); // => returns true regardless of the local timezone
38
+ * isUtcLeap(new Date("2000-01-01")); // => returns true regardless of the local timezone
39
+ * isUtcLeap(new Date("January 1, 2000 00:00:00 GMT+00:00")); // => returns true regardless of the local timezone
40
+ * isUtcLeap(new Date("December 31, 2000 23:59:59 GMT+00:00")); // => returns true regardless of the local timezone
41
+ * isUtcLeap(new Date("January 1, 2000 00:00:00 GMT+01:00")); // => returns false regardless of the local timezone
42
+ * isUtcLeap(new Date("December 31, 2000 23:59:59 GMT-01:00")); // => returns false regardless of the local timezone
43
+ * isUtcLeap(new Date("January 1, 2001 00:00:00 GMT+01:00")); // => returns true regardless of the local timezone
44
+ * isUtcLeap(new Date("December 31, 1999 23:59:59 GMT-01:00")); // => returns true regardless of the local timezone
45
+ * ```
46
+ *
47
+ * @param year year in number or Date format
48
+ */
49
+ export declare function isUtcLeap(year: Date | number): boolean;
@@ -0,0 +1,60 @@
1
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
2
+ // This module is browser compatible.
3
+ /**
4
+ * Returns whether the given date or year (in number) is a leap year or not in the local time zone.
5
+ * based on: https://docs.microsoft.com/en-us/office/troubleshoot/excel/determine-a-leap-year
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * import { isLeap } from "https://deno.land/std@$STD_VERSION/datetime/is_leap.ts";
10
+ *
11
+ * isLeap(new Date("1970-01-02")); // => returns false
12
+ * isLeap(new Date("1972-01-02")); // => returns true
13
+ * isLeap(new Date("2000-01-02")); // => returns true
14
+ * isLeap(new Date("2100-01-02")); // => returns false
15
+ * isLeap(1972); // => returns true
16
+ * ```
17
+ *
18
+ * Some dates may return different values depending on your timezone.
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * import { isLeap } from "https://deno.land/std@$STD_VERSION/datetime/is_leap.ts";
23
+ *
24
+ * isLeap(new Date("2000-01-01")); // => returns true if the local timezone is GMT+0, returns false if the local timezone is GMT-1
25
+ * isLeap(2000); // => returns true regardless of the local timezone
26
+ * ```
27
+ *
28
+ * @param year year in number or Date format
29
+ */
30
+ export function isLeap(year) {
31
+ const yearNumber = year instanceof Date ? year.getFullYear() : year;
32
+ return isYearNumberALeapYear(yearNumber);
33
+ }
34
+ /**
35
+ * Returns whether the given date or year (in number) is a leap year or not in UTC time. This always returns the same value regardless of the local timezone.
36
+ * based on: https://docs.microsoft.com/en-us/office/troubleshoot/excel/determine-a-leap-year
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * import { isUtcLeap } from "https://deno.land/std@$STD_VERSION/datetime/is_leap.ts";
41
+ *
42
+ * isUtcLeap(2000); // => returns true regardless of the local timezone
43
+ * isUtcLeap(new Date("2000-01-01")); // => returns true regardless of the local timezone
44
+ * isUtcLeap(new Date("January 1, 2000 00:00:00 GMT+00:00")); // => returns true regardless of the local timezone
45
+ * isUtcLeap(new Date("December 31, 2000 23:59:59 GMT+00:00")); // => returns true regardless of the local timezone
46
+ * isUtcLeap(new Date("January 1, 2000 00:00:00 GMT+01:00")); // => returns false regardless of the local timezone
47
+ * isUtcLeap(new Date("December 31, 2000 23:59:59 GMT-01:00")); // => returns false regardless of the local timezone
48
+ * isUtcLeap(new Date("January 1, 2001 00:00:00 GMT+01:00")); // => returns true regardless of the local timezone
49
+ * isUtcLeap(new Date("December 31, 1999 23:59:59 GMT-01:00")); // => returns true regardless of the local timezone
50
+ * ```
51
+ *
52
+ * @param year year in number or Date format
53
+ */
54
+ export function isUtcLeap(year) {
55
+ const yearNumber = year instanceof Date ? year.getUTCFullYear() : year;
56
+ return isYearNumberALeapYear(yearNumber);
57
+ }
58
+ function isYearNumberALeapYear(yearNumber) {
59
+ return ((yearNumber % 4 === 0 && yearNumber % 100 !== 0) || yearNumber % 400 === 0);
60
+ }
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Utilities for dealing with {@linkcode Date} objects.
3
+ *
4
+ * The following symbols from
5
+ * [unicode LDML](http://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table)
6
+ * are supported:
7
+ *
8
+ * - `yyyy` - numeric year.
9
+ * - `yy` - 2-digit year.
10
+ * - `M` - numeric month.
11
+ * - `MM` - 2-digit month.
12
+ * - `d` - numeric day.
13
+ * - `dd` - 2-digit day.
14
+ *
15
+ * - `H` - numeric hour (0-23 hours).
16
+ * - `HH` - 2-digit hour (00-23 hours).
17
+ * - `h` - numeric hour (1-12 hours).
18
+ * - `hh` - 2-digit hour (01-12 hours).
19
+ * - `m` - numeric minute.
20
+ * - `mm` - 2-digit minute.
21
+ * - `s` - numeric second.
22
+ * - `ss` - 2-digit second.
23
+ * - `S` - 1-digit fractionalSecond.
24
+ * - `SS` - 2-digit fractionalSecond.
25
+ * - `SSS` - 3-digit fractionalSecond.
26
+ *
27
+ * - `a` - dayPeriod, either `AM` or `PM`.
28
+ *
29
+ * - `'foo'` - quoted literal.
30
+ * - `./-` - unquoted literal.
31
+ *
32
+ * This module is browser compatible.
33
+ *
34
+ * @module
35
+ */
36
+ export * from "./constants.js";
37
+ export * from "./day_of_year.js";
38
+ export * from "./difference.js";
39
+ export * from "./format.js";
40
+ export * from "./is_leap.js";
41
+ export * from "./parse.js";
42
+ export * from "./to_imf.js";
43
+ export * from "./week_of_year.js";
@@ -0,0 +1,45 @@
1
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
2
+ // This module is browser compatible.
3
+ /**
4
+ * Utilities for dealing with {@linkcode Date} objects.
5
+ *
6
+ * The following symbols from
7
+ * [unicode LDML](http://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table)
8
+ * are supported:
9
+ *
10
+ * - `yyyy` - numeric year.
11
+ * - `yy` - 2-digit year.
12
+ * - `M` - numeric month.
13
+ * - `MM` - 2-digit month.
14
+ * - `d` - numeric day.
15
+ * - `dd` - 2-digit day.
16
+ *
17
+ * - `H` - numeric hour (0-23 hours).
18
+ * - `HH` - 2-digit hour (00-23 hours).
19
+ * - `h` - numeric hour (1-12 hours).
20
+ * - `hh` - 2-digit hour (01-12 hours).
21
+ * - `m` - numeric minute.
22
+ * - `mm` - 2-digit minute.
23
+ * - `s` - numeric second.
24
+ * - `ss` - 2-digit second.
25
+ * - `S` - 1-digit fractionalSecond.
26
+ * - `SS` - 2-digit fractionalSecond.
27
+ * - `SSS` - 3-digit fractionalSecond.
28
+ *
29
+ * - `a` - dayPeriod, either `AM` or `PM`.
30
+ *
31
+ * - `'foo'` - quoted literal.
32
+ * - `./-` - unquoted literal.
33
+ *
34
+ * This module is browser compatible.
35
+ *
36
+ * @module
37
+ */
38
+ export * from "./constants.js";
39
+ export * from "./day_of_year.js";
40
+ export * from "./difference.js";
41
+ export * from "./format.js";
42
+ export * from "./is_leap.js";
43
+ export * from "./parse.js";
44
+ export * from "./to_imf.js";
45
+ export * from "./week_of_year.js";
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Takes an input `string` and a `formatString` to parse to a `date`.
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * import { parse } from "https://deno.land/std@$STD_VERSION/datetime/parse.ts";
7
+ *
8
+ * parse("20-01-2019", "dd-MM-yyyy"); // output : new Date(2019, 0, 20)
9
+ * parse("2019-01-20", "yyyy-MM-dd"); // output : new Date(2019, 0, 20)
10
+ * parse("20.01.2019", "dd.MM.yyyy"); // output : new Date(2019, 0, 20)
11
+ * parse("01-20-2019 16:34", "MM-dd-yyyy HH:mm"); // output : new Date(2019, 0, 20, 16, 34)
12
+ * parse("01-20-2019 04:34 PM", "MM-dd-yyyy hh:mm a"); // output : new Date(2019, 0, 20, 16, 34)
13
+ * parse("16:34 01-20-2019", "HH:mm MM-dd-yyyy"); // output : new Date(2019, 0, 20, 16, 34)
14
+ * parse("01-20-2019 16:34:23.123", "MM-dd-yyyy HH:mm:ss.SSS"); // output : new Date(2019, 0, 20, 16, 34, 23, 123)
15
+ * ```
16
+ *
17
+ * @param dateString Date string
18
+ * @param formatString Format string
19
+ * @return Parsed date
20
+ */
21
+ export declare function parse(dateString: string, formatString: string): Date;
@@ -0,0 +1,29 @@
1
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
2
+ // This module is browser compatible.
3
+ import { DateTimeFormatter } from "./_common.js";
4
+ /**
5
+ * Takes an input `string` and a `formatString` to parse to a `date`.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * import { parse } from "https://deno.land/std@$STD_VERSION/datetime/parse.ts";
10
+ *
11
+ * parse("20-01-2019", "dd-MM-yyyy"); // output : new Date(2019, 0, 20)
12
+ * parse("2019-01-20", "yyyy-MM-dd"); // output : new Date(2019, 0, 20)
13
+ * parse("20.01.2019", "dd.MM.yyyy"); // output : new Date(2019, 0, 20)
14
+ * parse("01-20-2019 16:34", "MM-dd-yyyy HH:mm"); // output : new Date(2019, 0, 20, 16, 34)
15
+ * parse("01-20-2019 04:34 PM", "MM-dd-yyyy hh:mm a"); // output : new Date(2019, 0, 20, 16, 34)
16
+ * parse("16:34 01-20-2019", "HH:mm MM-dd-yyyy"); // output : new Date(2019, 0, 20, 16, 34)
17
+ * parse("01-20-2019 16:34:23.123", "MM-dd-yyyy HH:mm:ss.SSS"); // output : new Date(2019, 0, 20, 16, 34, 23, 123)
18
+ * ```
19
+ *
20
+ * @param dateString Date string
21
+ * @param formatString Format string
22
+ * @return Parsed date
23
+ */
24
+ export function parse(dateString, formatString) {
25
+ const formatter = new DateTimeFormatter(formatString);
26
+ const parts = formatter.parseToParts(dateString);
27
+ const sortParts = formatter.sortDateTimeFormatPart(parts);
28
+ return formatter.partsToDate(sortParts);
29
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Formats the given date to IMF date time format. (Reference:
3
+ * https://tools.ietf.org/html/rfc7231#section-7.1.1.1).
4
+ * IMF is the time format to use when generating times in HTTP
5
+ * headers. The time being formatted must be in UTC for Format to
6
+ * generate the correct format.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * import { toIMF } from "https://deno.land/std@$STD_VERSION/datetime/to_imf.ts";
11
+ *
12
+ * toIMF(new Date(0)); // => returns "Thu, 01 Jan 1970 00:00:00 GMT"
13
+ * ```
14
+ * @param date Date to parse
15
+ * @return IMF date formatted string
16
+ */
17
+ export declare function toIMF(date: Date): string;
@@ -0,0 +1,44 @@
1
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
2
+ // This module is browser compatible.
3
+ /**
4
+ * Formats the given date to IMF date time format. (Reference:
5
+ * https://tools.ietf.org/html/rfc7231#section-7.1.1.1).
6
+ * IMF is the time format to use when generating times in HTTP
7
+ * headers. The time being formatted must be in UTC for Format to
8
+ * generate the correct format.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * import { toIMF } from "https://deno.land/std@$STD_VERSION/datetime/to_imf.ts";
13
+ *
14
+ * toIMF(new Date(0)); // => returns "Thu, 01 Jan 1970 00:00:00 GMT"
15
+ * ```
16
+ * @param date Date to parse
17
+ * @return IMF date formatted string
18
+ */
19
+ export function toIMF(date) {
20
+ function dtPad(v, lPad = 2) {
21
+ return v.padStart(lPad, "0");
22
+ }
23
+ const d = dtPad(date.getUTCDate().toString());
24
+ const h = dtPad(date.getUTCHours().toString());
25
+ const min = dtPad(date.getUTCMinutes().toString());
26
+ const s = dtPad(date.getUTCSeconds().toString());
27
+ const y = date.getUTCFullYear();
28
+ const days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
29
+ const months = [
30
+ "Jan",
31
+ "Feb",
32
+ "Mar",
33
+ "Apr",
34
+ "May",
35
+ "Jun",
36
+ "Jul",
37
+ "Aug",
38
+ "Sep",
39
+ "Oct",
40
+ "Nov",
41
+ "Dec",
42
+ ];
43
+ return `${days[date.getUTCDay()]}, ${d} ${months[date.getUTCMonth()]} ${y} ${h}:${min}:${s} GMT`;
44
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Returns the ISO week number of the provided date (1-53).
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * import { weekOfYear } from "https://deno.land/std@$STD_VERSION/datetime/week_of_year.ts";
7
+ *
8
+ * weekOfYear(new Date("2020-12-28T03:24:00")); // Returns 53
9
+ * ```
10
+ *
11
+ * @return Number of the week in year
12
+ */
13
+ export declare function weekOfYear(date: Date): number;
@@ -0,0 +1,38 @@
1
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
2
+ // This module is browser compatible.
3
+ import { DAY, WEEK } from "./constants.js";
4
+ const DAYS_PER_WEEK = 7;
5
+ var Day;
6
+ (function (Day) {
7
+ Day[Day["Sun"] = 0] = "Sun";
8
+ Day[Day["Mon"] = 1] = "Mon";
9
+ Day[Day["Tue"] = 2] = "Tue";
10
+ Day[Day["Wed"] = 3] = "Wed";
11
+ Day[Day["Thu"] = 4] = "Thu";
12
+ Day[Day["Fri"] = 5] = "Fri";
13
+ Day[Day["Sat"] = 6] = "Sat";
14
+ })(Day || (Day = {}));
15
+ /**
16
+ * Returns the ISO week number of the provided date (1-53).
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * import { weekOfYear } from "https://deno.land/std@$STD_VERSION/datetime/week_of_year.ts";
21
+ *
22
+ * weekOfYear(new Date("2020-12-28T03:24:00")); // Returns 53
23
+ * ```
24
+ *
25
+ * @return Number of the week in year
26
+ */
27
+ export function weekOfYear(date) {
28
+ const workingDate = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
29
+ const day = workingDate.getUTCDay();
30
+ const nearestThursday = workingDate.getUTCDate() +
31
+ Day.Thu -
32
+ (day === Day.Sun ? DAYS_PER_WEEK : day);
33
+ workingDate.setUTCDate(nearestThursday);
34
+ // Get first day of year
35
+ const yearStart = new Date(Date.UTC(workingDate.getUTCFullYear(), 0, 1));
36
+ // return the calculated full weeks to nearest Thursday
37
+ return Math.ceil((workingDate.getTime() - yearStart.getTime() + DAY) / WEEK);
38
+ }