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.
- package/LICENSE +7 -0
- package/README.md +3 -0
- package/esm/_dnt.polyfills.d.ts +6 -0
- package/esm/_dnt.polyfills.js +1 -0
- package/esm/_dnt.shims.d.ts +19 -0
- package/esm/_dnt.shims.js +78 -0
- package/esm/deps/deno.land/std@0.170.0/fmt/colors.d.ts +270 -0
- package/esm/deps/deno.land/std@0.170.0/fmt/colors.js +473 -0
- package/esm/deps/deno.land/std@0.195.0/_util/os.d.ts +4 -0
- package/esm/deps/deno.land/std@0.195.0/_util/os.js +18 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert.d.ts +2 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert.js +8 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assertion_error.d.ts +4 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assertion_error.js +12 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/_common.d.ts +50 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/_common.js +545 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/constants.d.ts +55 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/constants.js +57 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/day_of_year.d.ts +26 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/day_of_year.js +45 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/difference.d.ts +38 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/difference.js +93 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/format.d.ts +22 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/format.js +28 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/is_leap.d.ts +49 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/is_leap.js +60 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/mod.d.ts +43 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/mod.js +45 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/parse.d.ts +21 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/parse.js +29 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/to_imf.d.ts +17 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/to_imf.js +44 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/week_of_year.d.ts +13 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/week_of_year.js +38 -0
- package/esm/deps/deno.land/std@0.195.0/fmt/colors.d.ts +270 -0
- package/esm/deps/deno.land/std@0.195.0/fmt/colors.js +474 -0
- package/esm/deps/deno.land/std@0.195.0/fmt/duration.d.ts +15 -0
- package/esm/deps/deno.land/std@0.195.0/fmt/duration.js +96 -0
- package/esm/deps/deno.land/std@0.195.0/fs/_util.d.ts +35 -0
- package/esm/deps/deno.land/std@0.195.0/fs/_util.js +80 -0
- package/esm/deps/deno.land/std@0.195.0/fs/copy.d.ts +51 -0
- package/esm/deps/deno.land/std@0.195.0/fs/copy.js +244 -0
- package/esm/deps/deno.land/std@0.195.0/fs/empty_dir.d.ts +31 -0
- package/esm/deps/deno.land/std@0.195.0/fs/empty_dir.js +74 -0
- package/esm/deps/deno.land/std@0.195.0/fs/ensure_dir.d.ts +27 -0
- package/esm/deps/deno.land/std@0.195.0/fs/ensure_dir.js +55 -0
- package/esm/deps/deno.land/std@0.195.0/fs/ensure_file.d.ts +33 -0
- package/esm/deps/deno.land/std@0.195.0/fs/ensure_file.js +75 -0
- package/esm/deps/deno.land/std@0.195.0/fs/ensure_link.d.ts +31 -0
- package/esm/deps/deno.land/std@0.195.0/fs/ensure_link.js +43 -0
- package/esm/deps/deno.land/std@0.195.0/fs/ensure_symlink.d.ts +17 -0
- package/esm/deps/deno.land/std@0.195.0/fs/ensure_symlink.js +68 -0
- package/esm/deps/deno.land/std@0.195.0/fs/eol.d.ts +40 -0
- package/esm/deps/deno.land/std@0.195.0/fs/eol.js +53 -0
- package/esm/deps/deno.land/std@0.195.0/fs/exists.d.ts +102 -0
- package/esm/deps/deno.land/std@0.195.0/fs/exists.js +163 -0
- package/esm/deps/deno.land/std@0.195.0/fs/expand_glob.d.ts +37 -0
- package/esm/deps/deno.land/std@0.195.0/fs/expand_glob.js +216 -0
- package/esm/deps/deno.land/std@0.195.0/fs/mod.d.ts +16 -0
- package/esm/deps/deno.land/std@0.195.0/fs/mod.js +17 -0
- package/esm/deps/deno.land/std@0.195.0/fs/move.d.ts +29 -0
- package/esm/deps/deno.land/std@0.195.0/fs/move.js +88 -0
- package/esm/deps/deno.land/std@0.195.0/fs/walk.d.ts +40 -0
- package/esm/deps/deno.land/std@0.195.0/fs/walk.js +158 -0
- package/esm/deps/deno.land/std@0.195.0/path/_constants.d.ts +39 -0
- package/esm/deps/deno.land/std@0.195.0/path/_constants.js +46 -0
- package/esm/deps/deno.land/std@0.195.0/path/_interface.d.ts +26 -0
- package/esm/deps/deno.land/std@0.195.0/path/_interface.js +3 -0
- package/esm/deps/deno.land/std@0.195.0/path/_util.d.ts +11 -0
- package/esm/deps/deno.land/std@0.195.0/path/_util.js +161 -0
- package/esm/deps/deno.land/std@0.195.0/path/common.d.ts +13 -0
- package/esm/deps/deno.land/std@0.195.0/path/common.js +36 -0
- package/esm/deps/deno.land/std@0.195.0/path/glob.d.ts +83 -0
- package/esm/deps/deno.land/std@0.195.0/path/glob.js +361 -0
- package/esm/deps/deno.land/std@0.195.0/path/mod.d.ts +9 -0
- package/esm/deps/deno.land/std@0.195.0/path/mod.js +33 -0
- package/esm/deps/deno.land/std@0.195.0/path/posix.d.ts +86 -0
- package/esm/deps/deno.land/std@0.195.0/path/posix.js +442 -0
- package/esm/deps/deno.land/std@0.195.0/path/separator.d.ts +2 -0
- package/esm/deps/deno.land/std@0.195.0/path/separator.js +5 -0
- package/esm/deps/deno.land/std@0.195.0/path/win32.d.ts +91 -0
- package/esm/deps/deno.land/std@0.195.0/path/win32.js +909 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/_utils/distance.d.ts +1 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/_utils/distance.js +26 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/_errors.d.ts +76 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/_errors.js +154 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/_utils.d.ts +32 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/_utils.js +105 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/command.d.ts +831 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/command.js +1701 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/_bash_completions_generator.d.ts +17 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/_bash_completions_generator.js +201 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/_fish_completions_generator.d.ts +14 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/_fish_completions_generator.js +141 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/_zsh_completions_generator.d.ts +21 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/_zsh_completions_generator.js +285 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/bash.d.ts +6 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/bash.js +38 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/complete.d.ts +8 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/complete.js +32 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/fish.d.ts +6 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/fish.js +38 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/mod.d.ts +6 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/mod.js +46 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/zsh.d.ts +6 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/zsh.js +38 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/deprecated.d.ts +45 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/deprecated.js +2 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/deps.d.ts +1 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/deps.js +1 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/help/_help_generator.d.ts +27 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/help/_help_generator.js +323 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/help/mod.d.ts +6 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/help/mod.js +34 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/mod.d.ts +18 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/mod.js +17 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/type.d.ts +41 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/type.js +24 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/action_list.d.ts +9 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/action_list.js +20 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/boolean.d.ts +9 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/boolean.js +13 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/child_command.d.ts +9 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/child_command.js +27 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/command.d.ts +7 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/command.js +9 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/enum.d.ts +10 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/enum.js +29 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/file.d.ts +5 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/file.js +12 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/integer.d.ts +7 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/integer.js +9 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/number.d.ts +7 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/number.js +9 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/string.d.ts +7 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/string.js +9 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types.d.ts +118 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types.js +2 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/mod.d.ts +5 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/mod.js +5 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/provider/deno_land.d.ts +14 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/provider/deno_land.js +46 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/provider/github.d.ts +26 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/provider/github.js +118 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/provider/nest_land.d.ts +14 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/provider/nest_land.js +55 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/provider.d.ts +27 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/provider.js +102 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/upgrade_command.d.ts +17 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/upgrade_command.js +75 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/_errors.d.ts +60 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/_errors.js +117 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/_utils.d.ts +18 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/_utils.js +106 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/_validate_flags.d.ts +10 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/_validate_flags.js +157 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/deprecated.d.ts +24 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/deprecated.js +9 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/flags.d.ts +33 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/flags.js +402 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types/boolean.d.ts +3 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types/boolean.js +11 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types/integer.d.ts +3 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types/integer.js +9 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types/number.d.ts +3 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types/number.js +9 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types/string.d.ts +3 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types/string.js +4 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types.d.ts +59 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types.js +1 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/border.d.ts +20 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/border.js +18 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/cell.d.ts +78 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/cell.js +128 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/deps.d.ts +1 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/deps.js +1 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/layout.d.ts +99 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/layout.js +529 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/row.d.ts +49 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/row.js +74 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/table.d.ts +135 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/table.js +237 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/utils.d.ts +13 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/utils.js +60 -0
- package/esm/package.json +3 -0
- package/esm/src/action/add.d.ts +1 -0
- package/esm/src/action/add.js +57 -0
- package/esm/src/action/clone.d.ts +6 -0
- package/esm/src/action/clone.js +108 -0
- package/esm/src/action/lang.d.ts +1 -0
- package/esm/src/action/lang.js +40 -0
- package/esm/src/action/pull.d.ts +1 -0
- package/esm/src/action/pull.js +22 -0
- package/esm/src/action/remove.d.ts +4 -0
- package/esm/src/action/remove.js +67 -0
- package/esm/src/action/reset.d.ts +1 -0
- package/esm/src/action/reset.js +21 -0
- package/esm/src/action/run.d.ts +4 -0
- package/esm/src/action/run.js +163 -0
- package/esm/src/action/status.d.ts +1 -0
- package/esm/src/action/status.js +5 -0
- package/esm/src/main.d.ts +2 -0
- package/esm/src/main.js +96 -0
- package/esm/src/meta.d.ts +3 -0
- package/esm/src/meta.js +51 -0
- package/esm/src/orca/client.d.ts +20 -0
- package/esm/src/orca/client.js +152 -0
- package/esm/src/orca/types.d.ts +54 -0
- package/esm/src/orca/types.js +12 -0
- package/esm/src/shared/config.d.ts +24 -0
- package/esm/src/shared/config.js +24 -0
- package/esm/src/shared/errors.d.ts +82 -0
- package/esm/src/shared/errors.js +228 -0
- package/esm/src/shared/file.d.ts +30 -0
- package/esm/src/shared/file.js +110 -0
- package/esm/src/shared/mod.d.ts +40 -0
- package/esm/src/shared/mod.js +383 -0
- package/esm/src/shared/types.d.ts +12 -0
- package/esm/src/shared/types.js +1 -0
- package/esm/src/track/client.d.ts +60 -0
- package/esm/src/track/client.js +268 -0
- package/esm/src/track/types.d.ts +210 -0
- package/esm/src/track/types.js +40 -0
- 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
|
+
}
|