diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 67aab4f..ba5807c 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -16,6 +16,8 @@ jobs: with: node-version: '20.x' registry-url: 'https://registry.npmjs.org' + - name: Install latest npm + run: npm install -g npm@latest - name: Install Dependencies run: npm ci --ignore-scripts - name: Audit Signatures diff --git a/.prettierignore b/.prettierignore deleted file mode 100644 index ec76c09..0000000 --- a/.prettierignore +++ /dev/null @@ -1,2 +0,0 @@ -src/date-fns/** -src/date-fns-tz/** \ No newline at end of file diff --git a/README.md b/README.md index 227ef96..d64c0f6 100644 --- a/README.md +++ b/README.md @@ -17,10 +17,10 @@ and date manipulation functions provided by date-fns. Features: Temporal (vs the millisecond precision of standard Date built-in) is useful for webservices recording the time of events, where concurrent activity may occur and millisecond precision does not provide adequate uniqueness and ordering. The [`date-fns`](https://date-fns.org) library is included. The only locale currently supported is `en-US`, but otherwise contains all -available functionality as of v2.29.1. +available functionality as of v3.6.0. Additionally, the [`date-fns-tz`](https://github.com/marnusw/date-fns-tz) library is included. Contains all -available functionality as of v1.3.7. +available functionality as of v1.3.7 except that the code in `fp` folder is excluded, which contains functional programming related stuff that is not used at the moment. ### `formatUtc` @@ -76,3 +76,12 @@ The reference documentation is here: https://tc39.es/proposal-temporal/docs/ The documentation for `date-fns` is here: https://date-fns.org/ The documentation for `date-fns-tz` is here: https://github.com/marnusw/date-fns-tz + +### Maintenance notes: + +When updating the latest code from the original repositories, except making all the necessary changes to make them fully typescript compatible, please remember to carry over the patches to overcome the following issues: + +- spring-forward support +- nanosecond support + +Please search for `[PATCH:]` in the existing codebase. diff --git a/package-lock.json b/package-lock.json index 4c18557..e40c1da 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,18 +1,18 @@ { "name": "@checkdigit/time", - "version": "3.0.0", + "version": "4.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@checkdigit/time", - "version": "3.0.0", + "version": "4.0.0", "license": "MIT", "devDependencies": { "@checkdigit/eslint-config": "^9.2.0", "@checkdigit/jest-config": "^6.0.0", "@checkdigit/prettier-config": "^5.3.0", - "@checkdigit/typescript-config": "^7.0.0", + "@checkdigit/typescript-config": "^7.0.1", "@js-temporal/polyfill": "^0.4.4", "rimraf": "^5.0.5" }, @@ -826,9 +826,9 @@ } }, "node_modules/@checkdigit/typescript-config": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/@checkdigit/typescript-config/-/typescript-config-7.0.0.tgz", - "integrity": "sha512-B/vsOumI7AD4p0n36XuGwwW0d/47rYaJzYbS8LlrT40TgS0JD/jc08quLfBSpGB4KxMVER3vmHCrE2EZMOUm0Q==", + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/@checkdigit/typescript-config/-/typescript-config-7.0.1.tgz", + "integrity": "sha512-CM3y0s22VLSsD+HlOK/0eQCIJZgPH1SHd6b9xrsS+iYgI3jO2T10I9vMQpGZfkxOB/iIL3Ob7ktWJeIOPff/xw==", "dev": true, "bin": { "builder": "bin/builder.mjs" @@ -838,14 +838,14 @@ }, "peerDependencies": { "@types/node": ">=20.11", - "esbuild": "0.20.1", - "typescript": ">=5.4.2 <5.5.0" + "esbuild": "0.20.2", + "typescript": ">=5.4.3 <5.5.0" } }, "node_modules/@esbuild/aix-ppc64": { - "version": "0.20.1", - "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.20.1.tgz", - "integrity": "sha512-m55cpeupQ2DbuRGQMMZDzbv9J9PgVelPjlcmM5kxHnrBdBx6REaEd7LamYV7Dm8N7rCyR/XwU6rVP8ploKtIkA==", + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.20.2.tgz", + "integrity": "sha512-D+EBOJHXdNZcLJRBkhENNG8Wji2kgc9AZ9KiPr1JuZjsNtyHzrsfLRrY0tk2H2aoFu6RANO1y1iPPUCDYWkb5g==", "cpu": [ "ppc64" ], @@ -860,9 +860,9 @@ } }, "node_modules/@esbuild/android-arm": { - "version": "0.20.1", - "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.20.1.tgz", - "integrity": "sha512-4j0+G27/2ZXGWR5okcJi7pQYhmkVgb4D7UKwxcqrjhvp5TKWx3cUjgB1CGj1mfdmJBQ9VnUGgUhign+FPF2Zgw==", + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.20.2.tgz", + "integrity": "sha512-t98Ra6pw2VaDhqNWO2Oph2LXbz/EJcnLmKLGBJwEwXX/JAN83Fym1rU8l0JUWK6HkIbWONCSSatf4sf2NBRx/w==", "cpu": [ "arm" ], @@ -877,9 +877,9 @@ } }, "node_modules/@esbuild/android-arm64": { - "version": "0.20.1", - "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.20.1.tgz", - "integrity": "sha512-hCnXNF0HM6AjowP+Zou0ZJMWWa1VkD77BXe959zERgGJBBxB+sV+J9f/rcjeg2c5bsukD/n17RKWXGFCO5dD5A==", + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.20.2.tgz", + "integrity": "sha512-mRzjLacRtl/tWU0SvD8lUEwb61yP9cqQo6noDZP/O8VkwafSYwZ4yWy24kan8jE/IMERpYncRt2dw438LP3Xmg==", "cpu": [ "arm64" ], @@ -894,9 +894,9 @@ } }, "node_modules/@esbuild/android-x64": { - "version": "0.20.1", - "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.20.1.tgz", - "integrity": "sha512-MSfZMBoAsnhpS+2yMFYIQUPs8Z19ajwfuaSZx+tSl09xrHZCjbeXXMsUF/0oq7ojxYEpsSo4c0SfjxOYXRbpaA==", + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.20.2.tgz", + "integrity": "sha512-btzExgV+/lMGDDa194CcUQm53ncxzeBrWJcncOBxuC6ndBkKxnHdFJn86mCIgTELsooUmwUm9FkhSp5HYu00Rg==", "cpu": [ "x64" ], @@ -911,9 +911,9 @@ } }, "node_modules/@esbuild/darwin-arm64": { - "version": "0.20.1", - "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.20.1.tgz", - "integrity": "sha512-Ylk6rzgMD8klUklGPzS414UQLa5NPXZD5tf8JmQU8GQrj6BrFA/Ic9tb2zRe1kOZyCbGl+e8VMbDRazCEBqPvA==", + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.20.2.tgz", + "integrity": "sha512-4J6IRT+10J3aJH3l1yzEg9y3wkTDgDk7TSDFX+wKFiWjqWp/iCfLIYzGyasx9l0SAFPT1HwSCR+0w/h1ES/MjA==", "cpu": [ "arm64" ], @@ -928,9 +928,9 @@ } }, "node_modules/@esbuild/darwin-x64": { - "version": "0.20.1", - "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.20.1.tgz", - "integrity": "sha512-pFIfj7U2w5sMp52wTY1XVOdoxw+GDwy9FsK3OFz4BpMAjvZVs0dT1VXs8aQm22nhwoIWUmIRaE+4xow8xfIDZA==", + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.20.2.tgz", + "integrity": "sha512-tBcXp9KNphnNH0dfhv8KYkZhjc+H3XBkF5DKtswJblV7KlT9EI2+jeA8DgBjp908WEuYll6pF+UStUCfEpdysA==", "cpu": [ "x64" ], @@ -945,9 +945,9 @@ } }, "node_modules/@esbuild/freebsd-arm64": { - "version": "0.20.1", - "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.20.1.tgz", - "integrity": "sha512-UyW1WZvHDuM4xDz0jWun4qtQFauNdXjXOtIy7SYdf7pbxSWWVlqhnR/T2TpX6LX5NI62spt0a3ldIIEkPM6RHw==", + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.20.2.tgz", + "integrity": "sha512-d3qI41G4SuLiCGCFGUrKsSeTXyWG6yem1KcGZVS+3FYlYhtNoNgYrWcvkOoaqMhwXSMrZRl69ArHsGJ9mYdbbw==", "cpu": [ "arm64" ], @@ -962,9 +962,9 @@ } }, "node_modules/@esbuild/freebsd-x64": { - "version": "0.20.1", - "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.20.1.tgz", - "integrity": "sha512-itPwCw5C+Jh/c624vcDd9kRCCZVpzpQn8dtwoYIt2TJF3S9xJLiRohnnNrKwREvcZYx0n8sCSbvGH349XkcQeg==", + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.20.2.tgz", + "integrity": "sha512-d+DipyvHRuqEeM5zDivKV1KuXn9WeRX6vqSqIDgwIfPQtwMP4jaDsQsDncjTDDsExT4lR/91OLjRo8bmC1e+Cw==", "cpu": [ "x64" ], @@ -979,9 +979,9 @@ } }, "node_modules/@esbuild/linux-arm": { - "version": "0.20.1", - "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.20.1.tgz", - "integrity": "sha512-LojC28v3+IhIbfQ+Vu4Ut5n3wKcgTu6POKIHN9Wpt0HnfgUGlBuyDDQR4jWZUZFyYLiz4RBBBmfU6sNfn6RhLw==", + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.20.2.tgz", + "integrity": "sha512-VhLPeR8HTMPccbuWWcEUD1Az68TqaTYyj6nfE4QByZIQEQVWBB8vup8PpR7y1QHL3CpcF6xd5WVBU/+SBEvGTg==", "cpu": [ "arm" ], @@ -996,9 +996,9 @@ } }, "node_modules/@esbuild/linux-arm64": { - "version": "0.20.1", - "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.20.1.tgz", - "integrity": "sha512-cX8WdlF6Cnvw/DO9/X7XLH2J6CkBnz7Twjpk56cshk9sjYVcuh4sXQBy5bmTwzBjNVZze2yaV1vtcJS04LbN8w==", + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.20.2.tgz", + "integrity": "sha512-9pb6rBjGvTFNira2FLIWqDk/uaf42sSyLE8j1rnUpuzsODBq7FvpwHYZxQ/It/8b+QOS1RYfqgGFNLRI+qlq2A==", "cpu": [ "arm64" ], @@ -1013,9 +1013,9 @@ } }, "node_modules/@esbuild/linux-ia32": { - "version": "0.20.1", - "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.20.1.tgz", - "integrity": "sha512-4H/sQCy1mnnGkUt/xszaLlYJVTz3W9ep52xEefGtd6yXDQbz/5fZE5dFLUgsPdbUOQANcVUa5iO6g3nyy5BJiw==", + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.20.2.tgz", + "integrity": "sha512-o10utieEkNPFDZFQm9CoP7Tvb33UutoJqg3qKf1PWVeeJhJw0Q347PxMvBgVVFgouYLGIhFYG0UGdBumROyiig==", "cpu": [ "ia32" ], @@ -1030,9 +1030,9 @@ } }, "node_modules/@esbuild/linux-loong64": { - "version": "0.20.1", - "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.20.1.tgz", - "integrity": "sha512-c0jgtB+sRHCciVXlyjDcWb2FUuzlGVRwGXgI+3WqKOIuoo8AmZAddzeOHeYLtD+dmtHw3B4Xo9wAUdjlfW5yYA==", + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.20.2.tgz", + "integrity": "sha512-PR7sp6R/UC4CFVomVINKJ80pMFlfDfMQMYynX7t1tNTeivQ6XdX5r2XovMmha/VjR1YN/HgHWsVcTRIMkymrgQ==", "cpu": [ "loong64" ], @@ -1047,9 +1047,9 @@ } }, "node_modules/@esbuild/linux-mips64el": { - "version": "0.20.1", - "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.20.1.tgz", - "integrity": "sha512-TgFyCfIxSujyuqdZKDZ3yTwWiGv+KnlOeXXitCQ+trDODJ+ZtGOzLkSWngynP0HZnTsDyBbPy7GWVXWaEl6lhA==", + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.20.2.tgz", + "integrity": "sha512-4BlTqeutE/KnOiTG5Y6Sb/Hw6hsBOZapOVF6njAESHInhlQAghVVZL1ZpIctBOoTFbQyGW+LsVYZ8lSSB3wkjA==", "cpu": [ "mips64el" ], @@ -1064,9 +1064,9 @@ } }, "node_modules/@esbuild/linux-ppc64": { - "version": "0.20.1", - "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.20.1.tgz", - "integrity": "sha512-b+yuD1IUeL+Y93PmFZDZFIElwbmFfIKLKlYI8M6tRyzE6u7oEP7onGk0vZRh8wfVGC2dZoy0EqX1V8qok4qHaw==", + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.20.2.tgz", + "integrity": "sha512-rD3KsaDprDcfajSKdn25ooz5J5/fWBylaaXkuotBDGnMnDP1Uv5DLAN/45qfnf3JDYyJv/ytGHQaziHUdyzaAg==", "cpu": [ "ppc64" ], @@ -1081,9 +1081,9 @@ } }, "node_modules/@esbuild/linux-riscv64": { - "version": "0.20.1", - "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.20.1.tgz", - "integrity": "sha512-wpDlpE0oRKZwX+GfomcALcouqjjV8MIX8DyTrxfyCfXxoKQSDm45CZr9fanJ4F6ckD4yDEPT98SrjvLwIqUCgg==", + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.20.2.tgz", + "integrity": "sha512-snwmBKacKmwTMmhLlz/3aH1Q9T8v45bKYGE3j26TsaOVtjIag4wLfWSiZykXzXuE1kbCE+zJRmwp+ZbIHinnVg==", "cpu": [ "riscv64" ], @@ -1098,9 +1098,9 @@ } }, "node_modules/@esbuild/linux-s390x": { - "version": "0.20.1", - "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.20.1.tgz", - "integrity": "sha512-5BepC2Au80EohQ2dBpyTquqGCES7++p7G+7lXe1bAIvMdXm4YYcEfZtQrP4gaoZ96Wv1Ute61CEHFU7h4FMueQ==", + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.20.2.tgz", + "integrity": "sha512-wcWISOobRWNm3cezm5HOZcYz1sKoHLd8VL1dl309DiixxVFoFe/o8HnwuIwn6sXre88Nwj+VwZUvJf4AFxkyrQ==", "cpu": [ "s390x" ], @@ -1115,9 +1115,9 @@ } }, "node_modules/@esbuild/linux-x64": { - "version": "0.20.1", - "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.20.1.tgz", - "integrity": "sha512-5gRPk7pKuaIB+tmH+yKd2aQTRpqlf1E4f/mC+tawIm/CGJemZcHZpp2ic8oD83nKgUPMEd0fNanrnFljiruuyA==", + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.20.2.tgz", + "integrity": "sha512-1MdwI6OOTsfQfek8sLwgyjOXAu+wKhLEoaOLTjbijk6E2WONYpH9ZU2mNtR+lZ2B4uwr+usqGuVfFT9tMtGvGw==", "cpu": [ "x64" ], @@ -1132,9 +1132,9 @@ } }, "node_modules/@esbuild/netbsd-x64": { - "version": "0.20.1", - "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.20.1.tgz", - "integrity": "sha512-4fL68JdrLV2nVW2AaWZBv3XEm3Ae3NZn/7qy2KGAt3dexAgSVT+Hc97JKSZnqezgMlv9x6KV0ZkZY7UO5cNLCg==", + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.20.2.tgz", + "integrity": "sha512-K8/DhBxcVQkzYc43yJXDSyjlFeHQJBiowJ0uVL6Tor3jGQfSGHNNJcWxNbOI8v5k82prYqzPuwkzHt3J1T1iZQ==", "cpu": [ "x64" ], @@ -1149,9 +1149,9 @@ } }, "node_modules/@esbuild/openbsd-x64": { - "version": "0.20.1", - "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.20.1.tgz", - "integrity": "sha512-GhRuXlvRE+twf2ES+8REbeCb/zeikNqwD3+6S5y5/x+DYbAQUNl0HNBs4RQJqrechS4v4MruEr8ZtAin/hK5iw==", + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.20.2.tgz", + "integrity": "sha512-eMpKlV0SThJmmJgiVyN9jTPJ2VBPquf6Kt/nAoo6DgHAoN57K15ZghiHaMvqjCye/uU4X5u3YSMgVBI1h3vKrQ==", "cpu": [ "x64" ], @@ -1166,9 +1166,9 @@ } }, "node_modules/@esbuild/sunos-x64": { - "version": "0.20.1", - "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.20.1.tgz", - "integrity": "sha512-ZnWEyCM0G1Ex6JtsygvC3KUUrlDXqOihw8RicRuQAzw+c4f1D66YlPNNV3rkjVW90zXVsHwZYWbJh3v+oQFM9Q==", + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.20.2.tgz", + "integrity": "sha512-2UyFtRC6cXLyejf/YEld4Hajo7UHILetzE1vsRcGL3earZEW77JxrFjH4Ez2qaTiEfMgAXxfAZCm1fvM/G/o8w==", "cpu": [ "x64" ], @@ -1183,9 +1183,9 @@ } }, "node_modules/@esbuild/win32-arm64": { - "version": "0.20.1", - "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.20.1.tgz", - "integrity": "sha512-QZ6gXue0vVQY2Oon9WyLFCdSuYbXSoxaZrPuJ4c20j6ICedfsDilNPYfHLlMH7vGfU5DQR0czHLmJvH4Nzis/A==", + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.20.2.tgz", + "integrity": "sha512-GRibxoawM9ZCnDxnP3usoUDO9vUkpAxIIZ6GQI+IlVmr5kP3zUq+l17xELTHMWTWzjxa2guPNyrpq1GWmPvcGQ==", "cpu": [ "arm64" ], @@ -1200,9 +1200,9 @@ } }, "node_modules/@esbuild/win32-ia32": { - "version": "0.20.1", - "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.20.1.tgz", - "integrity": "sha512-HzcJa1NcSWTAU0MJIxOho8JftNp9YALui3o+Ny7hCh0v5f90nprly1U3Sj1Ldj/CvKKdvvFsCRvDkpsEMp4DNw==", + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.20.2.tgz", + "integrity": "sha512-HfLOfn9YWmkSKRQqovpnITazdtquEW8/SoHW7pWpuEeguaZI4QnCRW6b+oZTztdBnZOS2hqJ6im/D5cPzBTTlQ==", "cpu": [ "ia32" ], @@ -1217,9 +1217,9 @@ } }, "node_modules/@esbuild/win32-x64": { - "version": "0.20.1", - "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.20.1.tgz", - "integrity": "sha512-0MBh53o6XtI6ctDnRMeQ+xoCN8kD2qI1rY1KgF/xdWQwoFeKou7puvDfV8/Wv4Ctx2rRpET/gGdz3YlNtNACSA==", + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.20.2.tgz", + "integrity": "sha512-N49X4lJX27+l9jbLKSqZ6bKNjzQvHaT8IIFUy+YIqmXQdjYCToGWwOItDrfby14c78aDd5NHQl29xingXfCdLQ==", "cpu": [ "x64" ], @@ -3555,9 +3555,9 @@ } }, "node_modules/esbuild": { - "version": "0.20.1", - "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.20.1.tgz", - "integrity": "sha512-OJwEgrpWm/PCMsLVWXKqvcjme3bHNpOgN7Tb6cQnR5n0TPbQx1/Xrn7rqM+wn17bYeT6MGB5sn1Bh5YiGi70nA==", + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.20.2.tgz", + "integrity": "sha512-WdOOppmUNU+IbZ0PaDiTst80zjnrOkyJNHoKupIcVyU8Lvla3Ugx94VzkQ32Ijqd7UhHJy75gNWDMUekcrSJ6g==", "dev": true, "hasInstallScript": true, "peer": true, @@ -3568,29 +3568,29 @@ "node": ">=12" }, "optionalDependencies": { - "@esbuild/aix-ppc64": "0.20.1", - "@esbuild/android-arm": "0.20.1", - "@esbuild/android-arm64": "0.20.1", - "@esbuild/android-x64": "0.20.1", - "@esbuild/darwin-arm64": "0.20.1", - "@esbuild/darwin-x64": "0.20.1", - "@esbuild/freebsd-arm64": "0.20.1", - "@esbuild/freebsd-x64": "0.20.1", - "@esbuild/linux-arm": "0.20.1", - "@esbuild/linux-arm64": "0.20.1", - "@esbuild/linux-ia32": "0.20.1", - "@esbuild/linux-loong64": "0.20.1", - "@esbuild/linux-mips64el": "0.20.1", - "@esbuild/linux-ppc64": "0.20.1", - "@esbuild/linux-riscv64": "0.20.1", - "@esbuild/linux-s390x": "0.20.1", - "@esbuild/linux-x64": "0.20.1", - "@esbuild/netbsd-x64": "0.20.1", - "@esbuild/openbsd-x64": "0.20.1", - "@esbuild/sunos-x64": "0.20.1", - "@esbuild/win32-arm64": "0.20.1", - "@esbuild/win32-ia32": "0.20.1", - "@esbuild/win32-x64": "0.20.1" + "@esbuild/aix-ppc64": "0.20.2", + "@esbuild/android-arm": "0.20.2", + "@esbuild/android-arm64": "0.20.2", + "@esbuild/android-x64": "0.20.2", + "@esbuild/darwin-arm64": "0.20.2", + "@esbuild/darwin-x64": "0.20.2", + "@esbuild/freebsd-arm64": "0.20.2", + "@esbuild/freebsd-x64": "0.20.2", + "@esbuild/linux-arm": "0.20.2", + "@esbuild/linux-arm64": "0.20.2", + "@esbuild/linux-ia32": "0.20.2", + "@esbuild/linux-loong64": "0.20.2", + "@esbuild/linux-mips64el": "0.20.2", + "@esbuild/linux-ppc64": "0.20.2", + "@esbuild/linux-riscv64": "0.20.2", + "@esbuild/linux-s390x": "0.20.2", + "@esbuild/linux-x64": "0.20.2", + "@esbuild/netbsd-x64": "0.20.2", + "@esbuild/openbsd-x64": "0.20.2", + "@esbuild/sunos-x64": "0.20.2", + "@esbuild/win32-arm64": "0.20.2", + "@esbuild/win32-ia32": "0.20.2", + "@esbuild/win32-x64": "0.20.2" } }, "node_modules/escalade": { @@ -8084,9 +8084,9 @@ } }, "node_modules/typescript": { - "version": "5.4.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.4.2.tgz", - "integrity": "sha512-+2/g0Fds1ERlP6JsakQQDXjZdZMM+rqpamFZJEKh4kwTIn3iDkgKtby0CeNd5ATNZ4Ry1ax15TMx0W2V+miizQ==", + "version": "5.4.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.4.3.tgz", + "integrity": "sha512-KrPd3PKaCLr78MalgiwJnA25Nm8HAmdwN3mYUYZgG/wizIo9EainNVQI9/yDavtVFRN2h3k8uf3GLHuhDMgEHg==", "dev": true, "peer": true, "bin": { diff --git a/package.json b/package.json index e8d8786..fe2d4af 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@checkdigit/time", - "version": "3.0.0", + "version": "4.0.0", "description": "Standard time handling", "author": "Check Digit, LLC", "license": "MIT", @@ -40,7 +40,7 @@ "@checkdigit/eslint-config": "^9.2.0", "@checkdigit/jest-config": "^6.0.0", "@checkdigit/prettier-config": "^5.3.0", - "@checkdigit/typescript-config": "^7.0.0", + "@checkdigit/typescript-config": "^7.0.1", "@js-temporal/polyfill": "^0.4.4", "rimraf": "^5.0.5" }, @@ -50,8 +50,8 @@ "build:dist-mjs": "rimraf dist-mjs && npx builder --type=module --sourceMap --outDir=dist-mjs && node dist-mjs/index.mjs", "lint": "eslint --max-warnings 0 --ignore-path .gitignore .", "lint:fix": "eslint --ignore-path .gitignore . --fix", - "prettier": "prettier --ignore-path .gitignore --ignore-path .prettierignore --list-different .", - "prettier:fix": "prettier --ignore-path .gitignore --ignore-path .prettierignore --write .", + "prettier": "prettier --ignore-path .gitignore --list-different .", + "prettier:fix": "prettier --ignore-path .gitignore --write .", "test": "npm run ci:compile && npm run ci:test && npm run ci:lint && npm run ci:style", "ci:compile": "tsc --noEmit", "ci:test": "NODE_OPTIONS=\"--disable-warning ExperimentalWarning --experimental-vm-modules\" jest --coverage=false", diff --git a/src/date-fns/_lib/assign/index.ts b/src/date-fns-tz/date-fns-v2-lib/assign/index.ts similarity index 100% rename from src/date-fns/_lib/assign/index.ts rename to src/date-fns-tz/date-fns-v2-lib/assign/index.ts diff --git a/src/date-fns/_lib/cloneObject/index.ts b/src/date-fns-tz/date-fns-v2-lib/cloneObject/index.ts similarity index 100% rename from src/date-fns/_lib/cloneObject/index.ts rename to src/date-fns-tz/date-fns-v2-lib/cloneObject/index.ts diff --git a/src/date-fns-tz/format/index.ts b/src/date-fns-tz/format/index.ts index f153dac..5c1f027 100644 --- a/src/date-fns-tz/format/index.ts +++ b/src/date-fns-tz/format/index.ts @@ -1,4 +1,4 @@ -import dateFnsFormat, { type FormatOptions } from '../../date-fns/format'; +import { format as dateFnsFormat, type FormatOptions } from '../../date-fns/format'; import type { OptionsWithTZ } from '../types'; import formatters from './formatters'; import toDate from '../toDate'; diff --git a/src/date-fns-tz/formatInTimeZone/index.ts b/src/date-fns-tz/formatInTimeZone/index.ts index ebcb604..64080b5 100644 --- a/src/date-fns-tz/formatInTimeZone/index.ts +++ b/src/date-fns-tz/formatInTimeZone/index.ts @@ -1,4 +1,4 @@ -import cloneObject from '../../date-fns/_lib/cloneObject'; +import cloneObject from '../date-fns-v2-lib/cloneObject'; import format from '../format'; import type { OptionsWithTZ } from '../types'; import utcToZonedTime from '../utcToZonedTime'; diff --git a/src/date-fns-tz/toDate/index.ts b/src/date-fns-tz/toDate/index.ts index 8c564bd..89412c0 100644 --- a/src/date-fns-tz/toDate/index.ts +++ b/src/date-fns-tz/toDate/index.ts @@ -1,4 +1,4 @@ -import getTimezoneOffsetInMilliseconds from '../../date-fns/_lib/getTimezoneOffsetInMilliseconds'; +import { getTimezoneOffsetInMilliseconds } from '../../date-fns/_lib/getTimezoneOffsetInMilliseconds'; import tzParseTimezone from '../_lib/tzParseTimezone'; import tzPattern from '../_lib/tzPattern'; import type { OptionsWithTZ } from '../types'; diff --git a/src/date-fns-tz/utcToZonedTime/index.ts b/src/date-fns-tz/utcToZonedTime/index.ts index 61899d6..98b19dc 100644 --- a/src/date-fns-tz/utcToZonedTime/index.ts +++ b/src/date-fns-tz/utcToZonedTime/index.ts @@ -43,7 +43,7 @@ export default function utcToZonedTime( resultDate.setHours(d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds(), d.getUTCMilliseconds()); - // this hack is required because setHours doesn't work for hours that are spring-forward + // [PATCH:] this hack is required because setHours doesn't work for hours that are spring-forward (resultDate as any)[Symbol.for('UTCHours')] = d.getUTCHours(); return resultDate; } diff --git a/src/date-fns-tz/zonedTimeToUtc/index.ts b/src/date-fns-tz/zonedTimeToUtc/index.ts index 9bee9e7..09a04c4 100644 --- a/src/date-fns-tz/zonedTimeToUtc/index.ts +++ b/src/date-fns-tz/zonedTimeToUtc/index.ts @@ -1,4 +1,4 @@ -import cloneObject from '../../date-fns/_lib/cloneObject'; +import cloneObject from '../date-fns-v2-lib/cloneObject'; import toDate from '../toDate'; import tzPattern from '../_lib/tzPattern'; import tzParseTimezone from '../_lib/tzParseTimezone'; diff --git a/src/date-fns/CHANGELOG.md b/src/date-fns/CHANGELOG.md index 5d0e385..67cdb47 100644 --- a/src/date-fns/CHANGELOG.md +++ b/src/date-fns/CHANGELOG.md @@ -8,7 +8,245 @@ This change log follows the format documented in [Keep a CHANGELOG]. [semantic versioning]: http://semver.org/ [keep a changelog]: http://keepachangelog.com/ -## v2.29.1 - 2022-07-22 +## v3.6.0 - 2024-03-18 + +On this release worked @kossnocorp and @world1dan. Also, thanks to [@seated](https://github.com/seated) [for sponsoring me](https://github.com/sponsors/kossnocorp). + +### Fixed + +- [Fixed weeks in the Belarisuan locale's `formatDistance`.](https://github.com/date-fns/date-fns/pull/3720) + +### Added + +- [Added CDN versions of modules compatible with older browsers.](https://github.com/date-fns/date-fns/pull/3737) [See the CDN guide.](https://date-fns.org/docs/CDN) + +## v3.5.0 - 2024-03-15 + +Kudos to @fturmel, @kossnocorp, @makstyle119, @tan75, @marcreichel, @tareknatsheh and @audunru for working on the release. Also, thanks to [@seated](https://github.com/seated) [for sponsoring me](https://github.com/sponsors/kossnocorp). + +### Fixed + +- [Fixed functions that use current date internally and made them work with date extensions like `UTCDate`.](https://github.com/date-fns/date-fns/issues/3730) + +- [Fixed `daysToWeeks` returning negative 0.](https://github.com/date-fns/date-fns/commit/882ced61c692c7c4a79eaaec6eb07cb9c8c9195b) + +- [Fixed German grammar for the "half a minute" string.](https://github.com/date-fns/date-fns/pull/3715) + +### Added + +- [Added the Northern Sámi (`se`) locale.](https://github.com/date-fns/date-fns/pull/3724) + +- Added the `constructNow` function that creates the current date using the passed reference date's constructor. + +## v3.4.0 - 2024-03-11 + +Kudos to @kossnocorp, @sakamossan and @Revan99 for working on the release. Also, thanks to [@seated](https://github.com/seated) [for sponsoring me](https://github.com/sponsors/kossnocorp). + +### Added + +- [Added `roundToNearestHours` function.](https://github.com/date-fns/date-fns/pull/2752) + +- [Added Central Kurdish (`ckb`) locale.](https://github.com/date-fns/date-fns/pull/3421) + +## v3.3.1 - 2024-01-22 + +Kudos to @kossnocorp and @fturmel for working on the release. + +### Fixed + +- Fixed DST issue in `getOverlappingDaysInIntervals`, resulting in an inconsistent number of days returned for intervals starting and ending in different DST periods. + +- Fixed functions incorrectly using `trunc` instead of `round`. The bug was introduced in v3.3.0. The affected functions: `differenceInCalendarDays`, `differenceInCalendarISOWeeks`, `differenceInCalendarWeeks`, `getISOWeek`, `getWeek`, and `getISOWeeksInYear`. + +## v3.3.0 - 2024-01-20 + +On this release worked @kossnocorp, @TheKvikk, @fturmel and @ckcherry23. + +### Fixed + +- Fixed the bug in `getOverlappingDaysInIntervals` caused by incorrect sorting of interval components that led to 0 for timestamps of different lengths. + +- Fixed bugs when working with negative numbers caused by using `Math.floor` (`-1.1` → `-2`) instead of `Math.trunc` (`-1.1` → `-1`). Most of the conversion functions (i.e., `hoursToMinutes`) were affected when passing some negative fractional input. Also, some other functions that could be possibly affected by unfortunate timezone/date combinations were fixed. + + The functions that were affected: `format`, `parse`, `getUnixTime`, `daysToWeeks`, `hoursToMilliseconds`, `hoursToMinutes`, `hoursToSeconds`, `milliseconds`, `minutesToMilliseconds`, `millisecondsToMinutes`, `monthsToYears`, `millisecondsToHours`, `millisecondsToSeconds`, `minutesToHours`, `minutesToSeconds`, `yearsToQuarters`, `yearsToMonths`, `yearsToDays`, `weeksToDays`, `secondsToMinutes`, `secondsToHours`, `quartersToYears`, `quartersToMonths` and `monthsToQuarters`. + +- [Fixed the Czech locale's `formatDistance` to include `1` in `formatDistance`.](https://github.com/date-fns/date-fns/pull/3269) + +- Fixed `differenceInSeconds` and other functions relying on rounding options that can produce a negative 0. + +- [Added a preprocessor to the locales API, enabling fixing a long-standing bug in the French locale.](https://github.com/date-fns/date-fns/pull/3662) ([#1391](https://github.com/date-fns/date-fns/issues/1391)) + +- Added missing `yearsToDays` to the FP submodule. + +- Made functions using rounding methods always return `0` instead of `-0`. + +### Added + +- [Added `format` alias `formatDate` with corresponding `FormatDateOptions` interface](https://github.com/date-fns/date-fns/pull/3653). + +## v3.2.0 - 2024-01-09 + +This release is brought to you by @kossnocorp, @fturmel, @grossbart, @MelvinVermeer, and @jcarstairs-scottlogic. + +### Fixed + +- Fixed types compatability with Lodash's `flow` and fp-ts's `pipe`. ([#3641](https://github.com/date-fns/date-fns/issues/3641)) + +- [Fixed inconsistent behavior of `roundToNearestMinutes`.](https://github.com/date-fns/date-fns/pull/3132) + +### Added + +- Added exports of `format`, `lightFormat`, and `parse` internals that enable 3rd-parties to consume those. + +## v3.1.0 - 2024-01-05 + +This release is brought to you by @kossnocorp, @makstyle119 and @dmgawel. + +### Fixed + +- [Fixed the plural form of weeks in Swedish](https://github.com/date-fns/date-fns/pull/3448). + +### Added + +- [Added `yearsToDays` function](https://github.com/date-fns/date-fns/pull/3540). + +- Added warning about using protected tokens like `Y` or `D` without passing a corresponding option. [See #2950](https://github.com/date-fns/date-fns/issues/2950). + +## v3.0.6 - 2023-12-22 + +On this release worked @imwh0im, @jamcry and @tyrw. + +### Fixed + +- [Fixed bug in `areIntervalsOverlapping` caused by incorrect sorting](https://github.com/date-fns/date-fns/pull/3628) ([#3614](https://github.com/date-fns/date-fns/issues/3614)) + +## v3.0.5 - 2023-12-21 + +This release is brought to you by @goku4199. + +### Fixed + +- [Fixed internal `toDate` not processing string arguments properly](https://github.com/date-fns/date-fns/pull/3626) + +## v3.0.4 - 2023-12-21 + +This release is brought to you by @kossnocorp. + +### Fixed + +- Fixed isWithinInterval bug caused by incorrectly sorting dates ([#3623](https://github.com/date-fns/date-fns/issues/3623)). + +## v3.0.3 - 2023-12-21 + +### Fixed + +- Rolled back pointing ESM types to the same `d.ts` files. Instead now it copies the content to avoid [the Masquerading as CJS problem](https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/FalseCJS.md) reported by "Are the types wrong?". + +## v3.0.2 - 2023-12-21 + +### Fixed + +- Fixed [yet another issue caused by ESM types](https://github.com/date-fns/date-fns/issues/3620) by pointing to the same `d.ts` files. + +- [Added `package.json` to exports](https://github.com/date-fns/date-fns/pull/3601) to provide access to tooling. + +- [Fixed TypeScript 5.4 build break](https://github.com/date-fns/date-fns/pull/3598) by using the latest type names. + +## v3.0.1 - 2023-12-20 + +### Fixed + +- [Fixed an error](https://github.com/date-fns/date-fns/pull/3618) in certain environments caused by `d.mts` files exporting only types. + +## v3.0.0 - 2023-12-18 + +### Changed + +- **BREAKING**: date-fns is now a dual-package with the support of both ESM and CommonJS. The files exports are now explicitly in the `package.json`. The ESM files now have `.mjs` extension. + +- **BREAKING**: The package now has a flat structure, meaning functions are now named `node_modules/date-fns/add.mjs`, locales are `node_modules/date-fns/locale/enUS.mjs`, etc. + +- **BREAKING**: Now all file content’s exported via named exports instead of `export default`, which will require change direct imports i.e. `const addDays = require(‘date-fns/addDays’)` to `const { addDays } = require(‘date-fns/addDays’)`. + +- **BREAKING**: TypeScript types are now completely rewritten, check out the `d.ts` files for more information. + +- **BREAKING**: `constants` now is not exported via the index, so to import one use `import { daysInYear } from "date-fns/constants";`. It improves compatibility with setups that modularize imports [like Next.js](https://twitter.com/kossnocorp/status/1731181274579325260). + +- **BREAKING**: Functions now don’t check the number of passed arguments, delegating this task to type checkers. The functions are now slimmer because of this. + +- **BREAKING** The arguments are not explicitly converted to the target types. Instead, they are passed as is, delegating this task to type checkers. + +- **BREAKING**: Functions that accept `Interval` arguments now do not throw an error if the start is before the end and handle it as a negative interval. If one of the properties in an `Invalid Date`, these functions also do not throw and handle them as invalid intervals. + + - `areIntervalsOverlapping` normalize intervals before comparison, so `{ start: a, end: b }` is practically equivalent to `{ start: b, end: a }`. When comparing intervals with one of the properties being `Invalid Date`, the function will return false unless the others are valid and equal, given the `inclusive` option is passed. Otherwise, and when even one of the intervals has both properties invalid, the function will always return `false`. + + - `getOverlappingDaysInIntervals` now normalizes intervals before comparison, so `{ start: a, end: b }` is practically equivalent to `{ start: b, end: a }`. If any of the intervals’ properties is an `Invalid Date`, the function will always return 0. + + - `isWithinInterval` now normalizes intervals before comparison, so `{ start: a, end: b }` is practically equivalent to `{ start: b, end: a }`. If any of the intervals’ properties is an `Invalid Date`, the function will always return false. + + - `intervalToDuration` now returns negative durations for negative intervals. If one or both of the interval properties are invalid, the function will return an empty object. + + - The eachXOfInterval functions (`eachDayOfInterval`, `eachHourOfInterval`, `eachMinuteOfInterval`, `eachMonthOfInterval`, `eachWeekendOfInterval`, `eachWeekendOfMonth`, `eachWeekendOfYear`, `eachWeekOfInterval`, `eachYearOfInterval`) now return a reversed array if the passed interval’s start is after the end. Invalid properties will result in an empty array. Functions that accept the `step` option now also allow negative, 0, and NaN values and return reversed results if the step is negative and an empty array otherwise. + +- **BREAKING**: `intervalToDuration` now skips 0 values in the resulting duration, resulting in more compact objects with only relevant properties. + +- **BREAKING**: `roundToNearestMinutes` now returns `Invalid Date` instead of throwing an error when `nearestTo` option is less than 1 or more than 30. + +- **BREAKING**: IE is no longer supported. + +- **BREAKING**: Now all functions use `Math.trunc` rounding method where rounding is required. The behavior is configurable on a per-function basis. + +- **BREAKING**: Undocumented `onlyNumeric` option was removed from `nn` and `sv` locales. If you relied on it, [please contact me](mailto:koss@nocorp.me). + +- **BREAKING**: Flow is not supported anymore. If you relied on it, [please contact me](mailto:koss@nocorp.me). + +- **BREAKING**: The locales now use regular functions instead of the UTC version, which should not break any code unless you used locales directly. + +### Added + +- All functions that accept date arguments now also accept strings. + +- All functions now export options interfaces. + +- Now functions allow passing custom Date extensions like [UTCDate](https://github.com/date-fns/utc). They will detect and use the arguments constructor to generate the result of the same class. + +- `eachMonthOfInterval`, `eachQuarterOfInterval`, `eachWeekOfInterval`, and `eachYearOfInterval` now accept the `step` option like most of the eachXOfInterval functions. + +- A new `interval` function that validates interval, emulating the v2 interval functions behavior. + +- `differenceInX` functions now accept options and allow setting up `roundingMethod` that configures how the result is rounded. `Math.trunc` is the default method. + +## v2.30.0 + +Kudos to @kossnocorp and @Andarist for working on the release. + +### Changes + +- Fixed increased build size after enabling compatibility with older browsers in the previous release. This was done by adding @babel/runtime as a dependency. [See more details](https://github.com/date-fns/date-fns/issues/3208#issuecomment-1528592465). + +## v2.29.3 - 2022-09-13 + +This release is prepared by our own @leshakoss. + +### Fixed + +- [Fixed Ukrainian (`uk`) locale grammar for `formatDistance`.](https://github.com/date-fns/date-fns/pull/3175) + +- [Improved browser compatibility by transforming the code with `@babel/preset-env`.](https://github.com/date-fns/date-fns/pull/3167) + +## v2.29.2 - 2022-08-18 + +This release is brought to you by @nopears, @vadimpopa and @leshakoss. + +### Fixed + +- [Fixed `sv` locale abbreviated months matcher.](https://github.com/date-fns/date-fns/pull/3160) + +- [Fixed `uk` locale abbreviated months matcher.](https://github.com/date-fns/date-fns/pull/3139) + +- [Fixed a breaking change in `intervalToDuration` by removing a recently introduced RangeError.](https://github.com/date-fns/date-fns/pull/3153) + +## v2.29.1 - 2022-08-18 Thanks to @fturmel for working on the release. diff --git a/src/date-fns/CONTRIBUTING.md b/src/date-fns/CONTRIBUTING.md deleted file mode 100644 index 8a24935..0000000 --- a/src/date-fns/CONTRIBUTING.md +++ /dev/null @@ -1,170 +0,0 @@ -# Contributing Guide - -**⚠⚠⚠ Please contribute new code in TypeScript ⚠⚠⚠** - -[Read more about migration to TypeScript](https://github.com/date-fns/date-fns/discussions/1932) - -## Table of Contents - -- [How to Help?](#how-to-help) - -- [Contribution Guidelines](#contribution-guidelines) - -- [Getting Started](#getting-started) - -- [Testing](#testing) - - - [Unit tests](#unit-tests) - - [REPL](#repl) - - [Test build](#test-build) - -- [Code Style Guide](#code-style-guide) - - - [Lint the Code](#lint-the-code) - -- [Documentation](#documentation) - - - [JSDoc](#jsdoc) - -## How to Help? - -Help is always welcome. There are areas where you can help: - -- The core functionality (performance improvements, bug fixes, - new features, etc.). - -- Documentation ([markdown documents](https://github.com/date-fns/date-fns/tree/master/docs), - [JSDoc annotations in source code](https://github.com/date-fns/date-fns/blob/master/src/toDate/index.ts)). - -- Test suite & development environment improvements. - -- The [website](https://github.com/date-fns/date-fns.org). - -If you see a gap, but don't have time, experience, or you just need help -with the library, don't hesitate to [start a discussion](https://github.com/date-fns/date-fns/discussions/new) or -[open a new issue](https://github.com/date-fns/date-fns/issues/new). - -The date-fns functionality is comprehensive and covers most of the use cases, -however it doesn't have an extended time zone support. Please leave a comment -to the [Extended time zones support issue](https://github.com/date-fns/date-fns/issues/180) -if you are interested in the functionality or want to help with development. - -If you are interested in Elm/ClojureScript/etc. wrappers, -please [file an issue](https://github.com/date-fns/date-fns/issues/new). - -## Contribution Guidelines - -Due to the modular nature of date-fns, it's more than open to new features. -However, when a new function duplicates the existing functionality, native API -or causes significant build size increase, a PR might be rejected or -the author can be asked to move the code to a new or another package. - -Please follow the main contributing rules, to maintain date-fns' top quality: - -- Follow style guides: - - - [Lint the code](#lint-the-code). - -- Write tests. - -- [Write documentation](#documentation). - -- Don't update the changelog. - -- Don't change the library version. - -## Getting Started - -1. Install [Node.js 14 or greater (LTS recommended)](https://nodejs.org/en/download/) - -2. Install or upgrade to the latest [Yarn classic (v1)](https://classic.yarnpkg.com/en/docs/install) by running `npm install -g yarn@latest` - -3. Fork the project, and clone your fork of the repo - -4. Run `yarn` to install the dev dependencies - -## Testing - -### Unit tests - -Karma + Mocha (Chrome): - -```sh -# all tests in watch mode -yarn test - -# all tests once -yarn test --single-run -``` - -Jest (Node.js): - -```sh -# all tests in watch mode -yarn jest --watch - -# all tests once -yarn jest -``` - -### REPL - -To test functions in a REPL, use `babel-node` located in `./node_modules/.bin` (mind the `-x` flag to also support TypeScript files): - -```sh -yarn babel-node -x .ts,.js -``` - -and then require invididual functions: - -```sh -> const toDate = require('./src/toDate') -undefined -> toDate(1392098430000).toString() -'Tue Feb 11 2014 01:00:30 GMT-0500 (Eastern Standard Time)' -> -``` - -or all functions (slower): - -```sh -> const fns = require('./src') -undefined -> fns.toDate(1392098430000).toString() -'Tue Feb 11 2014 01:00:30 GMT-0500 (Eastern Standard Time)' -> -``` - -### Test build - -Build date-fns from source to test in your project. The ouput is equivalent to what gets published on npm with each release. - -```sh -# replace {YOUR-PROJECT-PATH} with an absolute or relative path to your project root -env PACKAGE_OUTPUT_PATH="{YOUR-PROJECT-PATH}/node_modules/date-fns" ./scripts/build/package.sh -``` - -## Code Style Guide - -### Lint the Code - -The project follows [Prettier] code style and uses [ESLint] as the linter. -To lint the code, run: - -```bash -yarn lint -``` - -[prettier]: https://prettier.io/ -[eslint]: https://eslint.org/ - -## Documentation - -### JSDoc - -- [JSDoc](https://jsdoc.app/) is used for the code documentation. Along with the - standard JSDoc tags, date-fns uses `@category` tag that allows - to group functions. - -- [jsdoc-to-markdown](https://github.com/jsdoc2md/jsdoc-to-markdown/) is used to parse - JSDoc annotations. diff --git a/src/date-fns/_lib/addLeadingZeros/index.ts b/src/date-fns/_lib/addLeadingZeros/index.ts index a0cd3db..ce2e1bd 100644 --- a/src/date-fns/_lib/addLeadingZeros/index.ts +++ b/src/date-fns/_lib/addLeadingZeros/index.ts @@ -1,8 +1,5 @@ -export default function addLeadingZeros(number: number, targetLength: number): string { +export function addLeadingZeros(number: number, targetLength: number): string { const sign = number < 0 ? '-' : ''; - let output = Math.abs(number).toString(); - while (output.length < targetLength) { - output = '0' + output; - } + const output = Math.abs(number).toString().padStart(targetLength, '0'); return sign + output; } diff --git a/src/date-fns/_lib/defaultLocale/index.ts b/src/date-fns/_lib/defaultLocale/index.ts index ce28847..401e874 100644 --- a/src/date-fns/_lib/defaultLocale/index.ts +++ b/src/date-fns/_lib/defaultLocale/index.ts @@ -1,2 +1 @@ -import defaultLocale from '../../locale/en-US/index'; -export default defaultLocale; +export { enUS as defaultLocale } from '../../locale/en-US/index'; diff --git a/src/date-fns/_lib/defaultOptions/index.ts b/src/date-fns/_lib/defaultOptions/index.ts index 9ab24f4..ed55b57 100644 --- a/src/date-fns/_lib/defaultOptions/index.ts +++ b/src/date-fns/_lib/defaultOptions/index.ts @@ -1,6 +1,6 @@ -import type { FirstWeekContainsDateOptions, LocaleOptions, WeekStartOptions } from '../../types'; +import type { FirstWeekContainsDateOptions, Locale, LocalizedOptions, WeekOptions } from '../../types'; -export type DefaultOptions = LocaleOptions & WeekStartOptions & FirstWeekContainsDateOptions; +export type DefaultOptions = LocalizedOptions & WeekOptions & FirstWeekContainsDateOptions; let defaultOptions: DefaultOptions = {}; diff --git a/src/date-fns/_lib/format/formatters/index.ts b/src/date-fns/_lib/format/formatters/index.ts index be7789c..7cac323 100644 --- a/src/date-fns/_lib/format/formatters/index.ts +++ b/src/date-fns/_lib/format/formatters/index.ts @@ -1,20 +1,20 @@ -import getDayOfYear from '../../../getDayOfYear/index'; -import getISOWeek from '../../../getISOWeek/index'; -import getISOWeekYear from '../../../getISOWeekYear/index'; -import getWeek from '../../../getWeek/index'; -import getWeekYear from '../../../getWeekYear/index'; +import { getDayOfYear } from '../../../getDayOfYear/index'; +import { getISOWeek } from '../../../getISOWeek/index'; +import { getISOWeekYear } from '../../../getISOWeekYear/index'; +import { getWeek } from '../../../getWeek/index'; +import { getWeekYear } from '../../../getWeekYear/index'; import type { LocaleDayPeriod, Localize } from '../../../locale/types'; import type { Day, Era, FirstWeekContainsDateOptions, - LocaleOptions, + LocalizedOptions, Month, Quarter, - WeekStartOptions, + WeekOptions, } from '../../../types'; -import addLeadingZeros from '../../addLeadingZeros/index'; -import lightFormatters from '../lightFormatters/index'; +import { addLeadingZeros } from '../../addLeadingZeros/index'; +import { lightFormatters } from '../lightFormatters/index'; const dayPeriodEnum = { am: 'am', @@ -31,9 +31,7 @@ type Formatter = ( date: Date, token: string, localize: Localize, - options: Required & { - _originalDate: Date; - }, + options: Required & WeekOptions & FirstWeekContainsDateOptions>, ) => string; /* @@ -82,7 +80,7 @@ type Formatter = ( * - `p` is long localized time format */ -const formatters: { [token: string]: Formatter } = { +export const formatters: { [token: string]: Formatter } = { // Era G: function (date, token, localize) { const era: Era = date.getFullYear() > 0 ? 1 : 0; @@ -246,7 +244,10 @@ const formatters: { [token: string]: Formatter } = { }); // J, F, ..., D case 'MMMMM': - return localize.month(month, { width: 'narrow', context: 'formatting' }); + return localize.month(month, { + width: 'narrow', + context: 'formatting', + }); // January, February, ..., December case 'MMMM': default: @@ -275,7 +276,10 @@ const formatters: { [token: string]: Formatter } = { }); // J, F, ..., D case 'LLLLL': - return localize.month(month, { width: 'narrow', context: 'standalone' }); + return localize.month(month, { + width: 'narrow', + context: 'standalone', + }); // January, February, ..., December case 'LLLL': default: @@ -352,7 +356,10 @@ const formatters: { [token: string]: Formatter } = { // Tuesday case 'EEEE': default: - return localize.day(dayOfWeek, { width: 'wide', context: 'formatting' }); + return localize.day(dayOfWeek, { + width: 'wide', + context: 'formatting', + }); } }, @@ -390,7 +397,10 @@ const formatters: { [token: string]: Formatter } = { // Tuesday case 'eeee': default: - return localize.day(dayOfWeek, { width: 'wide', context: 'formatting' }); + return localize.day(dayOfWeek, { + width: 'wide', + context: 'formatting', + }); } }, @@ -428,7 +438,10 @@ const formatters: { [token: string]: Formatter } = { // Tuesday case 'cccc': default: - return localize.day(dayOfWeek, { width: 'wide', context: 'standalone' }); + return localize.day(dayOfWeek, { + width: 'wide', + context: 'standalone', + }); } }, @@ -467,7 +480,10 @@ const formatters: { [token: string]: Formatter } = { // Tuesday case 'iiii': default: - return localize.day(dayOfWeek, { width: 'wide', context: 'formatting' }); + return localize.day(dayOfWeek, { + width: 'wide', + context: 'formatting', + }); } }, @@ -647,9 +663,8 @@ const formatters: { [token: string]: Formatter } = { }, // Timezone (ISO-8601. If offset is 0, output is always `'Z'`) - X: function (date, token, _localize, options) { - const originalDate = options._originalDate || date; - const timezoneOffset = originalDate.getTimezoneOffset(); + X: function (date, token, _localize) { + const timezoneOffset = date.getTimezoneOffset(); if (timezoneOffset === 0) { return 'Z'; @@ -678,9 +693,8 @@ const formatters: { [token: string]: Formatter } = { }, // Timezone (ISO-8601. If offset is 0, output is `'+00:00'` or equivalent) - x: function (date, token, _localize, options) { - const originalDate = options._originalDate || date; - const timezoneOffset = originalDate.getTimezoneOffset(); + x: function (date, token, _localize) { + const timezoneOffset = date.getTimezoneOffset(); switch (token) { // Hours and optional minutes @@ -705,9 +719,8 @@ const formatters: { [token: string]: Formatter } = { }, // Timezone (GMT) - O: function (date, token, _localize, options) { - const originalDate = options._originalDate || date; - const timezoneOffset = originalDate.getTimezoneOffset(); + O: function (date, token, _localize) { + const timezoneOffset = date.getTimezoneOffset(); switch (token) { // Short @@ -723,9 +736,8 @@ const formatters: { [token: string]: Formatter } = { }, // Timezone (specific non-location) - z: function (date, token, _localize, options) { - const originalDate = options._originalDate || date; - const timezoneOffset = originalDate.getTimezoneOffset(); + z: function (date, token, _localize) { + const timezoneOffset = date.getTimezoneOffset(); switch (token) { // Short @@ -741,16 +753,14 @@ const formatters: { [token: string]: Formatter } = { }, // Seconds timestamp - t: function (date, token, _localize, options) { - const originalDate = options._originalDate || date; - const timestamp = Math.floor(originalDate.getTime() / 1000); + t: function (date, token, _localize) { + const timestamp = Math.trunc(date.getTime() / 1000); return addLeadingZeros(timestamp, token.length); }, // Milliseconds timestamp - T: function (date, token, _localize, options) { - const originalDate = options._originalDate || date; - const timestamp = originalDate.getTime(); + T: function (date, token, _localize) { + const timestamp = date.getTime(); return addLeadingZeros(timestamp, token.length); }, }; @@ -758,7 +768,7 @@ const formatters: { [token: string]: Formatter } = { function formatTimezoneShort(offset: number, delimiter: string = ''): string { const sign = offset > 0 ? '-' : '+'; const absOffset = Math.abs(offset); - const hours = Math.floor(absOffset / 60); + const hours = Math.trunc(absOffset / 60); const minutes = absOffset % 60; if (minutes === 0) { return sign + String(hours); @@ -777,9 +787,7 @@ function formatTimezoneWithOptionalMinutes(offset: number, delimiter?: string): function formatTimezone(offset: number, delimiter: string = ''): string { const sign = offset > 0 ? '-' : '+'; const absOffset = Math.abs(offset); - const hours = addLeadingZeros(Math.floor(absOffset / 60), 2); + const hours = addLeadingZeros(Math.trunc(absOffset / 60), 2); const minutes = addLeadingZeros(absOffset % 60, 2); return sign + hours + delimiter + minutes; } - -export default formatters; diff --git a/src/date-fns/_lib/format/lightFormatters/index.ts b/src/date-fns/_lib/format/lightFormatters/index.ts index e4233d8..edaff7d 100644 --- a/src/date-fns/_lib/format/lightFormatters/index.ts +++ b/src/date-fns/_lib/format/lightFormatters/index.ts @@ -1,4 +1,4 @@ -import addLeadingZeros from '../../addLeadingZeros/index'; +import { addLeadingZeros } from '../../addLeadingZeros/index'; /* * | | Unit | | Unit | @@ -13,7 +13,7 @@ import addLeadingZeros from '../../addLeadingZeros/index'; * Letters marked by * are not implemented but reserved by Unicode standard. */ -const formatters = { +export const lightFormatters = { // Year y(date: Date, token: string): string { // From http://www.unicode.org/reports/tr35/tr35-31/tr35-dates.html#Date_Format_tokens @@ -44,8 +44,10 @@ const formatters = { // AM or PM a(date: Date, token: string): string { - // this hack is required because setHours doesn't work for hours that are spring-forward + // [PATCH:] this hack is required because setHours doesn't work for hours that are spring-forward const dayPeriodEnumValue = ((date as any)[Symbol.for('UTCHours')] ?? date.getHours()) / 12 >= 1 ? 'pm' : 'am'; + // original: + // const dayPeriodEnumValue = date.getHours() / 12 >= 1 ? "pm" : "am"; switch (token) { case 'a': @@ -54,7 +56,7 @@ const formatters = { case 'aaa': return dayPeriodEnumValue; case 'aaaaa': - return dayPeriodEnumValue[0] as string; + return dayPeriodEnumValue[0]!; case 'aaaa': default: return dayPeriodEnumValue === 'am' ? 'a.m.' : 'p.m.'; @@ -63,14 +65,18 @@ const formatters = { // Hour [1-12] h(date: Date, token: string): string { - // this hack is required because setHours doesn't work for hours that are spring-forward + // [PATCH:] this hack is required because setHours doesn't work for hours that are spring-forward return addLeadingZeros(((date as any)[Symbol.for('UTCHours')] ?? date.getHours()) % 12 || 12, token.length); + // original: + // return addLeadingZeros(date.getHours() % 12 || 12, token.length); }, // Hour [0-23] H(date: Date, token: string): string { - // this hack is required because setHours doesn't work for hours that are spring-forward + // [PATCH:] this hack is required because setHours doesn't work for hours that are spring-forward return addLeadingZeros((date as any)[Symbol.for('UTCHours')] ?? date.getHours(), token.length); + // original: + // return addLeadingZeros(date.getHours(), token.length); }, // Minute @@ -87,9 +93,7 @@ const formatters = { S(date: Date, token: string): string { const numberOfDigits = token.length; const milliseconds = date.getMilliseconds(); - const fractionalSeconds = Math.floor(milliseconds * Math.pow(10, numberOfDigits - 3)); + const fractionalSeconds = Math.trunc(milliseconds * Math.pow(10, numberOfDigits - 3)); return addLeadingZeros(fractionalSeconds, token.length); }, }; - -export default formatters; diff --git a/src/date-fns/_lib/format/longFormatters/index.ts b/src/date-fns/_lib/format/longFormatters/index.ts index 95bf8ff..36fd000 100644 --- a/src/date-fns/_lib/format/longFormatters/index.ts +++ b/src/date-fns/_lib/format/longFormatters/index.ts @@ -32,7 +32,7 @@ const timeLongFormatter: LongFormatter = (pattern, formatLong) => { const dateTimeLongFormatter: LongFormatter = (pattern: string, formatLong: FormatLong) => { const matchResult = pattern.match(/(P+)(p+)?/) || []; - const datePattern = matchResult[1] as string; + const datePattern = matchResult[1]; const timePattern = matchResult[2]; if (!timePattern) { @@ -58,13 +58,11 @@ const dateTimeLongFormatter: LongFormatter = (pattern: string, formatLong: Forma } return dateTimeFormat - .replace('{{date}}', dateLongFormatter(datePattern, formatLong)) + .replace('{{date}}', dateLongFormatter(datePattern!, formatLong)) .replace('{{time}}', timeLongFormatter(timePattern, formatLong)); }; -const longFormatters: Record = { +export const longFormatters: Record = { p: timeLongFormatter, P: dateTimeLongFormatter, }; - -export default longFormatters; diff --git a/src/date-fns/_lib/getRoundingMethod/index.ts b/src/date-fns/_lib/getRoundingMethod/index.ts new file mode 100644 index 0000000..f1ce739 --- /dev/null +++ b/src/date-fns/_lib/getRoundingMethod/index.ts @@ -0,0 +1,10 @@ +import type { RoundingMethod } from '../../types'; + +export function getRoundingMethod(method: RoundingMethod | undefined) { + return (number: number) => { + const round = method ? Math[method] : Math.trunc; + const result = round(number); + // Prevent negative zero + return result === 0 ? 0 : result; + }; +} diff --git a/src/date-fns/_lib/getTimezoneOffsetInMilliseconds/index.ts b/src/date-fns/_lib/getTimezoneOffsetInMilliseconds/index.ts index eeaf0fc..3d5106b 100644 --- a/src/date-fns/_lib/getTimezoneOffsetInMilliseconds/index.ts +++ b/src/date-fns/_lib/getTimezoneOffsetInMilliseconds/index.ts @@ -1,3 +1,5 @@ +import { toDate } from '../../toDate/index'; + /** * Google Chrome as of 67.0.3396.87 introduced timezones with offset that includes seconds. * They usually appear for dates that denote time before the timezones were introduced @@ -9,18 +11,19 @@ * * This function returns the timezone offset in milliseconds that takes seconds in account. */ -export default function getTimezoneOffsetInMilliseconds(date: Date): number { +export function getTimezoneOffsetInMilliseconds(date: Date | number | string): number { + const _date = toDate(date); const utcDate = new Date( Date.UTC( - date.getFullYear(), - date.getMonth(), - date.getDate(), - date.getHours(), - date.getMinutes(), - date.getSeconds(), - date.getMilliseconds(), + _date.getFullYear(), + _date.getMonth(), + _date.getDate(), + _date.getHours(), + _date.getMinutes(), + _date.getSeconds(), + _date.getMilliseconds(), ), ); - utcDate.setUTCFullYear(date.getFullYear()); - return date.getTime() - utcDate.getTime(); + utcDate.setUTCFullYear(_date.getFullYear()); + return +date - +utcDate; } diff --git a/src/date-fns/_lib/protectedTokens/index.ts b/src/date-fns/_lib/protectedTokens/index.ts index a303937..dd541bf 100644 --- a/src/date-fns/_lib/protectedTokens/index.ts +++ b/src/date-fns/_lib/protectedTokens/index.ts @@ -1,30 +1,23 @@ -const protectedDayOfYearTokens = ['D', 'DD']; -const protectedWeekYearTokens = ['YY', 'YYYY']; +const dayOfYearTokenRE = /^D+$/; +const weekYearTokenRE = /^Y+$/; -export function isProtectedDayOfYearToken(token: string): boolean { - return protectedDayOfYearTokens.indexOf(token) !== -1; +const throwTokens = ['D', 'DD', 'YY', 'YYYY']; + +export function isProtectedDayOfYearToken(token: string) { + return dayOfYearTokenRE.test(token); +} + +export function isProtectedWeekYearToken(token: string) { + return weekYearTokenRE.test(token); } -export function isProtectedWeekYearToken(token: string): boolean { - return protectedWeekYearTokens.indexOf(token) !== -1; +export function warnOrThrowProtectedError(token: string, format: string, input: string): void { + const _message = message(token, format, input); + console.warn(_message); + if (throwTokens.includes(token)) throw new RangeError(_message); } -export function throwProtectedError(token: string, format: string, input: string): void { - if (token === 'YYYY') { - throw new RangeError( - `Use \`yyyy\` instead of \`YYYY\` (in \`${format}\`) for formatting years to the input \`${input}\`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md`, - ); - } else if (token === 'YY') { - throw new RangeError( - `Use \`yy\` instead of \`YY\` (in \`${format}\`) for formatting years to the input \`${input}\`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md`, - ); - } else if (token === 'D') { - throw new RangeError( - `Use \`d\` instead of \`D\` (in \`${format}\`) for formatting days of the month to the input \`${input}\`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md`, - ); - } else if (token === 'DD') { - throw new RangeError( - `Use \`dd\` instead of \`DD\` (in \`${format}\`) for formatting days of the month to the input \`${input}\`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md`, - ); - } +function message(token: string, format: string, input: string) { + const subject = token[0] === 'Y' ? 'years' : 'days of the month'; + return `Use \`${token.toLowerCase()}\` instead of \`${token}\` (in \`${format}\`) for formatting ${subject} to the input \`${input}\`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md`; } diff --git a/src/date-fns/_lib/roundingMethods/index.ts b/src/date-fns/_lib/roundingMethods/index.ts deleted file mode 100644 index c4951f4..0000000 --- a/src/date-fns/_lib/roundingMethods/index.ts +++ /dev/null @@ -1,18 +0,0 @@ -import type { RoundingMethod } from '../../types'; - -type RoundingFn = typeof Math.round; - -type RoundingFnsMap = { [method in RoundingMethod]: RoundingFn }; - -const roundingMap: RoundingFnsMap = { - ceil: Math.ceil, - round: Math.round, - floor: Math.floor, - trunc: (value: number) => (value < 0 ? Math.ceil(value) : Math.floor(value)), // Math.trunc is not supported by IE -}; - -const defaultRoundingMethod: RoundingMethod = 'trunc'; - -export function getRoundingMethod(method: RoundingMethod | undefined) { - return method ? roundingMap[method] : roundingMap[defaultRoundingMethod]; -} diff --git a/src/date-fns/_lib/test/index.ts b/src/date-fns/_lib/test/index.ts new file mode 100644 index 0000000..8b125e2 --- /dev/null +++ b/src/date-fns/_lib/test/index.ts @@ -0,0 +1,29 @@ +import { addLeadingZeros } from '../addLeadingZeros/index'; +import { setDefaultOptions } from '../defaultOptions/index'; + +export function assertType(_: T): void {} + +export function resetDefaultOptions(): void { + setDefaultOptions({}); +} + +// This makes sure we create the consistent offsets across timezones, no matter where these tests are ran. +export function generateOffset(originalDate: Date) { + // Add the timezone. + let offset = ''; + const tzOffset = originalDate.getTimezoneOffset(); + + if (tzOffset !== 0) { + const absoluteOffset = Math.abs(tzOffset); + const hourOffset = addLeadingZeros(Math.trunc(absoluteOffset / 60), 2); + const minuteOffset = addLeadingZeros(absoluteOffset % 60, 2); + // If less than 0, the sign is +, because it is ahead of time. + const sign = tzOffset < 0 ? '+' : '-'; + + offset = `${sign}${hourOffset}:${minuteOffset}`; + } else { + offset = 'Z'; + } + + return offset; +} diff --git a/src/date-fns/_test/dst/addBusinessDays/basic.ts b/src/date-fns/_test/dst/addBusinessDays/basic.ts new file mode 100644 index 0000000..ddebe6d --- /dev/null +++ b/src/date-fns/_test/dst/addBusinessDays/basic.ts @@ -0,0 +1,17 @@ +// This is basic DST test for addBusinessDays + +import assert from 'assert'; +import { addBusinessDays } from '../../../addBusinessDays/index.js'; + +if (process.env.TZ !== 'America/Santiago') throw new Error('The test must be run with TZ=America/Santiago'); + +if (parseInt(process.version.match(/^v(\d+)\./)?.[1] || '0') < 10) + throw new Error('The test must be run on Node.js version >= 10'); + +console.log(addBusinessDays(new Date(2014, 8 /* Sep */, 1), 10).toString()); + +assert.deepStrictEqual( + // new Date(2014, 8, 7) is the DST day + addBusinessDays(new Date(2014, 8 /* Sep */, 1), 10).toString(), + 'Mon Sep 15 2014 00:00:00 GMT-0300 (Chile Summer Time)', +); diff --git a/src/date-fns/_test/dst/eachDayOfInterval/basic.ts b/src/date-fns/_test/dst/eachDayOfInterval/basic.ts new file mode 100644 index 0000000..4bddb1c --- /dev/null +++ b/src/date-fns/_test/dst/eachDayOfInterval/basic.ts @@ -0,0 +1,21 @@ +// This is basic DST test for eachDayOfInterval + +import { eachDayOfInterval } from '../../../eachDayOfInterval/index.js'; +import assert from 'assert'; + +if (process.env.TZ !== 'Asia/Damascus') throw new Error('The test must be run with TZ=Asia/Damascus'); + +if (parseInt(process.version.match(/^v(\d+)\./)?.[1] || '0') < 10) + throw new Error('The test must be run on Node.js version >= 10'); + +assert.deepStrictEqual( + eachDayOfInterval({ + start: new Date(2020, 2, 26), + end: new Date(2020, 2, 28), + }).map((d) => d.toString()), + [ + 'Thu Mar 26 2020 00:00:00 GMT+0200 (GMT+03:00)', + 'Fri Mar 27 2020 01:00:00 GMT+0300 (GMT+03:00)', + 'Sat Mar 28 2020 00:00:00 GMT+0300 (GMT+03:00)', + ], +); diff --git a/src/date-fns/_test/dst/formatDistanceStrict/cairo.ts b/src/date-fns/_test/dst/formatDistanceStrict/cairo.ts new file mode 100644 index 0000000..513360f --- /dev/null +++ b/src/date-fns/_test/dst/formatDistanceStrict/cairo.ts @@ -0,0 +1,8 @@ +// This is DST test for formatDistanceStrict in the Cairo timezone + +import { formatDistanceStrict } from '../../../formatDistanceStrict/index.js'; +import assert from 'assert'; + +if (process.env.TZ !== 'Africa/Cairo') throw new Error('The test must be run with TZ=Africa/Cairo'); + +assert.strictEqual(formatDistanceStrict(new Date(1986, 3, 4, 10, 32, 0), new Date(1986, 4, 4, 10, 32, 0)), '1 month'); diff --git a/src/date-fns/_test/dst/formatDistanceStrict/melbourne.ts b/src/date-fns/_test/dst/formatDistanceStrict/melbourne.ts new file mode 100644 index 0000000..304ef62 --- /dev/null +++ b/src/date-fns/_test/dst/formatDistanceStrict/melbourne.ts @@ -0,0 +1,12 @@ +// This is DST test for formatDistanceStrict in the Melbourne timezone + +import { formatDistanceStrict } from '../../../formatDistanceStrict/index.js'; +import { parseISO } from '../../../parseISO/index.js'; +import assert from 'assert'; + +if (process.env.TZ !== 'Australia/Melbourne') throw new Error('The test must be run with TZ=Australia/Melbourne'); + +assert.strictEqual( + formatDistanceStrict(parseISO('2020-04-05T01:00:00+11:00'), parseISO('2020-04-05T03:00:00+10:00')), + '3 hours', +); diff --git a/src/date-fns/_test/dst/getOverlappingDaysInIntervals/basic.ts b/src/date-fns/_test/dst/getOverlappingDaysInIntervals/basic.ts new file mode 100644 index 0000000..31c17e6 --- /dev/null +++ b/src/date-fns/_test/dst/getOverlappingDaysInIntervals/basic.ts @@ -0,0 +1,16 @@ +import assert from 'assert'; +import { getOverlappingDaysInIntervals } from '../../../getOverlappingDaysInIntervals/index.js'; + +assert.strictEqual( + getOverlappingDaysInIntervals( + { + start: new Date(2001, 8 /* Sep */, 1, 16), + end: new Date(2023, 11 /* Dec */, 20, 16), + }, + { + start: new Date(2023, 11 /* Dec */, 21, 16), + end: new Date(2001, 8 /* Sep */, 9, 16), + }, + ), + 8137, +); diff --git a/src/date-fns/_test/dst/parseISO/basic.ts b/src/date-fns/_test/dst/parseISO/basic.ts new file mode 100644 index 0000000..2267ef8 --- /dev/null +++ b/src/date-fns/_test/dst/parseISO/basic.ts @@ -0,0 +1,23 @@ +// This is basic DST test for parseISO + +import { parseISO } from '../../../parseISO/index.js'; +import assert from 'assert'; + +if (process.env.TZ !== 'America/Sao_Paulo') throw new Error('The test must be run with TZ=America/Sao_Paulo'); + +if (parseInt(process.version.match(/^v(\d+)\./)?.[1] || '0') < 10) + throw new Error('The test must be run on Node.js version >= 10'); + +// Test DST start edge +assert.strictEqual(parseISO('2018-11-03').getDate(), 3); +assert.strictEqual(parseISO('2018-11-04').getDate(), 4); // DST start +assert.strictEqual(parseISO('2018-11-05').getDate(), 5); + +// Test DST end edge +assert.strictEqual(parseISO('2019-02-15').getDate(), 15); +assert.strictEqual(parseISO('2019-02-16').getDate(), 16); // DST end +assert.strictEqual(parseISO('2019-02-17').getDate(), 17); + +// Test creation of nonexistent time +assert.strictEqual(parseISO('2018-11-04T00:00').toString(), 'Sun Nov 04 2018 01:00:00 GMT-0200 (Brasilia Summer Time)'); +assert.strictEqual(parseISO('2018-11-04T00:30').toString(), 'Sun Nov 04 2018 01:30:00 GMT-0200 (Brasilia Summer Time)'); diff --git a/src/date-fns/_test/dst/parseISO/samoa.ts b/src/date-fns/_test/dst/parseISO/samoa.ts new file mode 100644 index 0000000..5330002 --- /dev/null +++ b/src/date-fns/_test/dst/parseISO/samoa.ts @@ -0,0 +1,12 @@ +// This is an edge case DST test for parseISO + +import { parseISO } from '../../../parseISO/index.js'; +import assert from 'assert'; + +if (process.env.TZ !== 'Pacific/Apia') throw new Error('The test must be run with TZ=Pacific/Apia'); + +if (parseInt(process.version.match(/^v(\d+)\./)?.[1] || '0') < 10) + throw new Error('The test must be run on Node.js version >= 10'); + +assert.strictEqual(parseISO('2011-12-30').getDate(), 31); +assert.strictEqual(parseISO('2011-12-30T03:30').toString(), 'Sat Dec 31 2011 03:30:00 GMT+1400 (Apia Daylight Time)'); diff --git a/src/date-fns/_test/dst/parseISO/sydney.ts b/src/date-fns/_test/dst/parseISO/sydney.ts new file mode 100644 index 0000000..a235d3e --- /dev/null +++ b/src/date-fns/_test/dst/parseISO/sydney.ts @@ -0,0 +1,57 @@ +// This is basic DST test for parseISO + +import { parseISO } from '../../../parseISO/index.js'; +import assert from 'assert'; + +if (process.env.TZ !== 'Australia/Sydney') throw new Error('The test must be run with TZ=Australia/Sydney'); + +if (parseInt(process.version.match(/^v(\d+)\./)?.[1] || '0') < 10) + throw new Error('The test must be run on Node.js version >= 10'); + +// Test DST start edge +assert.strictEqual(parseISO('2019-10-06').getDate(), 6); // DST start +assert.strictEqual(parseISO('2019-10-07').getDate(), 7); +assert.strictEqual( + parseISO('2019-10-06T01:00:00').toString(), + 'Sun Oct 06 2019 01:00:00 GMT+1000 (Australian Eastern Standard Time)', +); +assert.strictEqual( + parseISO('2019-10-06T02:00:00').toString(), + 'Sun Oct 06 2019 03:00:00 GMT+1100 (Australian Eastern Daylight Time)', +); + +assert.strictEqual( + parseISO('2019-10-06T05:00:00').toString(), + 'Sun Oct 06 2019 05:00:00 GMT+1100 (Australian Eastern Daylight Time)', +); + +// Test DST end edge +assert.strictEqual(parseISO('2019-04-06').getDate(), 6); +assert.strictEqual(parseISO('2019-04-07').getDate(), 7); // DST end +assert.strictEqual( + parseISO('2019-04-06T11:00:00').toString(), + 'Sat Apr 06 2019 11:00:00 GMT+1100 (Australian Eastern Daylight Time)', +); +assert.strictEqual( + parseISO('2019-04-07T11:00:00').toString(), + 'Sun Apr 07 2019 11:00:00 GMT+1000 (Australian Eastern Standard Time)', +); + +assert.strictEqual( + parseISO('2019-04-07T00:00:00').toString(), + 'Sun Apr 07 2019 00:00:00 GMT+1100 (Australian Eastern Daylight Time)', +); + +// test edge cases for months, years +assert.strictEqual( + parseISO('2020-01-01T00:00:00').toString(), + 'Wed Jan 01 2020 00:00:00 GMT+1100 (Australian Eastern Daylight Time)', +); +assert.strictEqual( + parseISO('2019-12-31T23:59:59').toString(), + 'Tue Dec 31 2019 23:59:59 GMT+1100 (Australian Eastern Daylight Time)', +); +assert.strictEqual( + parseISO('2020-02-29T23:59:59').toString(), + 'Sat Feb 29 2020 23:59:59 GMT+1100 (Australian Eastern Daylight Time)', +); diff --git a/src/date-fns/_test/dst/tzOffsetTransitions.ts b/src/date-fns/_test/dst/tzOffsetTransitions.ts new file mode 100644 index 0000000..22f60a2 --- /dev/null +++ b/src/date-fns/_test/dst/tzOffsetTransitions.ts @@ -0,0 +1,140 @@ +type PartialInterval = { + start: Date | undefined; + end: Date | undefined; +}; + +/** + * Fetch the start and end of DST for the local time + * zone in a given year. + * We'll assume that DST start & end are the first + * forward and the last back transitions in the year, + * except transitions in Jan or Dec which are likely + * to be permanent TZ changes rather than DST changes. + * @param year + * @returns object with two Date-valued properties: + * - `start` is the first instant of DST in the Spring, + * or undefined if there's no DST in this year. + * - `end` is the first instant of standard time + * in the Fall, or undefined if there's no DST in + * this year. + */ +export function getDstTransitions(year: number): PartialInterval { + const result: PartialInterval = { + start: undefined, + end: undefined, + }; + const transitions = getTzOffsetTransitions(year); + for (let i = 0; i < transitions.length; i++) { + const t = transitions[i]!; + const month = t.date.getMonth(); + if (month > 0 && month < 11) { + if (t.type === 'forward') result.start = t.date; + if (t.type === 'back' && !result.end) result.end = t.date; + } + } + return result; +} + +function isValidDate(date: unknown): date is Date { + return date instanceof Date && !isNaN(date.getTime()); +} + +const MINUTE = 1000 * 60; + +function firstTickInLocalDay(date: Date): Date { + const dateNumber = date.getDate(); + let prev = date; + let d = date; + do { + prev = d; + d = new Date(d.getTime() - MINUTE); + } while (dateNumber === d.getDate()); + return prev; +} + +function fiveMinutesLater(date: Date): Date { + return new Date(date.getTime() + 5 * MINUTE); +} + +function oneDayLater(date: Date): Date { + const d = new Date(date); + d.setDate(d.getDate() + 1); + return firstTickInLocalDay(d); +} + +function previousTickTimezoneOffset(date: Date): number { + const d = new Date(date.getTime() - 1); + return d.getTimezoneOffset(); +} + +/** + * Fetch all timezone-offset transitions in a given + * year. These are almost always DST transitions, + * but sometimes there are non-DST changes, e.g. + * when a country changes its time zone + * @param year + * @returns array of objects, each with the following + * propeerties: + * - `date` - a `Date` representing the first instant + * when the new timezone offset is effective. + * - `type` - either `forward` for skippnig time like + * the Spring transition to DST. + * - `before` - the timezone offset before the tranition. + * For example, the UTC-0400 offset will return -240. + * To match how times are displayed in ISO 8601 format, + * the sign of this value is reversed from the return + * value of `Date.getTimezoneOffset`. + * - `after` - the timezone offset after the tranition. + * Examples and caveats are the same as `before`. + + */ +export function getTzOffsetTransitions(year: number) { + // start at the end of the previous day + let date = firstTickInLocalDay(new Date(year, 0, 1)); + if (!isValidDate(date)) { + throw new Error('Invalid Date'); + } + let baseTzOffset = previousTickTimezoneOffset(date); + const transitions = []; + do { + let tzOffset = date.getTimezoneOffset(); + if (baseTzOffset !== tzOffset) { + if (tzOffset !== previousTickTimezoneOffset(date)) { + // Transition is the first tick of a local day. + transitions.push({ + date: date, + type: tzOffset < baseTzOffset ? 'forward' : 'back', + before: -baseTzOffset, + after: -tzOffset, + }); + baseTzOffset = tzOffset; + } else { + // transition was not at the start of the day, so it must have happened + // yesterday. Back up one day and find the minute where it happened. + let transitionDate = new Date(date.getTime()); + transitionDate.setDate(transitionDate.getDate() - 1); + + // Iterate through each 5 mins of the day until we find a transition. + // TODO: this could be optimized to search hours then minutes or by or + // by using a binary search. + const dayNumber = transitionDate.getDate(); + while (isValidDate(transitionDate) && transitionDate.getDate() === dayNumber) { + tzOffset = transitionDate.getTimezoneOffset(); + if (baseTzOffset !== tzOffset) { + transitions.push({ + date: transitionDate, + type: tzOffset < baseTzOffset ? 'forward' : 'back', + before: -baseTzOffset, + after: -tzOffset, + }); + baseTzOffset = tzOffset; + break; // assuming only 1 transition per day + } + transitionDate = fiveMinutesLater(transitionDate); + } + } + } + date = oneDayLater(date); + } while (date.getFullYear() === year); + return transitions; +} diff --git a/src/date-fns/_test/formatISO/india.ts b/src/date-fns/_test/formatISO/india.ts new file mode 100644 index 0000000..5b2e051 --- /dev/null +++ b/src/date-fns/_test/formatISO/india.ts @@ -0,0 +1,9 @@ +import { formatISO } from '../../formatISO/index.js'; +import assert from 'assert'; + +if (process.env.TZ !== 'Asia/Kolkata') throw new Error('The test must be run with TZ=Asia/Kolkata'); + +if (parseInt(process.version.match(/^v(\d+)\./)?.[1] || '0') < 10) + throw new Error('The test must be run on Node.js version >= 10'); + +assert.strictEqual(formatISO(new Date(1986, 3, 4, 10, 33, 1)), '1986-04-04T10:33:01+05:30'); diff --git a/src/date-fns/_test/formatRFC3339/australia.ts b/src/date-fns/_test/formatRFC3339/australia.ts new file mode 100644 index 0000000..77a7df1 --- /dev/null +++ b/src/date-fns/_test/formatRFC3339/australia.ts @@ -0,0 +1,20 @@ +import { formatRFC3339 } from '../../formatRFC3339/index.js'; +import assert from 'assert'; + +/** + * Australia/Eucla (Australia) is interesting for its positive to UTC time, with 45 minutes offset. + * It's independent from Standard and Summer time. + */ +if (process.env.TZ !== 'Australia/Eucla') throw new Error('The test must be run with TZ=Australia/Eucla (UTC+08:45)'); + +if (parseInt(process.version.match(/^v(\d+)\./)?.[1] || '0') < 10) + throw new Error('The test must be run on Node.js version >= 10'); + +// Old date +assert.strictEqual(formatRFC3339(new Date(1986, 3, 4, 10, 33, 1)), '1986-04-04T10:33:01+08:45'); + +// Standard time (Eucla have +08:45) +assert.strictEqual(formatRFC3339(new Date(2020, 0, 23, 5, 0, 54)), '2020-01-23T05:00:54+08:45'); + +// Summer time (Eucla have +08:45) +assert.strictEqual(formatRFC3339(new Date(2020, 6, 30, 20, 59, 1)), '2020-07-30T20:59:01+08:45'); diff --git a/src/date-fns/_test/formatRFC3339/india.ts b/src/date-fns/_test/formatRFC3339/india.ts new file mode 100644 index 0000000..d24209b --- /dev/null +++ b/src/date-fns/_test/formatRFC3339/india.ts @@ -0,0 +1,20 @@ +import { formatRFC3339 } from '../../formatRFC3339/index.js'; +import assert from 'assert'; + +/** + * Asia/Kolkata (India) is interesting for its positive to UTC time, with 30 minutes offset. + * It's independent from Standard and Summer time. + */ +if (process.env.TZ !== 'Asia/Kolkata') throw new Error('The test must be run with TZ=Asia/Kolkata'); + +if (parseInt(process.version.match(/^v(\d+)\./)?.[1] || '0') < 10) + throw new Error('The test must be run on Node.js version >= 10'); + +// Old date +assert.strictEqual(formatRFC3339(new Date(1986, 3, 4, 10, 33, 1)), '1986-04-04T10:33:01+05:30'); + +// Standard time (india always have +05:30) +assert.strictEqual(formatRFC3339(new Date(2020, 0, 23, 5, 0, 54)), '2020-01-23T05:00:54+05:30'); + +// Summer time (india always have +05:30) +assert.strictEqual(formatRFC3339(new Date(2020, 6, 30, 20, 59, 1)), '2020-07-30T20:59:01+05:30'); diff --git a/src/date-fns/_test/formatRFC3339/newfoundland.ts b/src/date-fns/_test/formatRFC3339/newfoundland.ts new file mode 100644 index 0000000..5985c30 --- /dev/null +++ b/src/date-fns/_test/formatRFC3339/newfoundland.ts @@ -0,0 +1,21 @@ +import { formatRFC3339 } from '../../formatRFC3339/index.js'; +import assert from 'assert'; + +/** + * America/St_Johns (Canada) is interesting for its negative to UTC time, with 30 minutes offset. + * Bonus: It depends on Standard and Summer time. + */ +if (process.env.TZ !== 'America/St_Johns') + throw new Error('The test must be run with TZ=America/St_Johns (UTC-02:30 or UTC-03:30)'); + +if (parseInt(process.version.match(/^v(\d+)\./)?.[1] || '0') < 10) + throw new Error('The test must be run on Node.js version >= 10'); + +// Old date +assert.strictEqual(formatRFC3339(new Date(1986, 3, 4, 10, 33, 1)), '1986-04-04T10:33:01-03:30'); + +// Standard time (Newfoundland and Labrador have -03:30) +assert.strictEqual(formatRFC3339(new Date(2020, 0, 23, 5, 0, 54)), '2020-01-23T05:00:54-03:30'); + +// Summer time (Newfoundland and Labrador have -02:30) +assert.strictEqual(formatRFC3339(new Date(2020, 6, 30, 20, 59, 1)), '2020-07-30T20:59:01-02:30'); diff --git a/src/date-fns/_test/formatRFC3339/newzealand.ts b/src/date-fns/_test/formatRFC3339/newzealand.ts new file mode 100644 index 0000000..a4c83ce --- /dev/null +++ b/src/date-fns/_test/formatRFC3339/newzealand.ts @@ -0,0 +1,21 @@ +import { formatRFC3339 } from '../../formatRFC3339/index.js'; +import assert from 'assert'; + +/** + * Pacific/Chatham (Chatham Islands, New Zealand) is interesting for being the farthest from UTC. + * It depends on Standard (+12:45) and Summer time (+13:45). + */ +if (process.env.TZ !== 'Pacific/Chatham') + throw new Error('The test must be run with TZ=Pacific/Chatham (UTC+12:45 or UTC+13:45)'); + +if (parseInt(process.version.match(/^v(\d+)\./)?.[1] || '0') < 10) + throw new Error('The test must be run on Node.js version >= 10'); + +// Old date +assert.strictEqual(formatRFC3339(new Date(1986, 3, 4, 10, 33, 1)), '1986-04-04T10:33:01+12:45'); + +// Standard time (Chatham have +13:45) +assert.strictEqual(formatRFC3339(new Date(2020, 8, 27, 20, 59, 1)), '2020-09-27T20:59:01+13:45'); + +// Summer time (Chatham have +12:45) +assert.strictEqual(formatRFC3339(new Date(2020, 3, 5, 5, 0, 54)), '2020-04-05T05:00:54+12:45'); diff --git a/src/date-fns/_test/formatRFC3339/poland.ts b/src/date-fns/_test/formatRFC3339/poland.ts new file mode 100644 index 0000000..e233799 --- /dev/null +++ b/src/date-fns/_test/formatRFC3339/poland.ts @@ -0,0 +1,20 @@ +import { formatRFC3339 } from '../../formatRFC3339/index.js'; +import assert from 'assert'; + +/** + * Europe/Warsaw (Poland) is regular full-hours timezone + */ +if (process.env.TZ !== 'Europe/Warsaw') + throw new Error('The test must be run with TZ=Europe/Warsaw (UTC+02:00 or UTC+01:00)'); + +if (parseInt(process.version.match(/^v(\d+)\./)?.[1] || '0') < 10) + throw new Error('The test must be run on Node.js version >= 10'); + +// Old date +assert.strictEqual(formatRFC3339(new Date(1986, 3, 4, 10, 33, 1)), '1986-04-04T10:33:01+02:00'); + +// Standard time (Warsaw have +01:00) +assert.strictEqual(formatRFC3339(new Date(2020, 0, 23, 5, 0, 54)), '2020-01-23T05:00:54+01:00'); + +// Summer time (Warsaw have +02:00) +assert.strictEqual(formatRFC3339(new Date(2020, 6, 30, 20, 59, 1)), '2020-07-30T20:59:01+02:00'); diff --git a/src/date-fns/add/index.ts b/src/date-fns/add/index.ts index f603a51..5f8b6ab 100644 --- a/src/date-fns/add/index.ts +++ b/src/date-fns/add/index.ts @@ -1,7 +1,7 @@ -import addDays from '../addDays/index'; -import addMonths from '../addMonths/index'; -import constructFrom from '../constructFrom/index'; -import toDate from '../toDate/index'; +import { addDays } from '../addDays/index'; +import { addMonths } from '../addMonths/index'; +import { constructFrom } from '../constructFrom/index'; +import { toDate } from '../toDate/index'; import type { Duration } from '../types'; /** @@ -12,8 +12,10 @@ import type { Duration } from '../types'; * @description * Add the specified years, months, weeks, days, hours, minutes and seconds to the given date. * - * @param date - the date to be changed - * @param duration - the object with years, months, weeks, days, hours, minutes and seconds to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`. + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The date to be changed + * @param duration - The object with years, months, weeks, days, hours, minutes and seconds to be added. * * | Key | Description | * |----------------|------------------------------------| @@ -27,7 +29,7 @@ import type { Duration } from '../types'; * * All values default to 0 * - * @returns the new date with the seconds added + * @returns The new date with the seconds added * * @example * // Add the following duration to 1 September 2014, 10:19:50 @@ -36,18 +38,18 @@ import type { Duration } from '../types'; * months: 9, * weeks: 1, * days: 7, - * hours: 5, + * hours: 5,\\-7 * minutes: 9, * seconds: 30, * }) * //=> Thu Jun 15 2017 15:29:20 */ -export default function add(dirtyDate: DateType | number, duration: Duration): DateType { +export function add(date: DateType | number | string, duration: Duration): DateType { const { years = 0, months = 0, weeks = 0, days = 0, hours = 0, minutes = 0, seconds = 0 } = duration; // Add years and months - const date = toDate(dirtyDate); - const dateWithMonths = months || years ? addMonths(date, months + years * 12) : date; + const _date = toDate(date); + const dateWithMonths = months || years ? addMonths(_date, months + years * 12) : _date; // Add weeks and days const dateWithDays = days || weeks ? addDays(dateWithMonths, days + weeks * 7) : dateWithMonths; @@ -56,7 +58,7 @@ export default function add(dirtyDate: DateType | number, const minutesToAdd = minutes + hours * 60; const secondsToAdd = seconds + minutesToAdd * 60; const msToAdd = secondsToAdd * 1000; - const finalDate = constructFrom(dirtyDate, dateWithDays.getTime() + msToAdd); + const finalDate = constructFrom(date, dateWithDays.getTime() + msToAdd); return finalDate; } diff --git a/src/date-fns/addBusinessDays/index.ts b/src/date-fns/addBusinessDays/index.ts index d72bfbc..704f389 100644 --- a/src/date-fns/addBusinessDays/index.ts +++ b/src/date-fns/addBusinessDays/index.ts @@ -1,8 +1,8 @@ -import constructFrom from '../constructFrom/index'; -import isSaturday from '../isSaturday/index'; -import isSunday from '../isSunday/index'; -import isWeekend from '../isWeekend/index'; -import toDate from '../toDate/index'; +import { constructFrom } from '../constructFrom/index'; +import { isSaturday } from '../isSaturday/index'; +import { isSunday } from '../isSunday/index'; +import { isWeekend } from '../isWeekend/index'; +import { toDate } from '../toDate/index'; /** * @name addBusinessDays @@ -12,48 +12,51 @@ import toDate from '../toDate/index'; * @description * Add the specified number of business days (mon - fri) to the given date, ignoring weekends. * - * @param date - the date to be changed - * @param amount - the amount of business days to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`. - * @returns the new date with the business days added + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The date to be changed + * @param amount - The amount of business days to be added. + * + * @returns The new date with the business days added * * @example * // Add 10 business days to 1 September 2014: * const result = addBusinessDays(new Date(2014, 8, 1), 10) * //=> Mon Sep 15 2014 00:00:00 (skipped weekend days) */ -export default function addBusinessDays(dirtyDate: DateType | number, amount: number): DateType { - const date = toDate(dirtyDate); - const startedOnWeekend = isWeekend(date); +export function addBusinessDays(date: DateType | number | string, amount: number): DateType { + const _date = toDate(date); + const startedOnWeekend = isWeekend(_date); - if (isNaN(amount)) return constructFrom(dirtyDate, NaN); + if (isNaN(amount)) return constructFrom(date, NaN); - const hours = date.getHours(); + const hours = _date.getHours(); const sign = amount < 0 ? -1 : 1; const fullWeeks = Math.trunc(amount / 5); - date.setDate(date.getDate() + fullWeeks * 7); + _date.setDate(_date.getDate() + fullWeeks * 7); // Get remaining days not part of a full week let restDays = Math.abs(amount % 5); // Loops over remaining days while (restDays > 0) { - date.setDate(date.getDate() + sign); - if (!isWeekend(date)) restDays -= 1; + _date.setDate(_date.getDate() + sign); + if (!isWeekend(_date)) restDays -= 1; } // If the date is a weekend day and we reduce a dividable of // 5 from it, we land on a weekend date. // To counter this, we add days accordingly to land on the next business day - if (startedOnWeekend && isWeekend(date) && amount !== 0) { + if (startedOnWeekend && isWeekend(_date) && amount !== 0) { // If we're reducing days, we want to add days until we land on a weekday // If we're adding days we want to reduce days until we land on a weekday - if (isSaturday(date)) date.setDate(date.getDate() + (sign < 0 ? 2 : -1)); - if (isSunday(date)) date.setDate(date.getDate() + (sign < 0 ? 1 : -2)); + if (isSaturday(_date)) _date.setDate(_date.getDate() + (sign < 0 ? 2 : -1)); + if (isSunday(_date)) _date.setDate(_date.getDate() + (sign < 0 ? 1 : -2)); } // Restore hours to avoid DST lag - date.setHours(hours); + _date.setHours(hours); - return date; + return _date; } diff --git a/src/date-fns/addDays/index.ts b/src/date-fns/addDays/index.ts index 0355723..bdcebd1 100644 --- a/src/date-fns/addDays/index.ts +++ b/src/date-fns/addDays/index.ts @@ -1,5 +1,5 @@ -import toDate from '../toDate/index'; -import constructFrom from '../constructFrom/index'; +import { toDate } from '../toDate/index'; +import { constructFrom } from '../constructFrom/index'; /** * @name addDays @@ -9,22 +9,25 @@ import constructFrom from '../constructFrom/index'; * @description * Add the specified number of days to the given date. * - * @param date - the date to be changed - * @param amount - the amount of days to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`. - * @returns - the new date with the days added + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The date to be changed + * @param amount - The amount of days to be added. + * + * @returns The new date with the days added * * @example * // Add 10 days to 1 September 2014: * const result = addDays(new Date(2014, 8, 1), 10) * //=> Thu Sep 11 2014 00:00:00 */ -export default function addDays(dirtyDate: DateType | number, amount: number): DateType { - const date = toDate(dirtyDate); - if (isNaN(amount)) return constructFrom(dirtyDate, NaN); +export function addDays(date: DateType | number | string, amount: number): DateType { + const _date = toDate(date); + if (isNaN(amount)) return constructFrom(date, NaN); if (!amount) { // If 0 days, no-op to avoid changing times in the hour before end of DST - return date; + return _date; } - date.setDate(date.getDate() + amount); - return date; + _date.setDate(_date.getDate() + amount); + return _date; } diff --git a/src/date-fns/addHours/index.ts b/src/date-fns/addHours/index.ts index d62f89a..7fe9a7a 100644 --- a/src/date-fns/addHours/index.ts +++ b/src/date-fns/addHours/index.ts @@ -1,4 +1,4 @@ -import addMilliseconds from '../addMilliseconds/index'; +import { addMilliseconds } from '../addMilliseconds/index'; import { millisecondsInHour } from '../constants/index'; /** @@ -9,15 +9,18 @@ import { millisecondsInHour } from '../constants/index'; * @description * Add the specified number of hours to the given date. * - * @param date - the date to be changed - * @param amount - the amount of hours to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`. - * @returns the new date with the hours added + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The date to be changed + * @param amount - The amount of hours to be added. + * + * @returns The new date with the hours added * * @example * // Add 2 hours to 10 July 2014 23:00:00: * const result = addHours(new Date(2014, 6, 10, 23, 0), 2) * //=> Fri Jul 11 2014 01:00:00 */ -export default function addHours(dirtyDate: DateType | number, amount: number): DateType { - return addMilliseconds(dirtyDate, amount * millisecondsInHour); +export function addHours(date: DateType | number | string, amount: number): DateType { + return addMilliseconds(date, amount * millisecondsInHour); } diff --git a/src/date-fns/addISOWeekYears/index.ts b/src/date-fns/addISOWeekYears/index.ts index 8795d64..eaadf39 100644 --- a/src/date-fns/addISOWeekYears/index.ts +++ b/src/date-fns/addISOWeekYears/index.ts @@ -1,5 +1,5 @@ -import getISOWeekYear from '../getISOWeekYear/index'; -import setISOWeekYear from '../setISOWeekYear/index'; +import { getISOWeekYear } from '../getISOWeekYear/index'; +import { setISOWeekYear } from '../setISOWeekYear/index'; /** * @name addISOWeekYears @@ -11,15 +11,18 @@ import setISOWeekYear from '../setISOWeekYear/index'; * * ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date * - * @param date - the date to be changed - * @param amount - the amount of ISO week-numbering years to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`. - * @returns the new date with the ISO week-numbering years added + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The date to be changed + * @param amount - The amount of ISO week-numbering years to be added. + * + * @returns The new date with the ISO week-numbering years added * * @example * // Add 5 ISO week-numbering years to 2 July 2010: * const result = addISOWeekYears(new Date(2010, 6, 2), 5) * //=> Fri Jn 26 2015 00:00:00 */ -export default function addISOWeekYears(dirtyDate: DateType | number, amount: number): DateType { - return setISOWeekYear(dirtyDate, getISOWeekYear(dirtyDate) + amount); +export function addISOWeekYears(date: DateType | number | string, amount: number): DateType { + return setISOWeekYear(date, getISOWeekYear(date) + amount); } diff --git a/src/date-fns/addMilliseconds/index.ts b/src/date-fns/addMilliseconds/index.ts index ad249f2..db8d4f0 100644 --- a/src/date-fns/addMilliseconds/index.ts +++ b/src/date-fns/addMilliseconds/index.ts @@ -1,5 +1,5 @@ -import toDate from '../toDate/index'; -import constructFrom from '../constructFrom/index'; +import { toDate } from '../toDate/index'; +import { constructFrom } from '../constructFrom/index'; /** * @name addMilliseconds @@ -9,16 +9,19 @@ import constructFrom from '../constructFrom/index'; * @description * Add the specified number of milliseconds to the given date. * - * @param date - the date to be changed - * @param amount - the amount of milliseconds to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`. - * @returns the new date with the milliseconds added + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The date to be changed + * @param amount - The amount of milliseconds to be added. + * + * @returns The new date with the milliseconds added * * @example * // Add 750 milliseconds to 10 July 2014 12:45:30.000: * const result = addMilliseconds(new Date(2014, 6, 10, 12, 45, 30, 0), 750) * //=> Thu Jul 10 2014 12:45:30.750 */ -export default function addMilliseconds(dirtyDate: DateType | number, amount: number): DateType { - const timestamp = toDate(dirtyDate).getTime(); - return constructFrom(dirtyDate, timestamp + amount); +export function addMilliseconds(date: DateType | number | string, amount: number): DateType { + const timestamp = +toDate(date); + return constructFrom(date, timestamp + amount); } diff --git a/src/date-fns/addMinutes/index.ts b/src/date-fns/addMinutes/index.ts index 1a8ac3d..26212e2 100644 --- a/src/date-fns/addMinutes/index.ts +++ b/src/date-fns/addMinutes/index.ts @@ -1,4 +1,4 @@ -import addMilliseconds from '../addMilliseconds/index'; +import { addMilliseconds } from '../addMilliseconds/index'; import { millisecondsInMinute } from '../constants/index'; /** @@ -9,15 +9,18 @@ import { millisecondsInMinute } from '../constants/index'; * @description * Add the specified number of minutes to the given date. * - * @param date - the date to be changed - * @param amount - the amount of minutes to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`. - * @returns the new date with the minutes added + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The date to be changed + * @param amount - The amount of minutes to be added. + * + * @returns The new date with the minutes added * * @example * // Add 30 minutes to 10 July 2014 12:00:00: * const result = addMinutes(new Date(2014, 6, 10, 12, 0), 30) * //=> Thu Jul 10 2014 12:30:00 */ -export default function addMinutes(dirtyDate: DateType | number, amount: number): DateType { - return addMilliseconds(dirtyDate, amount * millisecondsInMinute); +export function addMinutes(date: DateType | number | string, amount: number): DateType { + return addMilliseconds(date, amount * millisecondsInMinute); } diff --git a/src/date-fns/addMonths/index.ts b/src/date-fns/addMonths/index.ts index 994a8af..a03d273 100644 --- a/src/date-fns/addMonths/index.ts +++ b/src/date-fns/addMonths/index.ts @@ -1,5 +1,5 @@ -import toDate from '../toDate/index'; -import constructFrom from '../constructFrom/index'; +import { toDate } from '../toDate/index'; +import { constructFrom } from '../constructFrom/index'; /** * @name addMonths @@ -9,23 +9,30 @@ import constructFrom from '../constructFrom/index'; * @description * Add the specified number of months to the given date. * - * @param date - the date to be changed - * @param amount - the amount of months to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`. - * @returns the new date with the months added + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The date to be changed + * @param amount - The amount of months to be added. + * + * @returns The new date with the months added * * @example * // Add 5 months to 1 September 2014: * const result = addMonths(new Date(2014, 8, 1), 5) * //=> Sun Feb 01 2015 00:00:00 + * + * // Add one month to 30 January 2023: + * const result = addMonths(new Date(2023, 0, 30), 1) + * //=> Tue Feb 28 2023 00:00:00 */ -export default function addMonths(dirtyDate: DateType | number, amount: number): DateType { - const date = toDate(dirtyDate); - if (isNaN(amount)) return constructFrom(dirtyDate, NaN); +export function addMonths(date: DateType | number | string, amount: number): DateType { + const _date = toDate(date); + if (isNaN(amount)) return constructFrom(date, NaN); if (!amount) { // If 0 months, no-op to avoid changing times in the hour before end of DST - return date; + return _date; } - const dayOfMonth = date.getDate(); + const dayOfMonth = _date.getDate(); // The JS Date object supports date math by accepting out-of-bounds values for // month, day, etc. For example, new Date(2020, 0, 0) returns 31 Dec 2019 and @@ -35,8 +42,8 @@ export default function addMonths(dirtyDate: DateType | n // we'll default to the end of the desired month by adding 1 to the desired // month and using a date of 0 to back up one day to the end of the desired // month. - const endOfDesiredMonth = constructFrom(dirtyDate, date.getTime()); - endOfDesiredMonth.setMonth(date.getMonth() + amount + 1, 0); + const endOfDesiredMonth = constructFrom(date, _date.getTime()); + endOfDesiredMonth.setMonth(_date.getMonth() + amount + 1, 0); const daysInMonth = endOfDesiredMonth.getDate(); if (dayOfMonth >= daysInMonth) { // If we're already at the end of the month, then this is the correct date @@ -50,7 +57,7 @@ export default function addMonths(dirtyDate: DateType | n // the last day of the month and its local time was in the hour skipped or // repeated next to a DST transition. So we use `date` instead which is // guaranteed to still have the original time. - date.setFullYear(endOfDesiredMonth.getFullYear(), endOfDesiredMonth.getMonth(), dayOfMonth); - return date; + _date.setFullYear(endOfDesiredMonth.getFullYear(), endOfDesiredMonth.getMonth(), dayOfMonth); + return _date; } } diff --git a/src/date-fns/addQuarters/index.ts b/src/date-fns/addQuarters/index.ts index af3b0ff..93fa3c9 100644 --- a/src/date-fns/addQuarters/index.ts +++ b/src/date-fns/addQuarters/index.ts @@ -1,4 +1,4 @@ -import addMonths from '../addMonths/index'; +import { addMonths } from '../addMonths/index'; /** * @name addQuarters @@ -8,16 +8,19 @@ import addMonths from '../addMonths/index'; * @description * Add the specified number of year quarters to the given date. * - * @param date - the date to be changed - * @param amount - the amount of quarters to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`. - * @returns the new date with the quarters added + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The date to be changed + * @param amount - The amount of quarters to be added. + * + * @returns The new date with the quarters added * * @example * // Add 1 quarter to 1 September 2014: * const result = addQuarters(new Date(2014, 8, 1), 1) * //=> Mon Dec 01 2014 00:00:00 */ -export default function addQuarters(dirtyDate: DateType | number, amount: number): DateType { +export function addQuarters(date: DateType | number | string, amount: number): DateType { const months = amount * 3; - return addMonths(dirtyDate, months); + return addMonths(date, months); } diff --git a/src/date-fns/addSeconds/index.ts b/src/date-fns/addSeconds/index.ts index c93b4cb..ccd74d5 100644 --- a/src/date-fns/addSeconds/index.ts +++ b/src/date-fns/addSeconds/index.ts @@ -1,4 +1,4 @@ -import addMilliseconds from '../addMilliseconds/index'; +import { addMilliseconds } from '../addMilliseconds/index'; /** * @name addSeconds @@ -8,15 +8,18 @@ import addMilliseconds from '../addMilliseconds/index'; * @description * Add the specified number of seconds to the given date. * - * @param date - the date to be changed - * @param amount - the amount of seconds to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`. - * @returns the new date with the seconds added + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The date to be changed + * @param amount - The amount of seconds to be added. + * + * @returns The new date with the seconds added * * @example * // Add 30 seconds to 10 July 2014 12:45:00: * const result = addSeconds(new Date(2014, 6, 10, 12, 45, 0), 30) * //=> Thu Jul 10 2014 12:45:30 */ -export default function addSeconds(dirtyDate: DateType | number, amount: number): DateType { - return addMilliseconds(dirtyDate, amount * 1000); +export function addSeconds(date: DateType | number | string, amount: number): DateType { + return addMilliseconds(date, amount * 1000); } diff --git a/src/date-fns/addWeeks/index.ts b/src/date-fns/addWeeks/index.ts index eeb2cee..3b35c8a 100644 --- a/src/date-fns/addWeeks/index.ts +++ b/src/date-fns/addWeeks/index.ts @@ -1,4 +1,4 @@ -import addDays from '../addDays/index'; +import { addDays } from '../addDays/index'; /** * @name addWeeks @@ -8,16 +8,19 @@ import addDays from '../addDays/index'; * @description * Add the specified number of week to the given date. * - * @param date - the date to be changed - * @param amount - the amount of weeks to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`. - * @returns the new date with the weeks added + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The date to be changed + * @param amount - The amount of weeks to be added. + * + * @returns The new date with the weeks added * * @example * // Add 4 weeks to 1 September 2014: * const result = addWeeks(new Date(2014, 8, 1), 4) * //=> Mon Sep 29 2014 00:00:00 */ -export default function addWeeks(dirtyDate: DateType | number, amount: number): DateType { +export function addWeeks(date: DateType | number | string, amount: number): DateType { const days = amount * 7; - return addDays(dirtyDate, days); + return addDays(date, days); } diff --git a/src/date-fns/addYears/index.ts b/src/date-fns/addYears/index.ts index 9450a40..5de63d4 100644 --- a/src/date-fns/addYears/index.ts +++ b/src/date-fns/addYears/index.ts @@ -1,4 +1,4 @@ -import addMonths from '../addMonths/index'; +import { addMonths } from '../addMonths/index'; /** * @name addYears @@ -8,15 +8,18 @@ import addMonths from '../addMonths/index'; * @description * Add the specified number of years to the given date. * - * @param date - the date to be changed - * @param amount - the amount of years to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`. - * @returns the new date with the years added + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The date to be changed + * @param amount - The amount of years to be added. + * + * @returns The new date with the years added * * @example * // Add 5 years to 1 September 2014: * const result = addYears(new Date(2014, 8, 1), 5) * //=> Sun Sep 01 2019 00:00:00 */ -export default function addYears(dirtyDate: DateType | number, amount: number): DateType { - return addMonths(dirtyDate, amount * 12); +export function addYears(date: DateType | number | string, amount: number): DateType { + return addMonths(date, amount * 12); } diff --git a/src/date-fns/areIntervalsOverlapping/index.ts b/src/date-fns/areIntervalsOverlapping/index.ts index 3c4d7ac..d34be32 100644 --- a/src/date-fns/areIntervalsOverlapping/index.ts +++ b/src/date-fns/areIntervalsOverlapping/index.ts @@ -1,10 +1,11 @@ -import toDate from '../toDate/index'; +import { toDate } from '../toDate/index'; import type { Interval } from '../types'; /** * The {@link areIntervalsOverlapping} function options. */ export interface AreIntervalsOverlappingOptions { + /** Whether the comparison is inclusive or not */ inclusive?: boolean; } @@ -14,14 +15,13 @@ export interface AreIntervalsOverlappingOptions { * @summary Is the given time interval overlapping with another time interval? * * @description - * Is the given time interval overlapping with another time interval? Adjacent intervals do not count as overlapping. + * Is the given time interval overlapping with another time interval? Adjacent intervals do not count as overlapping unless `inclusive` is set to `true`. * - * @param intervalLeft - the first interval to compare. See [Interval]{@link https://date-fns.org/docs/Interval} - * @param intervalRight - the second interval to compare. See [Interval]{@link https://date-fns.org/docs/Interval} - * @param options - the object with options - * @returns whether the time intervals are overlapping - * @throws {RangeError} The start of an interval cannot be after its end - * @throws {RangeError} Date in interval cannot be `Invalid Date` + * @param intervalLeft - The first interval to compare. + * @param intervalRight - The second interval to compare. + * @param options - The object with options + * + * @returns Whether the time intervals are overlapping * * @example * // For overlapping time intervals: @@ -54,6 +54,8 @@ export interface AreIntervalsOverlappingOptions { * { start: new Date(2014, 0, 20), end: new Date(2014, 0, 24) } * ) * //=> false + * + * @example * areIntervalsOverlapping( * { start: new Date(2014, 0, 10), end: new Date(2014, 0, 20) }, * { start: new Date(2014, 0, 20), end: new Date(2014, 0, 24) }, @@ -61,24 +63,17 @@ export interface AreIntervalsOverlappingOptions { * ) * //=> true */ -export default function areIntervalsOverlapping( +export function areIntervalsOverlapping( intervalLeft: Interval, intervalRight: Interval, options?: AreIntervalsOverlappingOptions, ): boolean { - const leftStartTime = toDate(intervalLeft.start).getTime(); - const leftEndTime = toDate(intervalLeft.end).getTime(); - const rightStartTime = toDate(intervalRight.start).getTime(); - const rightEndTime = toDate(intervalRight.end).getTime(); - - // Throw an exception if start date is after end date or if any date is `Invalid Date` - if (!(leftStartTime <= leftEndTime && rightStartTime <= rightEndTime)) { - throw new RangeError('Invalid interval'); - } + const [leftStartTime, leftEndTime] = [+toDate(intervalLeft.start), +toDate(intervalLeft.end)].sort((a, b) => a - b); + const [rightStartTime, rightEndTime] = [+toDate(intervalRight.start), +toDate(intervalRight.end)].sort( + (a, b) => a - b, + ); - if (options?.inclusive) { - return leftStartTime <= rightEndTime && rightStartTime <= leftEndTime; - } + if (options?.inclusive) return leftStartTime! <= rightEndTime! && rightStartTime! <= leftEndTime!; - return leftStartTime < rightEndTime && rightStartTime < leftEndTime; + return leftStartTime! < rightEndTime! && rightStartTime! < leftEndTime!; } diff --git a/src/date-fns/clamp/index.ts b/src/date-fns/clamp/index.ts index 9e3dc28..42f91c5 100644 --- a/src/date-fns/clamp/index.ts +++ b/src/date-fns/clamp/index.ts @@ -1,5 +1,5 @@ -import max from '../max/index'; -import min from '../min/index'; +import { max } from '../max/index'; +import { min } from '../min/index'; import type { Interval } from '../types'; /** @@ -15,6 +15,13 @@ import type { Interval } from '../types'; * - When the date is greater than the end of the interval, the end is returned. * - Otherwise the date is returned. * + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The date to be bounded + * @param interval - The interval to bound to + * + * @returns The date bounded by the start and the end of the interval + * * @example * // What is Mar, 21, 2021 bounded to an interval starting at Mar, 22, 2021 and ending at Apr, 01, 2021 * const result = clamp(new Date(2021, 2, 21), { @@ -22,14 +29,7 @@ import type { Interval } from '../types'; * end: new Date(2021, 3, 1), * }) * //=> Mon Mar 22 2021 00:00:00 - * - * @param date - the date to be bounded - * @param interval - the interval to bound to - * @returns the date bounded by the start and the end of the interval */ -export default function clamp( - date: DateType | number, - { start, end }: Interval, -): DateType | Date { - return min([max([date, start]), end]); +export function clamp(date: DateType | number | string, interval: Interval): DateType | Date { + return min([max([date, interval.start]), interval.end]); } diff --git a/src/date-fns/closestIndexTo/index.ts b/src/date-fns/closestIndexTo/index.ts index 05d04ca..39f8ec7 100644 --- a/src/date-fns/closestIndexTo/index.ts +++ b/src/date-fns/closestIndexTo/index.ts @@ -1,4 +1,4 @@ -import toDate from '../toDate/index'; +import { toDate } from '../toDate/index'; /** * @name closestIndexTo @@ -8,9 +8,12 @@ import toDate from '../toDate/index'; * @description * Return an index of the closest date from the array comparing to the given date. * - * @param dateToCompare - the date to compare with - * @param datesArray - the array to search - * @returns an index of the date closest to the given date or undefined if no valid value is given + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param dateToCompare - The date to compare with + * @param dates - The array to search + * + * @returns An index of the date closest to the given date or undefined if no valid value is given * * @example * // Which date is closer to 6 September 2015? @@ -23,19 +26,19 @@ import toDate from '../toDate/index'; * const result = closestIndexTo(dateToCompare, datesArray) * //=> 1 */ -export default function closestIndexTo( - dirtyDateToCompare: DateType | number, - datesArray: Array, +export function closestIndexTo( + dateToCompare: DateType | number | string, + dates: Array, ): number | undefined { - const dateToCompare = toDate(dirtyDateToCompare); + const date = toDate(dateToCompare); - if (isNaN(Number(dateToCompare))) return NaN; + if (isNaN(Number(date))) return NaN; - const timeToCompare = dateToCompare.getTime(); + const timeToCompare = date.getTime(); let result: number | undefined; let minDistance: number; - datesArray.forEach(function (dirtyDate, index) { + dates.forEach(function (dirtyDate, index) { const currentDate = toDate(dirtyDate); if (isNaN(Number(currentDate))) { diff --git a/src/date-fns/closestTo/index.ts b/src/date-fns/closestTo/index.ts index 9138e2e..c5a86ed 100644 --- a/src/date-fns/closestTo/index.ts +++ b/src/date-fns/closestTo/index.ts @@ -1,5 +1,5 @@ -import constructFrom from '../constructFrom/index'; -import toDate from '../toDate/index'; +import { constructFrom } from '../constructFrom/index'; +import { toDate } from '../toDate/index'; /** * @name closestTo @@ -9,9 +9,12 @@ import toDate from '../toDate/index'; * @description * Return a date from the array closest to the given date. * - * @param dateToCompare - the date to compare with - * @param datesArray - the array to search - * @returns the date from the array closest to the given date or undefined if no valid value is given + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param dateToCompare - The date to compare with + * @param dates - The array to search + * + * @returns The date from the array closest to the given date or undefined if no valid value is given * * @example * // Which date is closer to 6 September 2015: 1 January 2000 or 1 January 2030? @@ -22,23 +25,23 @@ import toDate from '../toDate/index'; * ]) * //=> Tue Jan 01 2030 00:00:00 */ -export default function closestTo( - dirtyDateToCompare: DateType | number, - datesArray: Array, +export function closestTo( + dateToCompare: DateType | number | string, + dates: Array, ): DateType | undefined { - const dateToCompare = toDate(dirtyDateToCompare); + const date = toDate(dateToCompare); - if (isNaN(Number(dateToCompare))) return constructFrom(dirtyDateToCompare, NaN); + if (isNaN(Number(date))) return constructFrom(dateToCompare, NaN); - const timeToCompare = dateToCompare.getTime(); + const timeToCompare = date.getTime(); let result: DateType | undefined; let minDistance: number; - datesArray.forEach((dirtyDate) => { + dates.forEach((dirtyDate) => { const currentDate = toDate(dirtyDate); if (isNaN(Number(currentDate))) { - result = constructFrom(dirtyDateToCompare, NaN); + result = constructFrom(dateToCompare, NaN); minDistance = NaN; return; } diff --git a/src/date-fns/compareAsc/index.ts b/src/date-fns/compareAsc/index.ts index 48996ce..6d6a59d 100644 --- a/src/date-fns/compareAsc/index.ts +++ b/src/date-fns/compareAsc/index.ts @@ -1,4 +1,4 @@ -import toDate from '../toDate/index'; +import { toDate } from '../toDate/index'; /** * @name compareAsc @@ -9,9 +9,12 @@ import toDate from '../toDate/index'; * Compare the two dates and return 1 if the first date is after the second, * -1 if the first date is before the second or 0 if dates are equal. * - * @param dateLeft - the first date to compare - * @param dateRight - the second date to compare - * @returns the result of the comparison + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param dateLeft - The first date to compare + * @param dateRight - The second date to compare + * + * @returns The result of the comparison * * @example * // Compare 11 February 1987 and 10 July 1989: @@ -31,14 +34,14 @@ import toDate from '../toDate/index'; * // Sun Jul 02 1995 00:00:00 * // ] */ -export default function compareAsc( - dirtyDateLeft: DateType | number, - dirtyDateRight: DateType | number, +export function compareAsc( + dateLeft: DateType | number | string, + dateRight: DateType | number | string, ): number { - const dateLeft = toDate(dirtyDateLeft); - const dateRight = toDate(dirtyDateRight); + const _dateLeft = toDate(dateLeft); + const _dateRight = toDate(dateRight); - const diff = dateLeft.getTime() - dateRight.getTime(); + const diff = _dateLeft.getTime() - _dateRight.getTime(); if (diff < 0) { return -1; diff --git a/src/date-fns/compareDesc/index.ts b/src/date-fns/compareDesc/index.ts index 637d6c4..ac6d467 100644 --- a/src/date-fns/compareDesc/index.ts +++ b/src/date-fns/compareDesc/index.ts @@ -1,4 +1,4 @@ -import toDate from '../toDate/index'; +import { toDate } from '../toDate/index'; /** * @name compareDesc @@ -9,9 +9,12 @@ import toDate from '../toDate/index'; * Compare the two dates and return -1 if the first date is after the second, * 1 if the first date is before the second or 0 if dates are equal. * - * @param dateLeft - the first date to compare - * @param dateRight - the second date to compare - * @returns the result of the comparison + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param dateLeft - The first date to compare + * @param dateRight - The second date to compare + * + * @returns The result of the comparison * * @example * // Compare 11 February 1987 and 10 July 1989 reverse chronologically: @@ -31,14 +34,14 @@ import toDate from '../toDate/index'; * // Wed Feb 11 1987 00:00:00 * // ] */ -export default function compareDesc( - dirtyDateLeft: DateType | number, - dirtyDateRight: DateType | number, +export function compareDesc( + dateLeft: DateType | number | string, + dateRight: DateType | number | string, ): number { - const dateLeft = toDate(dirtyDateLeft); - const dateRight = toDate(dirtyDateRight); + const _dateLeft = toDate(dateLeft); + const _dateRight = toDate(dateRight); - const diff = dateLeft.getTime() - dateRight.getTime(); + const diff = _dateLeft.getTime() - _dateRight.getTime(); if (diff > 0) { return -1; diff --git a/src/date-fns/constants/index.ts b/src/date-fns/constants/index.ts index d499803..1453cf9 100644 --- a/src/date-fns/constants/index.ts +++ b/src/date-fns/constants/index.ts @@ -1,233 +1,203 @@ /** - * Days in 1 week. + * @module constants + * @summary Useful constants + * @description + * Collection of useful date constants. * - * @name daysInWeek + * The constants could be imported from `date-fns/constants`: + * + * ```ts + * import { maxTime, minTime } from "date-fns/constants"; + * + * function isAllowedTime(time) { + * return time <= maxTime && time >= minTime; + * } + * ``` + */ + +/** * @constant - * @type {number} - * @default + * @name daysInWeek + * @summary Days in 1 week. */ export const daysInWeek = 7; /** - * Days in 1 year + * @constant + * @name daysInYear + * @summary Days in 1 year. + * + * @description + * How many days in a year. + * * One years equals 365.2425 days according to the formula: * * > Leap year occures every 4 years, except for years that are divisable by 100 and not divisable by 400. * > 1 mean year = (365+1/4-1/100+1/400) days = 365.2425 days - * - * @name daysInYear - * @constant - * @type {number} - * @default */ -export const daysInYear: number = 365.2425; +export const daysInYear = 365.2425; /** - * Maximum allowed time. - * - * @name maxTime * @constant - * @type {number} - * @default + * @name maxTime + * @summary Maximum allowed time. + * + * @example + * import { maxTime } from "date-fns/constants"; + * + * const isValid = 8640000000000001 <= maxTime; + * //=> false + * + * new Date(8640000000000001); + * //=> Invalid Date */ export const maxTime = Math.pow(10, 8) * 24 * 60 * 60 * 1000; /** - * Milliseconds in 1 week. + * @constant + * @name minTime + * @summary Minimum allowed time. * - * @name millisecondsInWeek + * @example + * import { minTime } from "date-fns/constants"; + * + * const isValid = -8640000000000001 >= minTime; + * //=> false + * + * new Date(-8640000000000001) + * //=> Invalid Date + */ +export const minTime = -maxTime; + +/** * @constant - * @type {number} - * @default + * @name millisecondsInWeek + * @summary Milliseconds in 1 week. */ export const millisecondsInWeek = 604800000; /** - * Milliseconds in 1 day. - * - * @name millisecondsInDay * @constant - * @type {number} - * @default + * @name millisecondsInDay + * @summary Milliseconds in 1 day. */ export const millisecondsInDay = 86400000; /** - * Milliseconds in 1 minute - * - * @name millisecondsInMinute * @constant - * @type {number} - * @default + * @name millisecondsInMinute + * @summary Milliseconds in 1 minute */ export const millisecondsInMinute = 60000; /** - * Milliseconds in 1 hour - * - * @name millisecondsInHour * @constant - * @type {number} - * @default + * @name millisecondsInHour + * @summary Milliseconds in 1 hour */ export const millisecondsInHour = 3600000; /** - * Milliseconds in 1 second - * - * @name millisecondsInSecond * @constant - * @type {number} - * @default + * @name millisecondsInSecond + * @summary Milliseconds in 1 second */ export const millisecondsInSecond = 1000; /** - * Minimum allowed time. - * - * @name minTime * @constant - * @type {number} - * @default - */ -export const minTime = -maxTime; - -/** - * Minutes in 1 year. - * * @name minutesInYear - * @constant - * @type {number} - * @default + * @summary Minutes in 1 year. */ export const minutesInYear = 525600; /** - * Minutes in 1 month. - * - * @name minutesInMonth * @constant - * @type {number} - * @default + * @name minutesInMonth + * @summary Minutes in 1 month. */ export const minutesInMonth = 43200; /** - * Minutes in 1 day. - * - * @name minutesInDay * @constant - * @type {number} - * @default + * @name minutesInDay + * @summary Minutes in 1 day. */ export const minutesInDay = 1440; /** - * Minutes in 1 hour. - * - * @name minutesInHour * @constant - * @type {number} - * @default + * @name minutesInHour + * @summary Minutes in 1 hour. */ export const minutesInHour = 60; /** - * Months in 1 quarter. - * - * @name monthsInQuarter * @constant - * @type {number} - * @default + * @name monthsInQuarter + * @summary Months in 1 quarter. */ export const monthsInQuarter = 3; /** - * Months in 1 year. - * - * @name monthsInYear * @constant - * @type {number} - * @default + * @name monthsInYear + * @summary Months in 1 year. */ export const monthsInYear = 12; /** - * Quarters in 1 year - * - * @name quartersInYear * @constant - * @type {number} - * @default + * @name quartersInYear + * @summary Quarters in 1 year */ export const quartersInYear = 4; /** - * Seconds in 1 hour. - * - * @name secondsInHour * @constant - * @type {number} - * @default + * @name secondsInHour + * @summary Seconds in 1 hour. */ export const secondsInHour = 3600; /** - * Seconds in 1 minute. - * - * @name secondsInMinute * @constant - * @type {number} - * @default + * @name secondsInMinute + * @summary Seconds in 1 minute. */ export const secondsInMinute = 60; /** - * Seconds in 1 day. - * - * @name secondsInDay * @constant - * @type {number} - * @default + * @name secondsInDay + * @summary Seconds in 1 day. */ export const secondsInDay = secondsInHour * 24; /** - * Seconds in 1 week. - * - * @name secondsInWeek * @constant - * @type {number} - * @default + * @name secondsInWeek + * @summary Seconds in 1 week. */ export const secondsInWeek = secondsInDay * 7; /** - * Seconds in 1 year. - * - * @name secondsInYear * @constant - * @type {number} - * @default + * @name secondsInYear + * @summary Seconds in 1 year. */ export const secondsInYear = secondsInDay * daysInYear; /** - * Seconds in 1 month - * - * @name secondsInMonth * @constant - * @type {number} - * @default + * @name secondsInMonth + * @summary Seconds in 1 month */ export const secondsInMonth = secondsInYear / 12; /** - * Seconds in 1 quarter. - * - * @name secondsInQuarter * @constant - * @type {number} - * @default + * @name secondsInQuarter + * @summary Seconds in 1 quarter. */ export const secondsInQuarter = secondsInMonth * 3; diff --git a/src/date-fns/constructFrom/index.ts b/src/date-fns/constructFrom/index.ts index a7830a1..413e120 100644 --- a/src/date-fns/constructFrom/index.ts +++ b/src/date-fns/constructFrom/index.ts @@ -2,7 +2,7 @@ import type { GenericDateConstructor } from '../types'; /** * @name constructFrom - * @category Date Extension Helpers + * @category Generic Helpers * @summary Constructs a date using the reference date and the value * * @description @@ -10,9 +10,14 @@ import type { GenericDateConstructor } from '../types'; * date and the given value. It helps to build generic functions that accept * date extensions. * - * @param date {Date|number} - the reference date to take constructor from - * @param value {Date|number} - the value to create the date - * @returns date initialized using the given date and value + * It defaults to `Date` if the passed reference date is a number or a string. + * + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The reference date to take constructor from + * @param value - The value to create the date + * + * @returns Date initialized using the given date and value * * @example * import { constructFrom } from 'date-fns' @@ -25,7 +30,10 @@ import type { GenericDateConstructor } from '../types'; * ) * } */ -export default function constructFrom(date: DateType | number, value: Date | number): DateType { +export function constructFrom( + date: DateType | number | string, + value: Date | number | string, +): DateType { if (date instanceof Date) { return new (date.constructor as GenericDateConstructor)(value); } else { diff --git a/src/date-fns/constructNow/index.ts b/src/date-fns/constructNow/index.ts new file mode 100644 index 0000000..77d7ea7 --- /dev/null +++ b/src/date-fns/constructNow/index.ts @@ -0,0 +1,35 @@ +import { constructFrom } from '../constructFrom/index'; + +/** + * @name constructNow + * @category Generic Helpers + * @summary Constructs a new current date using the passed value constructor. + * @pure false + * + * @description + * The function constructs a new current date using the constructor from + * the reference date. It helps to build generic functions that accept date + * extensions and use the current date. + * + * It defaults to `Date` if the passed reference date is a number or a string. + * + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The reference date to take constructor from + * + * @returns Current date initialized using the given date constructor + * + * @example + * import { constructNow, isSameDay } from 'date-fns' + * + * function isToday( + * date: DateType | number | string, + * ): boolean { + * // If we were to use `new Date()` directly, the function would behave + * // differently in different timezones and return false for the same date. + * return isSameDay(date, constructNow(date)); + * } + */ +export function constructNow(date: DateType | number | string): DateType { + return constructFrom(date, Date.now()); +} diff --git a/src/date-fns/daysToWeeks/index.ts b/src/date-fns/daysToWeeks/index.ts index 4269c9e..e082edf 100644 --- a/src/date-fns/daysToWeeks/index.ts +++ b/src/date-fns/daysToWeeks/index.ts @@ -8,9 +8,11 @@ import { daysInWeek } from '../constants/index'; * @description * Convert a number of days to a full number of weeks. * - * @param days - number of days to be converted + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). * - * @returns the number of days converted in weeks + * @param days - The number of days to be converted + * + * @returns The number of days converted in weeks * * @example * // Convert 14 days to weeks: @@ -18,11 +20,13 @@ import { daysInWeek } from '../constants/index'; * //=> 2 * * @example - * // It uses floor rounding: + * // It uses trunc rounding: * const result = daysToWeeks(13) * //=> 1 */ -export default function daysToWeeks(days: number): number { +export function daysToWeeks(days: number): number { const weeks = days / daysInWeek; - return Math.floor(weeks); + const result = Math.trunc(weeks); + // Prevent negative zero + return result === 0 ? 0 : result; } diff --git a/src/date-fns/differenceInBusinessDays/index.ts b/src/date-fns/differenceInBusinessDays/index.ts index 68701b0..649f707 100644 --- a/src/date-fns/differenceInBusinessDays/index.ts +++ b/src/date-fns/differenceInBusinessDays/index.ts @@ -1,9 +1,9 @@ -import addDays from '../addDays/index'; -import differenceInCalendarDays from '../differenceInCalendarDays/index'; -import isSameDay from '../isSameDay/index'; -import isValid from '../isValid/index'; -import isWeekend from '../isWeekend/index'; -import toDate from '../toDate/index'; +import { addDays } from '../addDays/index'; +import { differenceInCalendarDays } from '../differenceInCalendarDays/index'; +import { isSameDay } from '../isSameDay/index'; +import { isValid } from '../isValid/index'; +import { isWeekend } from '../isWeekend/index'; +import { toDate } from '../toDate/index'; /** * @name differenceInBusinessDays @@ -16,9 +16,12 @@ import toDate from '../toDate/index'; * Like `differenceInCalendarDays`, the function removes the times from * the dates before calculating the difference. * - * @param dateLeft - the later date - * @param dateRight - the earlier date - * @returns the number of business days + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param dateLeft - The later date + * @param dateRight - The earlier date + * + * @returns The number of business days * * @example * // How many business days are between @@ -53,29 +56,30 @@ import toDate from '../toDate/index'; * ) * //=> 0 */ -export default function differenceInBusinessDays( - dirtyDateLeft: DateType | number, - dirtyDateRight: DateType | number, +export function differenceInBusinessDays( + dateLeft: DateType | number | string, + dateRight: DateType | number | string, ): number { - const dateLeft = toDate(dirtyDateLeft); - let dateRight = toDate(dirtyDateRight); + const _dateLeft = toDate(dateLeft); + let _dateRight = toDate(dateRight); - if (!isValid(dateLeft) || !isValid(dateRight)) return NaN; + if (!isValid(_dateLeft) || !isValid(_dateRight)) return NaN; - const calendarDifference = differenceInCalendarDays(dateLeft, dateRight); + const calendarDifference = differenceInCalendarDays(_dateLeft, _dateRight); const sign = calendarDifference < 0 ? -1 : 1; const weeks = Math.trunc(calendarDifference / 7); let result = weeks * 5; - dateRight = addDays(dateRight, weeks * 7); + _dateRight = addDays(_dateRight, weeks * 7); // the loop below will run at most 6 times to account for the remaining days that don't makeup a full week - while (!isSameDay(dateLeft, dateRight)) { + while (!isSameDay(_dateLeft, _dateRight)) { // sign is used to account for both negative and positive differences - result += isWeekend(dateRight) ? 0 : sign; - dateRight = addDays(dateRight, sign); + result += isWeekend(_dateRight) ? 0 : sign; + _dateRight = addDays(_dateRight, sign); } + // Prevent negative zero return result === 0 ? 0 : result; } diff --git a/src/date-fns/differenceInCalendarDays/index.ts b/src/date-fns/differenceInCalendarDays/index.ts index 23b39b7..57f8700 100644 --- a/src/date-fns/differenceInCalendarDays/index.ts +++ b/src/date-fns/differenceInCalendarDays/index.ts @@ -1,6 +1,6 @@ import { millisecondsInDay } from '../constants/index'; -import startOfDay from '../startOfDay/index'; -import getTimezoneOffsetInMilliseconds from '../_lib/getTimezoneOffsetInMilliseconds/index'; +import { startOfDay } from '../startOfDay/index'; +import { getTimezoneOffsetInMilliseconds } from '../_lib/getTimezoneOffsetInMilliseconds/index'; /** * @name differenceInCalendarDays @@ -11,9 +11,12 @@ import getTimezoneOffsetInMilliseconds from '../_lib/getTimezoneOffsetInMillisec * Get the number of calendar days between the given dates. This means that the times are removed * from the dates and then the difference in days is calculated. * - * @param dateLeft - the later date - * @param dateRight - the earlier date - * @returns the number of calendar days + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param dateLeft - The later date + * @param dateRight - The earlier date + * + * @returns The number of calendar days * * @example * // How many calendar days are between @@ -31,18 +34,18 @@ import getTimezoneOffsetInMilliseconds from '../_lib/getTimezoneOffsetInMillisec * ) * //=> 1 */ -export default function differenceInCalendarDays( - dirtyDateLeft: DateType | number, - dirtyDateRight: DateType | number, +export function differenceInCalendarDays( + dateLeft: DateType | number | string, + dateRight: DateType | number | string, ): number { - const startOfDayLeft = startOfDay(dirtyDateLeft); - const startOfDayRight = startOfDay(dirtyDateRight); + const startOfDayLeft = startOfDay(dateLeft); + const startOfDayRight = startOfDay(dateRight); - const timestampLeft = startOfDayLeft.getTime() - getTimezoneOffsetInMilliseconds(startOfDayLeft); - const timestampRight = startOfDayRight.getTime() - getTimezoneOffsetInMilliseconds(startOfDayRight); + const timestampLeft = +startOfDayLeft - getTimezoneOffsetInMilliseconds(startOfDayLeft); + const timestampRight = +startOfDayRight - getTimezoneOffsetInMilliseconds(startOfDayRight); - // Round the number of days to the nearest integer - // because the number of milliseconds in a day is not constant - // (e.g. it's different in the day of the daylight saving time clock shift) + // Round the number of days to the nearest integer because the number of + // milliseconds in a day is not constant (e.g. it's different in the week of + // the daylight saving time clock shift). return Math.round((timestampLeft - timestampRight) / millisecondsInDay); } diff --git a/src/date-fns/differenceInCalendarISOWeekYears/index.ts b/src/date-fns/differenceInCalendarISOWeekYears/index.ts index 08ea9a9..16a3bf8 100644 --- a/src/date-fns/differenceInCalendarISOWeekYears/index.ts +++ b/src/date-fns/differenceInCalendarISOWeekYears/index.ts @@ -1,4 +1,4 @@ -import getISOWeekYear from '../getISOWeekYear/index'; +import { getISOWeekYear } from '../getISOWeekYear/index'; /** * @name differenceInCalendarISOWeekYears @@ -10,9 +10,12 @@ import getISOWeekYear from '../getISOWeekYear/index'; * * ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date * - * @param dateLeft - the later date - * @param dateRight - the earlier date - * @returns the number of calendar ISO week-numbering years + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param dateLeft - The later date + * @param dateRight - The earlier date + * + * @returns The number of calendar ISO week-numbering years * * @example * // How many calendar ISO week-numbering years are 1 January 2010 and 1 January 2012? @@ -22,9 +25,9 @@ import getISOWeekYear from '../getISOWeekYear/index'; * ) * //=> 2 */ -export default function differenceInCalendarISOWeekYears( - dirtyDateLeft: DateType | number, - dirtyDateRight: DateType | number, +export function differenceInCalendarISOWeekYears( + dateLeft: DateType | number | string, + dateRight: DateType | number | string, ): number { - return getISOWeekYear(dirtyDateLeft) - getISOWeekYear(dirtyDateRight); + return getISOWeekYear(dateLeft) - getISOWeekYear(dateRight); } diff --git a/src/date-fns/differenceInCalendarISOWeeks/index.ts b/src/date-fns/differenceInCalendarISOWeeks/index.ts index b0f20ff..a3f693a 100644 --- a/src/date-fns/differenceInCalendarISOWeeks/index.ts +++ b/src/date-fns/differenceInCalendarISOWeeks/index.ts @@ -1,6 +1,6 @@ import { millisecondsInWeek } from '../constants/index'; -import startOfISOWeek from '../startOfISOWeek/index'; -import getTimezoneOffsetInMilliseconds from '../_lib/getTimezoneOffsetInMilliseconds/index'; +import { startOfISOWeek } from '../startOfISOWeek/index'; +import { getTimezoneOffsetInMilliseconds } from '../_lib/getTimezoneOffsetInMilliseconds/index'; /** * @name differenceInCalendarISOWeeks @@ -12,9 +12,12 @@ import getTimezoneOffsetInMilliseconds from '../_lib/getTimezoneOffsetInMillisec * * ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date * - * @param dateLeft - the later date - * @param dateRight - the earlier date - * @returns the number of calendar ISO weeks + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param dateLeft - The later date + * @param dateRight - The earlier date + * + * @returns The number of calendar ISO weeks * * @example * // How many calendar ISO weeks are between 6 July 2014 and 21 July 2014? @@ -24,18 +27,18 @@ import getTimezoneOffsetInMilliseconds from '../_lib/getTimezoneOffsetInMillisec * ) * //=> 3 */ -export default function differenceInCalendarISOWeeks( - dirtyDateLeft: DateType | number, - dirtyDateRight: DateType | number, +export function differenceInCalendarISOWeeks( + dateLeft: DateType | number | string, + dateRight: DateType | number | string, ): number { - const startOfISOWeekLeft = startOfISOWeek(dirtyDateLeft); - const startOfISOWeekRight = startOfISOWeek(dirtyDateRight); + const startOfISOWeekLeft = startOfISOWeek(dateLeft); + const startOfISOWeekRight = startOfISOWeek(dateRight); - const timestampLeft = startOfISOWeekLeft.getTime() - getTimezoneOffsetInMilliseconds(startOfISOWeekLeft); - const timestampRight = startOfISOWeekRight.getTime() - getTimezoneOffsetInMilliseconds(startOfISOWeekRight); + const timestampLeft = +startOfISOWeekLeft - getTimezoneOffsetInMilliseconds(startOfISOWeekLeft); + const timestampRight = +startOfISOWeekRight - getTimezoneOffsetInMilliseconds(startOfISOWeekRight); - // Round the number of days to the nearest integer - // because the number of milliseconds in a week is not constant - // (e.g. it's different in the week of the daylight saving time clock shift) + // Round the number of weeks to the nearest integer because the number of + // milliseconds in a week is not constant (e.g. it's different in the week of + // the daylight saving time clock shift). return Math.round((timestampLeft - timestampRight) / millisecondsInWeek); } diff --git a/src/date-fns/differenceInCalendarMonths/index.ts b/src/date-fns/differenceInCalendarMonths/index.ts index 46198f0..8a34372 100644 --- a/src/date-fns/differenceInCalendarMonths/index.ts +++ b/src/date-fns/differenceInCalendarMonths/index.ts @@ -1,4 +1,4 @@ -import toDate from '../toDate/index'; +import { toDate } from '../toDate/index'; /** * @name differenceInCalendarMonths @@ -8,9 +8,12 @@ import toDate from '../toDate/index'; * @description * Get the number of calendar months between the given dates. * - * @param dateLeft - the later date - * @param dateRight - the earlier date - * @returns the number of calendar months + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param dateLeft - The later date + * @param dateRight - The earlier date + * + * @returns The number of calendar months * * @example * // How many calendar months are between 31 January 2014 and 1 September 2014? @@ -20,15 +23,15 @@ import toDate from '../toDate/index'; * ) * //=> 8 */ -export default function differenceInCalendarMonths( - dirtyDateLeft: DateType | number, - dirtyDateRight: DateType | number, +export function differenceInCalendarMonths( + dateLeft: DateType | number | string, + dateRight: DateType | number | string, ): number { - const dateLeft = toDate(dirtyDateLeft); - const dateRight = toDate(dirtyDateRight); + const _dateLeft = toDate(dateLeft); + const _dateRight = toDate(dateRight); - const yearDiff = dateLeft.getFullYear() - dateRight.getFullYear(); - const monthDiff = dateLeft.getMonth() - dateRight.getMonth(); + const yearDiff = _dateLeft.getFullYear() - _dateRight.getFullYear(); + const monthDiff = _dateLeft.getMonth() - _dateRight.getMonth(); return yearDiff * 12 + monthDiff; } diff --git a/src/date-fns/differenceInCalendarQuarters/index.ts b/src/date-fns/differenceInCalendarQuarters/index.ts index ccef489..b020e86 100644 --- a/src/date-fns/differenceInCalendarQuarters/index.ts +++ b/src/date-fns/differenceInCalendarQuarters/index.ts @@ -1,5 +1,5 @@ -import getQuarter from '../getQuarter/index'; -import toDate from '../toDate/index'; +import { getQuarter } from '../getQuarter/index'; +import { toDate } from '../toDate/index'; /** * @name differenceInCalendarQuarters @@ -9,9 +9,12 @@ import toDate from '../toDate/index'; * @description * Get the number of calendar quarters between the given dates. * - * @param dateLeft - the later date - * @param dateRight - the earlier date - * @returns the number of calendar quarters + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param dateLeft - The later date + * @param dateRight - The earlier date + + * @returns The number of calendar quarters * * @example * // How many calendar quarters are between 31 December 2013 and 2 July 2014? @@ -21,15 +24,15 @@ import toDate from '../toDate/index'; * ) * //=> 3 */ -export default function differenceInCalendarQuarters( - dirtyDateLeft: DateType | number, - dirtyDateRight: DateType | number, +export function differenceInCalendarQuarters( + dateLeft: DateType | number | string, + dateRight: DateType | number | string, ): number { - const dateLeft = toDate(dirtyDateLeft); - const dateRight = toDate(dirtyDateRight); + const _dateLeft = toDate(dateLeft); + const _dateRight = toDate(dateRight); - const yearDiff = dateLeft.getFullYear() - dateRight.getFullYear(); - const quarterDiff = getQuarter(dateLeft) - getQuarter(dateRight); + const yearDiff = _dateLeft.getFullYear() - _dateRight.getFullYear(); + const quarterDiff = getQuarter(_dateLeft) - getQuarter(_dateRight); return yearDiff * 4 + quarterDiff; } diff --git a/src/date-fns/differenceInCalendarWeeks/index.ts b/src/date-fns/differenceInCalendarWeeks/index.ts index 9681be1..10cebdf 100644 --- a/src/date-fns/differenceInCalendarWeeks/index.ts +++ b/src/date-fns/differenceInCalendarWeeks/index.ts @@ -1,12 +1,12 @@ import { millisecondsInWeek } from '../constants/index'; -import startOfWeek from '../startOfWeek/index'; -import type { LocaleOptions, WeekStartOptions } from '../types'; -import getTimezoneOffsetInMilliseconds from '../_lib/getTimezoneOffsetInMilliseconds/index'; +import { startOfWeek } from '../startOfWeek/index'; +import type { LocalizedOptions, WeekOptions } from '../types'; +import { getTimezoneOffsetInMilliseconds } from '../_lib/getTimezoneOffsetInMilliseconds/index'; /** * The {@link differenceInCalendarWeeks} function options. */ -export interface DifferenceInCalendarWeeksOptions extends LocaleOptions, WeekStartOptions {} +export interface DifferenceInCalendarWeeksOptions extends LocalizedOptions<'options'>, WeekOptions {} /** * @name differenceInCalendarWeeks @@ -16,10 +16,13 @@ export interface DifferenceInCalendarWeeksOptions extends LocaleOptions, WeekSta * @description * Get the number of calendar weeks between the given dates. * - * @param dateLeft - the later date - * @param dateRight - the earlier date - * @param options - an object with options. - * @returns the number of calendar weeks + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param dateLeft - The later date + * @param dateRight - The earlier date + * @param options - An object with options. + * + * @returns The number of calendar weeks * * @example * // How many calendar weeks are between 5 July 2014 and 20 July 2014? @@ -39,19 +42,19 @@ export interface DifferenceInCalendarWeeksOptions extends LocaleOptions, WeekSta * ) * //=> 2 */ -export default function differenceInCalendarWeeks( - dirtyDateLeft: DateType | number, - dirtyDateRight: DateType | number, +export function differenceInCalendarWeeks( + dateLeft: DateType | number | string, + dateRight: DateType | number | string, options?: DifferenceInCalendarWeeksOptions, ): number { - const startOfWeekLeft = startOfWeek(dirtyDateLeft, options); - const startOfWeekRight = startOfWeek(dirtyDateRight, options); + const startOfWeekLeft = startOfWeek(dateLeft, options); + const startOfWeekRight = startOfWeek(dateRight, options); - const timestampLeft = startOfWeekLeft.getTime() - getTimezoneOffsetInMilliseconds(startOfWeekLeft); - const timestampRight = startOfWeekRight.getTime() - getTimezoneOffsetInMilliseconds(startOfWeekRight); + const timestampLeft = +startOfWeekLeft - getTimezoneOffsetInMilliseconds(startOfWeekLeft); + const timestampRight = +startOfWeekRight - getTimezoneOffsetInMilliseconds(startOfWeekRight); - // Round the number of days to the nearest integer - // because the number of milliseconds in a week is not constant - // (e.g. it's different in the week of the daylight saving time clock shift) + // Round the number of days to the nearest integer because the number of + // milliseconds in a days is not constant (e.g. it's different in the week of + // the daylight saving time clock shift). return Math.round((timestampLeft - timestampRight) / millisecondsInWeek); } diff --git a/src/date-fns/differenceInCalendarYears/index.ts b/src/date-fns/differenceInCalendarYears/index.ts index 4a55df3..34ef33e 100644 --- a/src/date-fns/differenceInCalendarYears/index.ts +++ b/src/date-fns/differenceInCalendarYears/index.ts @@ -1,4 +1,4 @@ -import toDate from '../toDate/index'; +import { toDate } from '../toDate/index'; /** * @name differenceInCalendarYears @@ -8,9 +8,12 @@ import toDate from '../toDate/index'; * @description * Get the number of calendar years between the given dates. * - * @param dateLeft - the later date - * @param dateRight - the earlier date - * @returns the number of calendar years + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param dateLeft - The later date + * @param dateRight - The earlier date + + * @returns The number of calendar years * * @example * // How many calendar years are between 31 December 2013 and 11 February 2015? @@ -20,12 +23,12 @@ import toDate from '../toDate/index'; * ) * //=> 2 */ -export default function differenceInCalendarYears( - dirtyDateLeft: DateType | number, - dirtyDateRight: DateType | number, +export function differenceInCalendarYears( + dateLeft: DateType | number | string, + dateRight: DateType | number | string, ): number { - const dateLeft = toDate(dirtyDateLeft); - const dateRight = toDate(dirtyDateRight); + const _dateLeft = toDate(dateLeft); + const _dateRight = toDate(dateRight); - return dateLeft.getFullYear() - dateRight.getFullYear(); + return _dateLeft.getFullYear() - _dateRight.getFullYear(); } diff --git a/src/date-fns/differenceInDays/index.ts b/src/date-fns/differenceInDays/index.ts index 9158e2c..88b1bf6 100644 --- a/src/date-fns/differenceInDays/index.ts +++ b/src/date-fns/differenceInDays/index.ts @@ -1,29 +1,5 @@ -import differenceInCalendarDays from '../differenceInCalendarDays/index'; -import toDate from '../toDate/index'; - -// Like `compareAsc` but uses local time not UTC, which is needed -// for accurate equality comparisons of UTC timestamps that end up -// having the same representation in local time, e.g. one hour before -// DST ends vs. the instant that DST ends. -function compareLocalAsc(dateLeft: DateType, dateRight: DateType): number { - const diff = - dateLeft.getFullYear() - dateRight.getFullYear() || - dateLeft.getMonth() - dateRight.getMonth() || - dateLeft.getDate() - dateRight.getDate() || - dateLeft.getHours() - dateRight.getHours() || - dateLeft.getMinutes() - dateRight.getMinutes() || - dateLeft.getSeconds() - dateRight.getSeconds() || - dateLeft.getMilliseconds() - dateRight.getMilliseconds(); - - if (diff < 0) { - return -1; - } else if (diff > 0) { - return 1; - // Return 0 if diff is 0; return NaN if diff is NaN - } else { - return diff; - } -} +import { differenceInCalendarDays } from '../differenceInCalendarDays/index'; +import { toDate } from '../toDate/index'; /** * @name differenceInDays @@ -39,12 +15,14 @@ function compareLocalAsc(dateLeft: DateType, dateRight: D * or more than 24 hours if a daylight savings change happens between two dates. * * To ignore DST and only measure exact 24-hour periods, use this instead: - * `Math.floor(differenceInHours(dateLeft, dateRight)/24)|0`. + * `Math.trunc(differenceInHours(dateLeft, dateRight)/24)|0`. * + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). * - * @param dateLeft - the later date - * @param dateRight - the earlier date - * @returns the number of full days according to the local timezone + * @param dateLeft - The later date + * @param dateRight - The earlier date + * + * @returns The number of full days according to the local timezone * * @example * // How many full days are between @@ -54,6 +32,8 @@ function compareLocalAsc(dateLeft: DateType, dateRight: D * new Date(2011, 6, 2, 23, 0) * ) * //=> 365 + * + * @example * // How many full days are between * // 2 July 2011 23:59:00 and 3 July 2011 00:01:00? * const result = differenceInDays( @@ -61,6 +41,8 @@ function compareLocalAsc(dateLeft: DateType, dateRight: D * new Date(2011, 6, 2, 23, 59) * ) * //=> 0 + * + * @example * // How many full days are between * // 1 March 2020 0:00 and 1 June 2020 0:00 ? * // Note: because local time is used, the @@ -71,24 +53,48 @@ function compareLocalAsc(dateLeft: DateType, dateRight: D * new Date(2020, 5, 1), * new Date(2020, 2, 1) * ) -//=> 92 + * //=> 92 */ -export default function differenceInDays( - dirtyDateLeft: DateType | number, - dirtyDateRight: DateType | number, +export function differenceInDays( + dateLeft: DateType | number | string, + dateRight: DateType | number | string, ): number { - const dateLeft = toDate(dirtyDateLeft); - const dateRight = toDate(dirtyDateRight); + const _dateLeft = toDate(dateLeft); + const _dateRight = toDate(dateRight); - const sign = compareLocalAsc(dateLeft, dateRight); - const difference = Math.abs(differenceInCalendarDays(dateLeft, dateRight)); + const sign = compareLocalAsc(_dateLeft, _dateRight); + const difference = Math.abs(differenceInCalendarDays(_dateLeft, _dateRight)); - dateLeft.setDate(dateLeft.getDate() - sign * difference); + _dateLeft.setDate(_dateLeft.getDate() - sign * difference); // Math.abs(diff in full days - diff in calendar days) === 1 if last calendar day is not full // If so, result must be decreased by 1 in absolute value - const isLastDayNotFull = Number(compareLocalAsc(dateLeft, dateRight) === -sign); + const isLastDayNotFull = Number(compareLocalAsc(_dateLeft, _dateRight) === -sign); const result = sign * (difference - isLastDayNotFull); // Prevent negative zero return result === 0 ? 0 : result; } + +// Like `compareAsc` but uses local time not UTC, which is needed +// for accurate equality comparisons of UTC timestamps that end up +// having the same representation in local time, e.g. one hour before +// DST ends vs. the instant that DST ends. +function compareLocalAsc(dateLeft: DateType, dateRight: DateType): number { + const diff = + dateLeft.getFullYear() - dateRight.getFullYear() || + dateLeft.getMonth() - dateRight.getMonth() || + dateLeft.getDate() - dateRight.getDate() || + dateLeft.getHours() - dateRight.getHours() || + dateLeft.getMinutes() - dateRight.getMinutes() || + dateLeft.getSeconds() - dateRight.getSeconds() || + dateLeft.getMilliseconds() - dateRight.getMilliseconds(); + + if (diff < 0) { + return -1; + } else if (diff > 0) { + return 1; + // Return 0 if diff is 0; return NaN if diff is NaN + } else { + return diff; + } +} diff --git a/src/date-fns/differenceInHours/index.ts b/src/date-fns/differenceInHours/index.ts index b8ba6f5..7cbba50 100644 --- a/src/date-fns/differenceInHours/index.ts +++ b/src/date-fns/differenceInHours/index.ts @@ -1,7 +1,7 @@ +import { getRoundingMethod } from '../_lib/getRoundingMethod/index'; import { millisecondsInHour } from '../constants/index'; -import differenceInMilliseconds from '../differenceInMilliseconds/index'; +import { differenceInMilliseconds } from '../differenceInMilliseconds/index'; import type { RoundingOptions } from '../types'; -import { getRoundingMethod } from '../_lib/roundingMethods/index'; /** * The {@link differenceInHours} function options. @@ -16,10 +16,13 @@ export interface DifferenceInHoursOptions extends RoundingOptions {} * @description * Get the number of hours between the given dates. * - * @param dateLeft - the later date - * @param dateRight - the earlier date - * @param options - an object with options. - * @returns the number of hours + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param dateLeft - The later date + * @param dateRight - The earlier date + * @param options - An object with options. + * + * @returns The number of hours * * @example * // How many hours are between 2 July 2014 06:50:00 and 2 July 2014 19:00:00? @@ -29,9 +32,9 @@ export interface DifferenceInHoursOptions extends RoundingOptions {} * ) * //=> 12 */ -export default function differenceInHours( - dateLeft: DateType | number, - dateRight: DateType | number, +export function differenceInHours( + dateLeft: DateType | number | string, + dateRight: DateType | number | string, options?: DifferenceInHoursOptions, ): number { const diff = differenceInMilliseconds(dateLeft, dateRight) / millisecondsInHour; diff --git a/src/date-fns/differenceInISOWeekYears/index.ts b/src/date-fns/differenceInISOWeekYears/index.ts index 92a3b9d..9426285 100644 --- a/src/date-fns/differenceInISOWeekYears/index.ts +++ b/src/date-fns/differenceInISOWeekYears/index.ts @@ -1,7 +1,7 @@ -import compareAsc from '../compareAsc/index'; -import differenceInCalendarISOWeekYears from '../differenceInCalendarISOWeekYears/index'; -import subISOWeekYears from '../subISOWeekYears/index'; -import toDate from '../toDate/index'; +import { compareAsc } from '../compareAsc/index'; +import { differenceInCalendarISOWeekYears } from '../differenceInCalendarISOWeekYears/index'; +import { subISOWeekYears } from '../subISOWeekYears/index'; +import { toDate } from '../toDate/index'; /** * @name differenceInISOWeekYears @@ -13,9 +13,12 @@ import toDate from '../toDate/index'; * * ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date * - * @param dateLeft - the later date - * @param dateRight - the earlier date - * @returns the number of full ISO week-numbering years + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param dateLeft - The later date + * @param dateRight - The earlier date + * + * @returns The number of full ISO week-numbering years * * @example * // How many full ISO week-numbering years are between 1 January 2010 and 1 January 2012? @@ -25,21 +28,21 @@ import toDate from '../toDate/index'; * ) * //=> 1 */ -export default function differenceInISOWeekYears( - dirtyDateLeft: DateType | number, - dirtyDateRight: DateType | number, +export function differenceInISOWeekYears( + dateLeft: DateType | number | string, + dateRight: DateType | number | string, ): number { - let dateLeft = toDate(dirtyDateLeft); - const dateRight = toDate(dirtyDateRight); + let _dateLeft = toDate(dateLeft); + const _dateRight = toDate(dateRight); - const sign = compareAsc(dateLeft, dateRight); - const difference = Math.abs(differenceInCalendarISOWeekYears(dateLeft, dateRight)); - dateLeft = subISOWeekYears(dateLeft, sign * difference); + const sign = compareAsc(_dateLeft, _dateRight); + const difference = Math.abs(differenceInCalendarISOWeekYears(_dateLeft, _dateRight)); + _dateLeft = subISOWeekYears(_dateLeft, sign * difference); // Math.abs(diff in full ISO years - diff in calendar ISO years) === 1 // if last calendar ISO year is not full // If so, result must be decreased by 1 in absolute value - const isLastISOWeekYearNotFull = Number(compareAsc(dateLeft, dateRight) === -sign); + const isLastISOWeekYearNotFull = Number(compareAsc(_dateLeft, _dateRight) === -sign); const result = sign * (difference - isLastISOWeekYearNotFull); // Prevent negative zero return result === 0 ? 0 : result; diff --git a/src/date-fns/differenceInMilliseconds/index.ts b/src/date-fns/differenceInMilliseconds/index.ts index 963ba6d..f339c4f 100644 --- a/src/date-fns/differenceInMilliseconds/index.ts +++ b/src/date-fns/differenceInMilliseconds/index.ts @@ -1,4 +1,4 @@ -import toDate from '../toDate/index'; +import { toDate } from '../toDate/index'; /** * @name differenceInMilliseconds @@ -8,9 +8,12 @@ import toDate from '../toDate/index'; * @description * Get the number of milliseconds between the given dates. * - * @param dateLeft - the later date - * @param dateRight - the earlier date - * @returns the number of milliseconds + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param dateLeft - The later date + * @param dateRight - The earlier date + * + * @returns The number of milliseconds * * @example * // How many milliseconds are between @@ -21,9 +24,9 @@ import toDate from '../toDate/index'; * ) * //=> 1100 */ -export default function differenceInMilliseconds( - dateLeft: DateType | number, - dateRight: DateType | number, +export function differenceInMilliseconds( + dateLeft: DateType | number | string, + dateRight: DateType | number | string, ): number { - return toDate(dateLeft).getTime() - toDate(dateRight).getTime(); + return +toDate(dateLeft) - +toDate(dateRight); } diff --git a/src/date-fns/differenceInMinutes/index.ts b/src/date-fns/differenceInMinutes/index.ts index abd201b..81a9f71 100644 --- a/src/date-fns/differenceInMinutes/index.ts +++ b/src/date-fns/differenceInMinutes/index.ts @@ -1,7 +1,7 @@ +import { getRoundingMethod } from '../_lib/getRoundingMethod/index'; import { millisecondsInMinute } from '../constants/index'; -import differenceInMilliseconds from '../differenceInMilliseconds/index'; +import { differenceInMilliseconds } from '../differenceInMilliseconds/index'; import type { RoundingOptions } from '../types'; -import { getRoundingMethod } from '../_lib/roundingMethods/index'; /** * The {@link differenceInMinutes} function options. @@ -16,10 +16,13 @@ export interface DifferenceInMinutesOptions extends RoundingOptions {} * @description * Get the signed number of full (rounded towards 0) minutes between the given dates. * - * @param dateLeft - the later date - * @param dateRight - the earlier date - * @param options - an object with options. - * @returns the number of minutes + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param dateLeft - The later date + * @param dateRight - The earlier date + * @param options - An object with options. + * + * @returns The number of minutes * * @example * // How many minutes are between 2 July 2014 12:07:59 and 2 July 2014 12:20:00? @@ -37,9 +40,9 @@ export interface DifferenceInMinutesOptions extends RoundingOptions {} * ) * //=> -1 */ -export default function differenceInMinutes( - dateLeft: DateType | number, - dateRight: DateType | number, +export function differenceInMinutes( + dateLeft: DateType | number | string, + dateRight: DateType | number | string, options?: DifferenceInMinutesOptions, ): number { const diff = differenceInMilliseconds(dateLeft, dateRight) / millisecondsInMinute; diff --git a/src/date-fns/differenceInMonths/index.ts b/src/date-fns/differenceInMonths/index.ts index 6038653..9452175 100644 --- a/src/date-fns/differenceInMonths/index.ts +++ b/src/date-fns/differenceInMonths/index.ts @@ -1,7 +1,7 @@ -import compareAsc from '../compareAsc/index'; -import differenceInCalendarMonths from '../differenceInCalendarMonths/index'; -import isLastDayOfMonth from '../isLastDayOfMonth/index'; -import toDate from '../toDate/index'; +import { compareAsc } from '../compareAsc/index'; +import { differenceInCalendarMonths } from '../differenceInCalendarMonths/index'; +import { isLastDayOfMonth } from '../isLastDayOfMonth/index'; +import { toDate } from '../toDate/index'; /** * @name differenceInMonths @@ -11,44 +11,47 @@ import toDate from '../toDate/index'; * @description * Get the number of full months between the given dates using trunc as a default rounding method. * - * @param dateLeft - the later date - * @param dateRight - the earlier date - * @returns the number of full months + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param dateLeft - The later date + * @param dateRight - The earlier date + * + * @returns The number of full months * * @example * // How many full months are between 31 January 2014 and 1 September 2014? * const result = differenceInMonths(new Date(2014, 8, 1), new Date(2014, 0, 31)) * //=> 7 */ -export default function differenceInMonths( - dirtyDateLeft: DateType | number, - dirtyDateRight: DateType | number, +export function differenceInMonths( + dateLeft: DateType | number | string, + dateRight: DateType | number | string, ): number { - const dateLeft = toDate(dirtyDateLeft); - const dateRight = toDate(dirtyDateRight); + const _dateLeft = toDate(dateLeft); + const _dateRight = toDate(dateRight); - const sign = compareAsc(dateLeft, dateRight); - const difference = Math.abs(differenceInCalendarMonths(dateLeft, dateRight)); + const sign = compareAsc(_dateLeft, _dateRight); + const difference = Math.abs(differenceInCalendarMonths(_dateLeft, _dateRight)); let result; // Check for the difference of less than month if (difference < 1) { result = 0; } else { - if (dateLeft.getMonth() === 1 && dateLeft.getDate() > 27) { + if (_dateLeft.getMonth() === 1 && _dateLeft.getDate() > 27) { // This will check if the date is end of Feb and assign a higher end of month date // to compare it with Jan - dateLeft.setDate(30); + _dateLeft.setDate(30); } - dateLeft.setMonth(dateLeft.getMonth() - sign * difference); + _dateLeft.setMonth(_dateLeft.getMonth() - sign * difference); // Math.abs(diff in full months - diff in calendar months) === 1 if last calendar month is not full // If so, result must be decreased by 1 in absolute value - let isLastMonthNotFull = compareAsc(dateLeft, dateRight) === -sign; + let isLastMonthNotFull = compareAsc(_dateLeft, _dateRight) === -sign; // Check for cases of one full calendar month - if (isLastDayOfMonth(toDate(dirtyDateLeft)) && difference === 1 && compareAsc(dirtyDateLeft, dateRight) === 1) { + if (isLastDayOfMonth(toDate(dateLeft)) && difference === 1 && compareAsc(dateLeft, _dateRight) === 1) { isLastMonthNotFull = false; } diff --git a/src/date-fns/differenceInQuarters/index.ts b/src/date-fns/differenceInQuarters/index.ts index 031a1e2..9ac98dc 100644 --- a/src/date-fns/differenceInQuarters/index.ts +++ b/src/date-fns/differenceInQuarters/index.ts @@ -1,6 +1,6 @@ -import differenceInMonths from '../differenceInMonths/index'; +import { getRoundingMethod } from '../_lib/getRoundingMethod/index'; +import { differenceInMonths } from '../differenceInMonths/index'; import type { RoundingOptions } from '../types'; -import { getRoundingMethod } from '../_lib/roundingMethods/index'; /** * The {@link differenceInQuarters} function options. @@ -15,19 +15,22 @@ export interface DifferenceInQuartersOptions extends RoundingOptions {} * @description * Get the number of quarters between the given dates. * - * @param dateLeft - the later date - * @param dateRight - the earlier date - * @param options - an object with options. - * @returns the number of full quarters + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param dateLeft - The later date + * @param dateRight - The earlier date + * @param options - An object with options. + * + * @returns The number of full quarters * * @example * // How many full quarters are between 31 December 2013 and 2 July 2014? * const result = differenceInQuarters(new Date(2014, 6, 2), new Date(2013, 11, 31)) * //=> 2 */ -export default function differenceInQuarters( - dateLeft: DateType | number, - dateRight: DateType | number, +export function differenceInQuarters( + dateLeft: DateType | number | string, + dateRight: DateType | number | string, options?: DifferenceInQuartersOptions, ): number { const diff = differenceInMonths(dateLeft, dateRight) / 3; diff --git a/src/date-fns/differenceInSeconds/index.ts b/src/date-fns/differenceInSeconds/index.ts index 6598ece..8c7c801 100644 --- a/src/date-fns/differenceInSeconds/index.ts +++ b/src/date-fns/differenceInSeconds/index.ts @@ -1,6 +1,6 @@ -import differenceInMilliseconds from '../differenceInMilliseconds/index'; +import { getRoundingMethod } from '../_lib/getRoundingMethod/index'; +import { differenceInMilliseconds } from '../differenceInMilliseconds/index'; import type { RoundingOptions } from '../types'; -import { getRoundingMethod } from '../_lib/roundingMethods/index'; /** * The {@link differenceInSeconds} function options. @@ -15,10 +15,13 @@ export interface DifferenceInSecondsOptions extends RoundingOptions {} * @description * Get the number of seconds between the given dates. * - * @param dateLeft - the later date - * @param dateRight - the earlier date - * @param options - an object with options. - * @returns the number of seconds + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param dateLeft - The later date + * @param dateRight - The earlier date + * @param options - An object with options. + * + * @returns The number of seconds * * @example * // How many seconds are between @@ -29,9 +32,9 @@ export interface DifferenceInSecondsOptions extends RoundingOptions {} * ) * //=> 12 */ -export default function differenceInSeconds( - dateLeft: DateType | number, - dateRight: DateType | number, +export function differenceInSeconds( + dateLeft: DateType | number | string, + dateRight: DateType | number | string, options?: DifferenceInSecondsOptions, ): number { const diff = differenceInMilliseconds(dateLeft, dateRight) / 1000; diff --git a/src/date-fns/differenceInWeeks/index.ts b/src/date-fns/differenceInWeeks/index.ts index 100acd6..8ffda89 100644 --- a/src/date-fns/differenceInWeeks/index.ts +++ b/src/date-fns/differenceInWeeks/index.ts @@ -1,6 +1,6 @@ -import differenceInDays from '../differenceInDays/index'; +import { getRoundingMethod } from '../_lib/getRoundingMethod/index'; +import { differenceInDays } from '../differenceInDays/index'; import type { RoundingOptions } from '../types'; -import { getRoundingMethod } from '../_lib/roundingMethods/index'; /** * The {@link differenceInWeeks} function options. @@ -21,19 +21,22 @@ export interface DifferenceInWeeksOptions extends RoundingOptions {} * or more than 7*24 hours if a daylight savings change happens between two dates. * * To ignore DST and only measure exact 7*24-hour periods, use this instead: - * `Math.floor(differenceInHours(dateLeft, dateRight)/(7*24))|0`. + * `Math.trunc(differenceInHours(dateLeft, dateRight)/(7*24))|0`. * + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). * - * @param dateLeft - the later date - * @param dateRight - the earlier date - * @param options - an object with options. - * @returns the number of full weeks + * @param dateLeft - The later date + * @param dateRight - The earlier date + * @param options - An object with options + * + * @returns The number of full weeks * * @example * // How many full weeks are between 5 July 2014 and 20 July 2014? * const result = differenceInWeeks(new Date(2014, 6, 20), new Date(2014, 6, 5)) * //=> 2 * + * @example * // How many full weeks are between * // 1 March 2020 0:00 and 6 June 2020 0:00 ? * // Note: because local time is used, the @@ -46,9 +49,9 @@ export interface DifferenceInWeeksOptions extends RoundingOptions {} * ) * //=> 8 */ -export default function differenceInWeeks( - dateLeft: DateType | number, - dateRight: DateType | number, +export function differenceInWeeks( + dateLeft: DateType | number | string, + dateRight: DateType | number | string, options?: DifferenceInWeeksOptions, ): number { const diff = differenceInDays(dateLeft, dateRight) / 7; diff --git a/src/date-fns/differenceInYears/index.ts b/src/date-fns/differenceInYears/index.ts index 4bc07b5..7b784cb 100644 --- a/src/date-fns/differenceInYears/index.ts +++ b/src/date-fns/differenceInYears/index.ts @@ -1,6 +1,6 @@ -import compareAsc from '../compareAsc/index'; -import differenceInCalendarYears from '../differenceInCalendarYears/index'; -import toDate from '../toDate/index'; +import { compareAsc } from '../compareAsc/index'; +import { differenceInCalendarYears } from '../differenceInCalendarYears/index'; +import { toDate } from '../toDate/index'; /** * @name differenceInYears @@ -10,34 +10,38 @@ import toDate from '../toDate/index'; * @description * Get the number of full years between the given dates. * - * @param dateLeft - the later date - * @param dateRight - the earlier date - * @returns the number of full years + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param dateLeft - The later date + * @param dateRight - The earlier date + * + * @returns The number of full years * * @example * // How many full years are between 31 December 2013 and 11 February 2015? * const result = differenceInYears(new Date(2015, 1, 11), new Date(2013, 11, 31)) * //=> 1 */ -export default function differenceInYears( - dirtyDateLeft: DateType | number, - dirtyDateRight: DateType | number, +export function differenceInYears( + dateLeft: DateType | number | string, + dateRight: DateType | number | string, ): number { - const dateLeft = toDate(dirtyDateLeft); - const dateRight = toDate(dirtyDateRight); + const _dateLeft = toDate(dateLeft); + const _dateRight = toDate(dateRight); - const sign = compareAsc(dateLeft, dateRight); - const difference = Math.abs(differenceInCalendarYears(dateLeft, dateRight)); + const sign = compareAsc(_dateLeft, _dateRight); + const difference = Math.abs(differenceInCalendarYears(_dateLeft, _dateRight)); // Set both dates to a valid leap year for accurate comparison when dealing // with leap days - dateLeft.setFullYear(1584); - dateRight.setFullYear(1584); + _dateLeft.setFullYear(1584); + _dateRight.setFullYear(1584); // Math.abs(diff in full years - diff in calendar years) === 1 if last calendar year is not full // If so, result must be decreased by 1 in absolute value - const isLastYearNotFull = compareAsc(dateLeft, dateRight) === -sign; - const result = sign * (difference - Number(isLastYearNotFull)); + const isLastYearNotFull = compareAsc(_dateLeft, _dateRight) === -sign; + const result = sign * (difference - +isLastYearNotFull); + // Prevent negative zero return result === 0 ? 0 : result; } diff --git a/src/date-fns/eachDayOfInterval/index.ts b/src/date-fns/eachDayOfInterval/index.ts index a536eba..0d4596f 100644 --- a/src/date-fns/eachDayOfInterval/index.ts +++ b/src/date-fns/eachDayOfInterval/index.ts @@ -1,4 +1,4 @@ -import toDate from '../toDate/index'; +import { toDate } from '../toDate/index'; import type { Interval, StepOptions } from '../types'; /** @@ -14,12 +14,12 @@ export interface EachDayOfIntervalOptions extends StepOptions {} * @description * Return the array of dates within the specified time interval. * - * @param interval - the interval. See [Interval]{@link https://date-fns.org/docs/Interval} - * @param options - an object with options. - * @returns the array with starts of days from the day of the interval start to the day of the interval end - * @throws {RangeError} `options.step` must be a number greater than 1 - * @throws {RangeError} The start of an interval cannot be after its end - * @throws {RangeError} Date in interval cannot be `Invalid Date` + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param interval - The interval. + * @param options - An object with options. + * + * @returns The array with starts of days from the day of the interval start to the day of the interval end * * @example * // Each day between 6 October 2014 and 10 October 2014: @@ -35,33 +35,32 @@ export interface EachDayOfIntervalOptions extends StepOptions {} * // Fri Oct 10 2014 00:00:00 * // ] */ -export default function eachDayOfInterval( +export function eachDayOfInterval( interval: Interval, options?: EachDayOfIntervalOptions, ): DateType[] { const startDate = toDate(interval.start); const endDate = toDate(interval.end); - const endTime = endDate.getTime(); + let reversed = +startDate > +endDate; + const endTime = reversed ? +startDate : +endDate; + const currentDate = reversed ? endDate : startDate; + currentDate.setHours(0, 0, 0, 0); - // Throw an exception if start date is after end date or if any date is `Invalid Date` - if (!(startDate.getTime() <= endTime)) { - throw new RangeError('Invalid interval'); + let step = options?.step ?? 1; + if (!step) return []; + if (step < 0) { + step = -step; + reversed = !reversed; } const dates = []; - const currentDate = startDate; - currentDate.setHours(0, 0, 0, 0); - - const step = options?.step ?? 1; - if (step < 1 || isNaN(step)) throw new RangeError('`options.step` must be a number greater than 1'); - - while (currentDate.getTime() <= endTime) { + while (+currentDate <= endTime) { dates.push(toDate(currentDate)); currentDate.setDate(currentDate.getDate() + step); currentDate.setHours(0, 0, 0, 0); } - return dates; + return reversed ? dates.reverse() : dates; } diff --git a/src/date-fns/eachHourOfInterval/index.ts b/src/date-fns/eachHourOfInterval/index.ts index 680f05c..cf4d97b 100644 --- a/src/date-fns/eachHourOfInterval/index.ts +++ b/src/date-fns/eachHourOfInterval/index.ts @@ -1,5 +1,5 @@ -import addHours from '../addHours/index'; -import toDate from '../toDate/index'; +import { addHours } from '../addHours/index'; +import { toDate } from '../toDate/index'; import type { Interval, StepOptions } from '../types'; /** @@ -15,12 +15,12 @@ export interface EachHourOfIntervalOptions extends StepOptions {} * @description * Return the array of hours within the specified time interval. * - * @param interval - the interval. See [Interval]{@link https://date-fns.org/docs/Interval} - * @param options - an object with options. - * @returns the array with starts of hours from the hour of the interval start to the hour of the interval end - * @throws {RangeError} `options.step` must be a number greater than 1 - * @throws {RangeError} The start of an interval cannot be after its end - * @throws {RangeError} Date in interval cannot be `Invalid Date` + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param interval - The interval. + * @param options - An object with options. + * + * @returns The array with starts of hours from the hour of the interval start to the hour of the interval end * * @example * // Each hour between 6 October 2014, 12:00 and 6 October 2014, 15:00 @@ -35,33 +35,31 @@ export interface EachHourOfIntervalOptions extends StepOptions {} * // Mon Oct 06 2014 15:00:00 * // ] */ -export default function eachHourOfInterval( +export function eachHourOfInterval( interval: Interval, options?: EachHourOfIntervalOptions, ): DateType[] { const startDate = toDate(interval.start); const endDate = toDate(interval.end); - const startTime = startDate.getTime(); - const endTime = endDate.getTime(); + let reversed = +startDate > +endDate; + const endTime = reversed ? +startDate : +endDate; + let currentDate = reversed ? endDate : startDate; + currentDate.setMinutes(0, 0, 0); - // Throw an exception if start date is after end date or if any date is `Invalid Date` - if (!(startTime <= endTime)) { - throw new RangeError('Invalid interval'); + let step = options?.step ?? 1; + if (!step) return []; + if (step < 0) { + step = -step; + reversed = !reversed; } const dates = []; - let currentDate = startDate; - currentDate.setMinutes(0, 0, 0); - - const step = options?.step ?? 1; - if (step < 1 || isNaN(step)) throw new RangeError('`options.step` must be a number greater than 1'); - - while (currentDate.getTime() <= endTime) { + while (+currentDate <= endTime) { dates.push(toDate(currentDate)); currentDate = addHours(currentDate, step); } - return dates; + return reversed ? dates.reverse() : dates; } diff --git a/src/date-fns/eachMinuteOfInterval/index.ts b/src/date-fns/eachMinuteOfInterval/index.ts index 03a0172..76c59e7 100644 --- a/src/date-fns/eachMinuteOfInterval/index.ts +++ b/src/date-fns/eachMinuteOfInterval/index.ts @@ -1,6 +1,6 @@ -import addMinutes from '../addMinutes/index'; -import startOfMinute from '../startOfMinute/index'; -import toDate from '../toDate/index'; +import { addMinutes } from '../addMinutes/index'; +import { startOfMinute } from '../startOfMinute/index'; +import { toDate } from '../toDate/index'; import type { Interval, StepOptions } from '../types'; /** @@ -16,12 +16,12 @@ export interface EachMinuteOfIntervalOptions extends StepOptions {} * @description * Returns the array of minutes within the specified time interval. * - * @param interval - the interval. See [Interval]{@link https://date-fns.org/docs/Interval} - * @param options - an object with options. - * @returns the array with starts of minutes from the minute of the interval start to the minute of the interval end - * @throws {RangeError} `options.step` must be a number equal to or greater than 1 - * @throws {RangeError} The start of an interval cannot be after its end - * @throws {RangeError} Date in interval cannot be `Invalid Date` + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param interval - The interval. + * @param options - An object with options. + * + * @returns The array with starts of minutes from the minute of the interval start to the minute of the interval end * * @example * // Each minute between 14 October 2020, 13:00 and 14 October 2020, 13:03 @@ -36,31 +36,30 @@ export interface EachMinuteOfIntervalOptions extends StepOptions {} * // Wed Oct 14 2014 13:03:00 * // ] */ -export default function eachMinuteOfInterval( +export function eachMinuteOfInterval( interval: Interval, options?: EachMinuteOfIntervalOptions, ): DateType[] { const startDate = startOfMinute(toDate(interval.start)); const endDate = toDate(interval.end); - const startTime = startDate.getTime(); - const endTime = endDate.getTime(); + let reversed = +startDate > +endDate; + const endTime = reversed ? +startDate : +endDate; + let currentDate = reversed ? endDate : startDate; - if (startTime >= endTime) { - throw new RangeError('Invalid interval'); + let step = options?.step ?? 1; + if (!step) return []; + if (step < 0) { + step = -step; + reversed = !reversed; } const dates = []; - let currentDate = startDate; - - const step = options?.step ?? 1; - if (step < 1 || isNaN(step)) throw new RangeError('`options.step` must be a number equal to or greater than 1'); - - while (currentDate.getTime() <= endTime) { + while (+currentDate <= endTime) { dates.push(toDate(currentDate)); currentDate = addMinutes(currentDate, step); } - return dates; + return reversed ? dates.reverse() : dates; } diff --git a/src/date-fns/eachMonthOfInterval/index.ts b/src/date-fns/eachMonthOfInterval/index.ts index fbcaf1f..fd195fa 100644 --- a/src/date-fns/eachMonthOfInterval/index.ts +++ b/src/date-fns/eachMonthOfInterval/index.ts @@ -1,5 +1,10 @@ -import toDate from '../toDate/index'; -import type { Interval } from '../types'; +import { toDate } from '../toDate/index'; +import type { Interval, StepOptions } from '../types'; + +/** + * The {@link eachMonthOfInterval} function options. + */ +export interface EachMonthOfIntervalOptions extends StepOptions {} /** * @name eachMonthOfInterval @@ -9,10 +14,11 @@ import type { Interval } from '../types'; * @description * Return the array of months within the specified time interval. * - * @param interval - the interval. See [Interval]{@link https://date-fns.org/docs/Interval} - * @returns the array with starts of months from the month of the interval start to the month of the interval end - * @throws {RangeError} The start of an interval cannot be after its end - * @throws {RangeError} Date in interval cannot be `Invalid Date` + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param interval - The interval + * + * @returns The array with starts of months from the month of the interval start to the month of the interval end * * @example * // Each month between 6 February 2014 and 10 August 2014: @@ -30,26 +36,32 @@ import type { Interval } from '../types'; * // Fri Aug 01 2014 00:00:00 * // ] */ -export default function eachMonthOfInterval(interval: Interval): DateType[] { +export function eachMonthOfInterval( + interval: Interval, + options?: EachMonthOfIntervalOptions, +): DateType[] { const startDate = toDate(interval.start); const endDate = toDate(interval.end); - const endTime = endDate.getTime(); - const dates = []; + let reversed = +startDate > +endDate; + const endTime = reversed ? +startDate : +endDate; + const currentDate = reversed ? endDate : startDate; + currentDate.setHours(0, 0, 0, 0); + currentDate.setDate(1); - // Throw an exception if start date is after end date or if any date is `Invalid Date` - if (!(startDate.getTime() <= endTime)) { - throw new RangeError('Invalid interval'); + let step = options?.step ?? 1; + if (!step) return []; + if (step < 0) { + step = -step; + reversed = !reversed; } - const currentDate = startDate; - currentDate.setHours(0, 0, 0, 0); - currentDate.setDate(1); + const dates = []; - while (currentDate.getTime() <= endTime) { + while (+currentDate <= endTime) { dates.push(toDate(currentDate)); - currentDate.setMonth(currentDate.getMonth() + 1); + currentDate.setMonth(currentDate.getMonth() + step); } - return dates; + return reversed ? dates.reverse() : dates; } diff --git a/src/date-fns/eachQuarterOfInterval/index.ts b/src/date-fns/eachQuarterOfInterval/index.ts index 5a4f1c6..030770d 100644 --- a/src/date-fns/eachQuarterOfInterval/index.ts +++ b/src/date-fns/eachQuarterOfInterval/index.ts @@ -1,7 +1,12 @@ -import addQuarters from '../addQuarters/index'; -import startOfQuarter from '../startOfQuarter/index'; -import toDate from '../toDate/index'; -import type { Interval } from '../types'; +import { addQuarters } from '../addQuarters/index'; +import { startOfQuarter } from '../startOfQuarter/index'; +import { toDate } from '../toDate/index'; +import type { Interval, StepOptions } from '../types'; + +/** + * The {@link eachQuarterOfInterval} function options. + */ +export interface EachQuarterOfIntervalOptions extends StepOptions {} /** * @name eachQuarterOfInterval @@ -11,10 +16,11 @@ import type { Interval } from '../types'; * @description * Return the array of quarters within the specified time interval. * - * @param interval - the interval. See [Interval]{@link https://date-fns.org/docs/Interval} - * @returns the array with starts of quarters from the quarter of the interval start to the quarter of the interval end - * @throws {RangeError} The start of an interval cannot be after its end - * @throws {RangeError} Date in interval cannot be `Invalid Date` + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param interval - The interval + * + * @returns The array with starts of quarters from the quarter of the interval start to the quarter of the interval end * * @example * // Each quarter within interval 6 February 2014 - 10 August 2014: @@ -28,30 +34,30 @@ import type { Interval } from '../types'; * // Tue Jul 01 2014 00:00:00, * // ] */ -export default function eachQuarterOfInterval(interval: Interval): DateType[] { +export function eachQuarterOfInterval( + interval: Interval, + options?: EachQuarterOfIntervalOptions, +): DateType[] { const startDate = toDate(interval.start); const endDate = toDate(interval.end); - let endTime = endDate.getTime(); + let reversed = +startDate > +endDate; + const endTime = reversed ? +startOfQuarter(startDate) : +startOfQuarter(endDate); + let currentDate = reversed ? startOfQuarter(endDate) : startOfQuarter(startDate); - // Throw an exception if start date is after end date or if any date is `Invalid Date` - if (!(startDate.getTime() <= endTime)) { - throw new RangeError('Invalid interval'); + let step = options?.step ?? 1; + if (!step) return []; + if (step < 0) { + step = -step; + reversed = !reversed; } - const startDateQuarter = startOfQuarter(startDate); - const endDateQuarter = startOfQuarter(endDate); - - endTime = endDateQuarter.getTime(); - - const quarters = []; - - let currentQuarter = startDateQuarter; + const dates = []; - while (currentQuarter.getTime() <= endTime) { - quarters.push(toDate(currentQuarter)); - currentQuarter = addQuarters(currentQuarter, 1); + while (+currentDate <= endTime) { + dates.push(toDate(currentDate)); + currentDate = addQuarters(currentDate, step); } - return quarters; + return reversed ? dates.reverse() : dates; } diff --git a/src/date-fns/eachWeekOfInterval/index.ts b/src/date-fns/eachWeekOfInterval/index.ts index 9291672..3763953 100644 --- a/src/date-fns/eachWeekOfInterval/index.ts +++ b/src/date-fns/eachWeekOfInterval/index.ts @@ -1,12 +1,12 @@ -import addWeeks from '../addWeeks/index'; -import startOfWeek from '../startOfWeek/index'; -import toDate from '../toDate/index'; -import type { Interval, LocaleOptions, WeekStartOptions } from '../types'; +import { addWeeks } from '../addWeeks/index'; +import { startOfWeek } from '../startOfWeek/index'; +import { toDate } from '../toDate/index'; +import type { Interval, LocalizedOptions, StepOptions, WeekOptions } from '../types'; /** * The {@link eachWeekOfInterval} function options. */ -export interface EachWeekOfIntervalOptions extends WeekStartOptions, LocaleOptions {} +export interface EachWeekOfIntervalOptions extends StepOptions, WeekOptions, LocalizedOptions<'options'> {} /** * @name eachWeekOfInterval @@ -16,11 +16,12 @@ export interface EachWeekOfIntervalOptions extends WeekStartOptions, LocaleOptio * @description * Return the array of weeks within the specified time interval. * - * @param interval - the interval. See [Interval]{@link https://date-fns.org/docs/Interval} - * @param options - an object with options. - * @returns the array with starts of weeks from the week of the interval start to the week of the interval end - * @throws {RangeError} The start of an interval cannot be after its end - * @throws {RangeError} Date in interval cannot be `Invalid Date` + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param interval - The interval. + * @param options - An object with options. + * + * @returns The array with starts of weeks from the week of the interval start to the week of the interval end * * @example * // Each week within interval 6 October 2014 - 23 November 2014: @@ -39,39 +40,39 @@ export interface EachWeekOfIntervalOptions extends WeekStartOptions, LocaleOptio * // Sun Nov 23 2014 00:00:00 * // ] */ -export default function eachWeekOfInterval( +export function eachWeekOfInterval( interval: Interval, options?: EachWeekOfIntervalOptions, ): DateType[] { const startDate = toDate(interval.start); const endDate = toDate(interval.end); - let endTime = endDate.getTime(); - - // Throw an exception if start date is after end date or if any date is `Invalid Date` - if (!(startDate.getTime() <= endTime)) { - throw new RangeError('Invalid interval'); - } - - const startDateWeek = startOfWeek(startDate, options); - const endDateWeek = startOfWeek(endDate, options); + let reversed = +startDate > +endDate; + const startDateWeek = reversed ? startOfWeek(endDate, options) : startOfWeek(startDate, options); + const endDateWeek = reversed ? startOfWeek(startDate, options) : startOfWeek(endDate, options); // Some timezones switch DST at midnight, making start of day unreliable in these timezones, 3pm is a safe bet startDateWeek.setHours(15); endDateWeek.setHours(15); - endTime = endDateWeek.getTime(); + const endTime = +endDateWeek.getTime(); + let currentDate = startDateWeek; - const weeks = []; + let step = options?.step ?? 1; + if (!step) return []; + if (step < 0) { + step = -step; + reversed = !reversed; + } - let currentWeek = startDateWeek; + const dates = []; - while (currentWeek.getTime() <= endTime) { - currentWeek.setHours(0); - weeks.push(toDate(currentWeek)); - currentWeek = addWeeks(currentWeek, 1); - currentWeek.setHours(15); + while (+currentDate <= endTime) { + currentDate.setHours(0); + dates.push(toDate(currentDate)); + currentDate = addWeeks(currentDate, step); + currentDate.setHours(15); } - return weeks; + return reversed ? dates.reverse() : dates; } diff --git a/src/date-fns/eachWeekendOfInterval/index.ts b/src/date-fns/eachWeekendOfInterval/index.ts index 32c0153..c6e5d2d 100644 --- a/src/date-fns/eachWeekendOfInterval/index.ts +++ b/src/date-fns/eachWeekendOfInterval/index.ts @@ -1,6 +1,5 @@ -import eachDayOfInterval from '../eachDayOfInterval/index'; -import isSunday from '../isSunday/index'; -import isWeekend from '../isWeekend/index'; +import { eachDayOfInterval } from '../eachDayOfInterval/index'; +import { isWeekend } from '../isWeekend/index'; import type { Interval } from '../types'; /** @@ -11,10 +10,11 @@ import type { Interval } from '../types'; * @description * Get all the Saturdays and Sundays in the given date interval. * - * @param interval - the given interval. See [Interval]{@link https://date-fns.org/docs/Interval} - * @returns an array containing all the Saturdays and Sundays - * @throws {RangeError} The start of an interval cannot be after its end - * @throws {RangeError} Date in interval cannot be `Invalid Date` + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param interval - The given interval + * + * @returns An array containing all the Saturdays and Sundays * * @example * // Lists all Saturdays and Sundays in the given date interval @@ -29,16 +29,13 @@ import type { Interval } from '../types'; * // Sun Sep 30 2018 00:00:00 * // ] */ -export default function eachWeekendOfInterval(interval: Interval): DateType[] { +export function eachWeekendOfInterval(interval: Interval): DateType[] { const dateInterval = eachDayOfInterval(interval); const weekends = []; let index = 0; while (index < dateInterval.length) { - const date = dateInterval[index++] as DateType; - if (isWeekend(date)) { - weekends.push(date); - if (isSunday(date)) index = index + 5; - } + const date = dateInterval[index++]; + if (isWeekend(date!)) weekends.push(date!); } return weekends; } diff --git a/src/date-fns/eachWeekendOfMonth/index.ts b/src/date-fns/eachWeekendOfMonth/index.ts index b38b71d..522d8c1 100644 --- a/src/date-fns/eachWeekendOfMonth/index.ts +++ b/src/date-fns/eachWeekendOfMonth/index.ts @@ -1,6 +1,6 @@ -import eachWeekendOfInterval from '../eachWeekendOfInterval/index'; -import endOfMonth from '../endOfMonth/index'; -import startOfMonth from '../startOfMonth/index'; +import { eachWeekendOfInterval } from '../eachWeekendOfInterval/index'; +import { endOfMonth } from '../endOfMonth/index'; +import { startOfMonth } from '../startOfMonth/index'; /** * @name eachWeekendOfMonth @@ -10,9 +10,11 @@ import startOfMonth from '../startOfMonth/index'; * @description * Get all the Saturdays and Sundays in the given month. * - * @param date - the given month - * @returns an array containing all the Saturdays and Sundays - * @throws {RangeError} The passed date is invalid + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The given month + * + * @returns An array containing all the Saturdays and Sundays * * @example * // Lists all Saturdays and Sundays in the given month @@ -28,10 +30,8 @@ import startOfMonth from '../startOfMonth/index'; * // Sun Feb 27 2022 00:00:00 * // ] */ -export default function eachWeekendOfMonth(dirtyDate: DateType): DateType[] { - const startDate = startOfMonth(dirtyDate); - if (isNaN(startDate.getTime())) throw new RangeError('The passed date is invalid'); - - const endDate = endOfMonth(dirtyDate); - return eachWeekendOfInterval({ start: startDate, end: endDate }); +export function eachWeekendOfMonth(date: DateType): DateType[] { + const start = startOfMonth(date); + const end = endOfMonth(date); + return eachWeekendOfInterval({ start, end }); } diff --git a/src/date-fns/eachWeekendOfYear/index.ts b/src/date-fns/eachWeekendOfYear/index.ts index c60d8b0..9f18649 100644 --- a/src/date-fns/eachWeekendOfYear/index.ts +++ b/src/date-fns/eachWeekendOfYear/index.ts @@ -1,6 +1,6 @@ -import eachWeekendOfInterval from '../eachWeekendOfInterval/index'; -import endOfYear from '../endOfYear/index'; -import startOfYear from '../startOfYear/index'; +import { eachWeekendOfInterval } from '../eachWeekendOfInterval/index'; +import { endOfYear } from '../endOfYear/index'; +import { startOfYear } from '../startOfYear/index'; /** * @name eachWeekendOfYear @@ -10,9 +10,11 @@ import startOfYear from '../startOfYear/index'; * @description * Get all the Saturdays and Sundays in the year. * - * @param date - the given year - * @returns an array containing all the Saturdays and Sundays - * @throws {RangeError} The passed date is invalid + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The given year + * + * @returns An array containing all the Saturdays and Sundays * * @example * // Lists all Saturdays and Sundays in the year @@ -25,8 +27,8 @@ import startOfYear from '../startOfYear/index'; * // ] * ] */ -export default function eachWeekendOfYear(dirtyDate: DateType | number): DateType[] { - const startDate = startOfYear(dirtyDate); - const endDate = endOfYear(dirtyDate); - return eachWeekendOfInterval({ start: startDate, end: endDate }); +export function eachWeekendOfYear(date: DateType | number | string): DateType[] { + const start = startOfYear(date); + const end = endOfYear(date); + return eachWeekendOfInterval({ start, end }); } diff --git a/src/date-fns/eachYearOfInterval/index.ts b/src/date-fns/eachYearOfInterval/index.ts index ea62e46..921181a 100644 --- a/src/date-fns/eachYearOfInterval/index.ts +++ b/src/date-fns/eachYearOfInterval/index.ts @@ -1,5 +1,10 @@ -import toDate from '../toDate/index'; -import type { Interval } from '../types'; +import { toDate } from '../toDate/index'; +import type { Interval, StepOptions } from '../types'; + +/** + * The {@link eachYearOfInterval} function options. + */ +export interface EachYearOfIntervalOptions extends StepOptions {} /** * @name eachYearOfInterval @@ -9,10 +14,11 @@ import type { Interval } from '../types'; * @description * Return the array of yearly timestamps within the specified time interval. * - * @param interval - the interval. See [Interval]{@link https://date-fns.org/docs/Interval} - * @returns the array with starts of yearly timestamps from the month of the interval start to the month of the interval end - * @throws {RangeError} The start of an interval cannot be after its end - * @throws {RangeError} Date in interval cannot be `Invalid Date` + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param interval - The interval. + * + * @returns The array with starts of yearly timestamps from the month of the interval start to the month of the interval end * * @example * // Each year between 6 February 2014 and 10 August 2017: @@ -27,27 +33,32 @@ import type { Interval } from '../types'; * // Sun Jan 01 2017 00:00:00 * // ] */ -export default function eachYearOfInterval(interval: Interval): DateType[] { +export function eachYearOfInterval( + interval: Interval, + options?: EachYearOfIntervalOptions, +): DateType[] { const startDate = toDate(interval.start); const endDate = toDate(interval.end); - const endTime = endDate.getTime(); + let reversed = +startDate > +endDate; + const endTime = reversed ? +startDate : +endDate; + const currentDate = reversed ? endDate : startDate; + currentDate.setHours(0, 0, 0, 0); + currentDate.setMonth(0, 1); - // Throw an exception if start date is after end date or if any date is `Invalid Date` - if (!(startDate.getTime() <= endTime)) { - throw new RangeError('Invalid interval'); + let step = options?.step ?? 1; + if (!step) return []; + if (step < 0) { + step = -step; + reversed = !reversed; } const dates = []; - const currentDate = startDate; - currentDate.setHours(0, 0, 0, 0); - currentDate.setMonth(0, 1); - - while (currentDate.getTime() <= endTime) { + while (+currentDate <= endTime) { dates.push(toDate(currentDate)); - currentDate.setFullYear(currentDate.getFullYear() + 1); + currentDate.setFullYear(currentDate.getFullYear() + step); } - return dates; + return reversed ? dates.reverse() : dates; } diff --git a/src/date-fns/endOfDay/index.ts b/src/date-fns/endOfDay/index.ts index 8d60b59..f931400 100644 --- a/src/date-fns/endOfDay/index.ts +++ b/src/date-fns/endOfDay/index.ts @@ -1,4 +1,4 @@ -import toDate from '../toDate/index'; +import { toDate } from '../toDate/index'; /** * @name endOfDay @@ -9,16 +9,19 @@ import toDate from '../toDate/index'; * Return the end of a day for the given date. * The result will be in the local timezone. * - * @param date - the original date - * @returns the end of a day + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The original date + * + * @returns The end of a day * * @example * // The end of a day for 2 September 2014 11:55:00: * const result = endOfDay(new Date(2014, 8, 2, 11, 55, 0)) * //=> Tue Sep 02 2014 23:59:59.999 */ -export default function endOfDay(dirtyDate: DateType | number): DateType { - const date = toDate(dirtyDate); - date.setHours(23, 59, 59, 999); - return date; +export function endOfDay(date: DateType | number | string): DateType { + const _date = toDate(date); + _date.setHours(23, 59, 59, 999); + return _date; } diff --git a/src/date-fns/endOfDecade/index.ts b/src/date-fns/endOfDecade/index.ts index 42188e3..0c64b7d 100644 --- a/src/date-fns/endOfDecade/index.ts +++ b/src/date-fns/endOfDecade/index.ts @@ -1,4 +1,4 @@ -import toDate from '../toDate/index'; +import { toDate } from '../toDate/index'; /** * @name endOfDecade @@ -8,19 +8,25 @@ import toDate from '../toDate/index'; * @description * Return the end of a decade for the given date. * - * @param date - the original date - * @returns the end of a decade + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The original date + * + * @returns The end of a decade * * @example * // The end of a decade for 12 May 1984 00:00:00: * const result = endOfDecade(new Date(1984, 4, 12, 00, 00, 00)) * //=> Dec 31 1989 23:59:59.999 */ -export default function endOfDecade(dirtyDate: DateType | number): DateType { - const date = toDate(dirtyDate); - const year = date.getFullYear(); +export function endOfDecade(date: DateType | number | string): DateType { + // TODO: Switch to more technical definition in of decades that start with 1 + // end with 0. I.e. 2001-2010 instead of current 2000-2009. It's a breaking + // change, so it can only be done in 4.0. + const _date = toDate(date); + const year = _date.getFullYear(); const decade = 9 + Math.floor(year / 10) * 10; - date.setFullYear(decade, 11, 31); - date.setHours(23, 59, 59, 999); - return date; + _date.setFullYear(decade, 11, 31); + _date.setHours(23, 59, 59, 999); + return _date; } diff --git a/src/date-fns/endOfHour/index.ts b/src/date-fns/endOfHour/index.ts index 885da33..1b249c9 100644 --- a/src/date-fns/endOfHour/index.ts +++ b/src/date-fns/endOfHour/index.ts @@ -1,4 +1,4 @@ -import toDate from '../toDate/index'; +import { toDate } from '../toDate/index'; /** * @name endOfHour @@ -9,16 +9,19 @@ import toDate from '../toDate/index'; * Return the end of an hour for the given date. * The result will be in the local timezone. * - * @param date - the original date - * @returns the end of an hour + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The original date + * + * @returns The end of an hour * * @example * // The end of an hour for 2 September 2014 11:55:00: * const result = endOfHour(new Date(2014, 8, 2, 11, 55)) * //=> Tue Sep 02 2014 11:59:59.999 */ -export default function endOfHour(dirtyDate: DateType | number): DateType { - const date = toDate(dirtyDate); - date.setMinutes(59, 59, 999); - return date; +export function endOfHour(date: DateType | number | string): DateType { + const _date = toDate(date); + _date.setMinutes(59, 59, 999); + return _date; } diff --git a/src/date-fns/endOfISOWeek/index.ts b/src/date-fns/endOfISOWeek/index.ts index 9011377..6e7984f 100644 --- a/src/date-fns/endOfISOWeek/index.ts +++ b/src/date-fns/endOfISOWeek/index.ts @@ -1,4 +1,4 @@ -import endOfWeek from '../endOfWeek/index'; +import { endOfWeek } from '../endOfWeek/index'; /** * @name endOfISOWeek @@ -11,14 +11,17 @@ import endOfWeek from '../endOfWeek/index'; * * ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date * - * @param date - the original date - * @returns the end of an ISO week + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The original date + * + * @returns The end of an ISO week * * @example * // The end of an ISO week for 2 September 2014 11:55:00: * const result = endOfISOWeek(new Date(2014, 8, 2, 11, 55, 0)) * //=> Sun Sep 07 2014 23:59:59.999 */ -export default function endOfISOWeek(dirtyDate: DateType | number): DateType { - return endOfWeek(dirtyDate, { weekStartsOn: 1 }); +export function endOfISOWeek(date: DateType | number | string): DateType { + return endOfWeek(date, { weekStartsOn: 1 }); } diff --git a/src/date-fns/endOfISOWeekYear/index.ts b/src/date-fns/endOfISOWeekYear/index.ts index 720df87..4a65ce4 100644 --- a/src/date-fns/endOfISOWeekYear/index.ts +++ b/src/date-fns/endOfISOWeekYear/index.ts @@ -1,6 +1,6 @@ -import getISOWeekYear from '../getISOWeekYear/index'; -import startOfISOWeek from '../startOfISOWeek/index'; -import constructFrom from '../constructFrom/index'; +import { getISOWeekYear } from '../getISOWeekYear/index'; +import { startOfISOWeek } from '../startOfISOWeek/index'; +import { constructFrom } from '../constructFrom/index'; /** * @name endOfISOWeekYear @@ -14,20 +14,23 @@ import constructFrom from '../constructFrom/index'; * * ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date * - * @param date - the original date - * @returns the end of an ISO week-numbering year + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The original date + * + * @returns The end of an ISO week-numbering year * * @example * // The end of an ISO week-numbering year for 2 July 2005: * const result = endOfISOWeekYear(new Date(2005, 6, 2)) * //=> Sun Jan 01 2006 23:59:59.999 */ -export default function endOfISOWeekYear(dirtyDate: DateType | number): DateType { - const year = getISOWeekYear(dirtyDate); - const fourthOfJanuaryOfNextYear = constructFrom(dirtyDate, 0); +export function endOfISOWeekYear(date: DateType | number | string): DateType { + const year = getISOWeekYear(date); + const fourthOfJanuaryOfNextYear = constructFrom(date, 0); fourthOfJanuaryOfNextYear.setFullYear(year + 1, 0, 4); fourthOfJanuaryOfNextYear.setHours(0, 0, 0, 0); - const date = startOfISOWeek(fourthOfJanuaryOfNextYear); - date.setMilliseconds(date.getMilliseconds() - 1); - return date; + const _date = startOfISOWeek(fourthOfJanuaryOfNextYear); + _date.setMilliseconds(_date.getMilliseconds() - 1); + return _date; } diff --git a/src/date-fns/endOfMinute/index.ts b/src/date-fns/endOfMinute/index.ts index 0cf6c6c..b8d01c0 100644 --- a/src/date-fns/endOfMinute/index.ts +++ b/src/date-fns/endOfMinute/index.ts @@ -1,4 +1,4 @@ -import toDate from '../toDate/index'; +import { toDate } from '../toDate/index'; /** * @name endOfMinute @@ -9,16 +9,19 @@ import toDate from '../toDate/index'; * Return the end of a minute for the given date. * The result will be in the local timezone. * - * @param date - the original date - * @returns the end of a minute + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The original date + * + * @returns The end of a minute * * @example * // The end of a minute for 1 December 2014 22:15:45.400: * const result = endOfMinute(new Date(2014, 11, 1, 22, 15, 45, 400)) * //=> Mon Dec 01 2014 22:15:59.999 */ -export default function endOfMinute(dirtyDate: DateType | number): DateType { - const date = toDate(dirtyDate); - date.setSeconds(59, 999); - return date; +export function endOfMinute(date: DateType | number | string): DateType { + const _date = toDate(date); + _date.setSeconds(59, 999); + return _date; } diff --git a/src/date-fns/endOfMonth/index.ts b/src/date-fns/endOfMonth/index.ts index d1b4cb4..d527794 100644 --- a/src/date-fns/endOfMonth/index.ts +++ b/src/date-fns/endOfMonth/index.ts @@ -1,4 +1,4 @@ -import toDate from '../toDate/index'; +import { toDate } from '../toDate/index'; /** * @name endOfMonth @@ -9,18 +9,21 @@ import toDate from '../toDate/index'; * Return the end of a month for the given date. * The result will be in the local timezone. * - * @param date - the original date - * @returns the end of a month + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The original date + * + * @returns The end of a month * * @example * // The end of a month for 2 September 2014 11:55:00: * const result = endOfMonth(new Date(2014, 8, 2, 11, 55, 0)) * //=> Tue Sep 30 2014 23:59:59.999 */ -export default function endOfMonth(dirtyDate: DateType | number): DateType { - const date = toDate(dirtyDate); - const month = date.getMonth(); - date.setFullYear(date.getFullYear(), month + 1, 0); - date.setHours(23, 59, 59, 999); - return date; +export function endOfMonth(date: DateType | number | string): DateType { + const _date = toDate(date); + const month = _date.getMonth(); + _date.setFullYear(_date.getFullYear(), month + 1, 0); + _date.setHours(23, 59, 59, 999); + return _date; } diff --git a/src/date-fns/endOfQuarter/index.ts b/src/date-fns/endOfQuarter/index.ts index 9e4e1f7..2184891 100644 --- a/src/date-fns/endOfQuarter/index.ts +++ b/src/date-fns/endOfQuarter/index.ts @@ -1,4 +1,4 @@ -import toDate from '../toDate/index'; +import { toDate } from '../toDate/index'; /** * @name endOfQuarter @@ -9,19 +9,22 @@ import toDate from '../toDate/index'; * Return the end of a year quarter for the given date. * The result will be in the local timezone. * - * @param date - the original date - * @returns the end of a quarter + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The original date + * + * @returns The end of a quarter * * @example * // The end of a quarter for 2 September 2014 11:55:00: * const result = endOfQuarter(new Date(2014, 8, 2, 11, 55, 0)) * //=> Tue Sep 30 2014 23:59:59.999 */ -export default function endOfQuarter(dirtyDate: DateType | number): DateType { - const date = toDate(dirtyDate); - const currentMonth = date.getMonth(); +export function endOfQuarter(date: DateType | number | string): DateType { + const _date = toDate(date); + const currentMonth = _date.getMonth(); const month = currentMonth - (currentMonth % 3) + 3; - date.setMonth(month, 0); - date.setHours(23, 59, 59, 999); - return date; + _date.setMonth(month, 0); + _date.setHours(23, 59, 59, 999); + return _date; } diff --git a/src/date-fns/endOfSecond/index.ts b/src/date-fns/endOfSecond/index.ts index be1a1ff..d818e37 100644 --- a/src/date-fns/endOfSecond/index.ts +++ b/src/date-fns/endOfSecond/index.ts @@ -1,4 +1,4 @@ -import toDate from '../toDate/index'; +import { toDate } from '../toDate/index'; /** * @name endOfSecond @@ -9,16 +9,19 @@ import toDate from '../toDate/index'; * Return the end of a second for the given date. * The result will be in the local timezone. * - * @param date - the original date - * @returns the end of a second + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The original date + * + * @returns The end of a second * * @example * // The end of a second for 1 December 2014 22:15:45.400: * const result = endOfSecond(new Date(2014, 11, 1, 22, 15, 45, 400)) * //=> Mon Dec 01 2014 22:15:45.999 */ -export default function endOfSecond(dirtyDate: DateType | number): DateType { - const date = toDate(dirtyDate); - date.setMilliseconds(999); - return date; +export function endOfSecond(date: DateType | number | string): DateType { + const _date = toDate(date); + _date.setMilliseconds(999); + return _date; } diff --git a/src/date-fns/endOfToday/index.ts b/src/date-fns/endOfToday/index.ts index 0527876..4f23e7e 100644 --- a/src/date-fns/endOfToday/index.ts +++ b/src/date-fns/endOfToday/index.ts @@ -1,4 +1,4 @@ -import endOfDay from '../endOfDay/index'; +import { endOfDay } from '../endOfDay/index'; /** * @name endOfToday @@ -9,16 +9,15 @@ import endOfDay from '../endOfDay/index'; * @description * Return the end of today. * - * > ⚠️ Please note that this function is not present in the FP submodule as - * > it uses `Date.now()` internally hence impure and can't be safely curried. + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). * - * @returns the end of today + * @returns The end of today * * @example * // If today is 6 October 2014: * const result = endOfToday() * //=> Mon Oct 6 2014 23:59:59.999 */ -export default function endOfToday(): Date { +export function endOfToday(): Date { return endOfDay(Date.now()); } diff --git a/src/date-fns/endOfTomorrow/index.ts b/src/date-fns/endOfTomorrow/index.ts index d44e472..df3e59f 100644 --- a/src/date-fns/endOfTomorrow/index.ts +++ b/src/date-fns/endOfTomorrow/index.ts @@ -7,17 +7,16 @@ * @description * Return the end of tomorrow. * - * > ⚠️ Please note that this function is not present in the FP submodule as - * > it uses `new Date()` internally hence impure and can't be safely curried. + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). * - * @returns the end of tomorrow + * @returns The end of tomorrow * * @example * // If today is 6 October 2014: * const result = endOfTomorrow() * //=> Tue Oct 7 2014 23:59:59.999 */ -export default function endOfTomorrow(): Date { +export function endOfTomorrow(): Date { const now = new Date(); const year = now.getFullYear(); const month = now.getMonth(); diff --git a/src/date-fns/endOfWeek/index.ts b/src/date-fns/endOfWeek/index.ts index a281a29..6a0ad31 100644 --- a/src/date-fns/endOfWeek/index.ts +++ b/src/date-fns/endOfWeek/index.ts @@ -1,11 +1,11 @@ -import toDate from '../toDate/index'; -import type { LocaleOptions, WeekStartOptions } from '../types'; +import { toDate } from '../toDate/index'; +import type { LocalizedOptions, WeekOptions } from '../types'; import { getDefaultOptions } from '../_lib/defaultOptions/index'; /** * The {@link endOfWeek} function options. */ -export interface EndOfWeekOptions extends WeekStartOptions, LocaleOptions {} +export interface EndOfWeekOptions extends WeekOptions, LocalizedOptions<'options'> {} /** * @name endOfWeek @@ -16,9 +16,12 @@ export interface EndOfWeekOptions extends WeekStartOptions, LocaleOptions {} * Return the end of a week for the given date. * The result will be in the local timezone. * - * @param date - the original date - * @param options - an object with options. - * @returns the end of a week + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The original date + * @param options - An object with options + * + * @returns The end of a week * * @example * // The end of a week for 2 September 2014 11:55:00: @@ -30,8 +33,8 @@ export interface EndOfWeekOptions extends WeekStartOptions, LocaleOptions {} * const result = endOfWeek(new Date(2014, 8, 2, 11, 55, 0), { weekStartsOn: 1 }) * //=> Sun Sep 07 2014 23:59:59.999 */ -export default function endOfWeek( - dirtyDate: DateType | number, +export function endOfWeek( + date: DateType | number | string, options?: EndOfWeekOptions, ): DateType { const defaultOptions = getDefaultOptions(); @@ -42,11 +45,11 @@ export default function endOfWeek( defaultOptions.locale?.options?.weekStartsOn ?? 0; - const date = toDate(dirtyDate); - const day = date.getDay(); + const _date = toDate(date); + const day = _date.getDay(); const diff = (day < weekStartsOn ? -7 : 0) + 6 - (day - weekStartsOn); - date.setDate(date.getDate() + diff); - date.setHours(23, 59, 59, 999); - return date; + _date.setDate(_date.getDate() + diff); + _date.setHours(23, 59, 59, 999); + return _date; } diff --git a/src/date-fns/endOfYear/index.ts b/src/date-fns/endOfYear/index.ts index b8a93dd..3dee94e 100644 --- a/src/date-fns/endOfYear/index.ts +++ b/src/date-fns/endOfYear/index.ts @@ -1,4 +1,4 @@ -import toDate from '../toDate/index'; +import { toDate } from '../toDate/index'; /** * @name endOfYear @@ -9,18 +9,21 @@ import toDate from '../toDate/index'; * Return the end of a year for the given date. * The result will be in the local timezone. * - * @param date - the original date - * @returns the end of a year + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The original date + * + * @returns The end of a year * * @example * // The end of a year for 2 September 2014 11:55:00: * const result = endOfYear(new Date(2014, 8, 2, 11, 55, 00)) * //=> Wed Dec 31 2014 23:59:59.999 */ -export default function endOfYear(dirtyDate: DateType | number): DateType { - const date = toDate(dirtyDate); - const year = date.getFullYear(); - date.setFullYear(year + 1, 0, 0); - date.setHours(23, 59, 59, 999); - return date; +export function endOfYear(date: DateType | number | string): DateType { + const _date = toDate(date); + const year = _date.getFullYear(); + _date.setFullYear(year + 1, 0, 0); + _date.setHours(23, 59, 59, 999); + return _date; } diff --git a/src/date-fns/endOfYesterday/index.ts b/src/date-fns/endOfYesterday/index.ts index 89abd90..7b272e7 100644 --- a/src/date-fns/endOfYesterday/index.ts +++ b/src/date-fns/endOfYesterday/index.ts @@ -7,17 +7,16 @@ * @description * Return the end of yesterday. * - * > ⚠️ Please note that this function is not present in the FP submodule as - * > it uses `new Date()` internally hence impure and can't be safely curried. + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). * - * @returns the end of yesterday + * @returns The end of yesterday * * @example * // If today is 6 October 2014: * const result = endOfYesterday() * //=> Sun Oct 5 2014 23:59:59.999 */ -export default function endOfYesterday(): Date { +export function endOfYesterday(): Date { const now = new Date(); const year = now.getFullYear(); const month = now.getMonth(); diff --git a/src/date-fns/format/index.ts b/src/date-fns/format/index.ts index de11700..0e2262c 100644 --- a/src/date-fns/format/index.ts +++ b/src/date-fns/format/index.ts @@ -1,23 +1,25 @@ -import type { Instant } from '../../instant'; -import isValid from '../isValid/index'; -import toDate from '../toDate/index'; -import type { - AdditionalTokensOptions, - Day, - FirstWeekContainsDate, - FirstWeekContainsDateOptions, - LocaleOptions, - WeekStartOptions, -} from '../types'; -import defaultLocale from '../_lib/defaultLocale/index'; +import { defaultLocale } from '../_lib/defaultLocale/index'; import { getDefaultOptions } from '../_lib/defaultOptions/index'; -import formatters from '../_lib/format/formatters/index'; -import longFormatters from '../_lib/format/longFormatters/index'; +import { formatters } from '../_lib/format/formatters/index'; +import { longFormatters } from '../_lib/format/longFormatters/index'; import { isProtectedDayOfYearToken, isProtectedWeekYearToken, - throwProtectedError, + warnOrThrowProtectedError, } from '../_lib/protectedTokens/index'; +import { isValid } from '../isValid/index'; +import { toDate } from '../toDate/index'; +import type { + AdditionalTokensOptions, + FirstWeekContainsDateOptions, + FormatPart, + LocalizedOptions, + WeekOptions, +} from '../types'; + +// Rexports of internal for libraries to use. +// See: https://github.com/date-fns/date-fns/issues/3638#issuecomment-1877082874 +export { formatters, longFormatters }; // This RegExp consists of three parts separated by `|`: // - [yYQqMLwIdDecihHKkms]o matches any available ordinal number token @@ -40,17 +42,21 @@ const escapedStringRegExp = /^'([^]*?)'?$/; const doubleQuoteRegExp = /''/g; const unescapedLatinCharacterRegExp = /[a-zA-Z]/; +export { format as formatDate }; +export type { FormatOptions as FormatDateOptions }; + /** * The {@link format} function options. */ export interface FormatOptions - extends LocaleOptions, - WeekStartOptions, + extends LocalizedOptions<'options' | 'localize' | 'formatLong'>, + WeekOptions, FirstWeekContainsDateOptions, AdditionalTokensOptions {} /** * @name format + * @alias formatDate * @category Common Helpers * @summary Format the date. * @@ -277,8 +283,8 @@ export interface FormatOptions * * The same difference is true for local and ISO week-numbering years (`Y` and `R`), * except local week-numbering years are dependent on `options.weekStartsOn` - * and `options.firstWeekContainsDate` (compare [getISOWeekYear]{@link https://date-fns.org/docs/getISOWeekYear} - * and [getWeekYear]{@link https://date-fns.org/docs/getWeekYear}). + * and `options.firstWeekContainsDate` (compare [getISOWeekYear](https://date-fns.org/docs/getISOWeekYear) + * and [getWeekYear](https://date-fns.org/docs/getWeekYear)). * * 6. Specific non-location timezones are currently unavailable in `date-fns`, * so right now these tokens fall back to GMT timezones. @@ -299,18 +305,22 @@ export interface FormatOptions * 9. `D` and `DD` tokens represent days of the year but they are often confused with days of the month. * You should enable `options.useAdditionalDayOfYearTokens` to use them. See: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md * - * @param date - the original date - * @param format - the string of tokens - * @param options - an object with options. - * @returns the formatted date string - * @throws {RangeError} `date` must not be Invalid Date - * @throws {RangeError} `options.locale` must contain `localize` property - * @throws {RangeError} `options.locale` must contain `formatLong` property - * @throws {RangeError} use `yyyy` instead of `YYYY` for formatting years using [format provided] to the input [input provided]; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md - * @throws {RangeError} use `yy` instead of `YY` for formatting years using [format provided] to the input [input provided]; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md - * @throws {RangeError} use `d` instead of `D` for formatting days of the month using [format provided] to the input [input provided]; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md - * @throws {RangeError} use `dd` instead of `DD` for formatting days of the month using [format provided] to the input [input provided]; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md - * @throws {RangeError} format string contains an unescaped latin alphabet character + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The original date + * @param format - The string of tokens + * @param options - An object with options + * + * @returns The formatted date string + * + * @throws `date` must not be Invalid Date + * @throws `options.locale` must contain `localize` property + * @throws `options.locale` must contain `formatLong` property + * @throws use `yyyy` instead of `YYYY` for formatting years using [format provided] to the input [input provided]; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md + * @throws use `yy` instead of `YY` for formatting years using [format provided] to the input [input provided]; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md + * @throws use `d` instead of `D` for formatting days of the month using [format provided] to the input [input provided]; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md + * @throws use `dd` instead of `DD` for formatting days of the month using [format provided] to the input [input provided]; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md + * @throws format string contains an unescaped latin alphabet character * * @example * // Represent 11 February 2014 in middle-endian format: @@ -330,9 +340,8 @@ export interface FormatOptions * const result = format(new Date(2014, 6, 2, 15), "h 'o''clock'") * //=> "3 o'clock" */ - -export default function format( - dirtyDate: Instant | DateType | number, +export function format( + date: DateType | number | string, formatStr: string, options?: FormatOptions, ): string { @@ -353,70 +362,74 @@ export default function format( defaultOptions.locale?.options?.weekStartsOn ?? 0; - if (!locale.localize) { - throw new RangeError('locale must contain localize property'); - } - - if (!locale.formatLong) { - throw new RangeError('locale must contain formatLong property'); - } - - const originalDate = toDate(dirtyDate); + const originalDate = toDate(date); if (!isValid(originalDate)) { throw new RangeError('Invalid time value'); } - const formatterOptions = { - firstWeekContainsDate: firstWeekContainsDate as FirstWeekContainsDate, - weekStartsOn: weekStartsOn as Day, - locale: locale, - _originalDate: originalDate, - }; - - const result = formatStr + let parts: FormatPart[] = formatStr .match(longFormattingTokensRegExp)! - .map(function (substring) { + .map((substring) => { const firstCharacter = substring[0]; if (firstCharacter === 'p' || firstCharacter === 'P') { const longFormatter = longFormatters[firstCharacter]; - return longFormatter?.(substring, locale.formatLong); + return longFormatter!(substring, locale.formatLong); } return substring; }) .join('') .match(formattingTokensRegExp)! - .map(function (substring) { + .map((substring) => { // Replace two single quote characters with one single quote character if (substring === "''") { - return "'"; + return { isToken: false, value: "'" }; } - const firstCharacter = substring[0] as string; + const firstCharacter = substring[0]; if (firstCharacter === "'") { - return cleanEscapedString(substring); + return { isToken: false, value: cleanEscapedString(substring) }; } - const formatter = formatters[firstCharacter]; - if (formatter) { - if (!options?.useAdditionalWeekYearTokens && isProtectedWeekYearToken(substring)) { - throwProtectedError(substring, formatStr, String(dirtyDate)); - } - if (!options?.useAdditionalDayOfYearTokens && isProtectedDayOfYearToken(substring)) { - throwProtectedError(substring, formatStr, String(dirtyDate)); - } - return formatter(originalDate, substring, locale.localize, formatterOptions); + if (formatters[firstCharacter!]) { + return { isToken: true, value: substring }; } - if (firstCharacter.match(unescapedLatinCharacterRegExp)) { + if (firstCharacter!.match(unescapedLatinCharacterRegExp)) { throw new RangeError('Format string contains an unescaped latin alphabet character `' + firstCharacter + '`'); } - return substring; + return { isToken: false, value: substring }; + }); + + // invoke localize preprocessor (only for french locales at the moment) + if (locale.localize.preprocessor) { + parts = locale.localize.preprocessor(originalDate, parts); + } + + const formatterOptions = { + firstWeekContainsDate, + weekStartsOn, + locale, + }; + + return parts + .map((part) => { + if (!part.isToken) return part.value; + + const token = part.value; + + if ( + (!options?.useAdditionalWeekYearTokens && isProtectedWeekYearToken(token)) || + (!options?.useAdditionalDayOfYearTokens && isProtectedDayOfYearToken(token)) + ) { + warnOrThrowProtectedError(token, formatStr, String(date)); + } + + const formatter = formatters[token[0]!]; + return formatter!(originalDate, token, locale.localize, formatterOptions); }) .join(''); - - return result; } function cleanEscapedString(input: string): string { @@ -426,5 +439,5 @@ function cleanEscapedString(input: string): string { return input; } - return matched[1]?.replace(doubleQuoteRegExp, "'") as string; + return matched[1]!.replace(doubleQuoteRegExp, "'"); } diff --git a/src/date-fns/formatDistance/index.ts b/src/date-fns/formatDistance/index.ts index cd97acc..269506c 100644 --- a/src/date-fns/formatDistance/index.ts +++ b/src/date-fns/formatDistance/index.ts @@ -1,20 +1,20 @@ -import compareAsc from '../compareAsc/index'; +import { compareAsc } from '../compareAsc/index'; import { minutesInDay, minutesInMonth } from '../constants/index'; -import differenceInMonths from '../differenceInMonths/index'; -import differenceInSeconds from '../differenceInSeconds/index'; -import toDate from '../toDate/index'; -import type { LocaleOptions } from '../types'; -import assign from '../_lib/assign/index'; -import cloneObject from '../_lib/cloneObject/index'; -import defaultLocale from '../_lib/defaultLocale/index'; +import { differenceInMonths } from '../differenceInMonths/index'; +import { differenceInSeconds } from '../differenceInSeconds/index'; +import { toDate } from '../toDate/index'; +import type { LocalizedOptions } from '../types'; +import { defaultLocale } from '../_lib/defaultLocale/index'; import { getDefaultOptions } from '../_lib/defaultOptions/index'; -import getTimezoneOffsetInMilliseconds from '../_lib/getTimezoneOffsetInMilliseconds/index'; +import { getTimezoneOffsetInMilliseconds } from '../_lib/getTimezoneOffsetInMilliseconds/index'; /** * The {@link formatDistance} function options. */ -export interface FormatDistanceOptions extends LocaleOptions { +export interface FormatDistanceOptions extends LocalizedOptions<'formatDistance'> { + /** Distances less than a minute are more detailed */ includeSeconds?: boolean; + /** Add "X ago"/"in X" in the locale language */ addSuffix?: boolean; } @@ -55,13 +55,17 @@ export interface FormatDistanceOptions extends LocaleOptions { * | 40 secs ... 60 secs | less than a minute | * | 60 secs ... 90 secs | 1 minute | * - * @param date - the date - * @param baseDate - the date to compare with - * @param options - an object with options. - * @returns the distance in words - * @throws {RangeError} `date` must not be Invalid Date - * @throws {RangeError} `baseDate` must not be Invalid Date - * @throws {RangeError} `options.locale` must contain `formatDistance` property + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The date + * @param baseDate - The date to compare with + * @param options - An object with options + * + * @returns The distance in words + * + * @throws `date` must not be Invalid Date + * @throws `baseDate` must not be Invalid Date + * @throws `options.locale` must contain `formatDistance` property * * @example * // What is the distance between 2 July 2014 and 1 January 2015? @@ -95,26 +99,22 @@ export interface FormatDistanceOptions extends LocaleOptions { * //=> 'pli ol 1 jaro' */ -export default function formatDistance( - dirtyDate: DateType | number, - dirtyBaseDate: DateType | number, +export function formatDistance( + date: DateType | number | string, + baseDate: DateType | number | string, options?: FormatDistanceOptions, ): string { const defaultOptions = getDefaultOptions(); const locale = options?.locale ?? defaultOptions.locale ?? defaultLocale; const minutesInAlmostTwoDays = 2520; - if (!locale.formatDistance) { - throw new RangeError('locale must contain formatDistance property'); - } - - const comparison = compareAsc(dirtyDate, dirtyBaseDate); + const comparison = compareAsc(date, baseDate); if (isNaN(comparison)) { throw new RangeError('Invalid time value'); } - const localizeOptions = assign(cloneObject(options), { + const localizeOptions = Object.assign({}, options, { addSuffix: options?.addSuffix, comparison: comparison as -1 | 0 | 1, }); @@ -122,11 +122,11 @@ export default function formatDistance( let dateLeft; let dateRight; if (comparison > 0) { - dateLeft = toDate(dirtyBaseDate); - dateRight = toDate(dirtyDate); + dateLeft = toDate(baseDate); + dateRight = toDate(date); } else { - dateLeft = toDate(dirtyDate); - dateRight = toDate(dirtyBaseDate); + dateLeft = toDate(date); + dateRight = toDate(baseDate); } const seconds = differenceInSeconds(dateRight, dateLeft); @@ -197,7 +197,7 @@ export default function formatDistance( // 1 year up to max Date } else { const monthsSinceStartOfYear = months % 12; - const years = Math.floor(months / 12); + const years = Math.trunc(months / 12); // N years up to 1 years 3 months if (monthsSinceStartOfYear < 3) { diff --git a/src/date-fns/formatDistanceStrict/index.ts b/src/date-fns/formatDistanceStrict/index.ts index 4713eb9..ff2b386 100644 --- a/src/date-fns/formatDistanceStrict/index.ts +++ b/src/date-fns/formatDistanceStrict/index.ts @@ -1,23 +1,27 @@ -import compareAsc from '../compareAsc/index'; -import { millisecondsInMinute, minutesInDay, minutesInMonth, minutesInYear } from '../constants/index'; -import toDate from '../toDate/index'; -import type { LocaleOptions, FormatDistanceStrictUnit } from '../types'; -import assign from '../_lib/assign/index'; -import cloneObject from '../_lib/cloneObject/index'; -import defaultLocale from '../_lib/defaultLocale/index'; +import { defaultLocale } from '../_lib/defaultLocale/index'; import { getDefaultOptions } from '../_lib/defaultOptions/index'; -import getTimezoneOffsetInMilliseconds from '../_lib/getTimezoneOffsetInMilliseconds/index'; -import { getRoundingMethod } from '../_lib/roundingMethods/index'; +import { getRoundingMethod } from '../_lib/getRoundingMethod/index'; +import { getTimezoneOffsetInMilliseconds } from '../_lib/getTimezoneOffsetInMilliseconds/index'; +import { compareAsc } from '../compareAsc/index'; +import { millisecondsInMinute, minutesInDay, minutesInMonth, minutesInYear } from '../constants/index'; +import { toDate } from '../toDate/index'; +import type { LocalizedOptions, RoundingOptions } from '../types'; /** * The {@link formatDistanceStrict} function options. */ -export interface FormatDistanceStrictOptions extends LocaleOptions { +export interface FormatDistanceStrictOptions extends LocalizedOptions<'formatDistance'>, RoundingOptions { + /** Add "X ago"/"in X" in the locale language */ addSuffix?: boolean; + /** If specified, will force the unit */ unit?: FormatDistanceStrictUnit; - roundingMethod?: 'floor' | 'ceil' | 'round'; } +/** + * The unit used to format the distance in {@link formatDistanceStrict}. + */ +export type FormatDistanceStrictUnit = 'second' | 'minute' | 'hour' | 'day' | 'month' | 'year'; + /** * @name formatDistanceStrict * @category Common Helpers @@ -37,14 +41,18 @@ export interface FormatDistanceStrictOptions extends LocaleOptions { * | 1 ... 11 months | [1..11] months | * | 1 ... N years | [1..N] years | * - * @param date - the date - * @param baseDate - the date to compare with - * @param options - an object with options. - * @returns the distance in words - * @throws {RangeError} `date` must not be Invalid Date - * @throws {RangeError} `baseDate` must not be Invalid Date - * @throws {RangeError} `options.unit` must be 'second', 'minute', 'hour', 'day', 'month' or 'year' - * @throws {RangeError} `options.locale` must contain `formatDistance` property + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The date + * @param baseDate - The date to compare with + * @param options - An object with options + * + * @returns The distance in words + * + * @throws `date` must not be Invalid Date + * @throws `baseDate` must not be Invalid Date + * @throws `options.unit` must be 'second', 'minute', 'hour', 'day', 'month' or 'year' + * @throws `options.locale` must contain `formatDistance` property * * @example * // What is the distance between 2 July 2014 and 1 January 2015? @@ -94,25 +102,21 @@ export interface FormatDistanceStrictOptions extends LocaleOptions { * //=> '1 jaro' */ -export default function formatDistanceStrict( - dirtyDate: DateType | number, - dirtyBaseDate: DateType | number, +export function formatDistanceStrict( + date: DateType | number | string, + baseDate: DateType | number | string, options?: FormatDistanceStrictOptions, ): string { const defaultOptions = getDefaultOptions(); const locale = options?.locale ?? defaultOptions.locale ?? defaultLocale; - if (!locale.formatDistance) { - throw new RangeError('locale must contain localize.formatDistance property'); - } - - const comparison = compareAsc(dirtyDate, dirtyBaseDate); + const comparison = compareAsc(date, baseDate); if (isNaN(comparison)) { throw new RangeError('Invalid time value'); } - const localizeOptions = assign(cloneObject(options), { + const localizeOptions = Object.assign({}, options, { addSuffix: options?.addSuffix, comparison: comparison as -1 | 0 | 1, }); @@ -120,11 +124,11 @@ export default function formatDistanceStrict( let dateLeft; let dateRight; if (comparison > 0) { - dateLeft = toDate(dirtyBaseDate); - dateRight = toDate(dirtyDate); + dateLeft = toDate(baseDate); + dateRight = toDate(date); } else { - dateLeft = toDate(dirtyDate); - dateRight = toDate(dirtyBaseDate); + dateLeft = toDate(date); + dateRight = toDate(baseDate); } const roundingMethod = getRoundingMethod(options?.roundingMethod ?? 'round'); diff --git a/src/date-fns/formatDistanceToNow/index.ts b/src/date-fns/formatDistanceToNow/index.ts index 92f165d..f370e1c 100644 --- a/src/date-fns/formatDistanceToNow/index.ts +++ b/src/date-fns/formatDistanceToNow/index.ts @@ -1,4 +1,6 @@ -import distanceInWords, { type FormatDistanceOptions } from '../formatDistance/index'; +import { constructNow } from '../constructNow/index'; +import type { FormatDistanceOptions } from '../formatDistance/index'; +import { formatDistance } from '../formatDistance/index'; /** * The {@link formatDistanceToNow} function options. @@ -43,14 +45,15 @@ export interface FormatDistanceToNowOptions extends FormatDistanceOptions {} * | 40 secs ... 60 secs | less than a minute | * | 60 secs ... 90 secs | 1 minute | * - * > ⚠️ Please note that this function is not present in the FP submodule as - * > it uses `Date.now()` internally hence impure and can't be safely curried. + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). * - * @param date - the given date - * @param options - the object with options - * @returns the distance in words - * @throws {RangeError} `date` must not be Invalid Date - * @throws {RangeError} `options.locale` must contain `formatDistance` property + * @param date - The given date + * @param options - The object with options + * + * @returns The distance in words + * + * @throws `date` must not be Invalid Date + * @throws `options.locale` must contain `formatDistance` property * * @example * // If today is 1 January 2015, what is the distance to 2 July 2014? @@ -87,9 +90,9 @@ export interface FormatDistanceToNowOptions extends FormatDistanceOptions {} * ) * //=> 'pli ol 1 jaro' */ -export default function formatDistanceToNow( - dirtyDate: DateType | number, +export function formatDistanceToNow( + date: DateType | number | string, options?: FormatDistanceToNowOptions, ): string { - return distanceInWords(dirtyDate, Date.now(), options); + return formatDistance(date, constructNow(date), options); } diff --git a/src/date-fns/formatDistanceToNowStrict/index.ts b/src/date-fns/formatDistanceToNowStrict/index.ts index 6eaf195..5c47ac5 100644 --- a/src/date-fns/formatDistanceToNowStrict/index.ts +++ b/src/date-fns/formatDistanceToNowStrict/index.ts @@ -1,4 +1,6 @@ -import formatDistanceStrict, { type FormatDistanceStrictOptions } from '../formatDistanceStrict/index'; +import type { FormatDistanceStrictOptions } from '../formatDistanceStrict/index'; +import { formatDistanceStrict } from '../formatDistanceStrict/index'; +import { constructNow } from '../constructNow/index'; /** * The {@link formatDistanceToNowStrict} function options. @@ -25,11 +27,15 @@ export interface FormatDistanceToNowStrictOptions extends FormatDistanceStrictOp * | 1 ... 11 months | [1..11] months | * | 1 ... N years | [1..N] years | * - * @param date - the given date - * @param options - an object with options. - * @returns the distance in words - * @throws {RangeError} `date` must not be Invalid Date - * @throws {RangeError} `options.locale` must contain `formatDistance` property + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The given date + * @param options - An object with options. + * + * @returns The distance in words + * + * @throws `date` must not be Invalid Date + * @throws `options.locale` must contain `formatDistance` property * * @example * // If today is 1 January 2015, what is the distance to 2 July 2014? @@ -74,9 +80,9 @@ export interface FormatDistanceToNowStrictOptions extends FormatDistanceStrictOp * ) * //=> '1 jaro' */ -export default function formatDistanceToNowStrict( - dirtyDate: DateType | number, +export function formatDistanceToNowStrict( + date: DateType | number | string, options?: FormatDistanceToNowStrictOptions, ): string { - return formatDistanceStrict(dirtyDate, Date.now(), options); + return formatDistanceStrict(date, constructNow(date), options); } diff --git a/src/date-fns/formatDuration/index.ts b/src/date-fns/formatDuration/index.ts index 531ea2e..c819bf5 100644 --- a/src/date-fns/formatDuration/index.ts +++ b/src/date-fns/formatDuration/index.ts @@ -1,14 +1,17 @@ import type { FormatDistanceToken } from '../locale/types'; -import type { Duration, DurationUnit, LocaleOptions } from '../types'; -import defaultLocale from '../_lib/defaultLocale/index'; +import type { Duration, DurationUnit, LocalizedOptions } from '../types'; +import { defaultLocale } from '../_lib/defaultLocale/index'; import { getDefaultOptions } from '../_lib/defaultOptions/index'; /** * The {@link formatDuration} function options. */ -export interface FormatDurationOptions extends LocaleOptions { +export interface FormatDurationOptions extends LocalizedOptions<'formatDistance'> { + /** The array of units to format */ format?: DurationUnit[]; + /** Should be zeros be included in the output? */ zero?: boolean; + /** The delimiter string to use */ delimiter?: string; } @@ -22,9 +25,12 @@ const defaultFormat: DurationUnit[] = ['years', 'months', 'weeks', 'days', 'hour * @description * Return human-readable duration string i.e. "9 months 2 days" * - * @param duration - the duration to format - * @param options - an object with options. - * @returns the formatted date string + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param duration - The duration to format + * @param options - An object with options. + * + * @returns The formatted date string * * @example * // Format full duration @@ -71,7 +77,7 @@ const defaultFormat: DurationUnit[] = ['years', 'months', 'weeks', 'days', 'hour * formatDuration({ years: 2, months: 9, weeks: 3 }, { delimiter: ', ' }) * //=> '2 years, 9 months, 3 weeks' */ -export default function formatDuration(duration: Duration, options?: FormatDurationOptions): string { +export function formatDuration(duration: Duration, options?: FormatDurationOptions): string { const defaultOptions = getDefaultOptions(); const locale = options?.locale ?? defaultOptions.locale ?? defaultLocale; const format = options?.format ?? defaultFormat; diff --git a/src/date-fns/formatISO/index.ts b/src/date-fns/formatISO/index.ts index 03c108d..a5ffaf5 100644 --- a/src/date-fns/formatISO/index.ts +++ b/src/date-fns/formatISO/index.ts @@ -1,11 +1,11 @@ -import toDate from '../toDate/index'; -import type { FormatOptions, RepresentationOptions } from '../types'; -import addLeadingZeros from '../_lib/addLeadingZeros/index'; +import { toDate } from '../toDate/index'; +import type { ISOFormatOptions } from '../types'; +import { addLeadingZeros } from '../_lib/addLeadingZeros/index'; /** * The {@link formatISO} function options. */ -export interface FormatISOOptions extends FormatOptions, RepresentationOptions {} +export interface FormatISOOptions extends ISOFormatOptions {} /** * @name formatISO @@ -15,10 +15,14 @@ export interface FormatISOOptions extends FormatOptions, RepresentationOptions { * @description * Return the formatted date string in ISO 8601 format. Options may be passed to control the parts and notations of the date. * - * @param date - the original date - * @param options - an object with options. - * @returns the formatted date string (in local time zone) - * @throws {RangeError} `date` must not be Invalid Date + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The original date + * @param options - An object with options. + * + * @returns The formatted date string (in loca.l time zone) + * + * @throws `date` must not be Invalid Date * * @example * // Represent 18 September 2019 in ISO 8601 format (local time zone is UTC): @@ -40,10 +44,10 @@ export interface FormatISOOptions extends FormatOptions, RepresentationOptions { * const result = formatISO(new Date(2019, 8, 18, 19, 0, 52), { representation: 'time' }) * //=> '19:00:52Z' */ -export default function formatISO(date: DateType | number, options?: FormatISOOptions): string { - const originalDate = toDate(date); +export function formatISO(date: DateType | number | string, options?: FormatISOOptions): string { + const _date = toDate(date); - if (isNaN(originalDate.getTime())) { + if (isNaN(_date.getTime())) { throw new RangeError('Invalid time value'); } @@ -58,9 +62,9 @@ export default function formatISO(date: DateType | number // Representation is either 'date' or 'complete' if (representation !== 'time') { - const day = addLeadingZeros(originalDate.getDate(), 2); - const month = addLeadingZeros(originalDate.getMonth() + 1, 2); - const year = addLeadingZeros(originalDate.getFullYear(), 4); + const day = addLeadingZeros(_date.getDate(), 2); + const month = addLeadingZeros(_date.getMonth() + 1, 2); + const year = addLeadingZeros(_date.getFullYear(), 4); // yyyyMMdd or yyyy-MM-dd. result = `${year}${dateDelimiter}${month}${dateDelimiter}${day}`; @@ -69,11 +73,11 @@ export default function formatISO(date: DateType | number // Representation is either 'time' or 'complete' if (representation !== 'date') { // Add the timezone. - const offset = originalDate.getTimezoneOffset(); + const offset = _date.getTimezoneOffset(); if (offset !== 0) { const absoluteOffset = Math.abs(offset); - const hourOffset = addLeadingZeros(Math.floor(absoluteOffset / 60), 2); + const hourOffset = addLeadingZeros(Math.trunc(absoluteOffset / 60), 2); const minuteOffset = addLeadingZeros(absoluteOffset % 60, 2); // If less than 0, the sign is +, because it is ahead of time. const sign = offset < 0 ? '+' : '-'; @@ -83,9 +87,9 @@ export default function formatISO(date: DateType | number tzOffset = 'Z'; } - const hour = addLeadingZeros(originalDate.getHours(), 2); - const minute = addLeadingZeros(originalDate.getMinutes(), 2); - const second = addLeadingZeros(originalDate.getSeconds(), 2); + const hour = addLeadingZeros(_date.getHours(), 2); + const minute = addLeadingZeros(_date.getMinutes(), 2); + const second = addLeadingZeros(_date.getSeconds(), 2); // If there's also date, separate it with time with 'T' const separator = result === '' ? '' : 'T'; diff --git a/src/date-fns/formatISO9075/index.ts b/src/date-fns/formatISO9075/index.ts index adc05d6..1e20657 100644 --- a/src/date-fns/formatISO9075/index.ts +++ b/src/date-fns/formatISO9075/index.ts @@ -1,12 +1,12 @@ -import isValid from '../isValid/index'; -import toDate from '../toDate/index'; -import type { FormatOptions, RepresentationOptions } from '../types'; -import addLeadingZeros from '../_lib/addLeadingZeros/index'; +import { isValid } from '../isValid/index'; +import { toDate } from '../toDate/index'; +import type { ISOFormatOptions } from '../types'; +import { addLeadingZeros } from '../_lib/addLeadingZeros/index'; /** * The {@link formatISO9075} function options. */ -export interface FormatISO9075Options extends FormatOptions, RepresentationOptions {} +export interface FormatISO9075Options extends ISOFormatOptions {} /** * @name formatISO9075 @@ -16,10 +16,14 @@ export interface FormatISO9075Options extends FormatOptions, RepresentationOptio * @description * Return the formatted date string in ISO 9075 format. Options may be passed to control the parts and notations of the date. * - * @param date - the original date - * @param options - an object with options. - * @returns the formatted date string - * @throws {RangeError} `date` must not be Invalid Date + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The original date + * @param options - An object with options. + * + * @returns The formatted date string + * + * @throws `date` must not be Invalid Date * * @example * // Represent 18 September 2019 in ISO 9075 format: @@ -41,13 +45,13 @@ export interface FormatISO9075Options extends FormatOptions, RepresentationOptio * const result = formatISO9075(new Date(2019, 8, 18, 19, 0, 52), { representation: 'time' }) * //=> '19:00:52' */ -export default function formatISO9075( - dirtyDate: DateType | number, +export function formatISO9075( + date: DateType | number | string, options?: FormatISO9075Options, ): string { - const originalDate = toDate(dirtyDate); + const _date = toDate(date); - if (!isValid(originalDate)) { + if (!isValid(_date)) { throw new RangeError('Invalid time value'); } @@ -61,9 +65,9 @@ export default function formatISO9075( // Representation is either 'date' or 'complete' if (representation !== 'time') { - const day = addLeadingZeros(originalDate.getDate(), 2); - const month = addLeadingZeros(originalDate.getMonth() + 1, 2); - const year = addLeadingZeros(originalDate.getFullYear(), 4); + const day = addLeadingZeros(_date.getDate(), 2); + const month = addLeadingZeros(_date.getMonth() + 1, 2); + const year = addLeadingZeros(_date.getFullYear(), 4); // yyyyMMdd or yyyy-MM-dd. result = `${year}${dateDelimiter}${month}${dateDelimiter}${day}`; @@ -71,9 +75,9 @@ export default function formatISO9075( // Representation is either 'time' or 'complete' if (representation !== 'date') { - const hour = addLeadingZeros(originalDate.getHours(), 2); - const minute = addLeadingZeros(originalDate.getMinutes(), 2); - const second = addLeadingZeros(originalDate.getSeconds(), 2); + const hour = addLeadingZeros(_date.getHours(), 2); + const minute = addLeadingZeros(_date.getMinutes(), 2); + const second = addLeadingZeros(_date.getSeconds(), 2); // If there's also date, separate it with time with a space const separator = result === '' ? '' : ' '; diff --git a/src/date-fns/formatISODuration/index.ts b/src/date-fns/formatISODuration/index.ts index 067316a..59c7104 100644 --- a/src/date-fns/formatISODuration/index.ts +++ b/src/date-fns/formatISODuration/index.ts @@ -6,9 +6,9 @@ import type { Duration } from '../types'; * @summary Format a duration object according as ISO 8601 duration string * * @description - * Format a duration object according to the ISO 8601 duration standard (https://www.digi.com/resources/documentation/digidocs/90001437-13/reference/r_iso_8601_duration_format.htm) + * Format a duration object according to the ISO 8601 duration standard (https://www.digi.com/resources/documentation/digidocs//90001488-13/reference/r_iso_8601_duration_format.htm) * - * @param duration - the duration to format + * @param duration - The duration to format * * @returns The ISO 8601 duration string * @@ -24,7 +24,7 @@ import type { Duration } from '../types'; * }) * //=> 'P39Y2M20DT0H0M0S' */ -export default function formatISODuration(duration: Duration): string { +export function formatISODuration(duration: Duration): string { const { years = 0, months = 0, days = 0, hours = 0, minutes = 0, seconds = 0 } = duration; return `P${years}Y${months}M${days}DT${hours}H${minutes}M${seconds}S`; diff --git a/src/date-fns/formatRFC3339/index.ts b/src/date-fns/formatRFC3339/index.ts index d129b91..625aeed 100644 --- a/src/date-fns/formatRFC3339/index.ts +++ b/src/date-fns/formatRFC3339/index.ts @@ -1,11 +1,12 @@ -import isValid from '../isValid/index'; -import toDate from '../toDate/index'; -import addLeadingZeros from '../_lib/addLeadingZeros/index'; +import { isValid } from '../isValid/index'; +import { toDate } from '../toDate/index'; +import { addLeadingZeros } from '../_lib/addLeadingZeros/index'; /** * The {@link formatRFC3339} function options. */ export interface FormatRFC3339Options { + /** The number of digits after the decimal point after seconds, defaults to 0 */ fractionDigits?: 0 | 1 | 2 | 3; } @@ -17,55 +18,56 @@ export interface FormatRFC3339Options { * @description * Return the formatted date string in RFC 3339 format. Options may be passed to control the parts and notations of the date. * - * @param date - the original date - * @param options - an object with options. - * @returns the formatted date string - * @throws {RangeError} `date` must not be Invalid Date + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The original date + * @param options - An object with options. + * + * @returns The formatted date string + * + * @throws `date` must not be Invalid Date * * @example * // Represent 18 September 2019 in RFC 3339 format: - * const result = formatRFC3339(new Date(2019, 8, 18, 19, 0, 52)) + * formatRFC3339(new Date(2019, 8, 18, 19, 0, 52)) * //=> '2019-09-18T19:00:52Z' * * @example - * // Represent 18 September 2019 in RFC 3339 format, 2 digits of second fraction: - * const result = formatRFC3339(new Date(2019, 8, 18, 19, 0, 52, 234), { fractionDigits: 2 }) - * //=> '2019-09-18T19:00:52.23Z' - * - * @example * // Represent 18 September 2019 in RFC 3339 format, 3 digits of second fraction - * const result = formatRFC3339(new Date(2019, 8, 18, 19, 0, 52, 234), { fractionDigits: 3 }) + * formatRFC3339(new Date(2019, 8, 18, 19, 0, 52, 234), { + * fractionDigits: 3 + * }) * //=> '2019-09-18T19:00:52.234Z' */ -export default function formatRFC3339( - dirtyDate: DateType | number, +export function formatRFC3339( + date: DateType | number | string, options?: FormatRFC3339Options, ): string { - const originalDate = toDate(dirtyDate); + const _date = toDate(date); - if (!isValid(originalDate)) { + if (!isValid(_date)) { throw new RangeError('Invalid time value'); } const fractionDigits = options?.fractionDigits ?? 0; - const day = addLeadingZeros(originalDate.getDate(), 2); - const month = addLeadingZeros(originalDate.getMonth() + 1, 2); - const year = originalDate.getFullYear(); + const day = addLeadingZeros(_date.getDate(), 2); + const month = addLeadingZeros(_date.getMonth() + 1, 2); + const year = _date.getFullYear(); - const hour = addLeadingZeros(originalDate.getHours(), 2); - const minute = addLeadingZeros(originalDate.getMinutes(), 2); - const second = addLeadingZeros(originalDate.getSeconds(), 2); + const hour = addLeadingZeros(_date.getHours(), 2); + const minute = addLeadingZeros(_date.getMinutes(), 2); + const second = addLeadingZeros(_date.getSeconds(), 2); let fractionalSecond = ''; if (fractionDigits > 0) { - const milliseconds = originalDate.getMilliseconds(); - const fractionalSeconds = Math.floor(milliseconds * Math.pow(10, fractionDigits - 3)); + const milliseconds = _date.getMilliseconds(); + const fractionalSeconds = Math.trunc(milliseconds * Math.pow(10, fractionDigits - 3)); fractionalSecond = '.' + addLeadingZeros(fractionalSeconds, fractionDigits); } let offset = ''; - const tzOffset = originalDate.getTimezoneOffset(); + const tzOffset = _date.getTimezoneOffset(); if (tzOffset !== 0) { const absoluteOffset = Math.abs(tzOffset); diff --git a/src/date-fns/formatRFC7231/index.ts b/src/date-fns/formatRFC7231/index.ts index 4aded61..3f85008 100644 --- a/src/date-fns/formatRFC7231/index.ts +++ b/src/date-fns/formatRFC7231/index.ts @@ -1,6 +1,6 @@ -import isValid from '../isValid/index'; -import toDate from '../toDate/index'; -import addLeadingZeros from '../_lib/addLeadingZeros/index'; +import { isValid } from '../isValid/index'; +import { toDate } from '../toDate/index'; +import { addLeadingZeros } from '../_lib/addLeadingZeros/index'; const days = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']; @@ -15,30 +15,34 @@ const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', ' * Return the formatted date string in RFC 7231 format. * The result will always be in UTC timezone. * - * @param date - the original date - * @returns the formatted date string - * @throws {RangeError} `date` must not be Invalid Date + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The original date + * + * @returns The formatted date string + * + * @throws `date` must not be Invalid Date * * @example * // Represent 18 September 2019 in RFC 7231 format: * const result = formatRFC7231(new Date(2019, 8, 18, 19, 0, 52)) * //=> 'Wed, 18 Sep 2019 19:00:52 GMT' */ -export default function formatRFC7231(dirtyDate: DateType | number): string { - const originalDate = toDate(dirtyDate); +export function formatRFC7231(date: DateType | number | string): string { + const _date = toDate(date); - if (!isValid(originalDate)) { + if (!isValid(_date)) { throw new RangeError('Invalid time value'); } - const dayName = days[originalDate.getUTCDay()]; - const dayOfMonth = addLeadingZeros(originalDate.getUTCDate(), 2); - const monthName = months[originalDate.getUTCMonth()]; - const year = originalDate.getUTCFullYear(); + const dayName = days[_date.getUTCDay()]; + const dayOfMonth = addLeadingZeros(_date.getUTCDate(), 2); + const monthName = months[_date.getUTCMonth()]; + const year = _date.getUTCFullYear(); - const hour = addLeadingZeros(originalDate.getUTCHours(), 2); - const minute = addLeadingZeros(originalDate.getUTCMinutes(), 2); - const second = addLeadingZeros(originalDate.getUTCSeconds(), 2); + const hour = addLeadingZeros(_date.getUTCHours(), 2); + const minute = addLeadingZeros(_date.getUTCMinutes(), 2); + const second = addLeadingZeros(_date.getUTCSeconds(), 2); // Result variables. return `${dayName}, ${dayOfMonth} ${monthName} ${year} ${hour}:${minute}:${second} GMT`; diff --git a/src/date-fns/formatRelative/index.ts b/src/date-fns/formatRelative/index.ts index e69fa26..ab1592d 100644 --- a/src/date-fns/formatRelative/index.ts +++ b/src/date-fns/formatRelative/index.ts @@ -1,15 +1,17 @@ -import differenceInCalendarDays from '../differenceInCalendarDays/index'; -import format from '../format/index'; +import { differenceInCalendarDays } from '../differenceInCalendarDays/index'; +import { format } from '../format/index'; import type { FormatRelativeToken } from '../locale/types'; -import toDate from '../toDate/index'; -import type { LocaleOptions, WeekStartOptions } from '../types'; -import defaultLocale from '../_lib/defaultLocale/index'; +import { toDate } from '../toDate/index'; +import type { LocalizedOptions, WeekOptions } from '../types'; +import { defaultLocale } from '../_lib/defaultLocale/index'; import { getDefaultOptions } from '../_lib/defaultOptions/index'; /** * The {@link formatRelative} function options. */ -export interface FormatRelativeOptions extends LocaleOptions, WeekStartOptions {} +export interface FormatRelativeOptions + extends LocalizedOptions<'options' | 'localize' | 'formatLong' | 'formatRelative'>, + WeekOptions {} /** * @name formatRelative @@ -28,28 +30,32 @@ export interface FormatRelativeOptions extends LocaleOptions, WeekStartOptions { * | Next 6 days | Sunday at 04:30 AM | * | Other | 12/31/2017 | * - * @param date - the date to format - * @param baseDate - the date to compare with - * @param options - an object with options. - * @returns the date in words - * @throws {RangeError} `date` must not be Invalid Date - * @throws {RangeError} `baseDate` must not be Invalid Date - * @throws {RangeError} `options.locale` must contain `localize` property - * @throws {RangeError} `options.locale` must contain `formatLong` property - * @throws {RangeError} `options.locale` must contain `formatRelative` property + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The date to format + * @param baseDate - The date to compare with + * @param options - An object with options + * + * @returns The date in words + * + * @throws `date` must not be Invalid Date + * @throws `baseDate` must not be Invalid Date + * @throws `options.locale` must contain `localize` property + * @throws `options.locale` must contain `formatLong` property + * @throws `options.locale` must contain `formatRelative` property * * @example * // Represent the date of 6 days ago in words relative to the given base date. In this example, today is Wednesday - * const result = formatRelative(addDays(new Date(), -6), new Date()) + * const result = formatRelative(subDays(new Date(), 6), new Date()) * //=> "last Thursday at 12:45 AM" */ -export default function formatRelative( - dirtyDate: DateType | number, - dirtyBaseDate: DateType | number, +export function formatRelative( + date: DateType | number | string, + baseDate: DateType | number | string, options?: FormatRelativeOptions, ): string { - const date = toDate(dirtyDate); - const baseDate = toDate(dirtyBaseDate); + const _date = toDate(date); + const _baseDate = toDate(baseDate); const defaultOptions = getDefaultOptions(); const locale = options?.locale ?? defaultOptions.locale ?? defaultLocale; @@ -60,19 +66,7 @@ export default function formatRelative( defaultOptions.locale?.options?.weekStartsOn ?? 0; - if (!locale.localize) { - throw new RangeError('locale must contain localize property'); - } - - if (!locale.formatLong) { - throw new RangeError('locale must contain formatLong property'); - } - - if (!locale.formatRelative) { - throw new RangeError('locale must contain formatRelative property'); - } - - const diff = differenceInCalendarDays(date, baseDate); + const diff = differenceInCalendarDays(_date, _baseDate); if (isNaN(diff)) { throw new RangeError('Invalid time value'); @@ -95,9 +89,9 @@ export default function formatRelative( token = 'other'; } - const formatStr = locale.formatRelative(token, date, baseDate, { + const formatStr = locale.formatRelative(token, _date, _baseDate, { locale, weekStartsOn, }); - return format(date, formatStr, { locale, weekStartsOn }); + return format(_date, formatStr, { locale, weekStartsOn }); } diff --git a/src/date-fns/fp/_lib/convertToFP/index.ts b/src/date-fns/fp/_lib/convertToFP/index.ts index e3a84fd..5f704a6 100644 --- a/src/date-fns/fp/_lib/convertToFP/index.ts +++ b/src/date-fns/fp/_lib/convertToFP/index.ts @@ -1,9 +1,25 @@ -export default function convertToFP(fn: Function, arity: number, a: any[] = []) { - if (a.length >= arity) { - return fn.apply(null, a.slice(0, arity).reverse()); - } +import type { FPArity, FPFn, FPFnInput } from '../../types'; - return function (...args: any[]) { - return convertToFP(fn, arity, a.concat(args)); - }; +/** + * Converts a function to a curried function that accepts arguments in reverse + * order. + * + * @param fn - The function to convert to FP + * @param arity - The arity of the function + * @param curriedArgs - The curried arguments + * + * @returns FP version of the function + * + * @private + */ +export function convertToFP( + fn: Fn, + arity: Arity, + curriedArgs: unknown[] = [], +): FPFn { + return ( + curriedArgs.length >= arity + ? fn(...curriedArgs.slice(0, arity).reverse()) + : (...args: unknown[]) => convertToFP(fn, arity, curriedArgs.concat(args)) + ) as FPFn; } diff --git a/src/date-fns/fp/add/index.ts b/src/date-fns/fp/add/index.ts index 6986de0..ad341de 100644 --- a/src/date-fns/fp/add/index.ts +++ b/src/date-fns/fp/add/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../add/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { add as fn } from '../../add/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const add = convertToFP(fn, 2); diff --git a/src/date-fns/fp/addBusinessDays/index.ts b/src/date-fns/fp/addBusinessDays/index.ts index a54b134..5d4a925 100644 --- a/src/date-fns/fp/addBusinessDays/index.ts +++ b/src/date-fns/fp/addBusinessDays/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../addBusinessDays/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { addBusinessDays as fn } from '../../addBusinessDays/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const addBusinessDays = convertToFP(fn, 2); diff --git a/src/date-fns/fp/addDays/index.ts b/src/date-fns/fp/addDays/index.ts index f7ebb0b..434867f 100644 --- a/src/date-fns/fp/addDays/index.ts +++ b/src/date-fns/fp/addDays/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../addDays/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { addDays as fn } from '../../addDays/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const addDays = convertToFP(fn, 2); diff --git a/src/date-fns/fp/addHours/index.ts b/src/date-fns/fp/addHours/index.ts index fedb3d3..537bf92 100644 --- a/src/date-fns/fp/addHours/index.ts +++ b/src/date-fns/fp/addHours/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../addHours/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { addHours as fn } from '../../addHours/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const addHours = convertToFP(fn, 2); diff --git a/src/date-fns/fp/addISOWeekYears/index.ts b/src/date-fns/fp/addISOWeekYears/index.ts index c55afd7..bf1a3f1 100644 --- a/src/date-fns/fp/addISOWeekYears/index.ts +++ b/src/date-fns/fp/addISOWeekYears/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../addISOWeekYears/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { addISOWeekYears as fn } from '../../addISOWeekYears/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const addISOWeekYears = convertToFP(fn, 2); diff --git a/src/date-fns/fp/addMilliseconds/index.ts b/src/date-fns/fp/addMilliseconds/index.ts index 3ee51b4..0a6ad7b 100644 --- a/src/date-fns/fp/addMilliseconds/index.ts +++ b/src/date-fns/fp/addMilliseconds/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../addMilliseconds/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { addMilliseconds as fn } from '../../addMilliseconds/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const addMilliseconds = convertToFP(fn, 2); diff --git a/src/date-fns/fp/addMinutes/index.ts b/src/date-fns/fp/addMinutes/index.ts index 1e65ee3..e8f2d7f 100644 --- a/src/date-fns/fp/addMinutes/index.ts +++ b/src/date-fns/fp/addMinutes/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../addMinutes/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { addMinutes as fn } from '../../addMinutes/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const addMinutes = convertToFP(fn, 2); diff --git a/src/date-fns/fp/addMonths/index.ts b/src/date-fns/fp/addMonths/index.ts index 9cb0828..85ff8ed 100644 --- a/src/date-fns/fp/addMonths/index.ts +++ b/src/date-fns/fp/addMonths/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../addMonths/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { addMonths as fn } from '../../addMonths/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const addMonths = convertToFP(fn, 2); diff --git a/src/date-fns/fp/addQuarters/index.ts b/src/date-fns/fp/addQuarters/index.ts index 8495c3b..9bc2a9e 100644 --- a/src/date-fns/fp/addQuarters/index.ts +++ b/src/date-fns/fp/addQuarters/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../addQuarters/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { addQuarters as fn } from '../../addQuarters/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const addQuarters = convertToFP(fn, 2); diff --git a/src/date-fns/fp/addSeconds/index.ts b/src/date-fns/fp/addSeconds/index.ts index 21112d7..1caef08 100644 --- a/src/date-fns/fp/addSeconds/index.ts +++ b/src/date-fns/fp/addSeconds/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../addSeconds/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { addSeconds as fn } from '../../addSeconds/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const addSeconds = convertToFP(fn, 2); diff --git a/src/date-fns/fp/addWeeks/index.ts b/src/date-fns/fp/addWeeks/index.ts index 770868f..a37afc8 100644 --- a/src/date-fns/fp/addWeeks/index.ts +++ b/src/date-fns/fp/addWeeks/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../addWeeks/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { addWeeks as fn } from '../../addWeeks/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const addWeeks = convertToFP(fn, 2); diff --git a/src/date-fns/fp/addYears/index.ts b/src/date-fns/fp/addYears/index.ts index 61b2e04..d774629 100644 --- a/src/date-fns/fp/addYears/index.ts +++ b/src/date-fns/fp/addYears/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../addYears/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { addYears as fn } from '../../addYears/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const addYears = convertToFP(fn, 2); diff --git a/src/date-fns/fp/areIntervalsOverlapping/index.ts b/src/date-fns/fp/areIntervalsOverlapping/index.ts index 8ffbfa7..c772694 100644 --- a/src/date-fns/fp/areIntervalsOverlapping/index.ts +++ b/src/date-fns/fp/areIntervalsOverlapping/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../areIntervalsOverlapping/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { areIntervalsOverlapping as fn } from '../../areIntervalsOverlapping/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const areIntervalsOverlapping = convertToFP(fn, 2); diff --git a/src/date-fns/fp/areIntervalsOverlappingWithOptions/index.ts b/src/date-fns/fp/areIntervalsOverlappingWithOptions/index.ts index ac1b0e9..327b117 100644 --- a/src/date-fns/fp/areIntervalsOverlappingWithOptions/index.ts +++ b/src/date-fns/fp/areIntervalsOverlappingWithOptions/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../areIntervalsOverlapping/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { areIntervalsOverlapping as fn } from '../../areIntervalsOverlapping/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 3); +export const areIntervalsOverlappingWithOptions = convertToFP(fn, 3); diff --git a/src/date-fns/fp/clamp/index.ts b/src/date-fns/fp/clamp/index.ts index 04d8152..050161d 100644 --- a/src/date-fns/fp/clamp/index.ts +++ b/src/date-fns/fp/clamp/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../clamp/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { clamp as fn } from '../../clamp/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const clamp = convertToFP(fn, 2); diff --git a/src/date-fns/fp/closestIndexTo/index.ts b/src/date-fns/fp/closestIndexTo/index.ts index 58e687f..a35ebc9 100644 --- a/src/date-fns/fp/closestIndexTo/index.ts +++ b/src/date-fns/fp/closestIndexTo/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../closestIndexTo/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { closestIndexTo as fn } from '../../closestIndexTo/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const closestIndexTo = convertToFP(fn, 2); diff --git a/src/date-fns/fp/closestTo/index.ts b/src/date-fns/fp/closestTo/index.ts index f264af2..5faa95b 100644 --- a/src/date-fns/fp/closestTo/index.ts +++ b/src/date-fns/fp/closestTo/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../closestTo/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { closestTo as fn } from '../../closestTo/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const closestTo = convertToFP(fn, 2); diff --git a/src/date-fns/fp/compareAsc/index.ts b/src/date-fns/fp/compareAsc/index.ts index acfcf88..32d3c9f 100644 --- a/src/date-fns/fp/compareAsc/index.ts +++ b/src/date-fns/fp/compareAsc/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../compareAsc/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { compareAsc as fn } from '../../compareAsc/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const compareAsc = convertToFP(fn, 2); diff --git a/src/date-fns/fp/compareDesc/index.ts b/src/date-fns/fp/compareDesc/index.ts index 2ad8b81..39b6c82 100644 --- a/src/date-fns/fp/compareDesc/index.ts +++ b/src/date-fns/fp/compareDesc/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../compareDesc/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { compareDesc as fn } from '../../compareDesc/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const compareDesc = convertToFP(fn, 2); diff --git a/src/date-fns/fp/constructFrom/index.ts b/src/date-fns/fp/constructFrom/index.ts new file mode 100644 index 0000000..33437b1 --- /dev/null +++ b/src/date-fns/fp/constructFrom/index.ts @@ -0,0 +1,6 @@ +// This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. + +import { constructFrom as fn } from '../../constructFrom/index'; +import { convertToFP } from '../_lib/convertToFP/index'; + +export const constructFrom = convertToFP(fn, 2); diff --git a/src/date-fns/fp/daysToWeeks/index.ts b/src/date-fns/fp/daysToWeeks/index.ts index 2fde821..06f5e83 100644 --- a/src/date-fns/fp/daysToWeeks/index.ts +++ b/src/date-fns/fp/daysToWeeks/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../daysToWeeks/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { daysToWeeks as fn } from '../../daysToWeeks/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const daysToWeeks = convertToFP(fn, 1); diff --git a/src/date-fns/fp/differenceInBusinessDays/index.ts b/src/date-fns/fp/differenceInBusinessDays/index.ts index 3099828..ef6f86b 100644 --- a/src/date-fns/fp/differenceInBusinessDays/index.ts +++ b/src/date-fns/fp/differenceInBusinessDays/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../differenceInBusinessDays/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { differenceInBusinessDays as fn } from '../../differenceInBusinessDays/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const differenceInBusinessDays = convertToFP(fn, 2); diff --git a/src/date-fns/fp/differenceInCalendarDays/index.ts b/src/date-fns/fp/differenceInCalendarDays/index.ts index 0cee66b..c1729f5 100644 --- a/src/date-fns/fp/differenceInCalendarDays/index.ts +++ b/src/date-fns/fp/differenceInCalendarDays/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../differenceInCalendarDays/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { differenceInCalendarDays as fn } from '../../differenceInCalendarDays/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const differenceInCalendarDays = convertToFP(fn, 2); diff --git a/src/date-fns/fp/differenceInCalendarISOWeekYears/index.ts b/src/date-fns/fp/differenceInCalendarISOWeekYears/index.ts index 4713949..154f8a4 100644 --- a/src/date-fns/fp/differenceInCalendarISOWeekYears/index.ts +++ b/src/date-fns/fp/differenceInCalendarISOWeekYears/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../differenceInCalendarISOWeekYears/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { differenceInCalendarISOWeekYears as fn } from '../../differenceInCalendarISOWeekYears/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const differenceInCalendarISOWeekYears = convertToFP(fn, 2); diff --git a/src/date-fns/fp/differenceInCalendarISOWeeks/index.ts b/src/date-fns/fp/differenceInCalendarISOWeeks/index.ts index 83f208f..638c18d 100644 --- a/src/date-fns/fp/differenceInCalendarISOWeeks/index.ts +++ b/src/date-fns/fp/differenceInCalendarISOWeeks/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../differenceInCalendarISOWeeks/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { differenceInCalendarISOWeeks as fn } from '../../differenceInCalendarISOWeeks/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const differenceInCalendarISOWeeks = convertToFP(fn, 2); diff --git a/src/date-fns/fp/differenceInCalendarMonths/index.ts b/src/date-fns/fp/differenceInCalendarMonths/index.ts index 16ca327..68836c1 100644 --- a/src/date-fns/fp/differenceInCalendarMonths/index.ts +++ b/src/date-fns/fp/differenceInCalendarMonths/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../differenceInCalendarMonths/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { differenceInCalendarMonths as fn } from '../../differenceInCalendarMonths/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const differenceInCalendarMonths = convertToFP(fn, 2); diff --git a/src/date-fns/fp/differenceInCalendarQuarters/index.ts b/src/date-fns/fp/differenceInCalendarQuarters/index.ts index a7050d6..569ff56 100644 --- a/src/date-fns/fp/differenceInCalendarQuarters/index.ts +++ b/src/date-fns/fp/differenceInCalendarQuarters/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../differenceInCalendarQuarters/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { differenceInCalendarQuarters as fn } from '../../differenceInCalendarQuarters/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const differenceInCalendarQuarters = convertToFP(fn, 2); diff --git a/src/date-fns/fp/differenceInCalendarWeeks/index.ts b/src/date-fns/fp/differenceInCalendarWeeks/index.ts index a59ed1a..d4eeca6 100644 --- a/src/date-fns/fp/differenceInCalendarWeeks/index.ts +++ b/src/date-fns/fp/differenceInCalendarWeeks/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../differenceInCalendarWeeks/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { differenceInCalendarWeeks as fn } from '../../differenceInCalendarWeeks/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const differenceInCalendarWeeks = convertToFP(fn, 2); diff --git a/src/date-fns/fp/differenceInCalendarWeeksWithOptions/index.ts b/src/date-fns/fp/differenceInCalendarWeeksWithOptions/index.ts index 54847cd..d4c24d3 100644 --- a/src/date-fns/fp/differenceInCalendarWeeksWithOptions/index.ts +++ b/src/date-fns/fp/differenceInCalendarWeeksWithOptions/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../differenceInCalendarWeeks/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { differenceInCalendarWeeks as fn } from '../../differenceInCalendarWeeks/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 3); +export const differenceInCalendarWeeksWithOptions = convertToFP(fn, 3); diff --git a/src/date-fns/fp/differenceInCalendarYears/index.ts b/src/date-fns/fp/differenceInCalendarYears/index.ts index 134f8f8..1f1bec9 100644 --- a/src/date-fns/fp/differenceInCalendarYears/index.ts +++ b/src/date-fns/fp/differenceInCalendarYears/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../differenceInCalendarYears/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { differenceInCalendarYears as fn } from '../../differenceInCalendarYears/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const differenceInCalendarYears = convertToFP(fn, 2); diff --git a/src/date-fns/fp/differenceInDays/index.ts b/src/date-fns/fp/differenceInDays/index.ts index ed4b342..7ff74cb 100644 --- a/src/date-fns/fp/differenceInDays/index.ts +++ b/src/date-fns/fp/differenceInDays/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../differenceInDays/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { differenceInDays as fn } from '../../differenceInDays/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const differenceInDays = convertToFP(fn, 2); diff --git a/src/date-fns/fp/differenceInHours/index.ts b/src/date-fns/fp/differenceInHours/index.ts index 921f2a3..493190e 100644 --- a/src/date-fns/fp/differenceInHours/index.ts +++ b/src/date-fns/fp/differenceInHours/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../differenceInHours/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { differenceInHours as fn } from '../../differenceInHours/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const differenceInHours = convertToFP(fn, 2); diff --git a/src/date-fns/fp/differenceInHoursWithOptions/index.ts b/src/date-fns/fp/differenceInHoursWithOptions/index.ts index 4d8d7af..71157d3 100644 --- a/src/date-fns/fp/differenceInHoursWithOptions/index.ts +++ b/src/date-fns/fp/differenceInHoursWithOptions/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../differenceInHours/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { differenceInHours as fn } from '../../differenceInHours/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 3); +export const differenceInHoursWithOptions = convertToFP(fn, 3); diff --git a/src/date-fns/fp/differenceInISOWeekYears/index.ts b/src/date-fns/fp/differenceInISOWeekYears/index.ts index 0c80d1a..5cafd45 100644 --- a/src/date-fns/fp/differenceInISOWeekYears/index.ts +++ b/src/date-fns/fp/differenceInISOWeekYears/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../differenceInISOWeekYears/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { differenceInISOWeekYears as fn } from '../../differenceInISOWeekYears/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const differenceInISOWeekYears = convertToFP(fn, 2); diff --git a/src/date-fns/fp/differenceInMilliseconds/index.ts b/src/date-fns/fp/differenceInMilliseconds/index.ts index c0a9eaa..c918cc6 100644 --- a/src/date-fns/fp/differenceInMilliseconds/index.ts +++ b/src/date-fns/fp/differenceInMilliseconds/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../differenceInMilliseconds/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { differenceInMilliseconds as fn } from '../../differenceInMilliseconds/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const differenceInMilliseconds = convertToFP(fn, 2); diff --git a/src/date-fns/fp/differenceInMinutes/index.ts b/src/date-fns/fp/differenceInMinutes/index.ts index 7e673bf..95062fb 100644 --- a/src/date-fns/fp/differenceInMinutes/index.ts +++ b/src/date-fns/fp/differenceInMinutes/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../differenceInMinutes/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { differenceInMinutes as fn } from '../../differenceInMinutes/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const differenceInMinutes = convertToFP(fn, 2); diff --git a/src/date-fns/fp/differenceInMinutesWithOptions/index.ts b/src/date-fns/fp/differenceInMinutesWithOptions/index.ts index 67fc5cf..888c91a 100644 --- a/src/date-fns/fp/differenceInMinutesWithOptions/index.ts +++ b/src/date-fns/fp/differenceInMinutesWithOptions/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../differenceInMinutes/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { differenceInMinutes as fn } from '../../differenceInMinutes/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 3); +export const differenceInMinutesWithOptions = convertToFP(fn, 3); diff --git a/src/date-fns/fp/differenceInMonths/index.ts b/src/date-fns/fp/differenceInMonths/index.ts index f668012..6e180e7 100644 --- a/src/date-fns/fp/differenceInMonths/index.ts +++ b/src/date-fns/fp/differenceInMonths/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../differenceInMonths/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { differenceInMonths as fn } from '../../differenceInMonths/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const differenceInMonths = convertToFP(fn, 2); diff --git a/src/date-fns/fp/differenceInQuarters/index.ts b/src/date-fns/fp/differenceInQuarters/index.ts index edc9a18..f21805d 100644 --- a/src/date-fns/fp/differenceInQuarters/index.ts +++ b/src/date-fns/fp/differenceInQuarters/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../differenceInQuarters/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { differenceInQuarters as fn } from '../../differenceInQuarters/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const differenceInQuarters = convertToFP(fn, 2); diff --git a/src/date-fns/fp/differenceInQuartersWithOptions/index.ts b/src/date-fns/fp/differenceInQuartersWithOptions/index.ts index bad978b..db01365 100644 --- a/src/date-fns/fp/differenceInQuartersWithOptions/index.ts +++ b/src/date-fns/fp/differenceInQuartersWithOptions/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../differenceInQuarters/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { differenceInQuarters as fn } from '../../differenceInQuarters/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 3); +export const differenceInQuartersWithOptions = convertToFP(fn, 3); diff --git a/src/date-fns/fp/differenceInSeconds/index.ts b/src/date-fns/fp/differenceInSeconds/index.ts index 41a87a3..234a5c5 100644 --- a/src/date-fns/fp/differenceInSeconds/index.ts +++ b/src/date-fns/fp/differenceInSeconds/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../differenceInSeconds/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { differenceInSeconds as fn } from '../../differenceInSeconds/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const differenceInSeconds = convertToFP(fn, 2); diff --git a/src/date-fns/fp/differenceInSecondsWithOptions/index.ts b/src/date-fns/fp/differenceInSecondsWithOptions/index.ts index 89b8627..4f17252 100644 --- a/src/date-fns/fp/differenceInSecondsWithOptions/index.ts +++ b/src/date-fns/fp/differenceInSecondsWithOptions/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../differenceInSeconds/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { differenceInSeconds as fn } from '../../differenceInSeconds/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 3); +export const differenceInSecondsWithOptions = convertToFP(fn, 3); diff --git a/src/date-fns/fp/differenceInWeeks/index.ts b/src/date-fns/fp/differenceInWeeks/index.ts index dd2956d..4d9ede5 100644 --- a/src/date-fns/fp/differenceInWeeks/index.ts +++ b/src/date-fns/fp/differenceInWeeks/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../differenceInWeeks/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { differenceInWeeks as fn } from '../../differenceInWeeks/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const differenceInWeeks = convertToFP(fn, 2); diff --git a/src/date-fns/fp/differenceInWeeksWithOptions/index.ts b/src/date-fns/fp/differenceInWeeksWithOptions/index.ts index 350dd2d..11df6f0 100644 --- a/src/date-fns/fp/differenceInWeeksWithOptions/index.ts +++ b/src/date-fns/fp/differenceInWeeksWithOptions/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../differenceInWeeks/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { differenceInWeeks as fn } from '../../differenceInWeeks/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 3); +export const differenceInWeeksWithOptions = convertToFP(fn, 3); diff --git a/src/date-fns/fp/differenceInYears/index.ts b/src/date-fns/fp/differenceInYears/index.ts index 27b3039..97d9ffe 100644 --- a/src/date-fns/fp/differenceInYears/index.ts +++ b/src/date-fns/fp/differenceInYears/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../differenceInYears/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { differenceInYears as fn } from '../../differenceInYears/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const differenceInYears = convertToFP(fn, 2); diff --git a/src/date-fns/fp/eachDayOfInterval/index.ts b/src/date-fns/fp/eachDayOfInterval/index.ts index 6212b9d..2989abf 100644 --- a/src/date-fns/fp/eachDayOfInterval/index.ts +++ b/src/date-fns/fp/eachDayOfInterval/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../eachDayOfInterval/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { eachDayOfInterval as fn } from '../../eachDayOfInterval/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const eachDayOfInterval = convertToFP(fn, 1); diff --git a/src/date-fns/fp/eachDayOfIntervalWithOptions/index.ts b/src/date-fns/fp/eachDayOfIntervalWithOptions/index.ts index fb7f013..8430d60 100644 --- a/src/date-fns/fp/eachDayOfIntervalWithOptions/index.ts +++ b/src/date-fns/fp/eachDayOfIntervalWithOptions/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../eachDayOfInterval/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { eachDayOfInterval as fn } from '../../eachDayOfInterval/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const eachDayOfIntervalWithOptions = convertToFP(fn, 2); diff --git a/src/date-fns/fp/eachHourOfInterval/index.ts b/src/date-fns/fp/eachHourOfInterval/index.ts index 6384895..ccedf31 100644 --- a/src/date-fns/fp/eachHourOfInterval/index.ts +++ b/src/date-fns/fp/eachHourOfInterval/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../eachHourOfInterval/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { eachHourOfInterval as fn } from '../../eachHourOfInterval/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const eachHourOfInterval = convertToFP(fn, 1); diff --git a/src/date-fns/fp/eachHourOfIntervalWithOptions/index.ts b/src/date-fns/fp/eachHourOfIntervalWithOptions/index.ts index 1c44ed7..a4bf09d 100644 --- a/src/date-fns/fp/eachHourOfIntervalWithOptions/index.ts +++ b/src/date-fns/fp/eachHourOfIntervalWithOptions/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../eachHourOfInterval/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { eachHourOfInterval as fn } from '../../eachHourOfInterval/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const eachHourOfIntervalWithOptions = convertToFP(fn, 2); diff --git a/src/date-fns/fp/eachMinuteOfInterval/index.ts b/src/date-fns/fp/eachMinuteOfInterval/index.ts index 315fbd2..fc1e290 100644 --- a/src/date-fns/fp/eachMinuteOfInterval/index.ts +++ b/src/date-fns/fp/eachMinuteOfInterval/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../eachMinuteOfInterval/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { eachMinuteOfInterval as fn } from '../../eachMinuteOfInterval/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const eachMinuteOfInterval = convertToFP(fn, 1); diff --git a/src/date-fns/fp/eachMinuteOfIntervalWithOptions/index.ts b/src/date-fns/fp/eachMinuteOfIntervalWithOptions/index.ts index d5657de..0079bec 100644 --- a/src/date-fns/fp/eachMinuteOfIntervalWithOptions/index.ts +++ b/src/date-fns/fp/eachMinuteOfIntervalWithOptions/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../eachMinuteOfInterval/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { eachMinuteOfInterval as fn } from '../../eachMinuteOfInterval/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const eachMinuteOfIntervalWithOptions = convertToFP(fn, 2); diff --git a/src/date-fns/fp/eachMonthOfInterval/index.ts b/src/date-fns/fp/eachMonthOfInterval/index.ts index 6cc9c26..8a4cb5d 100644 --- a/src/date-fns/fp/eachMonthOfInterval/index.ts +++ b/src/date-fns/fp/eachMonthOfInterval/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../eachMonthOfInterval/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { eachMonthOfInterval as fn } from '../../eachMonthOfInterval/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const eachMonthOfInterval = convertToFP(fn, 1); diff --git a/src/date-fns/fp/eachMonthOfIntervalWithOptions/index.ts b/src/date-fns/fp/eachMonthOfIntervalWithOptions/index.ts new file mode 100644 index 0000000..cec65d3 --- /dev/null +++ b/src/date-fns/fp/eachMonthOfIntervalWithOptions/index.ts @@ -0,0 +1,6 @@ +// This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. + +import { eachMonthOfInterval as fn } from '../../eachMonthOfInterval/index'; +import { convertToFP } from '../_lib/convertToFP/index'; + +export const eachMonthOfIntervalWithOptions = convertToFP(fn, 2); diff --git a/src/date-fns/fp/eachQuarterOfInterval/index.ts b/src/date-fns/fp/eachQuarterOfInterval/index.ts index 0637e8f..5d3d044 100644 --- a/src/date-fns/fp/eachQuarterOfInterval/index.ts +++ b/src/date-fns/fp/eachQuarterOfInterval/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../eachQuarterOfInterval/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { eachQuarterOfInterval as fn } from '../../eachQuarterOfInterval/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const eachQuarterOfInterval = convertToFP(fn, 1); diff --git a/src/date-fns/fp/eachQuarterOfIntervalWithOptions/index.ts b/src/date-fns/fp/eachQuarterOfIntervalWithOptions/index.ts new file mode 100644 index 0000000..b3d4f32 --- /dev/null +++ b/src/date-fns/fp/eachQuarterOfIntervalWithOptions/index.ts @@ -0,0 +1,6 @@ +// This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. + +import { eachQuarterOfInterval as fn } from '../../eachQuarterOfInterval/index'; +import { convertToFP } from '../_lib/convertToFP/index'; + +export const eachQuarterOfIntervalWithOptions = convertToFP(fn, 2); diff --git a/src/date-fns/fp/eachWeekOfInterval/index.ts b/src/date-fns/fp/eachWeekOfInterval/index.ts index c5dca77..16d69c1 100644 --- a/src/date-fns/fp/eachWeekOfInterval/index.ts +++ b/src/date-fns/fp/eachWeekOfInterval/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../eachWeekOfInterval/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { eachWeekOfInterval as fn } from '../../eachWeekOfInterval/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const eachWeekOfInterval = convertToFP(fn, 1); diff --git a/src/date-fns/fp/eachWeekOfIntervalWithOptions/index.ts b/src/date-fns/fp/eachWeekOfIntervalWithOptions/index.ts index 30fa12d..dd85290 100644 --- a/src/date-fns/fp/eachWeekOfIntervalWithOptions/index.ts +++ b/src/date-fns/fp/eachWeekOfIntervalWithOptions/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../eachWeekOfInterval/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { eachWeekOfInterval as fn } from '../../eachWeekOfInterval/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const eachWeekOfIntervalWithOptions = convertToFP(fn, 2); diff --git a/src/date-fns/fp/eachWeekendOfInterval/index.ts b/src/date-fns/fp/eachWeekendOfInterval/index.ts index d617196..38baef9 100644 --- a/src/date-fns/fp/eachWeekendOfInterval/index.ts +++ b/src/date-fns/fp/eachWeekendOfInterval/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../eachWeekendOfInterval/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { eachWeekendOfInterval as fn } from '../../eachWeekendOfInterval/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const eachWeekendOfInterval = convertToFP(fn, 1); diff --git a/src/date-fns/fp/eachWeekendOfMonth/index.ts b/src/date-fns/fp/eachWeekendOfMonth/index.ts index 3237dd2..f2ade8b 100644 --- a/src/date-fns/fp/eachWeekendOfMonth/index.ts +++ b/src/date-fns/fp/eachWeekendOfMonth/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../eachWeekendOfMonth/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { eachWeekendOfMonth as fn } from '../../eachWeekendOfMonth/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const eachWeekendOfMonth = convertToFP(fn, 1); diff --git a/src/date-fns/fp/eachWeekendOfYear/index.ts b/src/date-fns/fp/eachWeekendOfYear/index.ts index 2059b40..3de5f88 100644 --- a/src/date-fns/fp/eachWeekendOfYear/index.ts +++ b/src/date-fns/fp/eachWeekendOfYear/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../eachWeekendOfYear/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { eachWeekendOfYear as fn } from '../../eachWeekendOfYear/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const eachWeekendOfYear = convertToFP(fn, 1); diff --git a/src/date-fns/fp/eachYearOfInterval/index.ts b/src/date-fns/fp/eachYearOfInterval/index.ts index f13b1b6..4ac90a1 100644 --- a/src/date-fns/fp/eachYearOfInterval/index.ts +++ b/src/date-fns/fp/eachYearOfInterval/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../eachYearOfInterval/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { eachYearOfInterval as fn } from '../../eachYearOfInterval/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const eachYearOfInterval = convertToFP(fn, 1); diff --git a/src/date-fns/fp/eachYearOfIntervalWithOptions/index.ts b/src/date-fns/fp/eachYearOfIntervalWithOptions/index.ts new file mode 100644 index 0000000..91be636 --- /dev/null +++ b/src/date-fns/fp/eachYearOfIntervalWithOptions/index.ts @@ -0,0 +1,6 @@ +// This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. + +import { eachYearOfInterval as fn } from '../../eachYearOfInterval/index'; +import { convertToFP } from '../_lib/convertToFP/index'; + +export const eachYearOfIntervalWithOptions = convertToFP(fn, 2); diff --git a/src/date-fns/fp/endOfDay/index.ts b/src/date-fns/fp/endOfDay/index.ts index 6c21db5..a617823 100644 --- a/src/date-fns/fp/endOfDay/index.ts +++ b/src/date-fns/fp/endOfDay/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../endOfDay/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { endOfDay as fn } from '../../endOfDay/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const endOfDay = convertToFP(fn, 1); diff --git a/src/date-fns/fp/endOfDecade/index.ts b/src/date-fns/fp/endOfDecade/index.ts index d63e5b2..e4fd41d 100644 --- a/src/date-fns/fp/endOfDecade/index.ts +++ b/src/date-fns/fp/endOfDecade/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../endOfDecade/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { endOfDecade as fn } from '../../endOfDecade/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const endOfDecade = convertToFP(fn, 1); diff --git a/src/date-fns/fp/endOfDecadeWithOptions/index.ts b/src/date-fns/fp/endOfDecadeWithOptions/index.ts deleted file mode 100644 index 15b0e4a..0000000 --- a/src/date-fns/fp/endOfDecadeWithOptions/index.ts +++ /dev/null @@ -1,6 +0,0 @@ -// This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. - -import fn from '../../endOfDecade/index'; -import convertToFP from '../_lib/convertToFP/index'; - -export default convertToFP(fn, 2); diff --git a/src/date-fns/fp/endOfHour/index.ts b/src/date-fns/fp/endOfHour/index.ts index c7ee976..54f0a81 100644 --- a/src/date-fns/fp/endOfHour/index.ts +++ b/src/date-fns/fp/endOfHour/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../endOfHour/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { endOfHour as fn } from '../../endOfHour/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const endOfHour = convertToFP(fn, 1); diff --git a/src/date-fns/fp/endOfISOWeek/index.ts b/src/date-fns/fp/endOfISOWeek/index.ts index 2dd8193..7a95ccf 100644 --- a/src/date-fns/fp/endOfISOWeek/index.ts +++ b/src/date-fns/fp/endOfISOWeek/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../endOfISOWeek/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { endOfISOWeek as fn } from '../../endOfISOWeek/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const endOfISOWeek = convertToFP(fn, 1); diff --git a/src/date-fns/fp/endOfISOWeekYear/index.ts b/src/date-fns/fp/endOfISOWeekYear/index.ts index 42b5682..18a3714 100644 --- a/src/date-fns/fp/endOfISOWeekYear/index.ts +++ b/src/date-fns/fp/endOfISOWeekYear/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../endOfISOWeekYear/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { endOfISOWeekYear as fn } from '../../endOfISOWeekYear/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const endOfISOWeekYear = convertToFP(fn, 1); diff --git a/src/date-fns/fp/endOfMinute/index.ts b/src/date-fns/fp/endOfMinute/index.ts index d2e11d6..a76105b 100644 --- a/src/date-fns/fp/endOfMinute/index.ts +++ b/src/date-fns/fp/endOfMinute/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../endOfMinute/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { endOfMinute as fn } from '../../endOfMinute/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const endOfMinute = convertToFP(fn, 1); diff --git a/src/date-fns/fp/endOfMonth/index.ts b/src/date-fns/fp/endOfMonth/index.ts index 2bb0aa4..01a78e1 100644 --- a/src/date-fns/fp/endOfMonth/index.ts +++ b/src/date-fns/fp/endOfMonth/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../endOfMonth/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { endOfMonth as fn } from '../../endOfMonth/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const endOfMonth = convertToFP(fn, 1); diff --git a/src/date-fns/fp/endOfQuarter/index.ts b/src/date-fns/fp/endOfQuarter/index.ts index 8f20780..180c9cf 100644 --- a/src/date-fns/fp/endOfQuarter/index.ts +++ b/src/date-fns/fp/endOfQuarter/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../endOfQuarter/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { endOfQuarter as fn } from '../../endOfQuarter/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const endOfQuarter = convertToFP(fn, 1); diff --git a/src/date-fns/fp/endOfSecond/index.ts b/src/date-fns/fp/endOfSecond/index.ts index 01c4310..b59b98d 100644 --- a/src/date-fns/fp/endOfSecond/index.ts +++ b/src/date-fns/fp/endOfSecond/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../endOfSecond/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { endOfSecond as fn } from '../../endOfSecond/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const endOfSecond = convertToFP(fn, 1); diff --git a/src/date-fns/fp/endOfWeek/index.ts b/src/date-fns/fp/endOfWeek/index.ts index b4aa650..a3bf378 100644 --- a/src/date-fns/fp/endOfWeek/index.ts +++ b/src/date-fns/fp/endOfWeek/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../endOfWeek/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { endOfWeek as fn } from '../../endOfWeek/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const endOfWeek = convertToFP(fn, 1); diff --git a/src/date-fns/fp/endOfWeekWithOptions/index.ts b/src/date-fns/fp/endOfWeekWithOptions/index.ts index 4312815..e5043cc 100644 --- a/src/date-fns/fp/endOfWeekWithOptions/index.ts +++ b/src/date-fns/fp/endOfWeekWithOptions/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../endOfWeek/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { endOfWeek as fn } from '../../endOfWeek/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const endOfWeekWithOptions = convertToFP(fn, 2); diff --git a/src/date-fns/fp/endOfYear/index.ts b/src/date-fns/fp/endOfYear/index.ts index 6c2c981..aef3a42 100644 --- a/src/date-fns/fp/endOfYear/index.ts +++ b/src/date-fns/fp/endOfYear/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../endOfYear/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { endOfYear as fn } from '../../endOfYear/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const endOfYear = convertToFP(fn, 1); diff --git a/src/date-fns/fp/format/index.ts b/src/date-fns/fp/format/index.ts index e0ec303..c54dc5e 100644 --- a/src/date-fns/fp/format/index.ts +++ b/src/date-fns/fp/format/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../format/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { format as fn } from '../../format/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const format = convertToFP(fn, 2); diff --git a/src/date-fns/fp/formatDistance/index.ts b/src/date-fns/fp/formatDistance/index.ts index 03d74f0..dfcb98d 100644 --- a/src/date-fns/fp/formatDistance/index.ts +++ b/src/date-fns/fp/formatDistance/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../formatDistance/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { formatDistance as fn } from '../../formatDistance/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const formatDistance = convertToFP(fn, 2); diff --git a/src/date-fns/fp/formatDistanceStrict/index.ts b/src/date-fns/fp/formatDistanceStrict/index.ts index 36d77ee..42694d4 100644 --- a/src/date-fns/fp/formatDistanceStrict/index.ts +++ b/src/date-fns/fp/formatDistanceStrict/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../formatDistanceStrict/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { formatDistanceStrict as fn } from '../../formatDistanceStrict/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const formatDistanceStrict = convertToFP(fn, 2); diff --git a/src/date-fns/fp/formatDistanceStrictWithOptions/index.ts b/src/date-fns/fp/formatDistanceStrictWithOptions/index.ts index 048dece..f946a48 100644 --- a/src/date-fns/fp/formatDistanceStrictWithOptions/index.ts +++ b/src/date-fns/fp/formatDistanceStrictWithOptions/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../formatDistanceStrict/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { formatDistanceStrict as fn } from '../../formatDistanceStrict/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 3); +export const formatDistanceStrictWithOptions = convertToFP(fn, 3); diff --git a/src/date-fns/fp/formatDistanceWithOptions/index.ts b/src/date-fns/fp/formatDistanceWithOptions/index.ts index 2c6f39f..631fd9c 100644 --- a/src/date-fns/fp/formatDistanceWithOptions/index.ts +++ b/src/date-fns/fp/formatDistanceWithOptions/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../formatDistance/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { formatDistance as fn } from '../../formatDistance/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 3); +export const formatDistanceWithOptions = convertToFP(fn, 3); diff --git a/src/date-fns/fp/formatDuration/index.ts b/src/date-fns/fp/formatDuration/index.ts index cc4aba4..78cd554 100644 --- a/src/date-fns/fp/formatDuration/index.ts +++ b/src/date-fns/fp/formatDuration/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../formatDuration/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { formatDuration as fn } from '../../formatDuration/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const formatDuration = convertToFP(fn, 1); diff --git a/src/date-fns/fp/formatDurationWithOptions/index.ts b/src/date-fns/fp/formatDurationWithOptions/index.ts index baed686..10d706f 100644 --- a/src/date-fns/fp/formatDurationWithOptions/index.ts +++ b/src/date-fns/fp/formatDurationWithOptions/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../formatDuration/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { formatDuration as fn } from '../../formatDuration/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const formatDurationWithOptions = convertToFP(fn, 2); diff --git a/src/date-fns/fp/formatISO/index.ts b/src/date-fns/fp/formatISO/index.ts index 398a897..cfe81c9 100644 --- a/src/date-fns/fp/formatISO/index.ts +++ b/src/date-fns/fp/formatISO/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../formatISO/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { formatISO as fn } from '../../formatISO/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const formatISO = convertToFP(fn, 1); diff --git a/src/date-fns/fp/formatISO9075/index.ts b/src/date-fns/fp/formatISO9075/index.ts index 11e095c..61f5f20 100644 --- a/src/date-fns/fp/formatISO9075/index.ts +++ b/src/date-fns/fp/formatISO9075/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../formatISO9075/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { formatISO9075 as fn } from '../../formatISO9075/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const formatISO9075 = convertToFP(fn, 1); diff --git a/src/date-fns/fp/formatISO9075WithOptions/index.ts b/src/date-fns/fp/formatISO9075WithOptions/index.ts index 0f61096..46298c3 100644 --- a/src/date-fns/fp/formatISO9075WithOptions/index.ts +++ b/src/date-fns/fp/formatISO9075WithOptions/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../formatISO9075/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { formatISO9075 as fn } from '../../formatISO9075/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const formatISO9075WithOptions = convertToFP(fn, 2); diff --git a/src/date-fns/fp/formatISODuration/index.ts b/src/date-fns/fp/formatISODuration/index.ts index 1b81f0a..0b928ce 100644 --- a/src/date-fns/fp/formatISODuration/index.ts +++ b/src/date-fns/fp/formatISODuration/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../formatISODuration/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { formatISODuration as fn } from '../../formatISODuration/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const formatISODuration = convertToFP(fn, 1); diff --git a/src/date-fns/fp/formatISOWithOptions/index.ts b/src/date-fns/fp/formatISOWithOptions/index.ts index 9f37702..c19042a 100644 --- a/src/date-fns/fp/formatISOWithOptions/index.ts +++ b/src/date-fns/fp/formatISOWithOptions/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../formatISO/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { formatISO as fn } from '../../formatISO/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const formatISOWithOptions = convertToFP(fn, 2); diff --git a/src/date-fns/fp/formatRFC3339/index.ts b/src/date-fns/fp/formatRFC3339/index.ts index 5e4e262..87f2c7b 100644 --- a/src/date-fns/fp/formatRFC3339/index.ts +++ b/src/date-fns/fp/formatRFC3339/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../formatRFC3339/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { formatRFC3339 as fn } from '../../formatRFC3339/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const formatRFC3339 = convertToFP(fn, 1); diff --git a/src/date-fns/fp/formatRFC3339WithOptions/index.ts b/src/date-fns/fp/formatRFC3339WithOptions/index.ts index 976d656..32de9f4 100644 --- a/src/date-fns/fp/formatRFC3339WithOptions/index.ts +++ b/src/date-fns/fp/formatRFC3339WithOptions/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../formatRFC3339/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { formatRFC3339 as fn } from '../../formatRFC3339/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const formatRFC3339WithOptions = convertToFP(fn, 2); diff --git a/src/date-fns/fp/formatRFC7231/index.ts b/src/date-fns/fp/formatRFC7231/index.ts index 258be78..8415c2a 100644 --- a/src/date-fns/fp/formatRFC7231/index.ts +++ b/src/date-fns/fp/formatRFC7231/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../formatRFC7231/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { formatRFC7231 as fn } from '../../formatRFC7231/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const formatRFC7231 = convertToFP(fn, 1); diff --git a/src/date-fns/fp/formatRelative/index.ts b/src/date-fns/fp/formatRelative/index.ts index b6e8ecf..78c173b 100644 --- a/src/date-fns/fp/formatRelative/index.ts +++ b/src/date-fns/fp/formatRelative/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../formatRelative/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { formatRelative as fn } from '../../formatRelative/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const formatRelative = convertToFP(fn, 2); diff --git a/src/date-fns/fp/formatRelativeWithOptions/index.ts b/src/date-fns/fp/formatRelativeWithOptions/index.ts index 6db044d..9e32ef9 100644 --- a/src/date-fns/fp/formatRelativeWithOptions/index.ts +++ b/src/date-fns/fp/formatRelativeWithOptions/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../formatRelative/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { formatRelative as fn } from '../../formatRelative/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 3); +export const formatRelativeWithOptions = convertToFP(fn, 3); diff --git a/src/date-fns/fp/formatWithOptions/index.ts b/src/date-fns/fp/formatWithOptions/index.ts index 00056f1..66528d9 100644 --- a/src/date-fns/fp/formatWithOptions/index.ts +++ b/src/date-fns/fp/formatWithOptions/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../format/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { format as fn } from '../../format/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 3); +export const formatWithOptions = convertToFP(fn, 3); diff --git a/src/date-fns/fp/fromUnixTime/index.ts b/src/date-fns/fp/fromUnixTime/index.ts index 7964c6c..1b4b80e 100644 --- a/src/date-fns/fp/fromUnixTime/index.ts +++ b/src/date-fns/fp/fromUnixTime/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../fromUnixTime/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { fromUnixTime as fn } from '../../fromUnixTime/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const fromUnixTime = convertToFP(fn, 1); diff --git a/src/date-fns/fp/getDate/index.ts b/src/date-fns/fp/getDate/index.ts index 83981a3..d41cb99 100644 --- a/src/date-fns/fp/getDate/index.ts +++ b/src/date-fns/fp/getDate/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../getDate/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { getDate as fn } from '../../getDate/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const getDate = convertToFP(fn, 1); diff --git a/src/date-fns/fp/getDay/index.ts b/src/date-fns/fp/getDay/index.ts index a7c4d91..a487c3c 100644 --- a/src/date-fns/fp/getDay/index.ts +++ b/src/date-fns/fp/getDay/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../getDay/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { getDay as fn } from '../../getDay/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const getDay = convertToFP(fn, 1); diff --git a/src/date-fns/fp/getDayOfYear/index.ts b/src/date-fns/fp/getDayOfYear/index.ts index 63e0a7c..ea5a272 100644 --- a/src/date-fns/fp/getDayOfYear/index.ts +++ b/src/date-fns/fp/getDayOfYear/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../getDayOfYear/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { getDayOfYear as fn } from '../../getDayOfYear/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const getDayOfYear = convertToFP(fn, 1); diff --git a/src/date-fns/fp/getDaysInMonth/index.ts b/src/date-fns/fp/getDaysInMonth/index.ts index 8c9cb75..dda9287 100644 --- a/src/date-fns/fp/getDaysInMonth/index.ts +++ b/src/date-fns/fp/getDaysInMonth/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../getDaysInMonth/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { getDaysInMonth as fn } from '../../getDaysInMonth/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const getDaysInMonth = convertToFP(fn, 1); diff --git a/src/date-fns/fp/getDaysInYear/index.ts b/src/date-fns/fp/getDaysInYear/index.ts index 1b40173..f3ceffd 100644 --- a/src/date-fns/fp/getDaysInYear/index.ts +++ b/src/date-fns/fp/getDaysInYear/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../getDaysInYear/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { getDaysInYear as fn } from '../../getDaysInYear/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const getDaysInYear = convertToFP(fn, 1); diff --git a/src/date-fns/fp/getDecade/index.ts b/src/date-fns/fp/getDecade/index.ts index 9d77b39..bce6e7a 100644 --- a/src/date-fns/fp/getDecade/index.ts +++ b/src/date-fns/fp/getDecade/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../getDecade/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { getDecade as fn } from '../../getDecade/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const getDecade = convertToFP(fn, 1); diff --git a/src/date-fns/fp/getHours/index.ts b/src/date-fns/fp/getHours/index.ts index 8c6f08f..067cbc6 100644 --- a/src/date-fns/fp/getHours/index.ts +++ b/src/date-fns/fp/getHours/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../getHours/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { getHours as fn } from '../../getHours/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const getHours = convertToFP(fn, 1); diff --git a/src/date-fns/fp/getISODay/index.ts b/src/date-fns/fp/getISODay/index.ts index 322c396..22c2962 100644 --- a/src/date-fns/fp/getISODay/index.ts +++ b/src/date-fns/fp/getISODay/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../getISODay/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { getISODay as fn } from '../../getISODay/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const getISODay = convertToFP(fn, 1); diff --git a/src/date-fns/fp/getISOWeek/index.ts b/src/date-fns/fp/getISOWeek/index.ts index d004c86..c64d8ad 100644 --- a/src/date-fns/fp/getISOWeek/index.ts +++ b/src/date-fns/fp/getISOWeek/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../getISOWeek/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { getISOWeek as fn } from '../../getISOWeek/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const getISOWeek = convertToFP(fn, 1); diff --git a/src/date-fns/fp/getISOWeekYear/index.ts b/src/date-fns/fp/getISOWeekYear/index.ts index 84c9b2c..6af113b 100644 --- a/src/date-fns/fp/getISOWeekYear/index.ts +++ b/src/date-fns/fp/getISOWeekYear/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../getISOWeekYear/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { getISOWeekYear as fn } from '../../getISOWeekYear/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const getISOWeekYear = convertToFP(fn, 1); diff --git a/src/date-fns/fp/getISOWeeksInYear/index.ts b/src/date-fns/fp/getISOWeeksInYear/index.ts index 4c06b8d..f984898 100644 --- a/src/date-fns/fp/getISOWeeksInYear/index.ts +++ b/src/date-fns/fp/getISOWeeksInYear/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../getISOWeeksInYear/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { getISOWeeksInYear as fn } from '../../getISOWeeksInYear/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const getISOWeeksInYear = convertToFP(fn, 1); diff --git a/src/date-fns/fp/getMilliseconds/index.ts b/src/date-fns/fp/getMilliseconds/index.ts index 325fc53..de61d75 100644 --- a/src/date-fns/fp/getMilliseconds/index.ts +++ b/src/date-fns/fp/getMilliseconds/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../getMilliseconds/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { getMilliseconds as fn } from '../../getMilliseconds/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const getMilliseconds = convertToFP(fn, 1); diff --git a/src/date-fns/fp/getMinutes/index.ts b/src/date-fns/fp/getMinutes/index.ts index c9bdc52..56b9204 100644 --- a/src/date-fns/fp/getMinutes/index.ts +++ b/src/date-fns/fp/getMinutes/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../getMinutes/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { getMinutes as fn } from '../../getMinutes/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const getMinutes = convertToFP(fn, 1); diff --git a/src/date-fns/fp/getMonth/index.ts b/src/date-fns/fp/getMonth/index.ts index 2787297..a100095 100644 --- a/src/date-fns/fp/getMonth/index.ts +++ b/src/date-fns/fp/getMonth/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../getMonth/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { getMonth as fn } from '../../getMonth/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const getMonth = convertToFP(fn, 1); diff --git a/src/date-fns/fp/getOverlappingDaysInIntervals/index.ts b/src/date-fns/fp/getOverlappingDaysInIntervals/index.ts index 2771bfb..861bcae 100644 --- a/src/date-fns/fp/getOverlappingDaysInIntervals/index.ts +++ b/src/date-fns/fp/getOverlappingDaysInIntervals/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../getOverlappingDaysInIntervals/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { getOverlappingDaysInIntervals as fn } from '../../getOverlappingDaysInIntervals/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const getOverlappingDaysInIntervals = convertToFP(fn, 2); diff --git a/src/date-fns/fp/getQuarter/index.ts b/src/date-fns/fp/getQuarter/index.ts index 8b2db3d..af9b7de 100644 --- a/src/date-fns/fp/getQuarter/index.ts +++ b/src/date-fns/fp/getQuarter/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../getQuarter/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { getQuarter as fn } from '../../getQuarter/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const getQuarter = convertToFP(fn, 1); diff --git a/src/date-fns/fp/getSeconds/index.ts b/src/date-fns/fp/getSeconds/index.ts index a234ab4..c775598 100644 --- a/src/date-fns/fp/getSeconds/index.ts +++ b/src/date-fns/fp/getSeconds/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../getSeconds/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { getSeconds as fn } from '../../getSeconds/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const getSeconds = convertToFP(fn, 1); diff --git a/src/date-fns/fp/getTime/index.ts b/src/date-fns/fp/getTime/index.ts index 3254ffc..e43d805 100644 --- a/src/date-fns/fp/getTime/index.ts +++ b/src/date-fns/fp/getTime/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../getTime/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { getTime as fn } from '../../getTime/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const getTime = convertToFP(fn, 1); diff --git a/src/date-fns/fp/getUnixTime/index.ts b/src/date-fns/fp/getUnixTime/index.ts index 71fdc4f..afbee9b 100644 --- a/src/date-fns/fp/getUnixTime/index.ts +++ b/src/date-fns/fp/getUnixTime/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../getUnixTime/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { getUnixTime as fn } from '../../getUnixTime/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const getUnixTime = convertToFP(fn, 1); diff --git a/src/date-fns/fp/getWeek/index.ts b/src/date-fns/fp/getWeek/index.ts index 5eb37e2..578930d 100644 --- a/src/date-fns/fp/getWeek/index.ts +++ b/src/date-fns/fp/getWeek/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../getWeek/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { getWeek as fn } from '../../getWeek/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const getWeek = convertToFP(fn, 1); diff --git a/src/date-fns/fp/getWeekOfMonth/index.ts b/src/date-fns/fp/getWeekOfMonth/index.ts index ab44f07..94cb474 100644 --- a/src/date-fns/fp/getWeekOfMonth/index.ts +++ b/src/date-fns/fp/getWeekOfMonth/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../getWeekOfMonth/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { getWeekOfMonth as fn } from '../../getWeekOfMonth/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const getWeekOfMonth = convertToFP(fn, 1); diff --git a/src/date-fns/fp/getWeekOfMonthWithOptions/index.ts b/src/date-fns/fp/getWeekOfMonthWithOptions/index.ts index e83dd78..1340ba2 100644 --- a/src/date-fns/fp/getWeekOfMonthWithOptions/index.ts +++ b/src/date-fns/fp/getWeekOfMonthWithOptions/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../getWeekOfMonth/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { getWeekOfMonth as fn } from '../../getWeekOfMonth/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const getWeekOfMonthWithOptions = convertToFP(fn, 2); diff --git a/src/date-fns/fp/getWeekWithOptions/index.ts b/src/date-fns/fp/getWeekWithOptions/index.ts index 9dacd3d..bda0da6 100644 --- a/src/date-fns/fp/getWeekWithOptions/index.ts +++ b/src/date-fns/fp/getWeekWithOptions/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../getWeek/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { getWeek as fn } from '../../getWeek/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const getWeekWithOptions = convertToFP(fn, 2); diff --git a/src/date-fns/fp/getWeekYear/index.ts b/src/date-fns/fp/getWeekYear/index.ts index caad084..68e8b8c 100644 --- a/src/date-fns/fp/getWeekYear/index.ts +++ b/src/date-fns/fp/getWeekYear/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../getWeekYear/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { getWeekYear as fn } from '../../getWeekYear/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const getWeekYear = convertToFP(fn, 1); diff --git a/src/date-fns/fp/getWeekYearWithOptions/index.ts b/src/date-fns/fp/getWeekYearWithOptions/index.ts index 5e1a42f..3f4d835 100644 --- a/src/date-fns/fp/getWeekYearWithOptions/index.ts +++ b/src/date-fns/fp/getWeekYearWithOptions/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../getWeekYear/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { getWeekYear as fn } from '../../getWeekYear/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const getWeekYearWithOptions = convertToFP(fn, 2); diff --git a/src/date-fns/fp/getWeeksInMonth/index.ts b/src/date-fns/fp/getWeeksInMonth/index.ts index a8258d2..2863cee 100644 --- a/src/date-fns/fp/getWeeksInMonth/index.ts +++ b/src/date-fns/fp/getWeeksInMonth/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../getWeeksInMonth/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { getWeeksInMonth as fn } from '../../getWeeksInMonth/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const getWeeksInMonth = convertToFP(fn, 1); diff --git a/src/date-fns/fp/getWeeksInMonthWithOptions/index.ts b/src/date-fns/fp/getWeeksInMonthWithOptions/index.ts index 78fe41d..fdc4947 100644 --- a/src/date-fns/fp/getWeeksInMonthWithOptions/index.ts +++ b/src/date-fns/fp/getWeeksInMonthWithOptions/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../getWeeksInMonth/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { getWeeksInMonth as fn } from '../../getWeeksInMonth/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const getWeeksInMonthWithOptions = convertToFP(fn, 2); diff --git a/src/date-fns/fp/getYear/index.ts b/src/date-fns/fp/getYear/index.ts index 507ae2c..ab4e51c 100644 --- a/src/date-fns/fp/getYear/index.ts +++ b/src/date-fns/fp/getYear/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../getYear/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { getYear as fn } from '../../getYear/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const getYear = convertToFP(fn, 1); diff --git a/src/date-fns/fp/hoursToMilliseconds/index.ts b/src/date-fns/fp/hoursToMilliseconds/index.ts index 5fbf920..bd213c3 100644 --- a/src/date-fns/fp/hoursToMilliseconds/index.ts +++ b/src/date-fns/fp/hoursToMilliseconds/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../hoursToMilliseconds/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { hoursToMilliseconds as fn } from '../../hoursToMilliseconds/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const hoursToMilliseconds = convertToFP(fn, 1); diff --git a/src/date-fns/fp/hoursToMinutes/index.ts b/src/date-fns/fp/hoursToMinutes/index.ts index c81b195..5217afe 100644 --- a/src/date-fns/fp/hoursToMinutes/index.ts +++ b/src/date-fns/fp/hoursToMinutes/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../hoursToMinutes/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { hoursToMinutes as fn } from '../../hoursToMinutes/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const hoursToMinutes = convertToFP(fn, 1); diff --git a/src/date-fns/fp/hoursToSeconds/index.ts b/src/date-fns/fp/hoursToSeconds/index.ts index bd13d57..482e58f 100644 --- a/src/date-fns/fp/hoursToSeconds/index.ts +++ b/src/date-fns/fp/hoursToSeconds/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../hoursToSeconds/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { hoursToSeconds as fn } from '../../hoursToSeconds/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const hoursToSeconds = convertToFP(fn, 1); diff --git a/src/date-fns/fp/index.ts b/src/date-fns/fp/index.ts index 988d073..8609351 100644 --- a/src/date-fns/fp/index.ts +++ b/src/date-fns/fp/index.ts @@ -1,257 +1,265 @@ // This file is generated automatically by `scripts/build/indices.ts`. Please, don't change it. -export { default as add } from './add/index'; -export { default as addBusinessDays } from './addBusinessDays/index'; -export { default as addDays } from './addDays/index'; -export { default as addHours } from './addHours/index'; -export { default as addISOWeekYears } from './addISOWeekYears/index'; -export { default as addMilliseconds } from './addMilliseconds/index'; -export { default as addMinutes } from './addMinutes/index'; -export { default as addMonths } from './addMonths/index'; -export { default as addQuarters } from './addQuarters/index'; -export { default as addSeconds } from './addSeconds/index'; -export { default as addWeeks } from './addWeeks/index'; -export { default as addYears } from './addYears/index'; -export { default as areIntervalsOverlapping } from './areIntervalsOverlapping/index'; -export { default as areIntervalsOverlappingWithOptions } from './areIntervalsOverlappingWithOptions/index'; -export { default as clamp } from './clamp/index'; -export { default as closestIndexTo } from './closestIndexTo/index'; -export { default as closestTo } from './closestTo/index'; -export { default as compareAsc } from './compareAsc/index'; -export { default as compareDesc } from './compareDesc/index'; -export { default as daysToWeeks } from './daysToWeeks/index'; -export { default as differenceInBusinessDays } from './differenceInBusinessDays/index'; -export { default as differenceInCalendarDays } from './differenceInCalendarDays/index'; -export { default as differenceInCalendarISOWeekYears } from './differenceInCalendarISOWeekYears/index'; -export { default as differenceInCalendarISOWeeks } from './differenceInCalendarISOWeeks/index'; -export { default as differenceInCalendarMonths } from './differenceInCalendarMonths/index'; -export { default as differenceInCalendarQuarters } from './differenceInCalendarQuarters/index'; -export { default as differenceInCalendarWeeks } from './differenceInCalendarWeeks/index'; -export { default as differenceInCalendarWeeksWithOptions } from './differenceInCalendarWeeksWithOptions/index'; -export { default as differenceInCalendarYears } from './differenceInCalendarYears/index'; -export { default as differenceInDays } from './differenceInDays/index'; -export { default as differenceInHours } from './differenceInHours/index'; -export { default as differenceInHoursWithOptions } from './differenceInHoursWithOptions/index'; -export { default as differenceInISOWeekYears } from './differenceInISOWeekYears/index'; -export { default as differenceInMilliseconds } from './differenceInMilliseconds/index'; -export { default as differenceInMinutes } from './differenceInMinutes/index'; -export { default as differenceInMinutesWithOptions } from './differenceInMinutesWithOptions/index'; -export { default as differenceInMonths } from './differenceInMonths/index'; -export { default as differenceInQuarters } from './differenceInQuarters/index'; -export { default as differenceInQuartersWithOptions } from './differenceInQuartersWithOptions/index'; -export { default as differenceInSeconds } from './differenceInSeconds/index'; -export { default as differenceInSecondsWithOptions } from './differenceInSecondsWithOptions/index'; -export { default as differenceInWeeks } from './differenceInWeeks/index'; -export { default as differenceInWeeksWithOptions } from './differenceInWeeksWithOptions/index'; -export { default as differenceInYears } from './differenceInYears/index'; -export { default as eachDayOfInterval } from './eachDayOfInterval/index'; -export { default as eachDayOfIntervalWithOptions } from './eachDayOfIntervalWithOptions/index'; -export { default as eachHourOfInterval } from './eachHourOfInterval/index'; -export { default as eachHourOfIntervalWithOptions } from './eachHourOfIntervalWithOptions/index'; -export { default as eachMinuteOfInterval } from './eachMinuteOfInterval/index'; -export { default as eachMinuteOfIntervalWithOptions } from './eachMinuteOfIntervalWithOptions/index'; -export { default as eachMonthOfInterval } from './eachMonthOfInterval/index'; -export { default as eachQuarterOfInterval } from './eachQuarterOfInterval/index'; -export { default as eachWeekOfInterval } from './eachWeekOfInterval/index'; -export { default as eachWeekOfIntervalWithOptions } from './eachWeekOfIntervalWithOptions/index'; -export { default as eachWeekendOfInterval } from './eachWeekendOfInterval/index'; -export { default as eachWeekendOfMonth } from './eachWeekendOfMonth/index'; -export { default as eachWeekendOfYear } from './eachWeekendOfYear/index'; -export { default as eachYearOfInterval } from './eachYearOfInterval/index'; -export { default as endOfDay } from './endOfDay/index'; -export { default as endOfDecade } from './endOfDecade/index'; -export { default as endOfDecadeWithOptions } from './endOfDecadeWithOptions/index'; -export { default as endOfHour } from './endOfHour/index'; -export { default as endOfISOWeek } from './endOfISOWeek/index'; -export { default as endOfISOWeekYear } from './endOfISOWeekYear/index'; -export { default as endOfMinute } from './endOfMinute/index'; -export { default as endOfMonth } from './endOfMonth/index'; -export { default as endOfQuarter } from './endOfQuarter/index'; -export { default as endOfSecond } from './endOfSecond/index'; -export { default as endOfWeek } from './endOfWeek/index'; -export { default as endOfWeekWithOptions } from './endOfWeekWithOptions/index'; -export { default as endOfYear } from './endOfYear/index'; -export { default as format } from './format/index'; -export { default as formatDistance } from './formatDistance/index'; -export { default as formatDistanceStrict } from './formatDistanceStrict/index'; -export { default as formatDistanceStrictWithOptions } from './formatDistanceStrictWithOptions/index'; -export { default as formatDistanceWithOptions } from './formatDistanceWithOptions/index'; -export { default as formatDuration } from './formatDuration/index'; -export { default as formatDurationWithOptions } from './formatDurationWithOptions/index'; -export { default as formatISO } from './formatISO/index'; -export { default as formatISO9075 } from './formatISO9075/index'; -export { default as formatISO9075WithOptions } from './formatISO9075WithOptions/index'; -export { default as formatISODuration } from './formatISODuration/index'; -export { default as formatISOWithOptions } from './formatISOWithOptions/index'; -export { default as formatRFC3339 } from './formatRFC3339/index'; -export { default as formatRFC3339WithOptions } from './formatRFC3339WithOptions/index'; -export { default as formatRFC7231 } from './formatRFC7231/index'; -export { default as formatRelative } from './formatRelative/index'; -export { default as formatRelativeWithOptions } from './formatRelativeWithOptions/index'; -export { default as formatWithOptions } from './formatWithOptions/index'; -export { default as fromUnixTime } from './fromUnixTime/index'; -export { default as getDate } from './getDate/index'; -export { default as getDay } from './getDay/index'; -export { default as getDayOfYear } from './getDayOfYear/index'; -export { default as getDaysInMonth } from './getDaysInMonth/index'; -export { default as getDaysInYear } from './getDaysInYear/index'; -export { default as getDecade } from './getDecade/index'; -export { default as getHours } from './getHours/index'; -export { default as getISODay } from './getISODay/index'; -export { default as getISOWeek } from './getISOWeek/index'; -export { default as getISOWeekYear } from './getISOWeekYear/index'; -export { default as getISOWeeksInYear } from './getISOWeeksInYear/index'; -export { default as getMilliseconds } from './getMilliseconds/index'; -export { default as getMinutes } from './getMinutes/index'; -export { default as getMonth } from './getMonth/index'; -export { default as getOverlappingDaysInIntervals } from './getOverlappingDaysInIntervals/index'; -export { default as getQuarter } from './getQuarter/index'; -export { default as getSeconds } from './getSeconds/index'; -export { default as getTime } from './getTime/index'; -export { default as getUnixTime } from './getUnixTime/index'; -export { default as getWeek } from './getWeek/index'; -export { default as getWeekOfMonth } from './getWeekOfMonth/index'; -export { default as getWeekOfMonthWithOptions } from './getWeekOfMonthWithOptions/index'; -export { default as getWeekWithOptions } from './getWeekWithOptions/index'; -export { default as getWeekYear } from './getWeekYear/index'; -export { default as getWeekYearWithOptions } from './getWeekYearWithOptions/index'; -export { default as getWeeksInMonth } from './getWeeksInMonth/index'; -export { default as getWeeksInMonthWithOptions } from './getWeeksInMonthWithOptions/index'; -export { default as getYear } from './getYear/index'; -export { default as hoursToMilliseconds } from './hoursToMilliseconds/index'; -export { default as hoursToMinutes } from './hoursToMinutes/index'; -export { default as hoursToSeconds } from './hoursToSeconds/index'; -export { default as intervalToDuration } from './intervalToDuration/index'; -export { default as intlFormat } from './intlFormat/index'; -export { default as intlFormatDistance } from './intlFormatDistance/index'; -export { default as intlFormatDistanceWithOptions } from './intlFormatDistanceWithOptions/index'; -export { default as isAfter } from './isAfter/index'; -export { default as isBefore } from './isBefore/index'; -export { default as isDate } from './isDate/index'; -export { default as isEqual } from './isEqual/index'; -export { default as isExists } from './isExists/index'; -export { default as isFirstDayOfMonth } from './isFirstDayOfMonth/index'; -export { default as isFriday } from './isFriday/index'; -export { default as isLastDayOfMonth } from './isLastDayOfMonth/index'; -export { default as isLeapYear } from './isLeapYear/index'; -export { default as isMatch } from './isMatch/index'; -export { default as isMatchWithOptions } from './isMatchWithOptions/index'; -export { default as isMonday } from './isMonday/index'; -export { default as isSameDay } from './isSameDay/index'; -export { default as isSameHour } from './isSameHour/index'; -export { default as isSameISOWeek } from './isSameISOWeek/index'; -export { default as isSameISOWeekYear } from './isSameISOWeekYear/index'; -export { default as isSameMinute } from './isSameMinute/index'; -export { default as isSameMonth } from './isSameMonth/index'; -export { default as isSameQuarter } from './isSameQuarter/index'; -export { default as isSameSecond } from './isSameSecond/index'; -export { default as isSameWeek } from './isSameWeek/index'; -export { default as isSameWeekWithOptions } from './isSameWeekWithOptions/index'; -export { default as isSameYear } from './isSameYear/index'; -export { default as isSaturday } from './isSaturday/index'; -export { default as isSunday } from './isSunday/index'; -export { default as isThursday } from './isThursday/index'; -export { default as isTuesday } from './isTuesday/index'; -export { default as isValid } from './isValid/index'; -export { default as isWednesday } from './isWednesday/index'; -export { default as isWeekend } from './isWeekend/index'; -export { default as isWithinInterval } from './isWithinInterval/index'; -export { default as lastDayOfDecade } from './lastDayOfDecade/index'; -export { default as lastDayOfISOWeek } from './lastDayOfISOWeek/index'; -export { default as lastDayOfISOWeekYear } from './lastDayOfISOWeekYear/index'; -export { default as lastDayOfMonth } from './lastDayOfMonth/index'; -export { default as lastDayOfQuarter } from './lastDayOfQuarter/index'; -export { default as lastDayOfQuarterWithOptions } from './lastDayOfQuarterWithOptions/index'; -export { default as lastDayOfWeek } from './lastDayOfWeek/index'; -export { default as lastDayOfWeekWithOptions } from './lastDayOfWeekWithOptions/index'; -export { default as lastDayOfYear } from './lastDayOfYear/index'; -export { default as lightFormat } from './lightFormat/index'; -export { default as max } from './max/index'; -export { default as milliseconds } from './milliseconds/index'; -export { default as millisecondsToHours } from './millisecondsToHours/index'; -export { default as millisecondsToMinutes } from './millisecondsToMinutes/index'; -export { default as millisecondsToSeconds } from './millisecondsToSeconds/index'; -export { default as min } from './min/index'; -export { default as minutesToHours } from './minutesToHours/index'; -export { default as minutesToMilliseconds } from './minutesToMilliseconds/index'; -export { default as minutesToSeconds } from './minutesToSeconds/index'; -export { default as monthsToQuarters } from './monthsToQuarters/index'; -export { default as monthsToYears } from './monthsToYears/index'; -export { default as nextDay } from './nextDay/index'; -export { default as nextFriday } from './nextFriday/index'; -export { default as nextMonday } from './nextMonday/index'; -export { default as nextSaturday } from './nextSaturday/index'; -export { default as nextSunday } from './nextSunday/index'; -export { default as nextThursday } from './nextThursday/index'; -export { default as nextTuesday } from './nextTuesday/index'; -export { default as nextWednesday } from './nextWednesday/index'; -export { default as parse } from './parse/index'; -export { default as parseISO } from './parseISO/index'; -export { default as parseISOWithOptions } from './parseISOWithOptions/index'; -export { default as parseJSON } from './parseJSON/index'; -export { default as parseWithOptions } from './parseWithOptions/index'; -export { default as previousDay } from './previousDay/index'; -export { default as previousFriday } from './previousFriday/index'; -export { default as previousMonday } from './previousMonday/index'; -export { default as previousSaturday } from './previousSaturday/index'; -export { default as previousSunday } from './previousSunday/index'; -export { default as previousThursday } from './previousThursday/index'; -export { default as previousTuesday } from './previousTuesday/index'; -export { default as previousWednesday } from './previousWednesday/index'; -export { default as quartersToMonths } from './quartersToMonths/index'; -export { default as quartersToYears } from './quartersToYears/index'; -export { default as roundToNearestMinutes } from './roundToNearestMinutes/index'; -export { default as roundToNearestMinutesWithOptions } from './roundToNearestMinutesWithOptions/index'; -export { default as secondsToHours } from './secondsToHours/index'; -export { default as secondsToMilliseconds } from './secondsToMilliseconds/index'; -export { default as secondsToMinutes } from './secondsToMinutes/index'; -export { default as set } from './set/index'; -export { default as setDate } from './setDate/index'; -export { default as setDay } from './setDay/index'; -export { default as setDayOfYear } from './setDayOfYear/index'; -export { default as setDayWithOptions } from './setDayWithOptions/index'; -export { default as setHours } from './setHours/index'; -export { default as setISODay } from './setISODay/index'; -export { default as setISOWeek } from './setISOWeek/index'; -export { default as setISOWeekYear } from './setISOWeekYear/index'; -export { default as setMilliseconds } from './setMilliseconds/index'; -export { default as setMinutes } from './setMinutes/index'; -export { default as setMonth } from './setMonth/index'; -export { default as setQuarter } from './setQuarter/index'; -export { default as setSeconds } from './setSeconds/index'; -export { default as setWeek } from './setWeek/index'; -export { default as setWeekWithOptions } from './setWeekWithOptions/index'; -export { default as setWeekYear } from './setWeekYear/index'; -export { default as setWeekYearWithOptions } from './setWeekYearWithOptions/index'; -export { default as setYear } from './setYear/index'; -export { default as startOfDay } from './startOfDay/index'; -export { default as startOfDecade } from './startOfDecade/index'; -export { default as startOfHour } from './startOfHour/index'; -export { default as startOfISOWeek } from './startOfISOWeek/index'; -export { default as startOfISOWeekYear } from './startOfISOWeekYear/index'; -export { default as startOfMinute } from './startOfMinute/index'; -export { default as startOfMonth } from './startOfMonth/index'; -export { default as startOfQuarter } from './startOfQuarter/index'; -export { default as startOfSecond } from './startOfSecond/index'; -export { default as startOfWeek } from './startOfWeek/index'; -export { default as startOfWeekWithOptions } from './startOfWeekWithOptions/index'; -export { default as startOfWeekYear } from './startOfWeekYear/index'; -export { default as startOfWeekYearWithOptions } from './startOfWeekYearWithOptions/index'; -export { default as startOfYear } from './startOfYear/index'; -export { default as sub } from './sub/index'; -export { default as subBusinessDays } from './subBusinessDays/index'; -export { default as subDays } from './subDays/index'; -export { default as subHours } from './subHours/index'; -export { default as subISOWeekYears } from './subISOWeekYears/index'; -export { default as subMilliseconds } from './subMilliseconds/index'; -export { default as subMinutes } from './subMinutes/index'; -export { default as subMonths } from './subMonths/index'; -export { default as subQuarters } from './subQuarters/index'; -export { default as subSeconds } from './subSeconds/index'; -export { default as subWeeks } from './subWeeks/index'; -export { default as subYears } from './subYears/index'; -export { default as toDate } from './toDate/index'; -export { default as weeksToDays } from './weeksToDays/index'; -export { default as yearsToMonths } from './yearsToMonths/index'; -export { default as yearsToQuarters } from './yearsToQuarters/index'; -export * from '../constants/index'; +export * from './add/index'; +export * from './addBusinessDays/index'; +export * from './addDays/index'; +export * from './addHours/index'; +export * from './addISOWeekYears/index'; +export * from './addMilliseconds/index'; +export * from './addMinutes/index'; +export * from './addMonths/index'; +export * from './addQuarters/index'; +export * from './addSeconds/index'; +export * from './addWeeks/index'; +export * from './addYears/index'; +export * from './areIntervalsOverlapping/index'; +export * from './areIntervalsOverlappingWithOptions/index'; +export * from './clamp/index'; +export * from './closestIndexTo/index'; +export * from './closestTo/index'; +export * from './compareAsc/index'; +export * from './compareDesc/index'; +export * from './constructFrom/index'; +export * from './daysToWeeks/index'; +export * from './differenceInBusinessDays/index'; +export * from './differenceInCalendarDays/index'; +export * from './differenceInCalendarISOWeekYears/index'; +export * from './differenceInCalendarISOWeeks/index'; +export * from './differenceInCalendarMonths/index'; +export * from './differenceInCalendarQuarters/index'; +export * from './differenceInCalendarWeeks/index'; +export * from './differenceInCalendarWeeksWithOptions/index'; +export * from './differenceInCalendarYears/index'; +export * from './differenceInDays/index'; +export * from './differenceInHours/index'; +export * from './differenceInHoursWithOptions/index'; +export * from './differenceInISOWeekYears/index'; +export * from './differenceInMilliseconds/index'; +export * from './differenceInMinutes/index'; +export * from './differenceInMinutesWithOptions/index'; +export * from './differenceInMonths/index'; +export * from './differenceInQuarters/index'; +export * from './differenceInQuartersWithOptions/index'; +export * from './differenceInSeconds/index'; +export * from './differenceInSecondsWithOptions/index'; +export * from './differenceInWeeks/index'; +export * from './differenceInWeeksWithOptions/index'; +export * from './differenceInYears/index'; +export * from './eachDayOfInterval/index'; +export * from './eachDayOfIntervalWithOptions/index'; +export * from './eachHourOfInterval/index'; +export * from './eachHourOfIntervalWithOptions/index'; +export * from './eachMinuteOfInterval/index'; +export * from './eachMinuteOfIntervalWithOptions/index'; +export * from './eachMonthOfInterval/index'; +export * from './eachMonthOfIntervalWithOptions/index'; +export * from './eachQuarterOfInterval/index'; +export * from './eachQuarterOfIntervalWithOptions/index'; +export * from './eachWeekOfInterval/index'; +export * from './eachWeekOfIntervalWithOptions/index'; +export * from './eachWeekendOfInterval/index'; +export * from './eachWeekendOfMonth/index'; +export * from './eachWeekendOfYear/index'; +export * from './eachYearOfInterval/index'; +export * from './eachYearOfIntervalWithOptions/index'; +export * from './endOfDay/index'; +export * from './endOfDecade/index'; +export * from './endOfHour/index'; +export * from './endOfISOWeek/index'; +export * from './endOfISOWeekYear/index'; +export * from './endOfMinute/index'; +export * from './endOfMonth/index'; +export * from './endOfQuarter/index'; +export * from './endOfSecond/index'; +export * from './endOfWeek/index'; +export * from './endOfWeekWithOptions/index'; +export * from './endOfYear/index'; +export * from './format/index'; +export * from './formatDistance/index'; +export * from './formatDistanceStrict/index'; +export * from './formatDistanceStrictWithOptions/index'; +export * from './formatDistanceWithOptions/index'; +export * from './formatDuration/index'; +export * from './formatDurationWithOptions/index'; +export * from './formatISO/index'; +export * from './formatISO9075/index'; +export * from './formatISO9075WithOptions/index'; +export * from './formatISODuration/index'; +export * from './formatISOWithOptions/index'; +export * from './formatRFC3339/index'; +export * from './formatRFC3339WithOptions/index'; +export * from './formatRFC7231/index'; +export * from './formatRelative/index'; +export * from './formatRelativeWithOptions/index'; +export * from './formatWithOptions/index'; +export * from './fromUnixTime/index'; +export * from './getDate/index'; +export * from './getDay/index'; +export * from './getDayOfYear/index'; +export * from './getDaysInMonth/index'; +export * from './getDaysInYear/index'; +export * from './getDecade/index'; +export * from './getHours/index'; +export * from './getISODay/index'; +export * from './getISOWeek/index'; +export * from './getISOWeekYear/index'; +export * from './getISOWeeksInYear/index'; +export * from './getMilliseconds/index'; +export * from './getMinutes/index'; +export * from './getMonth/index'; +export * from './getOverlappingDaysInIntervals/index'; +export * from './getQuarter/index'; +export * from './getSeconds/index'; +export * from './getTime/index'; +export * from './getUnixTime/index'; +export * from './getWeek/index'; +export * from './getWeekOfMonth/index'; +export * from './getWeekOfMonthWithOptions/index'; +export * from './getWeekWithOptions/index'; +export * from './getWeekYear/index'; +export * from './getWeekYearWithOptions/index'; +export * from './getWeeksInMonth/index'; +export * from './getWeeksInMonthWithOptions/index'; +export * from './getYear/index'; +export * from './hoursToMilliseconds/index'; +export * from './hoursToMinutes/index'; +export * from './hoursToSeconds/index'; +export * from './interval/index'; +export * from './intervalToDuration/index'; +export * from './intervalWithOptions/index'; +export * from './intlFormat/index'; +export * from './intlFormatDistance/index'; +export * from './intlFormatDistanceWithOptions/index'; +export * from './isAfter/index'; +export * from './isBefore/index'; +export * from './isDate/index'; +export * from './isEqual/index'; +export * from './isExists/index'; +export * from './isFirstDayOfMonth/index'; +export * from './isFriday/index'; +export * from './isLastDayOfMonth/index'; +export * from './isLeapYear/index'; +export * from './isMatch/index'; +export * from './isMatchWithOptions/index'; +export * from './isMonday/index'; +export * from './isSameDay/index'; +export * from './isSameHour/index'; +export * from './isSameISOWeek/index'; +export * from './isSameISOWeekYear/index'; +export * from './isSameMinute/index'; +export * from './isSameMonth/index'; +export * from './isSameQuarter/index'; +export * from './isSameSecond/index'; +export * from './isSameWeek/index'; +export * from './isSameWeekWithOptions/index'; +export * from './isSameYear/index'; +export * from './isSaturday/index'; +export * from './isSunday/index'; +export * from './isThursday/index'; +export * from './isTuesday/index'; +export * from './isValid/index'; +export * from './isWednesday/index'; +export * from './isWeekend/index'; +export * from './isWithinInterval/index'; +export * from './lastDayOfDecade/index'; +export * from './lastDayOfISOWeek/index'; +export * from './lastDayOfISOWeekYear/index'; +export * from './lastDayOfMonth/index'; +export * from './lastDayOfQuarter/index'; +export * from './lastDayOfWeek/index'; +export * from './lastDayOfWeekWithOptions/index'; +export * from './lastDayOfYear/index'; +export * from './lightFormat/index'; +export * from './max/index'; +export * from './milliseconds/index'; +export * from './millisecondsToHours/index'; +export * from './millisecondsToMinutes/index'; +export * from './millisecondsToSeconds/index'; +export * from './min/index'; +export * from './minutesToHours/index'; +export * from './minutesToMilliseconds/index'; +export * from './minutesToSeconds/index'; +export * from './monthsToQuarters/index'; +export * from './monthsToYears/index'; +export * from './nextDay/index'; +export * from './nextFriday/index'; +export * from './nextMonday/index'; +export * from './nextSaturday/index'; +export * from './nextSunday/index'; +export * from './nextThursday/index'; +export * from './nextTuesday/index'; +export * from './nextWednesday/index'; +export * from './parse/index'; +export * from './parseISO/index'; +export * from './parseISOWithOptions/index'; +export * from './parseJSON/index'; +export * from './parseWithOptions/index'; +export * from './previousDay/index'; +export * from './previousFriday/index'; +export * from './previousMonday/index'; +export * from './previousSaturday/index'; +export * from './previousSunday/index'; +export * from './previousThursday/index'; +export * from './previousTuesday/index'; +export * from './previousWednesday/index'; +export * from './quartersToMonths/index'; +export * from './quartersToYears/index'; +export * from './roundToNearestHours/index'; +export * from './roundToNearestHoursWithOptions/index'; +export * from './roundToNearestMinutes/index'; +export * from './roundToNearestMinutesWithOptions/index'; +export * from './secondsToHours/index'; +export * from './secondsToMilliseconds/index'; +export * from './secondsToMinutes/index'; +export * from './set/index'; +export * from './setDate/index'; +export * from './setDay/index'; +export * from './setDayOfYear/index'; +export * from './setDayWithOptions/index'; +export * from './setHours/index'; +export * from './setISODay/index'; +export * from './setISOWeek/index'; +export * from './setISOWeekYear/index'; +export * from './setMilliseconds/index'; +export * from './setMinutes/index'; +export * from './setMonth/index'; +export * from './setQuarter/index'; +export * from './setSeconds/index'; +export * from './setWeek/index'; +export * from './setWeekWithOptions/index'; +export * from './setWeekYear/index'; +export * from './setWeekYearWithOptions/index'; +export * from './setYear/index'; +export * from './startOfDay/index'; +export * from './startOfDecade/index'; +export * from './startOfHour/index'; +export * from './startOfISOWeek/index'; +export * from './startOfISOWeekYear/index'; +export * from './startOfMinute/index'; +export * from './startOfMonth/index'; +export * from './startOfQuarter/index'; +export * from './startOfSecond/index'; +export * from './startOfWeek/index'; +export * from './startOfWeekWithOptions/index'; +export * from './startOfWeekYear/index'; +export * from './startOfWeekYearWithOptions/index'; +export * from './startOfYear/index'; +export * from './sub/index'; +export * from './subBusinessDays/index'; +export * from './subDays/index'; +export * from './subHours/index'; +export * from './subISOWeekYears/index'; +export * from './subMilliseconds/index'; +export * from './subMinutes/index'; +export * from './subMonths/index'; +export * from './subQuarters/index'; +export * from './subSeconds/index'; +export * from './subWeeks/index'; +export * from './subYears/index'; +export * from './toDate/index'; +export * from './transpose/index'; +export * from './weeksToDays/index'; +export * from './yearsToDays/index'; +export * from './yearsToMonths/index'; +export * from './yearsToQuarters/index'; +export type * from '../types'; diff --git a/src/date-fns/fp/interval/index.ts b/src/date-fns/fp/interval/index.ts new file mode 100644 index 0000000..534730f --- /dev/null +++ b/src/date-fns/fp/interval/index.ts @@ -0,0 +1,6 @@ +// This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. + +import { interval as fn } from '../../interval/index'; +import { convertToFP } from '../_lib/convertToFP/index'; + +export const interval = convertToFP(fn, 2); diff --git a/src/date-fns/fp/intervalToDuration/index.ts b/src/date-fns/fp/intervalToDuration/index.ts index 6776165..36b5557 100644 --- a/src/date-fns/fp/intervalToDuration/index.ts +++ b/src/date-fns/fp/intervalToDuration/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../intervalToDuration/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { intervalToDuration as fn } from '../../intervalToDuration/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const intervalToDuration = convertToFP(fn, 1); diff --git a/src/date-fns/fp/intervalWithOptions/index.ts b/src/date-fns/fp/intervalWithOptions/index.ts new file mode 100644 index 0000000..f8d42f5 --- /dev/null +++ b/src/date-fns/fp/intervalWithOptions/index.ts @@ -0,0 +1,6 @@ +// This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. + +import { interval as fn } from '../../interval/index'; +import { convertToFP } from '../_lib/convertToFP/index'; + +export const intervalWithOptions = convertToFP(fn, 3); diff --git a/src/date-fns/fp/intlFormat/index.ts b/src/date-fns/fp/intlFormat/index.ts index 1550693..8a19a58 100644 --- a/src/date-fns/fp/intlFormat/index.ts +++ b/src/date-fns/fp/intlFormat/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../intlFormat/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { intlFormat as fn } from '../../intlFormat/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 3); +export const intlFormat = convertToFP(fn, 3); diff --git a/src/date-fns/fp/intlFormatDistance/index.ts b/src/date-fns/fp/intlFormatDistance/index.ts index ab4e4d4..81ee1c0 100644 --- a/src/date-fns/fp/intlFormatDistance/index.ts +++ b/src/date-fns/fp/intlFormatDistance/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../intlFormatDistance/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { intlFormatDistance as fn } from '../../intlFormatDistance/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const intlFormatDistance = convertToFP(fn, 2); diff --git a/src/date-fns/fp/intlFormatDistanceWithOptions/index.ts b/src/date-fns/fp/intlFormatDistanceWithOptions/index.ts index 3fc6b80..9950e17 100644 --- a/src/date-fns/fp/intlFormatDistanceWithOptions/index.ts +++ b/src/date-fns/fp/intlFormatDistanceWithOptions/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../intlFormatDistance/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { intlFormatDistance as fn } from '../../intlFormatDistance/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 3); +export const intlFormatDistanceWithOptions = convertToFP(fn, 3); diff --git a/src/date-fns/fp/isAfter/index.ts b/src/date-fns/fp/isAfter/index.ts index a367ba2..fc72f28 100644 --- a/src/date-fns/fp/isAfter/index.ts +++ b/src/date-fns/fp/isAfter/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../isAfter/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { isAfter as fn } from '../../isAfter/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const isAfter = convertToFP(fn, 2); diff --git a/src/date-fns/fp/isBefore/index.ts b/src/date-fns/fp/isBefore/index.ts index c3e74e0..f8d2d3b 100644 --- a/src/date-fns/fp/isBefore/index.ts +++ b/src/date-fns/fp/isBefore/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../isBefore/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { isBefore as fn } from '../../isBefore/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const isBefore = convertToFP(fn, 2); diff --git a/src/date-fns/fp/isDate/index.ts b/src/date-fns/fp/isDate/index.ts index b5b2a79..cbeffe9 100644 --- a/src/date-fns/fp/isDate/index.ts +++ b/src/date-fns/fp/isDate/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../isDate/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { isDate as fn } from '../../isDate/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const isDate = convertToFP(fn, 1); diff --git a/src/date-fns/fp/isEqual/index.ts b/src/date-fns/fp/isEqual/index.ts index 02d5596..43755e5 100644 --- a/src/date-fns/fp/isEqual/index.ts +++ b/src/date-fns/fp/isEqual/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../isEqual/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { isEqual as fn } from '../../isEqual/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const isEqual = convertToFP(fn, 2); diff --git a/src/date-fns/fp/isExists/index.ts b/src/date-fns/fp/isExists/index.ts index 84e7728..1abc3b2 100644 --- a/src/date-fns/fp/isExists/index.ts +++ b/src/date-fns/fp/isExists/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../isExists/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { isExists as fn } from '../../isExists/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 3); +export const isExists = convertToFP(fn, 3); diff --git a/src/date-fns/fp/isFirstDayOfMonth/index.ts b/src/date-fns/fp/isFirstDayOfMonth/index.ts index 995f2c5..67ac38a 100644 --- a/src/date-fns/fp/isFirstDayOfMonth/index.ts +++ b/src/date-fns/fp/isFirstDayOfMonth/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../isFirstDayOfMonth/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { isFirstDayOfMonth as fn } from '../../isFirstDayOfMonth/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const isFirstDayOfMonth = convertToFP(fn, 1); diff --git a/src/date-fns/fp/isFriday/index.ts b/src/date-fns/fp/isFriday/index.ts index 2c44883..e045d75 100644 --- a/src/date-fns/fp/isFriday/index.ts +++ b/src/date-fns/fp/isFriday/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../isFriday/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { isFriday as fn } from '../../isFriday/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const isFriday = convertToFP(fn, 1); diff --git a/src/date-fns/fp/isLastDayOfMonth/index.ts b/src/date-fns/fp/isLastDayOfMonth/index.ts index d77bb28..340b09e 100644 --- a/src/date-fns/fp/isLastDayOfMonth/index.ts +++ b/src/date-fns/fp/isLastDayOfMonth/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../isLastDayOfMonth/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { isLastDayOfMonth as fn } from '../../isLastDayOfMonth/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const isLastDayOfMonth = convertToFP(fn, 1); diff --git a/src/date-fns/fp/isLeapYear/index.ts b/src/date-fns/fp/isLeapYear/index.ts index 70ceda0..d546fea 100644 --- a/src/date-fns/fp/isLeapYear/index.ts +++ b/src/date-fns/fp/isLeapYear/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../isLeapYear/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { isLeapYear as fn } from '../../isLeapYear/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const isLeapYear = convertToFP(fn, 1); diff --git a/src/date-fns/fp/isMatch/index.ts b/src/date-fns/fp/isMatch/index.ts index 9499def..96974d0 100644 --- a/src/date-fns/fp/isMatch/index.ts +++ b/src/date-fns/fp/isMatch/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../isMatch/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { isMatch as fn } from '../../isMatch/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const isMatch = convertToFP(fn, 2); diff --git a/src/date-fns/fp/isMatchWithOptions/index.ts b/src/date-fns/fp/isMatchWithOptions/index.ts index 0e52841..97895b9 100644 --- a/src/date-fns/fp/isMatchWithOptions/index.ts +++ b/src/date-fns/fp/isMatchWithOptions/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../isMatch/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { isMatch as fn } from '../../isMatch/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 3); +export const isMatchWithOptions = convertToFP(fn, 3); diff --git a/src/date-fns/fp/isMonday/index.ts b/src/date-fns/fp/isMonday/index.ts index c18b80e..4b3c6e5 100644 --- a/src/date-fns/fp/isMonday/index.ts +++ b/src/date-fns/fp/isMonday/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../isMonday/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { isMonday as fn } from '../../isMonday/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const isMonday = convertToFP(fn, 1); diff --git a/src/date-fns/fp/isSameDay/index.ts b/src/date-fns/fp/isSameDay/index.ts index d6886ad..6a866ca 100644 --- a/src/date-fns/fp/isSameDay/index.ts +++ b/src/date-fns/fp/isSameDay/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../isSameDay/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { isSameDay as fn } from '../../isSameDay/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const isSameDay = convertToFP(fn, 2); diff --git a/src/date-fns/fp/isSameHour/index.ts b/src/date-fns/fp/isSameHour/index.ts index 63c9f25..163ef54 100644 --- a/src/date-fns/fp/isSameHour/index.ts +++ b/src/date-fns/fp/isSameHour/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../isSameHour/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { isSameHour as fn } from '../../isSameHour/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const isSameHour = convertToFP(fn, 2); diff --git a/src/date-fns/fp/isSameISOWeek/index.ts b/src/date-fns/fp/isSameISOWeek/index.ts index 26caf21..dd61875 100644 --- a/src/date-fns/fp/isSameISOWeek/index.ts +++ b/src/date-fns/fp/isSameISOWeek/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../isSameISOWeek/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { isSameISOWeek as fn } from '../../isSameISOWeek/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const isSameISOWeek = convertToFP(fn, 2); diff --git a/src/date-fns/fp/isSameISOWeekYear/index.ts b/src/date-fns/fp/isSameISOWeekYear/index.ts index 39272b4..74daef7 100644 --- a/src/date-fns/fp/isSameISOWeekYear/index.ts +++ b/src/date-fns/fp/isSameISOWeekYear/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../isSameISOWeekYear/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { isSameISOWeekYear as fn } from '../../isSameISOWeekYear/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const isSameISOWeekYear = convertToFP(fn, 2); diff --git a/src/date-fns/fp/isSameMinute/index.ts b/src/date-fns/fp/isSameMinute/index.ts index 2a6f289..3cc58f0 100644 --- a/src/date-fns/fp/isSameMinute/index.ts +++ b/src/date-fns/fp/isSameMinute/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../isSameMinute/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { isSameMinute as fn } from '../../isSameMinute/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const isSameMinute = convertToFP(fn, 2); diff --git a/src/date-fns/fp/isSameMonth/index.ts b/src/date-fns/fp/isSameMonth/index.ts index 4c77bd7..91e0400 100644 --- a/src/date-fns/fp/isSameMonth/index.ts +++ b/src/date-fns/fp/isSameMonth/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../isSameMonth/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { isSameMonth as fn } from '../../isSameMonth/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const isSameMonth = convertToFP(fn, 2); diff --git a/src/date-fns/fp/isSameQuarter/index.ts b/src/date-fns/fp/isSameQuarter/index.ts index 3d2ae58..d689209 100644 --- a/src/date-fns/fp/isSameQuarter/index.ts +++ b/src/date-fns/fp/isSameQuarter/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../isSameQuarter/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { isSameQuarter as fn } from '../../isSameQuarter/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const isSameQuarter = convertToFP(fn, 2); diff --git a/src/date-fns/fp/isSameSecond/index.ts b/src/date-fns/fp/isSameSecond/index.ts index 6aeab67..b84ff61 100644 --- a/src/date-fns/fp/isSameSecond/index.ts +++ b/src/date-fns/fp/isSameSecond/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../isSameSecond/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { isSameSecond as fn } from '../../isSameSecond/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const isSameSecond = convertToFP(fn, 2); diff --git a/src/date-fns/fp/isSameWeek/index.ts b/src/date-fns/fp/isSameWeek/index.ts index 8c3e0be..1d42732 100644 --- a/src/date-fns/fp/isSameWeek/index.ts +++ b/src/date-fns/fp/isSameWeek/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../isSameWeek/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { isSameWeek as fn } from '../../isSameWeek/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const isSameWeek = convertToFP(fn, 2); diff --git a/src/date-fns/fp/isSameWeekWithOptions/index.ts b/src/date-fns/fp/isSameWeekWithOptions/index.ts index 4da0c6a..3493e62 100644 --- a/src/date-fns/fp/isSameWeekWithOptions/index.ts +++ b/src/date-fns/fp/isSameWeekWithOptions/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../isSameWeek/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { isSameWeek as fn } from '../../isSameWeek/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 3); +export const isSameWeekWithOptions = convertToFP(fn, 3); diff --git a/src/date-fns/fp/isSameYear/index.ts b/src/date-fns/fp/isSameYear/index.ts index 1d24895..db1ebc5 100644 --- a/src/date-fns/fp/isSameYear/index.ts +++ b/src/date-fns/fp/isSameYear/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../isSameYear/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { isSameYear as fn } from '../../isSameYear/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const isSameYear = convertToFP(fn, 2); diff --git a/src/date-fns/fp/isSaturday/index.ts b/src/date-fns/fp/isSaturday/index.ts index 9e67e14..7a84666 100644 --- a/src/date-fns/fp/isSaturday/index.ts +++ b/src/date-fns/fp/isSaturday/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../isSaturday/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { isSaturday as fn } from '../../isSaturday/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const isSaturday = convertToFP(fn, 1); diff --git a/src/date-fns/fp/isSunday/index.ts b/src/date-fns/fp/isSunday/index.ts index 8fc42c5..cbc1d7e 100644 --- a/src/date-fns/fp/isSunday/index.ts +++ b/src/date-fns/fp/isSunday/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../isSunday/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { isSunday as fn } from '../../isSunday/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const isSunday = convertToFP(fn, 1); diff --git a/src/date-fns/fp/isThursday/index.ts b/src/date-fns/fp/isThursday/index.ts index f2ceae7..91211fd 100644 --- a/src/date-fns/fp/isThursday/index.ts +++ b/src/date-fns/fp/isThursday/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../isThursday/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { isThursday as fn } from '../../isThursday/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const isThursday = convertToFP(fn, 1); diff --git a/src/date-fns/fp/isTuesday/index.ts b/src/date-fns/fp/isTuesday/index.ts index d5a9378..b0fcc87 100644 --- a/src/date-fns/fp/isTuesday/index.ts +++ b/src/date-fns/fp/isTuesday/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../isTuesday/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { isTuesday as fn } from '../../isTuesday/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const isTuesday = convertToFP(fn, 1); diff --git a/src/date-fns/fp/isValid/index.ts b/src/date-fns/fp/isValid/index.ts index bcdedcd..99e6181 100644 --- a/src/date-fns/fp/isValid/index.ts +++ b/src/date-fns/fp/isValid/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../isValid/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { isValid as fn } from '../../isValid/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const isValid = convertToFP(fn, 1); diff --git a/src/date-fns/fp/isWednesday/index.ts b/src/date-fns/fp/isWednesday/index.ts index 0d8de01..ec3d892 100644 --- a/src/date-fns/fp/isWednesday/index.ts +++ b/src/date-fns/fp/isWednesday/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../isWednesday/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { isWednesday as fn } from '../../isWednesday/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const isWednesday = convertToFP(fn, 1); diff --git a/src/date-fns/fp/isWeekend/index.ts b/src/date-fns/fp/isWeekend/index.ts index 5574a2d..70195e5 100644 --- a/src/date-fns/fp/isWeekend/index.ts +++ b/src/date-fns/fp/isWeekend/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../isWeekend/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { isWeekend as fn } from '../../isWeekend/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const isWeekend = convertToFP(fn, 1); diff --git a/src/date-fns/fp/isWithinInterval/index.ts b/src/date-fns/fp/isWithinInterval/index.ts index 85feb79..a91bcb3 100644 --- a/src/date-fns/fp/isWithinInterval/index.ts +++ b/src/date-fns/fp/isWithinInterval/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../isWithinInterval/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { isWithinInterval as fn } from '../../isWithinInterval/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const isWithinInterval = convertToFP(fn, 2); diff --git a/src/date-fns/fp/lastDayOfDecade/index.ts b/src/date-fns/fp/lastDayOfDecade/index.ts index 16b376f..c949c79 100644 --- a/src/date-fns/fp/lastDayOfDecade/index.ts +++ b/src/date-fns/fp/lastDayOfDecade/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../lastDayOfDecade/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { lastDayOfDecade as fn } from '../../lastDayOfDecade/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const lastDayOfDecade = convertToFP(fn, 1); diff --git a/src/date-fns/fp/lastDayOfISOWeek/index.ts b/src/date-fns/fp/lastDayOfISOWeek/index.ts index 0a15f82..89ddeb3 100644 --- a/src/date-fns/fp/lastDayOfISOWeek/index.ts +++ b/src/date-fns/fp/lastDayOfISOWeek/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../lastDayOfISOWeek/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { lastDayOfISOWeek as fn } from '../../lastDayOfISOWeek/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const lastDayOfISOWeek = convertToFP(fn, 1); diff --git a/src/date-fns/fp/lastDayOfISOWeekYear/index.ts b/src/date-fns/fp/lastDayOfISOWeekYear/index.ts index 8e022b5..62c5ece 100644 --- a/src/date-fns/fp/lastDayOfISOWeekYear/index.ts +++ b/src/date-fns/fp/lastDayOfISOWeekYear/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../lastDayOfISOWeekYear/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { lastDayOfISOWeekYear as fn } from '../../lastDayOfISOWeekYear/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const lastDayOfISOWeekYear = convertToFP(fn, 1); diff --git a/src/date-fns/fp/lastDayOfMonth/index.ts b/src/date-fns/fp/lastDayOfMonth/index.ts index e64f4ce..d23909e 100644 --- a/src/date-fns/fp/lastDayOfMonth/index.ts +++ b/src/date-fns/fp/lastDayOfMonth/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../lastDayOfMonth/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { lastDayOfMonth as fn } from '../../lastDayOfMonth/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const lastDayOfMonth = convertToFP(fn, 1); diff --git a/src/date-fns/fp/lastDayOfQuarter/index.ts b/src/date-fns/fp/lastDayOfQuarter/index.ts index e9ade34..3817b8b 100644 --- a/src/date-fns/fp/lastDayOfQuarter/index.ts +++ b/src/date-fns/fp/lastDayOfQuarter/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../lastDayOfQuarter/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { lastDayOfQuarter as fn } from '../../lastDayOfQuarter/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const lastDayOfQuarter = convertToFP(fn, 1); diff --git a/src/date-fns/fp/lastDayOfQuarterWithOptions/index.ts b/src/date-fns/fp/lastDayOfQuarterWithOptions/index.ts deleted file mode 100644 index 31507e9..0000000 --- a/src/date-fns/fp/lastDayOfQuarterWithOptions/index.ts +++ /dev/null @@ -1,6 +0,0 @@ -// This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. - -import fn from '../../lastDayOfQuarter/index'; -import convertToFP from '../_lib/convertToFP/index'; - -export default convertToFP(fn, 2); diff --git a/src/date-fns/fp/lastDayOfWeek/index.ts b/src/date-fns/fp/lastDayOfWeek/index.ts index dc0a4a6..484b8d5 100644 --- a/src/date-fns/fp/lastDayOfWeek/index.ts +++ b/src/date-fns/fp/lastDayOfWeek/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../lastDayOfWeek/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { lastDayOfWeek as fn } from '../../lastDayOfWeek/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const lastDayOfWeek = convertToFP(fn, 1); diff --git a/src/date-fns/fp/lastDayOfWeekWithOptions/index.ts b/src/date-fns/fp/lastDayOfWeekWithOptions/index.ts index c7e5850..f32f2d4 100644 --- a/src/date-fns/fp/lastDayOfWeekWithOptions/index.ts +++ b/src/date-fns/fp/lastDayOfWeekWithOptions/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../lastDayOfWeek/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { lastDayOfWeek as fn } from '../../lastDayOfWeek/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const lastDayOfWeekWithOptions = convertToFP(fn, 2); diff --git a/src/date-fns/fp/lastDayOfYear/index.ts b/src/date-fns/fp/lastDayOfYear/index.ts index ab6bef1..fb98cdc 100644 --- a/src/date-fns/fp/lastDayOfYear/index.ts +++ b/src/date-fns/fp/lastDayOfYear/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../lastDayOfYear/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { lastDayOfYear as fn } from '../../lastDayOfYear/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const lastDayOfYear = convertToFP(fn, 1); diff --git a/src/date-fns/fp/lightFormat/index.ts b/src/date-fns/fp/lightFormat/index.ts index 3caa58d..9c21351 100644 --- a/src/date-fns/fp/lightFormat/index.ts +++ b/src/date-fns/fp/lightFormat/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../lightFormat/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { lightFormat as fn } from '../../lightFormat/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const lightFormat = convertToFP(fn, 2); diff --git a/src/date-fns/fp/max/index.ts b/src/date-fns/fp/max/index.ts index 029699f..aab8ffb 100644 --- a/src/date-fns/fp/max/index.ts +++ b/src/date-fns/fp/max/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../max/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { max as fn } from '../../max/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const max = convertToFP(fn, 1); diff --git a/src/date-fns/fp/milliseconds/index.ts b/src/date-fns/fp/milliseconds/index.ts index f5d384c..d9f76d8 100644 --- a/src/date-fns/fp/milliseconds/index.ts +++ b/src/date-fns/fp/milliseconds/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../milliseconds/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { milliseconds as fn } from '../../milliseconds/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const milliseconds = convertToFP(fn, 1); diff --git a/src/date-fns/fp/millisecondsToHours/index.ts b/src/date-fns/fp/millisecondsToHours/index.ts index d261313..4f18564 100644 --- a/src/date-fns/fp/millisecondsToHours/index.ts +++ b/src/date-fns/fp/millisecondsToHours/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../millisecondsToHours/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { millisecondsToHours as fn } from '../../millisecondsToHours/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const millisecondsToHours = convertToFP(fn, 1); diff --git a/src/date-fns/fp/millisecondsToMinutes/index.ts b/src/date-fns/fp/millisecondsToMinutes/index.ts index 0bf2bda..b640264 100644 --- a/src/date-fns/fp/millisecondsToMinutes/index.ts +++ b/src/date-fns/fp/millisecondsToMinutes/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../millisecondsToMinutes/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { millisecondsToMinutes as fn } from '../../millisecondsToMinutes/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const millisecondsToMinutes = convertToFP(fn, 1); diff --git a/src/date-fns/fp/millisecondsToSeconds/index.ts b/src/date-fns/fp/millisecondsToSeconds/index.ts index 7a97bd8..8368f77 100644 --- a/src/date-fns/fp/millisecondsToSeconds/index.ts +++ b/src/date-fns/fp/millisecondsToSeconds/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../millisecondsToSeconds/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { millisecondsToSeconds as fn } from '../../millisecondsToSeconds/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const millisecondsToSeconds = convertToFP(fn, 1); diff --git a/src/date-fns/fp/min/index.ts b/src/date-fns/fp/min/index.ts index 316a2ce..7338580 100644 --- a/src/date-fns/fp/min/index.ts +++ b/src/date-fns/fp/min/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../min/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { min as fn } from '../../min/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const min = convertToFP(fn, 1); diff --git a/src/date-fns/fp/minutesToHours/index.ts b/src/date-fns/fp/minutesToHours/index.ts index 2a8c6f1..900d645 100644 --- a/src/date-fns/fp/minutesToHours/index.ts +++ b/src/date-fns/fp/minutesToHours/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../minutesToHours/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { minutesToHours as fn } from '../../minutesToHours/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const minutesToHours = convertToFP(fn, 1); diff --git a/src/date-fns/fp/minutesToMilliseconds/index.ts b/src/date-fns/fp/minutesToMilliseconds/index.ts index 8af578d..18aa899 100644 --- a/src/date-fns/fp/minutesToMilliseconds/index.ts +++ b/src/date-fns/fp/minutesToMilliseconds/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../minutesToMilliseconds/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { minutesToMilliseconds as fn } from '../../minutesToMilliseconds/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const minutesToMilliseconds = convertToFP(fn, 1); diff --git a/src/date-fns/fp/minutesToSeconds/index.ts b/src/date-fns/fp/minutesToSeconds/index.ts index f9afcbc..7586fe0 100644 --- a/src/date-fns/fp/minutesToSeconds/index.ts +++ b/src/date-fns/fp/minutesToSeconds/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../minutesToSeconds/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { minutesToSeconds as fn } from '../../minutesToSeconds/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const minutesToSeconds = convertToFP(fn, 1); diff --git a/src/date-fns/fp/monthsToQuarters/index.ts b/src/date-fns/fp/monthsToQuarters/index.ts index d7d86f8..bf524f3 100644 --- a/src/date-fns/fp/monthsToQuarters/index.ts +++ b/src/date-fns/fp/monthsToQuarters/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../monthsToQuarters/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { monthsToQuarters as fn } from '../../monthsToQuarters/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const monthsToQuarters = convertToFP(fn, 1); diff --git a/src/date-fns/fp/monthsToYears/index.ts b/src/date-fns/fp/monthsToYears/index.ts index cd54797..8b20671 100644 --- a/src/date-fns/fp/monthsToYears/index.ts +++ b/src/date-fns/fp/monthsToYears/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../monthsToYears/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { monthsToYears as fn } from '../../monthsToYears/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const monthsToYears = convertToFP(fn, 1); diff --git a/src/date-fns/fp/nextDay/index.ts b/src/date-fns/fp/nextDay/index.ts index ecc204c..4930a01 100644 --- a/src/date-fns/fp/nextDay/index.ts +++ b/src/date-fns/fp/nextDay/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../nextDay/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { nextDay as fn } from '../../nextDay/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const nextDay = convertToFP(fn, 2); diff --git a/src/date-fns/fp/nextFriday/index.ts b/src/date-fns/fp/nextFriday/index.ts index a14adcc..f590ea7 100644 --- a/src/date-fns/fp/nextFriday/index.ts +++ b/src/date-fns/fp/nextFriday/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../nextFriday/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { nextFriday as fn } from '../../nextFriday/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const nextFriday = convertToFP(fn, 1); diff --git a/src/date-fns/fp/nextMonday/index.ts b/src/date-fns/fp/nextMonday/index.ts index 5ff01cc..efb5d2b 100644 --- a/src/date-fns/fp/nextMonday/index.ts +++ b/src/date-fns/fp/nextMonday/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../nextMonday/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { nextMonday as fn } from '../../nextMonday/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const nextMonday = convertToFP(fn, 1); diff --git a/src/date-fns/fp/nextSaturday/index.ts b/src/date-fns/fp/nextSaturday/index.ts index 6886b9f..d3be636 100644 --- a/src/date-fns/fp/nextSaturday/index.ts +++ b/src/date-fns/fp/nextSaturday/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../nextSaturday/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { nextSaturday as fn } from '../../nextSaturday/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const nextSaturday = convertToFP(fn, 1); diff --git a/src/date-fns/fp/nextSunday/index.ts b/src/date-fns/fp/nextSunday/index.ts index 343cf48..75fb357 100644 --- a/src/date-fns/fp/nextSunday/index.ts +++ b/src/date-fns/fp/nextSunday/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../nextSunday/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { nextSunday as fn } from '../../nextSunday/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const nextSunday = convertToFP(fn, 1); diff --git a/src/date-fns/fp/nextThursday/index.ts b/src/date-fns/fp/nextThursday/index.ts index 08f0c0c..8a83f2e 100644 --- a/src/date-fns/fp/nextThursday/index.ts +++ b/src/date-fns/fp/nextThursday/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../nextThursday/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { nextThursday as fn } from '../../nextThursday/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const nextThursday = convertToFP(fn, 1); diff --git a/src/date-fns/fp/nextTuesday/index.ts b/src/date-fns/fp/nextTuesday/index.ts index a0c268f..44130e6 100644 --- a/src/date-fns/fp/nextTuesday/index.ts +++ b/src/date-fns/fp/nextTuesday/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../nextTuesday/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { nextTuesday as fn } from '../../nextTuesday/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const nextTuesday = convertToFP(fn, 1); diff --git a/src/date-fns/fp/nextWednesday/index.ts b/src/date-fns/fp/nextWednesday/index.ts index b7b4001..e81b526 100644 --- a/src/date-fns/fp/nextWednesday/index.ts +++ b/src/date-fns/fp/nextWednesday/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../nextWednesday/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { nextWednesday as fn } from '../../nextWednesday/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const nextWednesday = convertToFP(fn, 1); diff --git a/src/date-fns/fp/parse/index.ts b/src/date-fns/fp/parse/index.ts index 1a2d25d..16e864b 100644 --- a/src/date-fns/fp/parse/index.ts +++ b/src/date-fns/fp/parse/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../parse/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { parse as fn } from '../../parse/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 3); +export const parse = convertToFP(fn, 3); diff --git a/src/date-fns/fp/parseISO/index.ts b/src/date-fns/fp/parseISO/index.ts index e8ea151..6d4ebe8 100644 --- a/src/date-fns/fp/parseISO/index.ts +++ b/src/date-fns/fp/parseISO/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../parseISO/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { parseISO as fn } from '../../parseISO/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const parseISO = convertToFP(fn, 1); diff --git a/src/date-fns/fp/parseISOWithOptions/index.ts b/src/date-fns/fp/parseISOWithOptions/index.ts index 39bbcf3..f18012b 100644 --- a/src/date-fns/fp/parseISOWithOptions/index.ts +++ b/src/date-fns/fp/parseISOWithOptions/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../parseISO/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { parseISO as fn } from '../../parseISO/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const parseISOWithOptions = convertToFP(fn, 2); diff --git a/src/date-fns/fp/parseJSON/index.ts b/src/date-fns/fp/parseJSON/index.ts index 144565f..fdb5ef3 100644 --- a/src/date-fns/fp/parseJSON/index.ts +++ b/src/date-fns/fp/parseJSON/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../parseJSON/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { parseJSON as fn } from '../../parseJSON/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const parseJSON = convertToFP(fn, 1); diff --git a/src/date-fns/fp/parseWithOptions/index.ts b/src/date-fns/fp/parseWithOptions/index.ts index cf600c2..8ae534d 100644 --- a/src/date-fns/fp/parseWithOptions/index.ts +++ b/src/date-fns/fp/parseWithOptions/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../parse/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { parse as fn } from '../../parse/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 4); +export const parseWithOptions = convertToFP(fn, 4); diff --git a/src/date-fns/fp/previousDay/index.ts b/src/date-fns/fp/previousDay/index.ts index 5c4b9cb..75d0699 100644 --- a/src/date-fns/fp/previousDay/index.ts +++ b/src/date-fns/fp/previousDay/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../previousDay/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { previousDay as fn } from '../../previousDay/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const previousDay = convertToFP(fn, 2); diff --git a/src/date-fns/fp/previousFriday/index.ts b/src/date-fns/fp/previousFriday/index.ts index fe0a242..94b1a95 100644 --- a/src/date-fns/fp/previousFriday/index.ts +++ b/src/date-fns/fp/previousFriday/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../previousFriday/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { previousFriday as fn } from '../../previousFriday/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const previousFriday = convertToFP(fn, 1); diff --git a/src/date-fns/fp/previousMonday/index.ts b/src/date-fns/fp/previousMonday/index.ts index 45c223f..7bfaac2 100644 --- a/src/date-fns/fp/previousMonday/index.ts +++ b/src/date-fns/fp/previousMonday/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../previousMonday/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { previousMonday as fn } from '../../previousMonday/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const previousMonday = convertToFP(fn, 1); diff --git a/src/date-fns/fp/previousSaturday/index.ts b/src/date-fns/fp/previousSaturday/index.ts index 8a294c8..3442412 100644 --- a/src/date-fns/fp/previousSaturday/index.ts +++ b/src/date-fns/fp/previousSaturday/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../previousSaturday/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { previousSaturday as fn } from '../../previousSaturday/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const previousSaturday = convertToFP(fn, 1); diff --git a/src/date-fns/fp/previousSunday/index.ts b/src/date-fns/fp/previousSunday/index.ts index ee17e0a..c381fb9 100644 --- a/src/date-fns/fp/previousSunday/index.ts +++ b/src/date-fns/fp/previousSunday/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../previousSunday/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { previousSunday as fn } from '../../previousSunday/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const previousSunday = convertToFP(fn, 1); diff --git a/src/date-fns/fp/previousThursday/index.ts b/src/date-fns/fp/previousThursday/index.ts index b5f9332..c74023f 100644 --- a/src/date-fns/fp/previousThursday/index.ts +++ b/src/date-fns/fp/previousThursday/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../previousThursday/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { previousThursday as fn } from '../../previousThursday/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const previousThursday = convertToFP(fn, 1); diff --git a/src/date-fns/fp/previousTuesday/index.ts b/src/date-fns/fp/previousTuesday/index.ts index 9aec078..b531da5 100644 --- a/src/date-fns/fp/previousTuesday/index.ts +++ b/src/date-fns/fp/previousTuesday/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../previousTuesday/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { previousTuesday as fn } from '../../previousTuesday/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const previousTuesday = convertToFP(fn, 1); diff --git a/src/date-fns/fp/previousWednesday/index.ts b/src/date-fns/fp/previousWednesday/index.ts index 46975be..697f287 100644 --- a/src/date-fns/fp/previousWednesday/index.ts +++ b/src/date-fns/fp/previousWednesday/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../previousWednesday/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { previousWednesday as fn } from '../../previousWednesday/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const previousWednesday = convertToFP(fn, 1); diff --git a/src/date-fns/fp/quartersToMonths/index.ts b/src/date-fns/fp/quartersToMonths/index.ts index cdb3f79..26dde10 100644 --- a/src/date-fns/fp/quartersToMonths/index.ts +++ b/src/date-fns/fp/quartersToMonths/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../quartersToMonths/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { quartersToMonths as fn } from '../../quartersToMonths/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const quartersToMonths = convertToFP(fn, 1); diff --git a/src/date-fns/fp/quartersToYears/index.ts b/src/date-fns/fp/quartersToYears/index.ts index 50bcea8..fb89ae5 100644 --- a/src/date-fns/fp/quartersToYears/index.ts +++ b/src/date-fns/fp/quartersToYears/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../quartersToYears/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { quartersToYears as fn } from '../../quartersToYears/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const quartersToYears = convertToFP(fn, 1); diff --git a/src/date-fns/fp/roundToNearestHours/index.ts b/src/date-fns/fp/roundToNearestHours/index.ts new file mode 100644 index 0000000..4e7ee81 --- /dev/null +++ b/src/date-fns/fp/roundToNearestHours/index.ts @@ -0,0 +1,6 @@ +// This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. + +import { roundToNearestHours as fn } from '../../roundToNearestHours/index'; +import { convertToFP } from '../_lib/convertToFP/index'; + +export const roundToNearestHours = convertToFP(fn, 1); diff --git a/src/date-fns/fp/roundToNearestHoursWithOptions/index.ts b/src/date-fns/fp/roundToNearestHoursWithOptions/index.ts new file mode 100644 index 0000000..a24e28f --- /dev/null +++ b/src/date-fns/fp/roundToNearestHoursWithOptions/index.ts @@ -0,0 +1,6 @@ +// This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. + +import { roundToNearestHours as fn } from '../../roundToNearestHours/index'; +import { convertToFP } from '../_lib/convertToFP/index'; + +export const roundToNearestHoursWithOptions = convertToFP(fn, 2); diff --git a/src/date-fns/fp/roundToNearestMinutes/index.ts b/src/date-fns/fp/roundToNearestMinutes/index.ts index f9c497c..1f99417 100644 --- a/src/date-fns/fp/roundToNearestMinutes/index.ts +++ b/src/date-fns/fp/roundToNearestMinutes/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../roundToNearestMinutes/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { roundToNearestMinutes as fn } from '../../roundToNearestMinutes/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const roundToNearestMinutes = convertToFP(fn, 1); diff --git a/src/date-fns/fp/roundToNearestMinutesWithOptions/index.ts b/src/date-fns/fp/roundToNearestMinutesWithOptions/index.ts index d1508a7..7930fd2 100644 --- a/src/date-fns/fp/roundToNearestMinutesWithOptions/index.ts +++ b/src/date-fns/fp/roundToNearestMinutesWithOptions/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../roundToNearestMinutes/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { roundToNearestMinutes as fn } from '../../roundToNearestMinutes/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const roundToNearestMinutesWithOptions = convertToFP(fn, 2); diff --git a/src/date-fns/fp/secondsToHours/index.ts b/src/date-fns/fp/secondsToHours/index.ts index 0d442f2..4f37fc7 100644 --- a/src/date-fns/fp/secondsToHours/index.ts +++ b/src/date-fns/fp/secondsToHours/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../secondsToHours/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { secondsToHours as fn } from '../../secondsToHours/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const secondsToHours = convertToFP(fn, 1); diff --git a/src/date-fns/fp/secondsToMilliseconds/index.ts b/src/date-fns/fp/secondsToMilliseconds/index.ts index f9ab2bf..2352b6d 100644 --- a/src/date-fns/fp/secondsToMilliseconds/index.ts +++ b/src/date-fns/fp/secondsToMilliseconds/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../secondsToMilliseconds/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { secondsToMilliseconds as fn } from '../../secondsToMilliseconds/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const secondsToMilliseconds = convertToFP(fn, 1); diff --git a/src/date-fns/fp/secondsToMinutes/index.ts b/src/date-fns/fp/secondsToMinutes/index.ts index 705e55b..4979bf3 100644 --- a/src/date-fns/fp/secondsToMinutes/index.ts +++ b/src/date-fns/fp/secondsToMinutes/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../secondsToMinutes/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { secondsToMinutes as fn } from '../../secondsToMinutes/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const secondsToMinutes = convertToFP(fn, 1); diff --git a/src/date-fns/fp/set/index.ts b/src/date-fns/fp/set/index.ts index 4681790..10a1671 100644 --- a/src/date-fns/fp/set/index.ts +++ b/src/date-fns/fp/set/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../set/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { set as fn } from '../../set/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const set = convertToFP(fn, 2); diff --git a/src/date-fns/fp/setDate/index.ts b/src/date-fns/fp/setDate/index.ts index 36da9c3..5eb34a5 100644 --- a/src/date-fns/fp/setDate/index.ts +++ b/src/date-fns/fp/setDate/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../setDate/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { setDate as fn } from '../../setDate/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const setDate = convertToFP(fn, 2); diff --git a/src/date-fns/fp/setDay/index.ts b/src/date-fns/fp/setDay/index.ts index 76bc8d7..b1051f6 100644 --- a/src/date-fns/fp/setDay/index.ts +++ b/src/date-fns/fp/setDay/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../setDay/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { setDay as fn } from '../../setDay/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const setDay = convertToFP(fn, 2); diff --git a/src/date-fns/fp/setDayOfYear/index.ts b/src/date-fns/fp/setDayOfYear/index.ts index fbac6a0..7b43b0b 100644 --- a/src/date-fns/fp/setDayOfYear/index.ts +++ b/src/date-fns/fp/setDayOfYear/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../setDayOfYear/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { setDayOfYear as fn } from '../../setDayOfYear/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const setDayOfYear = convertToFP(fn, 2); diff --git a/src/date-fns/fp/setDayWithOptions/index.ts b/src/date-fns/fp/setDayWithOptions/index.ts index a8838e7..63237cc 100644 --- a/src/date-fns/fp/setDayWithOptions/index.ts +++ b/src/date-fns/fp/setDayWithOptions/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../setDay/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { setDay as fn } from '../../setDay/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 3); +export const setDayWithOptions = convertToFP(fn, 3); diff --git a/src/date-fns/fp/setHours/index.ts b/src/date-fns/fp/setHours/index.ts index 498bc75..3c1da05 100644 --- a/src/date-fns/fp/setHours/index.ts +++ b/src/date-fns/fp/setHours/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../setHours/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { setHours as fn } from '../../setHours/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const setHours = convertToFP(fn, 2); diff --git a/src/date-fns/fp/setISODay/index.ts b/src/date-fns/fp/setISODay/index.ts index 10e893a..d7c7e3b 100644 --- a/src/date-fns/fp/setISODay/index.ts +++ b/src/date-fns/fp/setISODay/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../setISODay/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { setISODay as fn } from '../../setISODay/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const setISODay = convertToFP(fn, 2); diff --git a/src/date-fns/fp/setISOWeek/index.ts b/src/date-fns/fp/setISOWeek/index.ts index e25af7a..c5a7306 100644 --- a/src/date-fns/fp/setISOWeek/index.ts +++ b/src/date-fns/fp/setISOWeek/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../setISOWeek/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { setISOWeek as fn } from '../../setISOWeek/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const setISOWeek = convertToFP(fn, 2); diff --git a/src/date-fns/fp/setISOWeekYear/index.ts b/src/date-fns/fp/setISOWeekYear/index.ts index 67cc9bd..d614eba 100644 --- a/src/date-fns/fp/setISOWeekYear/index.ts +++ b/src/date-fns/fp/setISOWeekYear/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../setISOWeekYear/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { setISOWeekYear as fn } from '../../setISOWeekYear/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const setISOWeekYear = convertToFP(fn, 2); diff --git a/src/date-fns/fp/setMilliseconds/index.ts b/src/date-fns/fp/setMilliseconds/index.ts index 53545b0..c870e9d 100644 --- a/src/date-fns/fp/setMilliseconds/index.ts +++ b/src/date-fns/fp/setMilliseconds/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../setMilliseconds/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { setMilliseconds as fn } from '../../setMilliseconds/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const setMilliseconds = convertToFP(fn, 2); diff --git a/src/date-fns/fp/setMinutes/index.ts b/src/date-fns/fp/setMinutes/index.ts index 29a698e..fd125ec 100644 --- a/src/date-fns/fp/setMinutes/index.ts +++ b/src/date-fns/fp/setMinutes/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../setMinutes/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { setMinutes as fn } from '../../setMinutes/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const setMinutes = convertToFP(fn, 2); diff --git a/src/date-fns/fp/setMonth/index.ts b/src/date-fns/fp/setMonth/index.ts index 72776f2..55bad93 100644 --- a/src/date-fns/fp/setMonth/index.ts +++ b/src/date-fns/fp/setMonth/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../setMonth/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { setMonth as fn } from '../../setMonth/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const setMonth = convertToFP(fn, 2); diff --git a/src/date-fns/fp/setQuarter/index.ts b/src/date-fns/fp/setQuarter/index.ts index 0160048..6cda1f2 100644 --- a/src/date-fns/fp/setQuarter/index.ts +++ b/src/date-fns/fp/setQuarter/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../setQuarter/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { setQuarter as fn } from '../../setQuarter/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const setQuarter = convertToFP(fn, 2); diff --git a/src/date-fns/fp/setSeconds/index.ts b/src/date-fns/fp/setSeconds/index.ts index f9673b3..263298a 100644 --- a/src/date-fns/fp/setSeconds/index.ts +++ b/src/date-fns/fp/setSeconds/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../setSeconds/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { setSeconds as fn } from '../../setSeconds/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const setSeconds = convertToFP(fn, 2); diff --git a/src/date-fns/fp/setWeek/index.ts b/src/date-fns/fp/setWeek/index.ts index 5776a31..1601596 100644 --- a/src/date-fns/fp/setWeek/index.ts +++ b/src/date-fns/fp/setWeek/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../setWeek/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { setWeek as fn } from '../../setWeek/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const setWeek = convertToFP(fn, 2); diff --git a/src/date-fns/fp/setWeekWithOptions/index.ts b/src/date-fns/fp/setWeekWithOptions/index.ts index f0b0fa7..e233613 100644 --- a/src/date-fns/fp/setWeekWithOptions/index.ts +++ b/src/date-fns/fp/setWeekWithOptions/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../setWeek/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { setWeek as fn } from '../../setWeek/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 3); +export const setWeekWithOptions = convertToFP(fn, 3); diff --git a/src/date-fns/fp/setWeekYear/index.ts b/src/date-fns/fp/setWeekYear/index.ts index 247242d..1c8c5df 100644 --- a/src/date-fns/fp/setWeekYear/index.ts +++ b/src/date-fns/fp/setWeekYear/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../setWeekYear/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { setWeekYear as fn } from '../../setWeekYear/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const setWeekYear = convertToFP(fn, 2); diff --git a/src/date-fns/fp/setWeekYearWithOptions/index.ts b/src/date-fns/fp/setWeekYearWithOptions/index.ts index 809adff..e4ab1eb 100644 --- a/src/date-fns/fp/setWeekYearWithOptions/index.ts +++ b/src/date-fns/fp/setWeekYearWithOptions/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../setWeekYear/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { setWeekYear as fn } from '../../setWeekYear/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 3); +export const setWeekYearWithOptions = convertToFP(fn, 3); diff --git a/src/date-fns/fp/setYear/index.ts b/src/date-fns/fp/setYear/index.ts index 99ada5d..4eb7507 100644 --- a/src/date-fns/fp/setYear/index.ts +++ b/src/date-fns/fp/setYear/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../setYear/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { setYear as fn } from '../../setYear/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const setYear = convertToFP(fn, 2); diff --git a/src/date-fns/fp/startOfDay/index.ts b/src/date-fns/fp/startOfDay/index.ts index afb8a26..a3d0822 100644 --- a/src/date-fns/fp/startOfDay/index.ts +++ b/src/date-fns/fp/startOfDay/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../startOfDay/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { startOfDay as fn } from '../../startOfDay/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const startOfDay = convertToFP(fn, 1); diff --git a/src/date-fns/fp/startOfDecade/index.ts b/src/date-fns/fp/startOfDecade/index.ts index b8305c3..50217ac 100644 --- a/src/date-fns/fp/startOfDecade/index.ts +++ b/src/date-fns/fp/startOfDecade/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../startOfDecade/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { startOfDecade as fn } from '../../startOfDecade/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const startOfDecade = convertToFP(fn, 1); diff --git a/src/date-fns/fp/startOfHour/index.ts b/src/date-fns/fp/startOfHour/index.ts index 956a8ed..2b2afd6 100644 --- a/src/date-fns/fp/startOfHour/index.ts +++ b/src/date-fns/fp/startOfHour/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../startOfHour/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { startOfHour as fn } from '../../startOfHour/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const startOfHour = convertToFP(fn, 1); diff --git a/src/date-fns/fp/startOfISOWeek/index.ts b/src/date-fns/fp/startOfISOWeek/index.ts index e96308e..e239cd2 100644 --- a/src/date-fns/fp/startOfISOWeek/index.ts +++ b/src/date-fns/fp/startOfISOWeek/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../startOfISOWeek/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { startOfISOWeek as fn } from '../../startOfISOWeek/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const startOfISOWeek = convertToFP(fn, 1); diff --git a/src/date-fns/fp/startOfISOWeekYear/index.ts b/src/date-fns/fp/startOfISOWeekYear/index.ts index 8985311..6141a23 100644 --- a/src/date-fns/fp/startOfISOWeekYear/index.ts +++ b/src/date-fns/fp/startOfISOWeekYear/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../startOfISOWeekYear/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { startOfISOWeekYear as fn } from '../../startOfISOWeekYear/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const startOfISOWeekYear = convertToFP(fn, 1); diff --git a/src/date-fns/fp/startOfMinute/index.ts b/src/date-fns/fp/startOfMinute/index.ts index b1e054b..39a7d88 100644 --- a/src/date-fns/fp/startOfMinute/index.ts +++ b/src/date-fns/fp/startOfMinute/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../startOfMinute/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { startOfMinute as fn } from '../../startOfMinute/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const startOfMinute = convertToFP(fn, 1); diff --git a/src/date-fns/fp/startOfMonth/index.ts b/src/date-fns/fp/startOfMonth/index.ts index 83ec9f7..4423d2f 100644 --- a/src/date-fns/fp/startOfMonth/index.ts +++ b/src/date-fns/fp/startOfMonth/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../startOfMonth/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { startOfMonth as fn } from '../../startOfMonth/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const startOfMonth = convertToFP(fn, 1); diff --git a/src/date-fns/fp/startOfQuarter/index.ts b/src/date-fns/fp/startOfQuarter/index.ts index ec69ae7..ffe290e 100644 --- a/src/date-fns/fp/startOfQuarter/index.ts +++ b/src/date-fns/fp/startOfQuarter/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../startOfQuarter/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { startOfQuarter as fn } from '../../startOfQuarter/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const startOfQuarter = convertToFP(fn, 1); diff --git a/src/date-fns/fp/startOfSecond/index.ts b/src/date-fns/fp/startOfSecond/index.ts index 2f11e40..8d91170 100644 --- a/src/date-fns/fp/startOfSecond/index.ts +++ b/src/date-fns/fp/startOfSecond/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../startOfSecond/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { startOfSecond as fn } from '../../startOfSecond/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const startOfSecond = convertToFP(fn, 1); diff --git a/src/date-fns/fp/startOfWeek/index.ts b/src/date-fns/fp/startOfWeek/index.ts index af03a14..8e8d68a 100644 --- a/src/date-fns/fp/startOfWeek/index.ts +++ b/src/date-fns/fp/startOfWeek/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../startOfWeek/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { startOfWeek as fn } from '../../startOfWeek/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const startOfWeek = convertToFP(fn, 1); diff --git a/src/date-fns/fp/startOfWeekWithOptions/index.ts b/src/date-fns/fp/startOfWeekWithOptions/index.ts index e585a80..1118a07 100644 --- a/src/date-fns/fp/startOfWeekWithOptions/index.ts +++ b/src/date-fns/fp/startOfWeekWithOptions/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../startOfWeek/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { startOfWeek as fn } from '../../startOfWeek/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const startOfWeekWithOptions = convertToFP(fn, 2); diff --git a/src/date-fns/fp/startOfWeekYear/index.ts b/src/date-fns/fp/startOfWeekYear/index.ts index 1bf2095..a6baced 100644 --- a/src/date-fns/fp/startOfWeekYear/index.ts +++ b/src/date-fns/fp/startOfWeekYear/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../startOfWeekYear/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { startOfWeekYear as fn } from '../../startOfWeekYear/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const startOfWeekYear = convertToFP(fn, 1); diff --git a/src/date-fns/fp/startOfWeekYearWithOptions/index.ts b/src/date-fns/fp/startOfWeekYearWithOptions/index.ts index c398451..fb39d71 100644 --- a/src/date-fns/fp/startOfWeekYearWithOptions/index.ts +++ b/src/date-fns/fp/startOfWeekYearWithOptions/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../startOfWeekYear/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { startOfWeekYear as fn } from '../../startOfWeekYear/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const startOfWeekYearWithOptions = convertToFP(fn, 2); diff --git a/src/date-fns/fp/startOfYear/index.ts b/src/date-fns/fp/startOfYear/index.ts index 14ed548..538947b 100644 --- a/src/date-fns/fp/startOfYear/index.ts +++ b/src/date-fns/fp/startOfYear/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../startOfYear/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { startOfYear as fn } from '../../startOfYear/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const startOfYear = convertToFP(fn, 1); diff --git a/src/date-fns/fp/sub/index.ts b/src/date-fns/fp/sub/index.ts index a32450a..ee77d9b 100644 --- a/src/date-fns/fp/sub/index.ts +++ b/src/date-fns/fp/sub/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../sub/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { sub as fn } from '../../sub/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const sub = convertToFP(fn, 2); diff --git a/src/date-fns/fp/subBusinessDays/index.ts b/src/date-fns/fp/subBusinessDays/index.ts index d83033c..faaf5d3 100644 --- a/src/date-fns/fp/subBusinessDays/index.ts +++ b/src/date-fns/fp/subBusinessDays/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../subBusinessDays/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { subBusinessDays as fn } from '../../subBusinessDays/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const subBusinessDays = convertToFP(fn, 2); diff --git a/src/date-fns/fp/subDays/index.ts b/src/date-fns/fp/subDays/index.ts index df1b1c2..06e38b2 100644 --- a/src/date-fns/fp/subDays/index.ts +++ b/src/date-fns/fp/subDays/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../subDays/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { subDays as fn } from '../../subDays/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const subDays = convertToFP(fn, 2); diff --git a/src/date-fns/fp/subHours/index.ts b/src/date-fns/fp/subHours/index.ts index 04dc7fa..cdb436c 100644 --- a/src/date-fns/fp/subHours/index.ts +++ b/src/date-fns/fp/subHours/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../subHours/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { subHours as fn } from '../../subHours/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const subHours = convertToFP(fn, 2); diff --git a/src/date-fns/fp/subISOWeekYears/index.ts b/src/date-fns/fp/subISOWeekYears/index.ts index c7f3c5c..c8f2cdc 100644 --- a/src/date-fns/fp/subISOWeekYears/index.ts +++ b/src/date-fns/fp/subISOWeekYears/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../subISOWeekYears/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { subISOWeekYears as fn } from '../../subISOWeekYears/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const subISOWeekYears = convertToFP(fn, 2); diff --git a/src/date-fns/fp/subMilliseconds/index.ts b/src/date-fns/fp/subMilliseconds/index.ts index 5d53eac..f0cb01f 100644 --- a/src/date-fns/fp/subMilliseconds/index.ts +++ b/src/date-fns/fp/subMilliseconds/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../subMilliseconds/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { subMilliseconds as fn } from '../../subMilliseconds/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const subMilliseconds = convertToFP(fn, 2); diff --git a/src/date-fns/fp/subMinutes/index.ts b/src/date-fns/fp/subMinutes/index.ts index cbcf5e9..172375b 100644 --- a/src/date-fns/fp/subMinutes/index.ts +++ b/src/date-fns/fp/subMinutes/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../subMinutes/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { subMinutes as fn } from '../../subMinutes/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const subMinutes = convertToFP(fn, 2); diff --git a/src/date-fns/fp/subMonths/index.ts b/src/date-fns/fp/subMonths/index.ts index 0f62004..f08c8f1 100644 --- a/src/date-fns/fp/subMonths/index.ts +++ b/src/date-fns/fp/subMonths/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../subMonths/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { subMonths as fn } from '../../subMonths/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const subMonths = convertToFP(fn, 2); diff --git a/src/date-fns/fp/subQuarters/index.ts b/src/date-fns/fp/subQuarters/index.ts index 732e8c5..4415f24 100644 --- a/src/date-fns/fp/subQuarters/index.ts +++ b/src/date-fns/fp/subQuarters/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../subQuarters/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { subQuarters as fn } from '../../subQuarters/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const subQuarters = convertToFP(fn, 2); diff --git a/src/date-fns/fp/subSeconds/index.ts b/src/date-fns/fp/subSeconds/index.ts index 2c82498..8f67365 100644 --- a/src/date-fns/fp/subSeconds/index.ts +++ b/src/date-fns/fp/subSeconds/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../subSeconds/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { subSeconds as fn } from '../../subSeconds/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const subSeconds = convertToFP(fn, 2); diff --git a/src/date-fns/fp/subWeeks/index.ts b/src/date-fns/fp/subWeeks/index.ts index c07d4d7..a0fb51e 100644 --- a/src/date-fns/fp/subWeeks/index.ts +++ b/src/date-fns/fp/subWeeks/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../subWeeks/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { subWeeks as fn } from '../../subWeeks/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const subWeeks = convertToFP(fn, 2); diff --git a/src/date-fns/fp/subYears/index.ts b/src/date-fns/fp/subYears/index.ts index a6ec4ea..b0de8f3 100644 --- a/src/date-fns/fp/subYears/index.ts +++ b/src/date-fns/fp/subYears/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../subYears/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { subYears as fn } from '../../subYears/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 2); +export const subYears = convertToFP(fn, 2); diff --git a/src/date-fns/fp/toDate/index.ts b/src/date-fns/fp/toDate/index.ts index 3ef9f28..5f6a4ce 100644 --- a/src/date-fns/fp/toDate/index.ts +++ b/src/date-fns/fp/toDate/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../toDate/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { toDate as fn } from '../../toDate/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const toDate = convertToFP(fn, 1); diff --git a/src/date-fns/fp/transpose/index.ts b/src/date-fns/fp/transpose/index.ts new file mode 100644 index 0000000..0774437 --- /dev/null +++ b/src/date-fns/fp/transpose/index.ts @@ -0,0 +1,6 @@ +// This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. + +import { transpose as fn } from '../../transpose/index'; +import { convertToFP } from '../_lib/convertToFP/index'; + +export const transpose = convertToFP(fn, 2); diff --git a/src/date-fns/fp/types.ts b/src/date-fns/fp/types.ts new file mode 100644 index 0000000..633f85e --- /dev/null +++ b/src/date-fns/fp/types.ts @@ -0,0 +1,120 @@ +/** + * The type of a function that can be converted to FP. + */ +// eslint-disable-next-line @typescript-eslint/no-explicit-any -- We want any here. +export type FPFnInput = (...args: any[]) => any; + +/** + * The supported arity type. + */ +export type FPArity = 1 | 2 | 3 | 4; + +/** + * FP function interface. It infers the arity of the function and returns the + * corresponding FP function interface. + */ +export type FPFn = Arity extends 4 + ? FPFn4, Parameters[3], Parameters[2], Parameters[1], Parameters[0]> + : Arity extends 3 + ? FPFn3, Parameters[2], Parameters[1], Parameters[0]> + : Arity extends 2 + ? FPFn2, Parameters[1], Parameters[0]> + : Arity extends 1 + ? FPFn1, Parameters[0]> + : never; + +/** + * FP function interface with 1 arguments. + */ +export interface FPFn1 { + /** + * Curried version of the function. Returns itself. + */ + (): FPFn1; + + /** + * Returns the result of the function call. + */ + (arg: Arg): Result; +} + +/** + * FP function interface with 2 arguments. + */ +export interface FPFn2 { + /** + * Curried version of the function. Returns itself. + */ + (): FPFn2; + + /** + * Curried version of the function. Returns a function that accepts the rest + * arguments. + */ + (arg2: Arg2): FPFn1; + + /** + * Returns the result of the function call. + */ + (arg2: Arg2, arg1: Arg1): Result; +} + +/** + * FP function interface with 3 arguments. + */ +export interface FPFn3 { + /** + * Curried version of the function. Returns itself. + */ + (): FPFn3; + + /** + * Curried version of the function. Returns a function that accepts the rest + * arguments. + */ + (arg3: Arg3): FPFn2; + + /** + * Curried version of the function. Returns a function that accepts the rest + * arguments. + */ + (arg3: Arg3, arg2: Arg2): FPFn1; + + /** + * Returns the result of the function call. + */ + (arg3: Arg3, arg2: Arg2, arg1: Arg1): Result; +} + +/** + * FP function interface with 4 arguments. + */ +export interface FPFn4 { + /** + * Curried version of the function. Returns itself. + */ + (): FPFn4; + + /** + * Curried version of the function. Returns a function that accepts the rest + * arguments. + */ + (arg4: Arg4): FPFn3; + + /** + * Curried version of the function. Returns a function that accepts the rest + * arguments. + */ + (arg4: Arg4, arg3: Arg3): FPFn2; + + /** + * Curried version of the function. Returns a function that accepts the rest + * arguments. + */ + (arg4: Arg4, arg3: Arg3, arg2: Arg2): FPFn1; + + /** + * Returns the result of the function call. + */ + (arg4: Arg4, arg3: Arg3, arg2: Arg2, arg1: Arg1): Result; +} diff --git a/src/date-fns/fp/weeksToDays/index.ts b/src/date-fns/fp/weeksToDays/index.ts index 4776f81..edeb75d 100644 --- a/src/date-fns/fp/weeksToDays/index.ts +++ b/src/date-fns/fp/weeksToDays/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../weeksToDays/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { weeksToDays as fn } from '../../weeksToDays/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const weeksToDays = convertToFP(fn, 1); diff --git a/src/date-fns/fp/yearsToDays/index.ts b/src/date-fns/fp/yearsToDays/index.ts new file mode 100644 index 0000000..0986948 --- /dev/null +++ b/src/date-fns/fp/yearsToDays/index.ts @@ -0,0 +1,6 @@ +// This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. + +import { yearsToDays as fn } from '../../yearsToDays/index'; +import { convertToFP } from '../_lib/convertToFP/index'; + +export const yearsToDays = convertToFP(fn, 1); diff --git a/src/date-fns/fp/yearsToMonths/index.ts b/src/date-fns/fp/yearsToMonths/index.ts index b99eeb3..8221811 100644 --- a/src/date-fns/fp/yearsToMonths/index.ts +++ b/src/date-fns/fp/yearsToMonths/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../yearsToMonths/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { yearsToMonths as fn } from '../../yearsToMonths/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const yearsToMonths = convertToFP(fn, 1); diff --git a/src/date-fns/fp/yearsToQuarters/index.ts b/src/date-fns/fp/yearsToQuarters/index.ts index 6624b82..51ad4b4 100644 --- a/src/date-fns/fp/yearsToQuarters/index.ts +++ b/src/date-fns/fp/yearsToQuarters/index.ts @@ -1,6 +1,6 @@ // This file is generated automatically by `scripts/build/fp.ts`. Please, don't change it. -import fn from '../../yearsToQuarters/index'; -import convertToFP from '../_lib/convertToFP/index'; +import { yearsToQuarters as fn } from '../../yearsToQuarters/index'; +import { convertToFP } from '../_lib/convertToFP/index'; -export default convertToFP(fn, 1); +export const yearsToQuarters = convertToFP(fn, 1); diff --git a/src/date-fns/fromUnixTime/index.ts b/src/date-fns/fromUnixTime/index.ts index f2b856d..2d68c98 100644 --- a/src/date-fns/fromUnixTime/index.ts +++ b/src/date-fns/fromUnixTime/index.ts @@ -1,4 +1,4 @@ -import toDate from '../toDate/index'; +import { toDate } from '../toDate/index'; /** * @name fromUnixTime @@ -8,14 +8,15 @@ import toDate from '../toDate/index'; * @description * Create a date from a Unix timestamp (in seconds). Decimal values will be discarded. * - * @param unixTime - the given Unix timestamp (in seconds) - * @returns the date + * @param unixTime - The given Unix timestamp (in seconds) + * + * @returns The date * * @example * // Create the date 29 February 2012 11:45:05: * const result = fromUnixTime(1330515905) * //=> Wed Feb 29 2012 11:45:05 */ -export default function fromUnixTime(unixTime: number): Date { +export function fromUnixTime(unixTime: number): Date { return toDate(unixTime * 1000); } diff --git a/src/date-fns/getDate/index.ts b/src/date-fns/getDate/index.ts index 43f46bf..d28485a 100644 --- a/src/date-fns/getDate/index.ts +++ b/src/date-fns/getDate/index.ts @@ -1,4 +1,4 @@ -import toDate from '../toDate/index'; +import { toDate } from '../toDate/index'; /** * @name getDate @@ -8,16 +8,19 @@ import toDate from '../toDate/index'; * @description * Get the day of the month of the given date. * - * @param date - the given date - * @returns the day of month + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The given date + * + * @returns The day of month * * @example * // Which day of the month is 29 February 2012? * const result = getDate(new Date(2012, 1, 29)) * //=> 29 */ -export default function getDate(dirtyDate: DateType | number): number { - const date = toDate(dirtyDate); - const dayOfMonth = date.getDate(); +export function getDate(date: DateType | number | string): number { + const _date = toDate(date); + const dayOfMonth = _date.getDate(); return dayOfMonth; } diff --git a/src/date-fns/getDay/index.ts b/src/date-fns/getDay/index.ts index e9582db..2b756a8 100644 --- a/src/date-fns/getDay/index.ts +++ b/src/date-fns/getDay/index.ts @@ -1,4 +1,4 @@ -import toDate from '../toDate/index'; +import { toDate } from '../toDate/index'; /** * @name getDay @@ -8,16 +8,19 @@ import toDate from '../toDate/index'; * @description * Get the day of the week of the given date. * - * @param date - the given date - * @returns the day of week, 0 represents Sunday + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The given date + * + * @returns The day of week, 0 represents Sunday * * @example * // Which day of the week is 29 February 2012? * const result = getDay(new Date(2012, 1, 29)) * //=> 3 */ -export default function getDay(dirtyDate: DateType | number): number { - const date = toDate(dirtyDate); - const day = date.getDay(); +export function getDay(date: DateType | number | string): number { + const _date = toDate(date); + const day = _date.getDay(); return day; } diff --git a/src/date-fns/getDayOfYear/index.ts b/src/date-fns/getDayOfYear/index.ts index 618ce4d..63ad3c9 100644 --- a/src/date-fns/getDayOfYear/index.ts +++ b/src/date-fns/getDayOfYear/index.ts @@ -1,6 +1,6 @@ -import differenceInCalendarDays from '../differenceInCalendarDays/index'; -import startOfYear from '../startOfYear/index'; -import toDate from '../toDate/index'; +import { differenceInCalendarDays } from '../differenceInCalendarDays/index'; +import { startOfYear } from '../startOfYear/index'; +import { toDate } from '../toDate/index'; /** * @name getDayOfYear @@ -10,17 +10,20 @@ import toDate from '../toDate/index'; * @description * Get the day of the year of the given date. * - * @param date - the given date - * @returns the day of year + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The given date + * + * @returns The day of year * * @example * // Which day of the year is 2 July 2014? * const result = getDayOfYear(new Date(2014, 6, 2)) * //=> 183 */ -export default function getDayOfYear(dirtyDate: DateType | number): number { - const date = toDate(dirtyDate); - const diff = differenceInCalendarDays(date, startOfYear(date)); +export function getDayOfYear(date: DateType | number | string): number { + const _date = toDate(date); + const diff = differenceInCalendarDays(_date, startOfYear(_date)); const dayOfYear = diff + 1; return dayOfYear; } diff --git a/src/date-fns/getDaysInMonth/index.ts b/src/date-fns/getDaysInMonth/index.ts index 19ed053..5504f12 100644 --- a/src/date-fns/getDaysInMonth/index.ts +++ b/src/date-fns/getDaysInMonth/index.ts @@ -1,5 +1,5 @@ -import toDate from '../toDate/index'; -import constructFrom from '../constructFrom/index'; +import { toDate } from '../toDate/index'; +import { constructFrom } from '../constructFrom/index'; /** * @name getDaysInMonth @@ -9,19 +9,22 @@ import constructFrom from '../constructFrom/index'; * @description * Get the number of days in a month of the given date. * - * @param date - the given date - * @returns the number of days in a month + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The given date + * + * @returns The number of days in a month * * @example * // How many days are in February 2000? * const result = getDaysInMonth(new Date(2000, 1)) * //=> 29 */ -export default function getDaysInMonth(dirtyDate: DateType | number): number { - const date = toDate(dirtyDate); - const year = date.getFullYear(); - const monthIndex = date.getMonth(); - const lastDayOfMonth = constructFrom(dirtyDate, 0); +export function getDaysInMonth(date: DateType | number | string): number { + const _date = toDate(date); + const year = _date.getFullYear(); + const monthIndex = _date.getMonth(); + const lastDayOfMonth = constructFrom(date, 0); lastDayOfMonth.setFullYear(year, monthIndex + 1, 0); lastDayOfMonth.setHours(0, 0, 0, 0); return lastDayOfMonth.getDate(); diff --git a/src/date-fns/getDaysInYear/index.ts b/src/date-fns/getDaysInYear/index.ts index 242c890..dfc05de 100644 --- a/src/date-fns/getDaysInYear/index.ts +++ b/src/date-fns/getDaysInYear/index.ts @@ -1,5 +1,5 @@ -import isLeapYear from '../isLeapYear/index'; -import toDate from '../toDate/index'; +import { isLeapYear } from '../isLeapYear/index'; +import { toDate } from '../toDate/index'; /** * @name getDaysInYear @@ -9,20 +9,23 @@ import toDate from '../toDate/index'; * @description * Get the number of days in a year of the given date. * - * @param date - the given date - * @returns the number of days in a year + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The given date + * + * @returns The number of days in a year * * @example * // How many days are in 2012? * const result = getDaysInYear(new Date(2012, 0, 1)) * //=> 366 */ -export default function getDaysInYear(dirtyDate: DateType | number): number { - const date = toDate(dirtyDate); +export function getDaysInYear(date: DateType | number | string): number { + const _date = toDate(date); - if (String(new Date(date)) === 'Invalid Date') { + if (String(new Date(_date)) === 'Invalid Date') { return NaN; } - return isLeapYear(date) ? 366 : 365; + return isLeapYear(_date) ? 366 : 365; } diff --git a/src/date-fns/getDecade/index.ts b/src/date-fns/getDecade/index.ts index 957687e..d723a6f 100644 --- a/src/date-fns/getDecade/index.ts +++ b/src/date-fns/getDecade/index.ts @@ -1,4 +1,4 @@ -import toDate from '../toDate/index'; +import { toDate } from '../toDate/index'; /** * @name getDecade @@ -8,17 +8,23 @@ import toDate from '../toDate/index'; * @description * Get the decade of the given date. * - * @param date - the given date - * @returns the year of decade + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The given date + * + * @returns The year of decade * * @example * // Which decade belongs 27 November 1942? * const result = getDecade(new Date(1942, 10, 27)) * //=> 1940 */ -export default function getDecade(dirtyDate: DateType | number): number { - const date = toDate(dirtyDate); - const year = date.getFullYear(); +export function getDecade(date: DateType | number | string): number { + // TODO: Switch to more technical definition in of decades that start with 1 + // end with 0. I.e. 2001-2010 instead of current 2000-2009. It's a breaking + // change, so it can only be done in 4.0. + const _date = toDate(date); + const year = _date.getFullYear(); const decade = Math.floor(year / 10) * 10; return decade; } diff --git a/src/date-fns/getDefaultOptions/index.ts b/src/date-fns/getDefaultOptions/index.ts index a71070d..8df1d8a 100644 --- a/src/date-fns/getDefaultOptions/index.ts +++ b/src/date-fns/getDefaultOptions/index.ts @@ -1,5 +1,5 @@ -import assign from '../_lib/assign/index'; -import { type DefaultOptions, getDefaultOptions as getInternalDefaultOptions } from '../_lib/defaultOptions/index'; +import type { DefaultOptions } from '../_lib/defaultOptions/index'; +import { getDefaultOptions as getInternalDefaultOptions } from '../_lib/defaultOptions/index'; /** * @name getDefaultOptions @@ -12,9 +12,9 @@ import { type DefaultOptions, getDefaultOptions as getInternalDefaultOptions } f * `options.locale`, `options.weekStartsOn` and `options.firstWeekContainsDate` * arguments for all functions. * - * You can change these with [setDefaultOptions]{@link https://date-fns.org/docs/setDefaultOptions}. + * You can change these with [setDefaultOptions](https://date-fns.org/docs/setDefaultOptions). * - * @returns default options + * @returns The default options * * @example * const result = getDefaultOptions() @@ -25,6 +25,6 @@ import { type DefaultOptions, getDefaultOptions as getInternalDefaultOptions } f * const result = getDefaultOptions() * //=> { weekStarsOn: 1, firstWeekContainsDate: 4 } */ -export default function getDefaultOptions(): DefaultOptions { - return assign({}, getInternalDefaultOptions()); +export function getDefaultOptions(): DefaultOptions { + return Object.assign({}, getInternalDefaultOptions()); } diff --git a/src/date-fns/getHours/index.ts b/src/date-fns/getHours/index.ts index 0429aaa..9dce651 100644 --- a/src/date-fns/getHours/index.ts +++ b/src/date-fns/getHours/index.ts @@ -1,4 +1,4 @@ -import toDate from '../toDate/index'; +import { toDate } from '../toDate/index'; /** * @name getHours @@ -8,16 +8,19 @@ import toDate from '../toDate/index'; * @description * Get the hours of the given date. * - * @param date - the given date - * @returns the hours + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The given date + * + * @returns The hours * * @example * // Get the hours of 29 February 2012 11:45:00: * const result = getHours(new Date(2012, 1, 29, 11, 45)) * //=> 11 */ -export default function getHours(dirtyDate: DateType | number): number { - const date = toDate(dirtyDate); - const hours = date.getHours(); +export function getHours(date: DateType | number | string): number { + const _date = toDate(date); + const hours = _date.getHours(); return hours; } diff --git a/src/date-fns/getISODay/index.ts b/src/date-fns/getISODay/index.ts index 1846020..824371c 100644 --- a/src/date-fns/getISODay/index.ts +++ b/src/date-fns/getISODay/index.ts @@ -1,4 +1,4 @@ -import toDate from '../toDate/index'; +import { toDate } from '../toDate/index'; /** * @name getISODay @@ -11,17 +11,20 @@ import toDate from '../toDate/index'; * * ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date * - * @param date - the given date - * @returns the day of ISO week + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The given date + * + * @returns The day of ISO week * * @example * // Which day of the ISO week is 26 February 2012? * const result = getISODay(new Date(2012, 1, 26)) * //=> 7 */ -export default function getISODay(dirtyDate: DateType | number): number { - const date = toDate(dirtyDate); - let day = date.getDay(); +export function getISODay(date: DateType | number | string): number { + const _date = toDate(date); + let day = _date.getDay(); if (day === 0) { day = 7; diff --git a/src/date-fns/getISOWeek/index.ts b/src/date-fns/getISOWeek/index.ts index 07600e1..e853b3b 100644 --- a/src/date-fns/getISOWeek/index.ts +++ b/src/date-fns/getISOWeek/index.ts @@ -1,7 +1,7 @@ import { millisecondsInWeek } from '../constants/index'; -import startOfISOWeek from '../startOfISOWeek/index'; -import startOfISOWeekYear from '../startOfISOWeekYear/index'; -import toDate from '../toDate/index'; +import { startOfISOWeek } from '../startOfISOWeek/index'; +import { startOfISOWeekYear } from '../startOfISOWeekYear/index'; +import { toDate } from '../toDate/index'; /** * @name getISOWeek @@ -13,20 +13,23 @@ import toDate from '../toDate/index'; * * ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date * - * @param date - the given date - * @returns the ISO week + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The given date + * + * @returns The ISO week * * @example * // Which week of the ISO-week numbering year is 2 January 2005? * const result = getISOWeek(new Date(2005, 0, 2)) * //=> 53 */ -export default function getISOWeek(dirtyDate: DateType | number): number { - const date = toDate(dirtyDate); - const diff = startOfISOWeek(date).getTime() - startOfISOWeekYear(date).getTime(); +export function getISOWeek(date: DateType | number | string): number { + const _date = toDate(date); + const diff = +startOfISOWeek(_date) - +startOfISOWeekYear(_date); - // Round the number of days to the nearest integer - // because the number of milliseconds in a week is not constant - // (e.g. it's different in the week of the daylight saving time clock shift) + // Round the number of weeks to the nearest integer because the number of + // milliseconds in a week is not constant (e.g. it's different in the week of + // the daylight saving time clock shift). return Math.round(diff / millisecondsInWeek) + 1; } diff --git a/src/date-fns/getISOWeekYear/index.ts b/src/date-fns/getISOWeekYear/index.ts index 5197311..d9b30ef 100644 --- a/src/date-fns/getISOWeekYear/index.ts +++ b/src/date-fns/getISOWeekYear/index.ts @@ -1,6 +1,6 @@ -import constructFrom from '../constructFrom/index'; -import startOfISOWeek from '../startOfISOWeek/index'; -import toDate from '../toDate/index'; +import { constructFrom } from '../constructFrom/index'; +import { startOfISOWeek } from '../startOfISOWeek/index'; +import { toDate } from '../toDate/index'; /** * @name getISOWeekYear @@ -13,31 +13,34 @@ import toDate from '../toDate/index'; * * ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date * - * @param date - the given date - * @returns the ISO week-numbering year + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The given date + * + * @returns The ISO week-numbering year * * @example * // Which ISO-week numbering year is 2 January 2005? * const result = getISOWeekYear(new Date(2005, 0, 2)) * //=> 2004 */ -export default function getISOWeekYear(dirtyDate: DateType | number): number { - const date = toDate(dirtyDate); - const year = date.getFullYear(); +export function getISOWeekYear(date: DateType | number | string): number { + const _date = toDate(date); + const year = _date.getFullYear(); - const fourthOfJanuaryOfNextYear = constructFrom(dirtyDate, 0); + const fourthOfJanuaryOfNextYear = constructFrom(date, 0); fourthOfJanuaryOfNextYear.setFullYear(year + 1, 0, 4); fourthOfJanuaryOfNextYear.setHours(0, 0, 0, 0); const startOfNextYear = startOfISOWeek(fourthOfJanuaryOfNextYear); - const fourthOfJanuaryOfThisYear = constructFrom(dirtyDate, 0); + const fourthOfJanuaryOfThisYear = constructFrom(date, 0); fourthOfJanuaryOfThisYear.setFullYear(year, 0, 4); fourthOfJanuaryOfThisYear.setHours(0, 0, 0, 0); const startOfThisYear = startOfISOWeek(fourthOfJanuaryOfThisYear); - if (date.getTime() >= startOfNextYear.getTime()) { + if (_date.getTime() >= startOfNextYear.getTime()) { return year + 1; - } else if (date.getTime() >= startOfThisYear.getTime()) { + } else if (_date.getTime() >= startOfThisYear.getTime()) { return year; } else { return year - 1; diff --git a/src/date-fns/getISOWeeksInYear/index.ts b/src/date-fns/getISOWeeksInYear/index.ts index d731ccc..765183e 100644 --- a/src/date-fns/getISOWeeksInYear/index.ts +++ b/src/date-fns/getISOWeeksInYear/index.ts @@ -1,6 +1,6 @@ -import addWeeks from '../addWeeks/index'; +import { addWeeks } from '../addWeeks/index'; import { millisecondsInWeek } from '../constants/index'; -import startOfISOWeekYear from '../startOfISOWeekYear/index'; +import { startOfISOWeekYear } from '../startOfISOWeekYear/index'; /** * @name getISOWeeksInYear @@ -12,20 +12,24 @@ import startOfISOWeekYear from '../startOfISOWeekYear/index'; * * ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date * - * @param date - the given date - * @returns the number of ISO weeks in a year + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The given date + * + * @returns The number of ISO weeks in a year * * @example * // How many weeks are in ISO week-numbering year 2015? * const result = getISOWeeksInYear(new Date(2015, 1, 11)) * //=> 53 */ -export default function getISOWeeksInYear(dirtyDate: DateType | number): number { - const thisYear = startOfISOWeekYear(dirtyDate); +export function getISOWeeksInYear(date: DateType | number | string): number { + const thisYear = startOfISOWeekYear(date); const nextYear = startOfISOWeekYear(addWeeks(thisYear, 60)); - const diff = nextYear.valueOf() - thisYear.valueOf(); - // Round the number of weeks to the nearest integer - // because the number of milliseconds in a week is not constant - // (e.g. it's different in the week of the daylight saving time clock shift) + const diff = +nextYear - +thisYear; + + // Round the number of weeks to the nearest integer because the number of + // milliseconds in a week is not constant (e.g. it's different in the week of + // the daylight saving time clock shift). return Math.round(diff / millisecondsInWeek); } diff --git a/src/date-fns/getMilliseconds/index.ts b/src/date-fns/getMilliseconds/index.ts index 0d04a42..03834f2 100644 --- a/src/date-fns/getMilliseconds/index.ts +++ b/src/date-fns/getMilliseconds/index.ts @@ -1,4 +1,4 @@ -import toDate from '../toDate/index'; +import { toDate } from '../toDate/index'; /** * @name getMilliseconds @@ -8,16 +8,19 @@ import toDate from '../toDate/index'; * @description * Get the milliseconds of the given date. * - * @param date - the given date - * @returns the milliseconds + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The given date + * + * @returns The milliseconds * * @example * // Get the milliseconds of 29 February 2012 11:45:05.123: * const result = getMilliseconds(new Date(2012, 1, 29, 11, 45, 5, 123)) * //=> 123 */ -export default function getMilliseconds(dirtyDate: DateType | number): number { - const date = toDate(dirtyDate); - const milliseconds = date.getMilliseconds(); +export function getMilliseconds(date: DateType | number | string): number { + const _date = toDate(date); + const milliseconds = _date.getMilliseconds(); return milliseconds; } diff --git a/src/date-fns/getMinutes/index.ts b/src/date-fns/getMinutes/index.ts index 0bfaada..64960fe 100644 --- a/src/date-fns/getMinutes/index.ts +++ b/src/date-fns/getMinutes/index.ts @@ -1,4 +1,4 @@ -import toDate from '../toDate/index'; +import { toDate } from '../toDate/index'; /** * @name getMinutes @@ -8,16 +8,19 @@ import toDate from '../toDate/index'; * @description * Get the minutes of the given date. * - * @param date - the given date - * @returns the minutes + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The given date + * + * @returns The minutes * * @example * // Get the minutes of 29 February 2012 11:45:05: * const result = getMinutes(new Date(2012, 1, 29, 11, 45, 5)) * //=> 45 */ -export default function getMinutes(dirtyDate: DateType | number): number { - const date = toDate(dirtyDate); - const minutes = date.getMinutes(); +export function getMinutes(date: DateType | number | string): number { + const _date = toDate(date); + const minutes = _date.getMinutes(); return minutes; } diff --git a/src/date-fns/getMonth/index.ts b/src/date-fns/getMonth/index.ts index dd8db7f..330cb16 100644 --- a/src/date-fns/getMonth/index.ts +++ b/src/date-fns/getMonth/index.ts @@ -1,4 +1,4 @@ -import toDate from '../toDate/index'; +import { toDate } from '../toDate/index'; /** * @name getMonth @@ -8,16 +8,19 @@ import toDate from '../toDate/index'; * @description * Get the month of the given date. * - * @param date - the given date - * @returns the month + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The given date + * + * @returns The month index (0-11) * * @example * // Which month is 29 February 2012? * const result = getMonth(new Date(2012, 1, 29)) * //=> 1 */ -export default function getMonth(dirtyDate: DateType | number): number { - const date = toDate(dirtyDate); - const month = date.getMonth(); +export function getMonth(date: DateType | number | string): number { + const _date = toDate(date); + const month = _date.getMonth(); return month; } diff --git a/src/date-fns/getOverlappingDaysInIntervals/index.ts b/src/date-fns/getOverlappingDaysInIntervals/index.ts index c8aa82b..3e8c5d8 100644 --- a/src/date-fns/getOverlappingDaysInIntervals/index.ts +++ b/src/date-fns/getOverlappingDaysInIntervals/index.ts @@ -1,5 +1,6 @@ +import { getTimezoneOffsetInMilliseconds } from '../_lib/getTimezoneOffsetInMilliseconds/index'; import { millisecondsInDay } from '../constants/index'; -import toDate from '../toDate/index'; +import { toDate } from '../toDate/index'; import type { Interval } from '../types'; /** @@ -8,13 +9,19 @@ import type { Interval } from '../types'; * @summary Get the number of days that overlap in two time intervals * * @description - * Get the number of days that overlap in two time intervals + * Get the number of days that overlap in two time intervals. It uses the time + * between dates to calculate the number of days, rounding it up to include + * partial days. * - * @param intervalLeft - the first interval to compare. See [Interval]{@link docs/Interval} - * @param intervalRight - the second interval to compare. See [Interval]{@link docs/Interval} - * @returns the number of days that overlap in two time intervals - * @throws {RangeError} The start of an interval cannot be after its end - * @throws {RangeError} Date in interval cannot be `Invalid Date` + * Two equal 0-length intervals will result in 0. Two equal 1ms intervals will + * result in 1. + * + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param intervalLeft - The first interval to compare. + * @param intervalRight - The second interval to compare. + * + * @returns The number of days that overlap in two time intervals * * @example * // For overlapping time intervals adds 1 for each started overlapping day: @@ -33,31 +40,23 @@ import type { Interval } from '../types'; * //=> 0 */ -export default function getOverlappingDaysInIntervals( +export function getOverlappingDaysInIntervals( intervalLeft: Interval, intervalRight: Interval, ): number { - const leftStartTime = toDate(intervalLeft.start).getTime(); - const leftEndTime = toDate(intervalLeft.end).getTime(); - const rightStartTime = toDate(intervalRight.start).getTime(); - const rightEndTime = toDate(intervalRight.end).getTime(); - - // Throw an exception if start date is after end date or if any date is `Invalid Date` - if (!(leftStartTime <= leftEndTime && rightStartTime <= rightEndTime)) { - throw new RangeError('Invalid interval'); - } - - const isOverlapping = leftStartTime < rightEndTime && rightStartTime < leftEndTime; - - if (!isOverlapping) { - return 0; - } - - const overlapStartDate = rightStartTime < leftStartTime ? leftStartTime : rightStartTime; + const [leftStart, leftEnd] = [+toDate(intervalLeft.start), +toDate(intervalLeft.end)].sort((a, b) => a - b); + const [rightStart, rightEnd] = [+toDate(intervalRight.start), +toDate(intervalRight.end)].sort((a, b) => a - b); - const overlapEndDate = rightEndTime > leftEndTime ? leftEndTime : rightEndTime; + // Prevent NaN result if intervals don't overlap at all. + const isOverlapping = leftStart! < rightEnd! && rightStart! < leftEnd!; + if (!isOverlapping) return 0; - const differenceInMs = overlapEndDate - overlapStartDate; + // Remove the timezone offset to negate the DST effect on calculations. + const overlapLeft = rightStart! < leftStart! ? leftStart : rightStart; + const left = overlapLeft! - getTimezoneOffsetInMilliseconds(overlapLeft!); + const overlapRight = rightEnd! > leftEnd! ? leftEnd : rightEnd; + const right = overlapRight! - getTimezoneOffsetInMilliseconds(overlapRight!); - return Math.ceil(differenceInMs / millisecondsInDay); + // Ceil the number to include partial days too. + return Math.ceil((right - left) / millisecondsInDay); } diff --git a/src/date-fns/getQuarter/index.ts b/src/date-fns/getQuarter/index.ts index d56dfbc..adc6173 100644 --- a/src/date-fns/getQuarter/index.ts +++ b/src/date-fns/getQuarter/index.ts @@ -1,4 +1,4 @@ -import toDate from '../toDate/index'; +import { toDate } from '../toDate/index'; /** * @name getQuarter @@ -8,16 +8,19 @@ import toDate from '../toDate/index'; * @description * Get the year quarter of the given date. * - * @param date - the given date - * @returns the quarter + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The given date + * + * @returns The quarter * * @example * // Which quarter is 2 July 2014? * const result = getQuarter(new Date(2014, 6, 2)) * //=> 3 */ -export default function getQuarter(dirtyDate: DateType | number): number { - const date = toDate(dirtyDate); - const quarter = Math.floor(date.getMonth() / 3) + 1; +export function getQuarter(date: DateType | number | string): number { + const _date = toDate(date); + const quarter = Math.trunc(_date.getMonth() / 3) + 1; return quarter; } diff --git a/src/date-fns/getSeconds/index.ts b/src/date-fns/getSeconds/index.ts index cd7a544..132b575 100644 --- a/src/date-fns/getSeconds/index.ts +++ b/src/date-fns/getSeconds/index.ts @@ -1,4 +1,4 @@ -import toDate from '../toDate/index'; +import { toDate } from '../toDate/index'; /** * @name getSeconds @@ -8,16 +8,19 @@ import toDate from '../toDate/index'; * @description * Get the seconds of the given date. * - * @param date - the given date - * @returns the seconds + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The given date + * + * @returns The seconds * * @example * // Get the seconds of 29 February 2012 11:45:05.123: * const result = getSeconds(new Date(2012, 1, 29, 11, 45, 5, 123)) * //=> 5 */ -export default function getSeconds(dirtyDate: DateType | number): number { - const date = toDate(dirtyDate); - const seconds = date.getSeconds(); +export function getSeconds(date: DateType | number | string): number { + const _date = toDate(date); + const seconds = _date.getSeconds(); return seconds; } diff --git a/src/date-fns/getTime/index.ts b/src/date-fns/getTime/index.ts index f60cc4b..0ba154f 100644 --- a/src/date-fns/getTime/index.ts +++ b/src/date-fns/getTime/index.ts @@ -1,4 +1,4 @@ -import toDate from '../toDate/index'; +import { toDate } from '../toDate/index'; /** * @name getTime @@ -8,16 +8,19 @@ import toDate from '../toDate/index'; * @description * Get the milliseconds timestamp of the given date. * - * @param date - the given date - * @returns the timestamp + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The given date + * + * @returns The timestamp * * @example * // Get the timestamp of 29 February 2012 11:45:05.123: * const result = getTime(new Date(2012, 1, 29, 11, 45, 5, 123)) * //=> 1330515905123 */ -export default function getTime(dirtyDate: DateType | number): number { - const date = toDate(dirtyDate); - const timestamp = date.getTime(); +export function getTime(date: DateType | number | string): number { + const _date = toDate(date); + const timestamp = _date.getTime(); return timestamp; } diff --git a/src/date-fns/getUnixTime/index.ts b/src/date-fns/getUnixTime/index.ts index df2d8f6..b1a8a13 100644 --- a/src/date-fns/getUnixTime/index.ts +++ b/src/date-fns/getUnixTime/index.ts @@ -1,4 +1,4 @@ -import getTime from '../getTime/index'; +import { toDate } from '../toDate/index'; /** * @name getUnixTime @@ -8,14 +8,17 @@ import getTime from '../getTime/index'; * @description * Get the seconds timestamp of the given date. * - * @param date - the given date - * @returns the timestamp + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The given date + * + * @returns The timestamp * * @example * // Get the timestamp of 29 February 2012 11:45:05 CET: * const result = getUnixTime(new Date(2012, 1, 29, 11, 45, 5)) * //=> 1330512305 */ -export default function getUnixTime(dirtyDate: DateType | number): number { - return Math.floor(getTime(dirtyDate) / 1000); +export function getUnixTime(date: DateType | number | string): number { + return Math.trunc(+toDate(date) / 1000); } diff --git a/src/date-fns/getWeek/index.ts b/src/date-fns/getWeek/index.ts index fbdef15..fb3e0eb 100644 --- a/src/date-fns/getWeek/index.ts +++ b/src/date-fns/getWeek/index.ts @@ -1,13 +1,13 @@ import { millisecondsInWeek } from '../constants/index'; -import startOfWeek from '../startOfWeek/index'; -import startOfWeekYear from '../startOfWeekYear/index'; -import toDate from '../toDate/index'; -import type { FirstWeekContainsDateOptions, LocaleOptions, WeekStartOptions } from '../types'; +import { startOfWeek } from '../startOfWeek/index'; +import { startOfWeekYear } from '../startOfWeekYear/index'; +import { toDate } from '../toDate/index'; +import type { FirstWeekContainsDateOptions, LocalizedOptions, WeekOptions } from '../types'; /** * The {@link getWeek} function options. */ -export interface GetWeekOptions extends LocaleOptions, WeekStartOptions, FirstWeekContainsDateOptions {} +export interface GetWeekOptions extends LocalizedOptions<'options'>, WeekOptions, FirstWeekContainsDateOptions {} /** * @name getWeek @@ -21,17 +21,21 @@ export interface GetWeekOptions extends LocaleOptions, WeekStartOptions, FirstWe * and `options.firstWeekContainsDate` (which is the day of January, which is always in * the first week of the week-numbering year) * - * Week numbering: https://en.wikipedia.org/wiki/Week#Week_numbering + * Week numbering: https://en.wikipedia.org/wiki/Week#The_ISO_week_date_system * - * @param date - the given date - * @param options - an object with options. - * @returns the week + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The given date + * @param options - An object with options + * + * @returns The week * * @example * // Which week of the local week numbering year is 2 January 2005 with default options? * const result = getWeek(new Date(2005, 0, 2)) * //=> 2 * + * @example * // Which week of the local week numbering year is 2 January 2005, * // if Monday is the first day of the week, * // and the first week of the year always contains 4 January? @@ -42,12 +46,12 @@ export interface GetWeekOptions extends LocaleOptions, WeekStartOptions, FirstWe * //=> 53 */ -export default function getWeek(dirtyDate: DateType | number, options?: GetWeekOptions): number { - const date = toDate(dirtyDate); - const diff = startOfWeek(date, options).getTime() - startOfWeekYear(date, options).getTime(); +export function getWeek(date: DateType | number | string, options?: GetWeekOptions): number { + const _date = toDate(date); + const diff = +startOfWeek(_date, options) - +startOfWeekYear(_date, options); - // Round the number of days to the nearest integer - // because the number of milliseconds in a week is not constant - // (e.g. it's different in the week of the daylight saving time clock shift) + // Round the number of weeks to the nearest integer because the number of + // milliseconds in a week is not constant (e.g. it's different in the week of + // the daylight saving time clock shift). return Math.round(diff / millisecondsInWeek) + 1; } diff --git a/src/date-fns/getWeekOfMonth/index.ts b/src/date-fns/getWeekOfMonth/index.ts index 31d570a..949491c 100644 --- a/src/date-fns/getWeekOfMonth/index.ts +++ b/src/date-fns/getWeekOfMonth/index.ts @@ -1,13 +1,13 @@ -import getDate from '../getDate/index'; -import getDay from '../getDay/index'; -import startOfMonth from '../startOfMonth/index'; -import type { LocaleOptions, WeekStartOptions } from '../types'; +import { getDate } from '../getDate/index'; +import { getDay } from '../getDay/index'; +import { startOfMonth } from '../startOfMonth/index'; +import type { LocalizedOptions, WeekOptions } from '../types'; import { getDefaultOptions } from '../_lib/defaultOptions/index'; /** * The {@link getWeekOfMonth} function options. */ -export interface GetWeekOfMonthOptions extends LocaleOptions, WeekStartOptions {} +export interface GetWeekOfMonthOptions extends LocalizedOptions<'options'>, WeekOptions {} /** * @name getWeekOfMonth @@ -17,17 +17,20 @@ export interface GetWeekOfMonthOptions extends LocaleOptions, WeekStartOptions { * @description * Get the week of the month of the given date. * - * @param date - the given date - * @param options - an object with options. - * @returns the week of month + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The given date + * @param options - An object with options. + * + * @returns The week of month * * @example * // Which week of the month is 9 November 2017? * const result = getWeekOfMonth(new Date(2017, 10, 9)) * //=> 2 */ -export default function getWeekOfMonth( - date: DateType | number, +export function getWeekOfMonth( + date: DateType | number | string, options?: GetWeekOfMonthOptions, ): number { const defaultOptions = getDefaultOptions(); diff --git a/src/date-fns/getWeekYear/index.ts b/src/date-fns/getWeekYear/index.ts index c6a07b2..f14600b 100644 --- a/src/date-fns/getWeekYear/index.ts +++ b/src/date-fns/getWeekYear/index.ts @@ -1,13 +1,13 @@ -import dateFrom from '../constructFrom/index'; -import startOfWeek from '../startOfWeek/index'; -import toDate from '../toDate/index'; -import type { FirstWeekContainsDateOptions, LocaleOptions, WeekStartOptions } from '../types'; +import { constructFrom } from '../constructFrom/index'; +import { startOfWeek } from '../startOfWeek/index'; +import { toDate } from '../toDate/index'; +import type { FirstWeekContainsDateOptions, LocalizedOptions, WeekOptions } from '../types'; import { getDefaultOptions } from '../_lib/defaultOptions/index'; /** * The {@link getWeekYear} function options. */ -export interface GetWeekYearOptions extends LocaleOptions, WeekStartOptions, FirstWeekContainsDateOptions {} +export interface GetWeekYearOptions extends LocalizedOptions<'options'>, WeekOptions, FirstWeekContainsDateOptions {} /** * @name getWeekYear @@ -21,11 +21,14 @@ export interface GetWeekYearOptions extends LocaleOptions, WeekStartOptions, Fir * and `options.firstWeekContainsDate` (which is the day of January, which is always in * the first week of the week-numbering year) * - * Week numbering: https://en.wikipedia.org/wiki/Week#Week_numbering + * Week numbering: https://en.wikipedia.org/wiki/Week#The_ISO_week_date_system * - * @param date - the given date - * @param options - an object with options. - * @returns the local week-numbering year + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The given date + * @param options - An object with options. + * + * @returns The local week-numbering year * * @example * // Which week numbering year is 26 December 2004 with the default settings? @@ -42,12 +45,12 @@ export interface GetWeekYearOptions extends LocaleOptions, WeekStartOptions, Fir * const result = getWeekYear(new Date(2004, 11, 26), { firstWeekContainsDate: 4 }) * //=> 2004 */ -export default function getWeekYear( - dirtyDate: DateType | number, +export function getWeekYear( + date: DateType | number | string, options?: GetWeekYearOptions, ): number { - const date = toDate(dirtyDate); - const year = date.getFullYear(); + const _date = toDate(date); + const year = _date.getFullYear(); const defaultOptions = getDefaultOptions(); const firstWeekContainsDate = @@ -57,19 +60,19 @@ export default function getWeekYear( defaultOptions.locale?.options?.firstWeekContainsDate ?? 1; - const firstWeekOfNextYear = dateFrom(dirtyDate, 0); + const firstWeekOfNextYear = constructFrom(date, 0); firstWeekOfNextYear.setFullYear(year + 1, 0, firstWeekContainsDate); firstWeekOfNextYear.setHours(0, 0, 0, 0); const startOfNextYear = startOfWeek(firstWeekOfNextYear, options); - const firstWeekOfThisYear = dateFrom(dirtyDate, 0); + const firstWeekOfThisYear = constructFrom(date, 0); firstWeekOfThisYear.setFullYear(year, 0, firstWeekContainsDate); firstWeekOfThisYear.setHours(0, 0, 0, 0); const startOfThisYear = startOfWeek(firstWeekOfThisYear, options); - if (date.getTime() >= startOfNextYear.getTime()) { + if (_date.getTime() >= startOfNextYear.getTime()) { return year + 1; - } else if (date.getTime() >= startOfThisYear.getTime()) { + } else if (_date.getTime() >= startOfThisYear.getTime()) { return year; } else { return year - 1; diff --git a/src/date-fns/getWeeksInMonth/index.ts b/src/date-fns/getWeeksInMonth/index.ts index 7974904..b715c3b 100644 --- a/src/date-fns/getWeeksInMonth/index.ts +++ b/src/date-fns/getWeeksInMonth/index.ts @@ -1,12 +1,12 @@ -import differenceInCalendarWeeks from '../differenceInCalendarWeeks/index'; -import lastDayOfMonth from '../lastDayOfMonth/index'; -import startOfMonth from '../startOfMonth/index'; -import type { LocaleOptions, WeekStartOptions } from '../types'; +import { differenceInCalendarWeeks } from '../differenceInCalendarWeeks/index'; +import { lastDayOfMonth } from '../lastDayOfMonth/index'; +import { startOfMonth } from '../startOfMonth/index'; +import type { LocalizedOptions, WeekOptions } from '../types'; /** * The {@link getWeeksInMonth} function options. */ -export interface GetWeeksInMonthOptions extends LocaleOptions, WeekStartOptions {} +export interface GetWeeksInMonthOptions extends LocalizedOptions<'options'>, WeekOptions {} /** * @name getWeeksInMonth @@ -16,9 +16,12 @@ export interface GetWeeksInMonthOptions extends LocaleOptions, WeekStartOptions * @description * Get the number of calendar weeks the month in the given date spans. * - * @param date - the given date - * @param options - an object with options. - * @returns the number of calendar weeks + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The given date + * @param options - An object with options. + * + * @returns The number of calendar weeks * * @example * // How many calendar weeks does February 2015 span? @@ -31,8 +34,8 @@ export interface GetWeeksInMonthOptions extends LocaleOptions, WeekStartOptions * const result = getWeeksInMonth(new Date(2017, 6, 5), { weekStartsOn: 1 }) * //=> 6 */ -export default function getWeeksInMonth( - date: DateType | number, +export function getWeeksInMonth( + date: DateType | number | string, options?: GetWeeksInMonthOptions, ): number { return differenceInCalendarWeeks(lastDayOfMonth(date), startOfMonth(date), options) + 1; diff --git a/src/date-fns/getYear/index.ts b/src/date-fns/getYear/index.ts index da1d394..e3a41a1 100644 --- a/src/date-fns/getYear/index.ts +++ b/src/date-fns/getYear/index.ts @@ -1,4 +1,4 @@ -import toDate from '../toDate/index'; +import { toDate } from '../toDate/index'; /** * @name getYear @@ -8,14 +8,17 @@ import toDate from '../toDate/index'; * @description * Get the year of the given date. * - * @param date - the given date - * @returns the year + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The given date + * + * @returns The year * * @example * // Which year is 2 July 2014? * const result = getYear(new Date(2014, 6, 2)) * //=> 2014 */ -export default function getYear(dirtyDate: DateType | number): number { - return toDate(dirtyDate).getFullYear(); +export function getYear(date: DateType | number | string): number { + return toDate(date).getFullYear(); } diff --git a/src/date-fns/hoursToMilliseconds/index.ts b/src/date-fns/hoursToMilliseconds/index.ts index 5841d95..f4ffe08 100644 --- a/src/date-fns/hoursToMilliseconds/index.ts +++ b/src/date-fns/hoursToMilliseconds/index.ts @@ -8,15 +8,17 @@ import { millisecondsInHour } from '../constants/index'; * @description * Convert a number of hours to a full number of milliseconds. * + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * * @param hours - number of hours to be converted * - * @returns the number of hours converted to milliseconds + * @returns The number of hours converted to milliseconds * * @example * // Convert 2 hours to milliseconds: * const result = hoursToMilliseconds(2) * //=> 7200000 */ -export default function hoursToMilliseconds(hours: number): number { - return Math.floor(hours * millisecondsInHour); +export function hoursToMilliseconds(hours: number): number { + return Math.trunc(hours * millisecondsInHour); } diff --git a/src/date-fns/hoursToMinutes/index.ts b/src/date-fns/hoursToMinutes/index.ts index c5eafe4..52e1d12 100644 --- a/src/date-fns/hoursToMinutes/index.ts +++ b/src/date-fns/hoursToMinutes/index.ts @@ -8,15 +8,17 @@ import { minutesInHour } from '../constants/index'; * @description * Convert a number of hours to a full number of minutes. * + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * * @param hours - number of hours to be converted * - * @returns the number of hours converted in minutes + * @returns The number of hours converted in minutes * * @example * // Convert 2 hours to minutes: * const result = hoursToMinutes(2) * //=> 120 */ -export default function hoursToMinutes(hours: number): number { - return Math.floor(hours * minutesInHour); +export function hoursToMinutes(hours: number): number { + return Math.trunc(hours * minutesInHour); } diff --git a/src/date-fns/hoursToSeconds/index.ts b/src/date-fns/hoursToSeconds/index.ts index 46f1dbb..2fe0dd5 100644 --- a/src/date-fns/hoursToSeconds/index.ts +++ b/src/date-fns/hoursToSeconds/index.ts @@ -8,15 +8,17 @@ import { secondsInHour } from '../constants/index'; * @description * Convert a number of hours to a full number of seconds. * - * @param hours - number of hours to be converted + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). * - * @returns the number of hours converted in seconds + * @param hours - The number of hours to be converted + * + * @returns The number of hours converted in seconds * * @example * // Convert 2 hours to seconds: * const result = hoursToSeconds(2) * //=> 7200 */ -export default function hoursToSeconds(hours: number): number { - return Math.floor(hours * secondsInHour); +export function hoursToSeconds(hours: number): number { + return Math.trunc(hours * secondsInHour); } diff --git a/src/date-fns/index.ts b/src/date-fns/index.ts index 6c1baf6..cdf4d54 100755 --- a/src/date-fns/index.ts +++ b/src/date-fns/index.ts @@ -1,242 +1,248 @@ // This file is generated automatically by `scripts/build/indices.ts`. Please, don't change it. -export { default as add } from './add/index'; -export { default as addBusinessDays } from './addBusinessDays/index'; -export { default as addDays } from './addDays/index'; -export { default as addHours } from './addHours/index'; -export { default as addISOWeekYears } from './addISOWeekYears/index'; -export { default as addMilliseconds } from './addMilliseconds/index'; -export { default as addMinutes } from './addMinutes/index'; -export { default as addMonths } from './addMonths/index'; -export { default as addQuarters } from './addQuarters/index'; -export { default as addSeconds } from './addSeconds/index'; -export { default as addWeeks } from './addWeeks/index'; -export { default as addYears } from './addYears/index'; -export { default as areIntervalsOverlapping } from './areIntervalsOverlapping/index'; -export { default as clamp } from './clamp/index'; -export { default as closestIndexTo } from './closestIndexTo/index'; -export { default as closestTo } from './closestTo/index'; -export { default as compareAsc } from './compareAsc/index'; -export { default as compareDesc } from './compareDesc/index'; -export { default as daysToWeeks } from './daysToWeeks/index'; -export { default as differenceInBusinessDays } from './differenceInBusinessDays/index'; -export { default as differenceInCalendarDays } from './differenceInCalendarDays/index'; -export { default as differenceInCalendarISOWeekYears } from './differenceInCalendarISOWeekYears/index'; -export { default as differenceInCalendarISOWeeks } from './differenceInCalendarISOWeeks/index'; -export { default as differenceInCalendarMonths } from './differenceInCalendarMonths/index'; -export { default as differenceInCalendarQuarters } from './differenceInCalendarQuarters/index'; -export { default as differenceInCalendarWeeks } from './differenceInCalendarWeeks/index'; -export { default as differenceInCalendarYears } from './differenceInCalendarYears/index'; -export { default as differenceInDays } from './differenceInDays/index'; -export { default as differenceInHours } from './differenceInHours/index'; -export { default as differenceInISOWeekYears } from './differenceInISOWeekYears/index'; -export { default as differenceInMilliseconds } from './differenceInMilliseconds/index'; -export { default as differenceInMinutes } from './differenceInMinutes/index'; -export { default as differenceInMonths } from './differenceInMonths/index'; -export { default as differenceInQuarters } from './differenceInQuarters/index'; -export { default as differenceInSeconds } from './differenceInSeconds/index'; -export { default as differenceInWeeks } from './differenceInWeeks/index'; -export { default as differenceInYears } from './differenceInYears/index'; -export { default as eachDayOfInterval } from './eachDayOfInterval/index'; -export { default as eachHourOfInterval } from './eachHourOfInterval/index'; -export { default as eachMinuteOfInterval } from './eachMinuteOfInterval/index'; -export { default as eachMonthOfInterval } from './eachMonthOfInterval/index'; -export { default as eachQuarterOfInterval } from './eachQuarterOfInterval/index'; -export { default as eachWeekOfInterval } from './eachWeekOfInterval/index'; -export { default as eachWeekendOfInterval } from './eachWeekendOfInterval/index'; -export { default as eachWeekendOfMonth } from './eachWeekendOfMonth/index'; -export { default as eachWeekendOfYear } from './eachWeekendOfYear/index'; -export { default as eachYearOfInterval } from './eachYearOfInterval/index'; -export { default as endOfDay } from './endOfDay/index'; -export { default as endOfDecade } from './endOfDecade/index'; -export { default as endOfHour } from './endOfHour/index'; -export { default as endOfISOWeek } from './endOfISOWeek/index'; -export { default as endOfISOWeekYear } from './endOfISOWeekYear/index'; -export { default as endOfMinute } from './endOfMinute/index'; -export { default as endOfMonth } from './endOfMonth/index'; -export { default as endOfQuarter } from './endOfQuarter/index'; -export { default as endOfSecond } from './endOfSecond/index'; -export { default as endOfToday } from './endOfToday/index'; -export { default as endOfTomorrow } from './endOfTomorrow/index'; -export { default as endOfWeek } from './endOfWeek/index'; -export { default as endOfYear } from './endOfYear/index'; -export { default as endOfYesterday } from './endOfYesterday/index'; -export { default as format } from './format/index'; -export { default as formatDistance } from './formatDistance/index'; -export { default as formatDistanceStrict } from './formatDistanceStrict/index'; -export { default as formatDistanceToNow } from './formatDistanceToNow/index'; -export { default as formatDistanceToNowStrict } from './formatDistanceToNowStrict/index'; -export { default as formatDuration } from './formatDuration/index'; -export { default as formatISO } from './formatISO/index'; -export { default as formatISO9075 } from './formatISO9075/index'; -export { default as formatISODuration } from './formatISODuration/index'; -export { default as formatRFC3339 } from './formatRFC3339/index'; -export { default as formatRFC7231 } from './formatRFC7231/index'; -export { default as formatRelative } from './formatRelative/index'; -export { default as fromUnixTime } from './fromUnixTime/index'; -export { default as getDate } from './getDate/index'; -export { default as getDay } from './getDay/index'; -export { default as getDayOfYear } from './getDayOfYear/index'; -export { default as getDaysInMonth } from './getDaysInMonth/index'; -export { default as getDaysInYear } from './getDaysInYear/index'; -export { default as getDecade } from './getDecade/index'; -export { default as getDefaultOptions } from './getDefaultOptions/index'; -export { default as getHours } from './getHours/index'; -export { default as getISODay } from './getISODay/index'; -export { default as getISOWeek } from './getISOWeek/index'; -export { default as getISOWeekYear } from './getISOWeekYear/index'; -export { default as getISOWeeksInYear } from './getISOWeeksInYear/index'; -export { default as getMilliseconds } from './getMilliseconds/index'; -export { default as getMinutes } from './getMinutes/index'; -export { default as getMonth } from './getMonth/index'; -export { default as getOverlappingDaysInIntervals } from './getOverlappingDaysInIntervals/index'; -export { default as getQuarter } from './getQuarter/index'; -export { default as getSeconds } from './getSeconds/index'; -export { default as getTime } from './getTime/index'; -export { default as getUnixTime } from './getUnixTime/index'; -export { default as getWeek } from './getWeek/index'; -export { default as getWeekOfMonth } from './getWeekOfMonth/index'; -export { default as getWeekYear } from './getWeekYear/index'; -export { default as getWeeksInMonth } from './getWeeksInMonth/index'; -export { default as getYear } from './getYear/index'; -export { default as hoursToMilliseconds } from './hoursToMilliseconds/index'; -export { default as hoursToMinutes } from './hoursToMinutes/index'; -export { default as hoursToSeconds } from './hoursToSeconds/index'; -export { default as intervalToDuration } from './intervalToDuration/index'; -export { default as intlFormat } from './intlFormat/index'; -export { default as intlFormatDistance } from './intlFormatDistance/index'; -export { default as isAfter } from './isAfter/index'; -export { default as isBefore } from './isBefore/index'; -export { default as isDate } from './isDate/index'; -export { default as isEqual } from './isEqual/index'; -export { default as isExists } from './isExists/index'; -export { default as isFirstDayOfMonth } from './isFirstDayOfMonth/index'; -export { default as isFriday } from './isFriday/index'; -export { default as isFuture } from './isFuture/index'; -export { default as isLastDayOfMonth } from './isLastDayOfMonth/index'; -export { default as isLeapYear } from './isLeapYear/index'; -export { default as isMatch } from './isMatch/index'; -export { default as isMonday } from './isMonday/index'; -export { default as isPast } from './isPast/index'; -export { default as isSameDay } from './isSameDay/index'; -export { default as isSameHour } from './isSameHour/index'; -export { default as isSameISOWeek } from './isSameISOWeek/index'; -export { default as isSameISOWeekYear } from './isSameISOWeekYear/index'; -export { default as isSameMinute } from './isSameMinute/index'; -export { default as isSameMonth } from './isSameMonth/index'; -export { default as isSameQuarter } from './isSameQuarter/index'; -export { default as isSameSecond } from './isSameSecond/index'; -export { default as isSameWeek } from './isSameWeek/index'; -export { default as isSameYear } from './isSameYear/index'; -export { default as isSaturday } from './isSaturday/index'; -export { default as isSunday } from './isSunday/index'; -export { default as isThisHour } from './isThisHour/index'; -export { default as isThisISOWeek } from './isThisISOWeek/index'; -export { default as isThisMinute } from './isThisMinute/index'; -export { default as isThisMonth } from './isThisMonth/index'; -export { default as isThisQuarter } from './isThisQuarter/index'; -export { default as isThisSecond } from './isThisSecond/index'; -export { default as isThisWeek } from './isThisWeek/index'; -export { default as isThisYear } from './isThisYear/index'; -export { default as isThursday } from './isThursday/index'; -export { default as isToday } from './isToday/index'; -export { default as isTomorrow } from './isTomorrow/index'; -export { default as isTuesday } from './isTuesday/index'; -export { default as isValid } from './isValid/index'; -export { default as isWednesday } from './isWednesday/index'; -export { default as isWeekend } from './isWeekend/index'; -export { default as isWithinInterval } from './isWithinInterval/index'; -export { default as isYesterday } from './isYesterday/index'; -export { default as lastDayOfDecade } from './lastDayOfDecade/index'; -export { default as lastDayOfISOWeek } from './lastDayOfISOWeek/index'; -export { default as lastDayOfISOWeekYear } from './lastDayOfISOWeekYear/index'; -export { default as lastDayOfMonth } from './lastDayOfMonth/index'; -export { default as lastDayOfQuarter } from './lastDayOfQuarter/index'; -export { default as lastDayOfWeek } from './lastDayOfWeek/index'; -export { default as lastDayOfYear } from './lastDayOfYear/index'; -export { default as lightFormat } from './lightFormat/index'; -export { default as max } from './max/index'; -export { default as milliseconds } from './milliseconds/index'; -export { default as millisecondsToHours } from './millisecondsToHours/index'; -export { default as millisecondsToMinutes } from './millisecondsToMinutes/index'; -export { default as millisecondsToSeconds } from './millisecondsToSeconds/index'; -export { default as min } from './min/index'; -export { default as minutesToHours } from './minutesToHours/index'; -export { default as minutesToMilliseconds } from './minutesToMilliseconds/index'; -export { default as minutesToSeconds } from './minutesToSeconds/index'; -export { default as monthsToQuarters } from './monthsToQuarters/index'; -export { default as monthsToYears } from './monthsToYears/index'; -export { default as nextDay } from './nextDay/index'; -export { default as nextFriday } from './nextFriday/index'; -export { default as nextMonday } from './nextMonday/index'; -export { default as nextSaturday } from './nextSaturday/index'; -export { default as nextSunday } from './nextSunday/index'; -export { default as nextThursday } from './nextThursday/index'; -export { default as nextTuesday } from './nextTuesday/index'; -export { default as nextWednesday } from './nextWednesday/index'; -export { default as parse } from './parse/index'; -export { default as parseISO } from './parseISO/index'; -export { default as parseJSON } from './parseJSON/index'; -export { default as previousDay } from './previousDay/index'; -export { default as previousFriday } from './previousFriday/index'; -export { default as previousMonday } from './previousMonday/index'; -export { default as previousSaturday } from './previousSaturday/index'; -export { default as previousSunday } from './previousSunday/index'; -export { default as previousThursday } from './previousThursday/index'; -export { default as previousTuesday } from './previousTuesday/index'; -export { default as previousWednesday } from './previousWednesday/index'; -export { default as quartersToMonths } from './quartersToMonths/index'; -export { default as quartersToYears } from './quartersToYears/index'; -export { default as roundToNearestMinutes } from './roundToNearestMinutes/index'; -export { default as secondsToHours } from './secondsToHours/index'; -export { default as secondsToMilliseconds } from './secondsToMilliseconds/index'; -export { default as secondsToMinutes } from './secondsToMinutes/index'; -export { default as set } from './set/index'; -export { default as setDate } from './setDate/index'; -export { default as setDay } from './setDay/index'; -export { default as setDayOfYear } from './setDayOfYear/index'; -export { default as setDefaultOptions } from './setDefaultOptions/index'; -export { default as setHours } from './setHours/index'; -export { default as setISODay } from './setISODay/index'; -export { default as setISOWeek } from './setISOWeek/index'; -export { default as setISOWeekYear } from './setISOWeekYear/index'; -export { default as setMilliseconds } from './setMilliseconds/index'; -export { default as setMinutes } from './setMinutes/index'; -export { default as setMonth } from './setMonth/index'; -export { default as setQuarter } from './setQuarter/index'; -export { default as setSeconds } from './setSeconds/index'; -export { default as setWeek } from './setWeek/index'; -export { default as setWeekYear } from './setWeekYear/index'; -export { default as setYear } from './setYear/index'; -export { default as startOfDay } from './startOfDay/index'; -export { default as startOfDecade } from './startOfDecade/index'; -export { default as startOfHour } from './startOfHour/index'; -export { default as startOfISOWeek } from './startOfISOWeek/index'; -export { default as startOfISOWeekYear } from './startOfISOWeekYear/index'; -export { default as startOfMinute } from './startOfMinute/index'; -export { default as startOfMonth } from './startOfMonth/index'; -export { default as startOfQuarter } from './startOfQuarter/index'; -export { default as startOfSecond } from './startOfSecond/index'; -export { default as startOfToday } from './startOfToday/index'; -export { default as startOfTomorrow } from './startOfTomorrow/index'; -export { default as startOfWeek } from './startOfWeek/index'; -export { default as startOfWeekYear } from './startOfWeekYear/index'; -export { default as startOfYear } from './startOfYear/index'; -export { default as startOfYesterday } from './startOfYesterday/index'; -export { default as sub } from './sub/index'; -export { default as subBusinessDays } from './subBusinessDays/index'; -export { default as subDays } from './subDays/index'; -export { default as subHours } from './subHours/index'; -export { default as subISOWeekYears } from './subISOWeekYears/index'; -export { default as subMilliseconds } from './subMilliseconds/index'; -export { default as subMinutes } from './subMinutes/index'; -export { default as subMonths } from './subMonths/index'; -export { default as subQuarters } from './subQuarters/index'; -export { default as subSeconds } from './subSeconds/index'; -export { default as subWeeks } from './subWeeks/index'; -export { default as subYears } from './subYears/index'; -export { default as toDate } from './toDate/index'; -export { default as weeksToDays } from './weeksToDays/index'; -export { default as yearsToMonths } from './yearsToMonths/index'; -export { default as yearsToQuarters } from './yearsToQuarters/index'; -export * from './constants/index'; +export * from './add/index'; +export * from './addBusinessDays/index'; +export * from './addDays/index'; +export * from './addHours/index'; +export * from './addISOWeekYears/index'; +export * from './addMilliseconds/index'; +export * from './addMinutes/index'; +export * from './addMonths/index'; +export * from './addQuarters/index'; +export * from './addSeconds/index'; +export * from './addWeeks/index'; +export * from './addYears/index'; +export * from './areIntervalsOverlapping/index'; +export * from './clamp/index'; +export * from './closestIndexTo/index'; +export * from './closestTo/index'; +export * from './compareAsc/index'; +export * from './compareDesc/index'; +export * from './constructFrom/index'; +export * from './constructNow/index'; +export * from './daysToWeeks/index'; +export * from './differenceInBusinessDays/index'; +export * from './differenceInCalendarDays/index'; +export * from './differenceInCalendarISOWeekYears/index'; +export * from './differenceInCalendarISOWeeks/index'; +export * from './differenceInCalendarMonths/index'; +export * from './differenceInCalendarQuarters/index'; +export * from './differenceInCalendarWeeks/index'; +export * from './differenceInCalendarYears/index'; +export * from './differenceInDays/index'; +export * from './differenceInHours/index'; +export * from './differenceInISOWeekYears/index'; +export * from './differenceInMilliseconds/index'; +export * from './differenceInMinutes/index'; +export * from './differenceInMonths/index'; +export * from './differenceInQuarters/index'; +export * from './differenceInSeconds/index'; +export * from './differenceInWeeks/index'; +export * from './differenceInYears/index'; +export * from './eachDayOfInterval/index'; +export * from './eachHourOfInterval/index'; +export * from './eachMinuteOfInterval/index'; +export * from './eachMonthOfInterval/index'; +export * from './eachQuarterOfInterval/index'; +export * from './eachWeekOfInterval/index'; +export * from './eachWeekendOfInterval/index'; +export * from './eachWeekendOfMonth/index'; +export * from './eachWeekendOfYear/index'; +export * from './eachYearOfInterval/index'; +export * from './endOfDay/index'; +export * from './endOfDecade/index'; +export * from './endOfHour/index'; +export * from './endOfISOWeek/index'; +export * from './endOfISOWeekYear/index'; +export * from './endOfMinute/index'; +export * from './endOfMonth/index'; +export * from './endOfQuarter/index'; +export * from './endOfSecond/index'; +export * from './endOfToday/index'; +export * from './endOfTomorrow/index'; +export * from './endOfWeek/index'; +export * from './endOfYear/index'; +export * from './endOfYesterday/index'; +export * from './format/index'; +export * from './formatDistance/index'; +export * from './formatDistanceStrict/index'; +export * from './formatDistanceToNow/index'; +export * from './formatDistanceToNowStrict/index'; +export * from './formatDuration/index'; +export * from './formatISO/index'; +export * from './formatISO9075/index'; +export * from './formatISODuration/index'; +export * from './formatRFC3339/index'; +export * from './formatRFC7231/index'; +export * from './formatRelative/index'; +export * from './fromUnixTime/index'; +export * from './getDate/index'; +export * from './getDay/index'; +export * from './getDayOfYear/index'; +export * from './getDaysInMonth/index'; +export * from './getDaysInYear/index'; +export * from './getDecade/index'; +export * from './getDefaultOptions/index'; +export * from './getHours/index'; +export * from './getISODay/index'; +export * from './getISOWeek/index'; +export * from './getISOWeekYear/index'; +export * from './getISOWeeksInYear/index'; +export * from './getMilliseconds/index'; +export * from './getMinutes/index'; +export * from './getMonth/index'; +export * from './getOverlappingDaysInIntervals/index'; +export * from './getQuarter/index'; +export * from './getSeconds/index'; +export * from './getTime/index'; +export * from './getUnixTime/index'; +export * from './getWeek/index'; +export * from './getWeekOfMonth/index'; +export * from './getWeekYear/index'; +export * from './getWeeksInMonth/index'; +export * from './getYear/index'; +export * from './hoursToMilliseconds/index'; +export * from './hoursToMinutes/index'; +export * from './hoursToSeconds/index'; +export * from './interval/index'; +export * from './intervalToDuration/index'; +export * from './intlFormat/index'; +export * from './intlFormatDistance/index'; +export * from './isAfter/index'; +export * from './isBefore/index'; +export * from './isDate/index'; +export * from './isEqual/index'; +export * from './isExists/index'; +export * from './isFirstDayOfMonth/index'; +export * from './isFriday/index'; +export * from './isFuture/index'; +export * from './isLastDayOfMonth/index'; +export * from './isLeapYear/index'; +export * from './isMatch/index'; +export * from './isMonday/index'; +export * from './isPast/index'; +export * from './isSameDay/index'; +export * from './isSameHour/index'; +export * from './isSameISOWeek/index'; +export * from './isSameISOWeekYear/index'; +export * from './isSameMinute/index'; +export * from './isSameMonth/index'; +export * from './isSameQuarter/index'; +export * from './isSameSecond/index'; +export * from './isSameWeek/index'; +export * from './isSameYear/index'; +export * from './isSaturday/index'; +export * from './isSunday/index'; +export * from './isThisHour/index'; +export * from './isThisISOWeek/index'; +export * from './isThisMinute/index'; +export * from './isThisMonth/index'; +export * from './isThisQuarter/index'; +export * from './isThisSecond/index'; +export * from './isThisWeek/index'; +export * from './isThisYear/index'; +export * from './isThursday/index'; +export * from './isToday/index'; +export * from './isTomorrow/index'; +export * from './isTuesday/index'; +export * from './isValid/index'; +export * from './isWednesday/index'; +export * from './isWeekend/index'; +export * from './isWithinInterval/index'; +export * from './isYesterday/index'; +export * from './lastDayOfDecade/index'; +export * from './lastDayOfISOWeek/index'; +export * from './lastDayOfISOWeekYear/index'; +export * from './lastDayOfMonth/index'; +export * from './lastDayOfQuarter/index'; +export * from './lastDayOfWeek/index'; +export * from './lastDayOfYear/index'; +export * from './lightFormat/index'; +export * from './max/index'; +export * from './milliseconds/index'; +export * from './millisecondsToHours/index'; +export * from './millisecondsToMinutes/index'; +export * from './millisecondsToSeconds/index'; +export * from './min/index'; +export * from './minutesToHours/index'; +export * from './minutesToMilliseconds/index'; +export * from './minutesToSeconds/index'; +export * from './monthsToQuarters/index'; +export * from './monthsToYears/index'; +export * from './nextDay/index'; +export * from './nextFriday/index'; +export * from './nextMonday/index'; +export * from './nextSaturday/index'; +export * from './nextSunday/index'; +export * from './nextThursday/index'; +export * from './nextTuesday/index'; +export * from './nextWednesday/index'; +export * from './parse/index'; +export * from './parseISO/index'; +export * from './parseJSON/index'; +export * from './previousDay/index'; +export * from './previousFriday/index'; +export * from './previousMonday/index'; +export * from './previousSaturday/index'; +export * from './previousSunday/index'; +export * from './previousThursday/index'; +export * from './previousTuesday/index'; +export * from './previousWednesday/index'; +export * from './quartersToMonths/index'; +export * from './quartersToYears/index'; +export * from './roundToNearestHours/index'; +export * from './roundToNearestMinutes/index'; +export * from './secondsToHours/index'; +export * from './secondsToMilliseconds/index'; +export * from './secondsToMinutes/index'; +export * from './set/index'; +export * from './setDate/index'; +export * from './setDay/index'; +export * from './setDayOfYear/index'; +export * from './setDefaultOptions/index'; +export * from './setHours/index'; +export * from './setISODay/index'; +export * from './setISOWeek/index'; +export * from './setISOWeekYear/index'; +export * from './setMilliseconds/index'; +export * from './setMinutes/index'; +export * from './setMonth/index'; +export * from './setQuarter/index'; +export * from './setSeconds/index'; +export * from './setWeek/index'; +export * from './setWeekYear/index'; +export * from './setYear/index'; +export * from './startOfDay/index'; +export * from './startOfDecade/index'; +export * from './startOfHour/index'; +export * from './startOfISOWeek/index'; +export * from './startOfISOWeekYear/index'; +export * from './startOfMinute/index'; +export * from './startOfMonth/index'; +export * from './startOfQuarter/index'; +export * from './startOfSecond/index'; +export * from './startOfToday/index'; +export * from './startOfTomorrow/index'; +export * from './startOfWeek/index'; +export * from './startOfWeekYear/index'; +export * from './startOfYear/index'; +export * from './startOfYesterday/index'; +export * from './sub/index'; +export * from './subBusinessDays/index'; +export * from './subDays/index'; +export * from './subHours/index'; +export * from './subISOWeekYears/index'; +export * from './subMilliseconds/index'; +export * from './subMinutes/index'; +export * from './subMonths/index'; +export * from './subQuarters/index'; +export * from './subSeconds/index'; +export * from './subWeeks/index'; +export * from './subYears/index'; +export * from './toDate/index'; +export * from './transpose/index'; +export * from './weeksToDays/index'; +export * from './yearsToDays/index'; +export * from './yearsToMonths/index'; +export * from './yearsToQuarters/index'; +export type * from './types'; diff --git a/src/date-fns/interval/index.ts b/src/date-fns/interval/index.ts new file mode 100644 index 0000000..c544e61 --- /dev/null +++ b/src/date-fns/interval/index.ts @@ -0,0 +1,46 @@ +import { toDate } from '../toDate/index'; +import type { NormalizedInterval } from '../types'; + +/** + * The {@link interval} function options. + */ +export interface IntervalOptions { + /** Asserts that the interval is positive (start is after the end). */ + assertPositive?: boolean; +} + +/** + * @name interval + * @category Interval Helpers + * @summary Creates an interval object and validates its values. + * + * @description + * Creates a normalized interval object and validates its values. If the interval is invalid, an exception is thrown. + * + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param start - The start of the interval. + * @param end - The end of the interval. + * @param options - The options object. + * + * @throws `Start date is invalid` when `start` is invalid. + * @throws `End date is invalid` when `end` is invalid. + * @throws `End date must be after start date` when end is before `start` and `options.assertPositive` is true. + * + * @returns The normalized and validated interval object. + */ +export function interval( + start: DateType | number | string, + end: DateType | number | string, + options?: IntervalOptions, +): NormalizedInterval { + const _start = toDate(start); + if (isNaN(+_start)) throw new TypeError('Start date is invalid'); + + const _end = toDate(end); + if (isNaN(+_end)) throw new TypeError('End date is invalid'); + + if (options?.assertPositive && +_start > +_end) throw new TypeError('End date must be after start date'); + + return { start: _start, end: _end }; +} diff --git a/src/date-fns/intervalToDuration/index.ts b/src/date-fns/intervalToDuration/index.ts index 19f5653..6a4e9b7 100644 --- a/src/date-fns/intervalToDuration/index.ts +++ b/src/date-fns/intervalToDuration/index.ts @@ -1,11 +1,11 @@ -import add from '../add/index'; -import differenceInDays from '../differenceInDays/index'; -import differenceInHours from '../differenceInHours/index'; -import differenceInMinutes from '../differenceInMinutes/index'; -import differenceInMonths from '../differenceInMonths/index'; -import differenceInSeconds from '../differenceInSeconds/index'; -import differenceInYears from '../differenceInYears/index'; -import toDate from '../toDate/index'; +import { add } from '../add/index'; +import { differenceInDays } from '../differenceInDays/index'; +import { differenceInHours } from '../differenceInHours/index'; +import { differenceInMinutes } from '../differenceInMinutes/index'; +import { differenceInMonths } from '../differenceInMonths/index'; +import { differenceInSeconds } from '../differenceInSeconds/index'; +import { differenceInYears } from '../differenceInYears/index'; +import { toDate } from '../toDate/index'; import type { Duration, Interval } from '../types'; /** @@ -16,12 +16,11 @@ import type { Duration, Interval } from '../types'; * @description * Convert a interval object to a duration object. * - * @param interval - the interval to convert to duration + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). * - * @returns The duration Object - * @throws {RangeError} `start` must not be Invalid Date - * @throws {RangeError} `end` must not be Invalid Date - * @throws {RangeError} The start of an interval cannot be after its end + * @param interval - The interval to convert to duration + * + * @returns The duration object * * @example * // Get the duration between January 15, 1929 and April 4, 1968. @@ -31,34 +30,40 @@ import type { Duration, Interval } from '../types'; * }) * // => { years: 39, months: 2, days: 20, hours: 7, minutes: 5, seconds: 0 } */ -export default function interval(interval: Interval): Duration { +export function intervalToDuration(interval: Interval): Duration { const start = toDate(interval.start); const end = toDate(interval.end); - if (isNaN(start.getTime())) throw new RangeError('Start Date is invalid'); - if (isNaN(end.getTime())) throw new RangeError('End Date is invalid'); - if (start > end) { - throw new RangeError('The start of an interval cannot be after its end'); - } + const duration: Duration = {}; + + const years = differenceInYears(end, start); + if (years) duration.years = years; + + // @ts-ignore + const remainingMonths = add(start, { years: duration.years }); + + const months = differenceInMonths(end, remainingMonths); + if (months) duration.months = months; + + const remainingDays = add(remainingMonths, { months: duration.months! }); + + const days = differenceInDays(end, remainingDays); + if (days) duration.days = days; - const duration: Duration = { - years: differenceInYears(end, start), - }; + const remainingHours = add(remainingDays, { days: duration.days! }); - const remainingMonths = add(start, { years: duration.years as number }); - duration.months = differenceInMonths(end, remainingMonths); + const hours = differenceInHours(end, remainingHours); + if (hours) duration.hours = hours; - const remainingDays = add(remainingMonths, { months: duration.months }); - duration.days = differenceInDays(end, remainingDays); + const remainingMinutes = add(remainingHours, { hours: duration.hours! }); - const remainingHours = add(remainingDays, { days: duration.days }); - duration.hours = differenceInHours(end, remainingHours); + const minutes = differenceInMinutes(end, remainingMinutes); + if (minutes) duration.minutes = minutes; - const remainingMinutes = add(remainingHours, { hours: duration.hours }); - duration.minutes = differenceInMinutes(end, remainingMinutes); + const remainingSeconds = add(remainingMinutes, { minutes: duration.minutes! }); - const remainingSeconds = add(remainingMinutes, { minutes: duration.minutes }); - duration.seconds = differenceInSeconds(end, remainingSeconds); + const seconds = differenceInSeconds(end, remainingSeconds); + if (seconds) duration.seconds = seconds; return duration; } diff --git a/src/date-fns/intlFormat/index.ts b/src/date-fns/intlFormat/index.ts index e7c101b..840f512 100644 --- a/src/date-fns/intlFormat/index.ts +++ b/src/date-fns/intlFormat/index.ts @@ -1,23 +1,27 @@ -type Locale = Intl.ResolvedDateTimeFormatOptions['locale']; -type FormatOptions = Intl.DateTimeFormatOptions; -type LocaleOptions = { locale: Locale | Locale[] }; +import { toDate } from '../toDate/index'; -export default function intlFormat(date: DateType): string; - -export default function intlFormat(date: DateType, localeOptions: LocaleOptions): string; +/** + * The locale string (see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#locales_argument). + */ +export type IntlFormatLocale = Intl.ResolvedDateTimeFormatOptions['locale']; -export default function intlFormat(date: DateType, formatOptions: FormatOptions): string; +/** + * The format options (see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#options) + */ +export type IntlFormatFormatOptions = Intl.DateTimeFormatOptions; -export default function intlFormat( - date: DateType, - formatOptions: FormatOptions, - localeOptions: LocaleOptions, -): string; +/** + * The locale options. + */ +export interface IntlFormatLocaleOptions { + /** The locale(s) to use (see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#locales_argument) */ + locale: IntlFormatLocale | IntlFormatLocale[]; +} /** * @name intlFormat * @category Common Helpers - * @summary Format the date with Intl.DateTimeFormat (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat). + * @summary Format the date with Intl.DateTimeFormat (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat). * * @description * Return the formatted date string in the given format. @@ -26,69 +30,106 @@ export default function intlFormat( * * > ⚠️ Please note that before Node version 13.0.0, only the locale data for en-US is available by default. * - * @param argument - the original date. - * @param formatOptions - an object with options. - * @param formatOptions.localeMatcher - locale selection algorithm. - * @param formatOptions.weekday - representation the days of the week. - * @param formatOptions.era - representation of eras. - * @param formatOptions.year - representation of years. - * @param formatOptions.month - representation of month. - * @param formatOptions.day - representation of day. - * @param formatOptions.hour - representation of hours. - * @param formatOptions.minute - representation of minutes. - * @param formatOptions.second - representation of seconds. - * @param formatOptions.timeZoneName - representation of names of time zones. - * @param formatOptions.formatMatcher - format selection algorithm. - * @param formatOptions.hour12 - determines whether to use 12-hour time format. - * @param formatOptions.timeZone - the time zone to use. - * @param localeOptions - an object with locale. - * @param localeOptions.locale - the locale code - * @returns the formatted date string. - * @throws {RangeError} `date` must not be Invalid Date + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The date to format + * + * @returns The formatted date string + * + * @throws `date` must not be Invalid Date * * @example - * // Represent 10 October 2019 in German. - * // Convert the date with format's options and locale's options. + * // Represent 4 October 2019 in middle-endian format: + * const result = intlFormat(new Date(2019, 9, 4, 12, 30, 13, 456)) + * //=> 10/4/2019 + */ +export function intlFormat(date: DateType | number | string): string; + +/** + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The date to format + * @param localeOptions - An object with locale + * + * @returns The formatted date string + * + * @throws `date` must not be Invalid Date + * + * @example + * // Represent 4 October 2019 in Korean. + * // Convert the date with locale's options. * const result = intlFormat(new Date(2019, 9, 4, 12, 30, 13, 456), { - * weekday: 'long', - * year: 'numeric', - * month: 'long', - * day: 'numeric', - * }, { - * locale: 'de-DE', - * }) - * //=> Freitag, 4. Oktober 2019 + * locale: 'ko-KR', + * }) + * //=> 2019. 10. 4. + */ +export function intlFormat( + date: DateType | number | string, + localeOptions: IntlFormatLocaleOptions, +): string; + +/** + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The date to format + * @param formatOptions - The format options + * + * @returns The formatted date string + * + * @throws `date` must not be Invalid Date * * @example - * // Represent 10 October 2019. + * // Represent 4 October 2019. * // Convert the date with format's options. * const result = intlFormat.default(new Date(2019, 9, 4, 12, 30, 13, 456), { - * year: 'numeric', - * month: 'numeric', - * day: 'numeric', - * hour: 'numeric', - * }) + * year: 'numeric', + * month: 'numeric', + * day: 'numeric', + * hour: 'numeric', + * }) * //=> 10/4/2019, 12 PM + */ +export function intlFormat( + date: DateType | number | string, + formatOptions: IntlFormatFormatOptions, +): string; + +/** + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). * - * @example - * // Represent 10 October 2019 in Korean. - * // Convert the date with locale's options. - * const result = intlFormat(new Date(2019, 9, 4, 12, 30, 13, 456), { - * locale: 'ko-KR', - * }) - * //=> 2019. 10. 4. + * @param date - The date to format + * @param formatOptions - The format options + * @param localeOptions - An object with locale + * + * @returns The formatted date string + * + * @throws `date` must not be Invalid Date * * @example - * // Represent 10 October 2019 in middle-endian format: - * const result = intlFormat(new Date(2019, 9, 4, 12, 30, 13, 456)) - * //=> 10/4/2019 + * // Represent 4 October 2019 in German. + * // Convert the date with format's options and locale's options. + * const result = intlFormat(new Date(2019, 9, 4, 12, 30, 13, 456), { + * weekday: 'long', + * year: 'numeric', + * month: 'long', + * day: 'numeric', + * }, { + * locale: 'de-DE', + * }) + * //=> Freitag, 4. Oktober 2019 */ -export default function intlFormat( - date: DateType, - formatOrLocale?: FormatOptions | LocaleOptions, - localeOptions?: LocaleOptions, +export function intlFormat( + date: DateType | number | string, + formatOptions: IntlFormatFormatOptions, + localeOptions: IntlFormatLocaleOptions, +): string; + +export function intlFormat( + date: DateType | number | string, + formatOrLocale?: IntlFormatFormatOptions | IntlFormatLocaleOptions, + localeOptions?: IntlFormatLocaleOptions, ): string { - let formatOptions: FormatOptions | undefined; + let formatOptions: IntlFormatFormatOptions | undefined; if (isFormatOptions(formatOrLocale)) { formatOptions = formatOrLocale; @@ -96,9 +137,11 @@ export default function intlFormat( localeOptions = formatOrLocale; } - return new Intl.DateTimeFormat(localeOptions?.locale, formatOptions).format(date); + return new Intl.DateTimeFormat(localeOptions?.locale, formatOptions).format(toDate(date)); } -function isFormatOptions(opts: LocaleOptions | FormatOptions | undefined): opts is FormatOptions { +function isFormatOptions( + opts: IntlFormatLocaleOptions | IntlFormatFormatOptions | undefined, +): opts is IntlFormatFormatOptions { return opts !== undefined && !('locale' in opts); } diff --git a/src/date-fns/intlFormatDistance/index.ts b/src/date-fns/intlFormatDistance/index.ts index 210298a..b339545 100644 --- a/src/date-fns/intlFormatDistance/index.ts +++ b/src/date-fns/intlFormatDistance/index.ts @@ -7,28 +7,37 @@ import { secondsInWeek, secondsInYear, } from '../constants/index'; -import differenceInCalendarDays from '../differenceInCalendarDays/index'; -import differenceInCalendarMonths from '../differenceInCalendarMonths/index'; -import differenceInCalendarQuarters from '../differenceInCalendarQuarters/index'; -import differenceInCalendarWeeks from '../differenceInCalendarWeeks/index'; -import differenceInCalendarYears from '../differenceInCalendarYears/index'; -import differenceInHours from '../differenceInHours/index'; -import differenceInMinutes from '../differenceInMinutes/index'; -import differenceInSeconds from '../differenceInSeconds/index'; -import toDate from '../toDate/index'; -import type { IntlOptionsUnit } from '../types'; +import { differenceInCalendarDays } from '../differenceInCalendarDays/index'; +import { differenceInCalendarMonths } from '../differenceInCalendarMonths/index'; +import { differenceInCalendarQuarters } from '../differenceInCalendarQuarters/index'; +import { differenceInCalendarWeeks } from '../differenceInCalendarWeeks/index'; +import { differenceInCalendarYears } from '../differenceInCalendarYears/index'; +import { differenceInHours } from '../differenceInHours/index'; +import { differenceInMinutes } from '../differenceInMinutes/index'; +import { differenceInSeconds } from '../differenceInSeconds/index'; +import { toDate } from '../toDate/index'; /** * The {@link intlFormatDistance} function options. */ export interface IntlFormatDistanceOptions { - unit?: IntlOptionsUnit; - locale?: string; // [TODO:} the original type is Intl.BCP47LanguageTag, it's changed to string due to compilation error (Namespace 'Intl' has no exported member 'BCP47LanguageTag'.). hopefully this workaround won't be necessary once https://github.com/checkdigit/time/issues/15 is addressed + /** Force the distance unit */ + unit?: IntlFormatDistanceUnit; + /** The locale(s) to use (see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#locales_argument) */ + locale?: Intl.UnicodeBCP47LocaleIdentifier | Intl.UnicodeBCP47LocaleIdentifier[]; + /** The locale matching algorithm to use. Other value: 'lookup'. See MDN for details [Locale identification and negotiation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#locale_identification_and_negotiation) */ localeMatcher?: Intl.RelativeTimeFormatLocaleMatcher; + /** The output message format. The values are 'auto' (e.g. `yesterday`), 'always'(e.g. `1 day ago`) */ numeric?: Intl.RelativeTimeFormatNumeric; + /** The length of the result. The values are: 'long' (e.g. `1 month`), 'short' (e.g. 'in 1 mo.'), 'narrow' (e.g. 'in 1 mo.'). The narrow one could be similar to the short one for some locales. */ style?: Intl.RelativeTimeFormatStyle; } +/** + * The unit used to format the distance in {@link intlFormatDistance}. + */ +export type IntlFormatDistanceUnit = 'year' | 'quarter' | 'month' | 'week' | 'day' | 'hour' | 'minute' | 'second'; + /** * @name intlFormatDistance * @category Common Helpers @@ -59,19 +68,23 @@ export interface IntlFormatDistanceOptions { * | 1 year | last year | next year | * | 2+ years | X years ago | in X years | * - * @param date - the date - * @param baseDate - the date to compare with. - * @param options - an object with options. + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The date + * @param baseDate - The date to compare with. + * @param options - An object with options. * See MDN for details [Locale identification and negotiation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#locale_identification_and_negotiation) * The narrow one could be similar to the short one for some locales. - * @returns the distance in words according to language-sensitive relative time formatting. - * @throws {RangeError} `date` must not be Invalid Date - * @throws {RangeError} `baseDate` must not be Invalid Date - * @throws {RangeError} `options.unit` must not be invalid Unit - * @throws {RangeError} `options.locale` must not be invalid locale - * @throws {RangeError} `options.localeMatcher` must not be invalid localeMatcher - * @throws {RangeError} `options.numeric` must not be invalid numeric - * @throws {RangeError} `options.style` must not be invalid style + * + * @returns The distance in words according to language-sensitive relative time formatting. + * + * @throws `date` must not be Invalid Date + * @throws `baseDate` must not be Invalid Date + * @throws `options.unit` must not be invalid Unit + * @throws `options.locale` must not be invalid locale + * @throws `options.localeMatcher` must not be invalid localeMatcher + * @throws `options.numeric` must not be invalid numeric + * @throws `options.style` must not be invalid style * * @example * // What is the distance between the dates when the fist date is after the second? @@ -124,9 +137,9 @@ export interface IntlFormatDistanceOptions { * ) * //=> 'in 2 yr' */ -export default function intlFormatDistance( - date: Date | number, - baseDate: Date | number, +export function intlFormatDistance( + date: DateType | number | string, + baseDate: DateType | number | string, options?: IntlFormatDistanceOptions, ): string { let value: number = 0; @@ -195,9 +208,9 @@ export default function intlFormatDistance( } const rtf = new Intl.RelativeTimeFormat(options?.locale, { - localeMatcher: options?.localeMatcher as Intl.RelativeTimeFormatLocaleMatcher, + ...(options?.localeMatcher === undefined ? {} : { localeMatcher: options?.localeMatcher }), numeric: options?.numeric || 'auto', - style: options?.style as Intl.RelativeTimeFormatStyle, + ...(options?.style === undefined ? {} : { style: options?.style }), }); return rtf.format(value, unit); diff --git a/src/date-fns/isAfter/index.ts b/src/date-fns/isAfter/index.ts index eb5126c..3c69c91 100644 --- a/src/date-fns/isAfter/index.ts +++ b/src/date-fns/isAfter/index.ts @@ -1,4 +1,4 @@ -import toDate from '../toDate/index'; +import { toDate } from '../toDate/index'; /** * @name isAfter @@ -8,20 +8,23 @@ import toDate from '../toDate/index'; * @description * Is the first date after the second one? * - * @param date - the date that should be after the other one to return true - * @param dateToCompare - the date to compare with - * @returns the first date is after the second date + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The date that should be after the other one to return true + * @param dateToCompare - The date to compare with + * + * @returns The first date is after the second date * * @example * // Is 10 July 1989 after 11 February 1987? * const result = isAfter(new Date(1989, 6, 10), new Date(1987, 1, 11)) * //=> true */ -export default function isAfter( - dirtyDate: DateType | number, - dirtyDateToCompare: DateType | number, +export function isAfter( + date: DateType | number | string, + dateToCompare: DateType | number | string, ): boolean { - const date = toDate(dirtyDate); - const dateToCompare = toDate(dirtyDateToCompare); - return date.getTime() > dateToCompare.getTime(); + const _date = toDate(date); + const _dateToCompare = toDate(dateToCompare); + return _date.getTime() > _dateToCompare.getTime(); } diff --git a/src/date-fns/isBefore/index.ts b/src/date-fns/isBefore/index.ts index b64a15f..dbbe416 100644 --- a/src/date-fns/isBefore/index.ts +++ b/src/date-fns/isBefore/index.ts @@ -1,4 +1,4 @@ -import toDate from '../toDate/index'; +import { toDate } from '../toDate/index'; /** * @name isBefore @@ -8,20 +8,23 @@ import toDate from '../toDate/index'; * @description * Is the first date before the second one? * - * @param date - the date that should be before the other one to return true - * @param dateToCompare - the date to compare with - * @returns the first date is before the second date + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The date that should be before the other one to return true + * @param dateToCompare - The date to compare with + * + * @returns The first date is before the second date * * @example * // Is 10 July 1989 before 11 February 1987? * const result = isBefore(new Date(1989, 6, 10), new Date(1987, 1, 11)) * //=> false */ -export default function isBefore( - dirtyDate: DateType | number, - dirtyDateToCompare: DateType | number, +export function isBefore( + date: DateType | number | string, + dateToCompare: DateType | number | string, ): boolean { - const date = toDate(dirtyDate); - const dateToCompare = toDate(dirtyDateToCompare); - return date.getTime() < dateToCompare.getTime(); + const _date = toDate(date); + const _dateToCompare = toDate(dateToCompare); + return +_date < +_dateToCompare; } diff --git a/src/date-fns/isDate/index.ts b/src/date-fns/isDate/index.ts index 7f0d314..3c9f3b0 100644 --- a/src/date-fns/isDate/index.ts +++ b/src/date-fns/isDate/index.ts @@ -6,8 +6,9 @@ * @description * Returns true if the given value is an instance of Date. The function works for dates transferred across iframes. * - * @param value - the value to check - * @returns true if the given value is a date + * @param value - The value to check + * + * @returns True if the given value is a date * * @example * // For a valid date: @@ -29,7 +30,7 @@ * const result = isDate({}) * //=> false */ -export default function isDate(value: unknown): value is Date { +export function isDate(value: unknown): value is Date { return ( value instanceof Date || (typeof value === 'object' && Object.prototype.toString.call(value) === '[object Date]') ); diff --git a/src/date-fns/isEqual/index.ts b/src/date-fns/isEqual/index.ts index 5cf327d..a279196 100644 --- a/src/date-fns/isEqual/index.ts +++ b/src/date-fns/isEqual/index.ts @@ -1,4 +1,4 @@ -import toDate from '../toDate/index'; +import { toDate } from '../toDate/index'; /** * @name isEqual @@ -8,9 +8,12 @@ import toDate from '../toDate/index'; * @description * Are the given dates equal? * - * @param dateLeft - the first date to compare - * @param dateRight - the second date to compare - * @returns the dates are equal + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param dateLeft - The first date to compare + * @param dateRight - The second date to compare + * + * @returns The dates are equal * * @example * // Are 2 July 2014 06:30:45.000 and 2 July 2014 06:30:45.500 equal? @@ -20,11 +23,11 @@ import toDate from '../toDate/index'; * ) * //=> false */ -export default function isEqual( - dirtyLeftDate: DateType | number, - dirtyRightDate: DateType | number, +export function isEqual( + leftDate: DateType | number | string, + rightDate: DateType | number | string, ): boolean { - const dateLeft = toDate(dirtyLeftDate); - const dateRight = toDate(dirtyRightDate); - return dateLeft.getTime() === dateRight.getTime(); + const _dateLeft = toDate(leftDate); + const _dateRight = toDate(rightDate); + return +_dateLeft === +_dateRight; } diff --git a/src/date-fns/isExists/index.ts b/src/date-fns/isExists/index.ts index 34f35c4..bf51f19 100644 --- a/src/date-fns/isExists/index.ts +++ b/src/date-fns/isExists/index.ts @@ -6,10 +6,11 @@ * @description * Checks if the given arguments convert to an existing date. * - * @param year of the date to check - * @param month of the date to check - * @param day of the date to check - * @returns the date exists + * @param year - The year of the date to check + * @param month - The month of the date to check + * @param day - The day of the date to check + * + * @returns `true` if the date exists * * @example * // For the valid date: @@ -21,7 +22,7 @@ * const result = isExists(2018, 1, 31) * //=> false */ -export default function isExists(year: number, month: number, day: number): boolean { +export function isExists(year: number, month: number, day: number): boolean { const date = new Date(year, month, day); return date.getFullYear() === year && date.getMonth() === month && date.getDate() === day; } diff --git a/src/date-fns/isFirstDayOfMonth/index.ts b/src/date-fns/isFirstDayOfMonth/index.ts index 5f49270..3a37316 100644 --- a/src/date-fns/isFirstDayOfMonth/index.ts +++ b/src/date-fns/isFirstDayOfMonth/index.ts @@ -1,4 +1,4 @@ -import toDate from '../toDate/index'; +import { toDate } from '../toDate/index'; /** * @name isFirstDayOfMonth @@ -8,14 +8,17 @@ import toDate from '../toDate/index'; * @description * Is the given date the first day of a month? * - * @param date - the date to check - * @returns the date is the first day of a month + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The date to check + + * @returns The date is the first day of a month * * @example * // Is 1 September 2014 the first day of a month? * const result = isFirstDayOfMonth(new Date(2014, 8, 1)) * //=> true */ -export default function isFirstDayOfMonth(dirtyDate: DateType | number): boolean { - return toDate(dirtyDate).getDate() === 1; +export function isFirstDayOfMonth(date: DateType | number | string): boolean { + return toDate(date).getDate() === 1; } diff --git a/src/date-fns/isFriday/index.ts b/src/date-fns/isFriday/index.ts index 51d6343..f7405f5 100644 --- a/src/date-fns/isFriday/index.ts +++ b/src/date-fns/isFriday/index.ts @@ -1,4 +1,4 @@ -import toDate from '../toDate/index'; +import { toDate } from '../toDate/index'; /** * @name isFriday @@ -8,14 +8,17 @@ import toDate from '../toDate/index'; * @description * Is the given date Friday? * - * @param date - the date to check - * @returns the date is Friday + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The date to check + * + * @returns The date is Friday * * @example * // Is 26 September 2014 Friday? * const result = isFriday(new Date(2014, 8, 26)) * //=> true */ -export default function isFriday(dirtyDate: DateType | number): boolean { - return toDate(dirtyDate).getDay() === 5; +export function isFriday(date: DateType | number | string): boolean { + return toDate(date).getDay() === 5; } diff --git a/src/date-fns/isFuture/index.ts b/src/date-fns/isFuture/index.ts index d7074b3..c1dabbf 100644 --- a/src/date-fns/isFuture/index.ts +++ b/src/date-fns/isFuture/index.ts @@ -1,4 +1,4 @@ -import toDate from '../toDate/index'; +import { toDate } from '../toDate/index'; /** * @name isFuture @@ -9,17 +9,17 @@ import toDate from '../toDate/index'; * @description * Is the given date in the future? * - * > ⚠️ Please note that this function is not present in the FP submodule as - * > it uses `Date.now()` internally hence impure and can't be safely curried. + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). * - * @param date - the date to check - * @returns the date is in the future + * @param date - The date to check + * + * @returns The date is in the future * * @example * // If today is 6 October 2014, is 31 December 2014 in the future? * const result = isFuture(new Date(2014, 11, 31)) * //=> true */ -export default function isFuture(dirtyDate: DateType | number): boolean { - return toDate(dirtyDate).getTime() > Date.now(); +export function isFuture(date: DateType | number | string): boolean { + return +toDate(date) > Date.now(); } diff --git a/src/date-fns/isLastDayOfMonth/index.ts b/src/date-fns/isLastDayOfMonth/index.ts index 9741cf3..3814e54 100644 --- a/src/date-fns/isLastDayOfMonth/index.ts +++ b/src/date-fns/isLastDayOfMonth/index.ts @@ -1,6 +1,6 @@ -import endOfDay from '../endOfDay/index'; -import endOfMonth from '../endOfMonth/index'; -import toDate from '../toDate/index'; +import { endOfDay } from '../endOfDay/index'; +import { endOfMonth } from '../endOfMonth/index'; +import { toDate } from '../toDate/index'; /** * @name isLastDayOfMonth @@ -10,15 +10,18 @@ import toDate from '../toDate/index'; * @description * Is the given date the last day of a month? * - * @param date - the date to check - * @returns the date is the last day of a month + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The date to check + + * @returns The date is the last day of a month * * @example * // Is 28 February 2014 the last day of a month? * const result = isLastDayOfMonth(new Date(2014, 1, 28)) * //=> true */ -export default function isLastDayOfMonth(dirtyDate: DateType | number): boolean { - const date = toDate(dirtyDate); - return endOfDay(date).getTime() === endOfMonth(date).getTime(); +export function isLastDayOfMonth(date: DateType | number | string): boolean { + const _date = toDate(date); + return +endOfDay(_date) === +endOfMonth(_date); } diff --git a/src/date-fns/isLeapYear/index.ts b/src/date-fns/isLeapYear/index.ts index 45fcc90..25a6cf9 100644 --- a/src/date-fns/isLeapYear/index.ts +++ b/src/date-fns/isLeapYear/index.ts @@ -1,4 +1,4 @@ -import toDate from '../toDate/index'; +import { toDate } from '../toDate/index'; /** * @name isLeapYear @@ -8,16 +8,19 @@ import toDate from '../toDate/index'; * @description * Is the given date in the leap year? * - * @param date - the date to check - * @returns the date is in the leap year + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The date to check + * + * @returns The date is in the leap year * * @example * // Is 1 September 2012 in the leap year? * const result = isLeapYear(new Date(2012, 8, 1)) * //=> true */ -export default function isLeapYear(dirtyDate: DateType | number): boolean { - const date = toDate(dirtyDate); - const year = date.getFullYear(); +export function isLeapYear(date: DateType | number | string): boolean { + const _date = toDate(date); + const year = _date.getFullYear(); return year % 400 === 0 || (year % 4 === 0 && year % 100 !== 0); } diff --git a/src/date-fns/isMatch/index.ts b/src/date-fns/isMatch/index.ts index dc2d2ae..0cd4b94 100644 --- a/src/date-fns/isMatch/index.ts +++ b/src/date-fns/isMatch/index.ts @@ -1,13 +1,13 @@ -import isValid from '../isValid/index'; -import parse from '../parse/index'; -import type { AdditionalTokensOptions, FirstWeekContainsDateOptions, LocaleOptions, WeekStartOptions } from '../types'; +import { isValid } from '../isValid/index'; +import { parse } from '../parse/index'; +import type { AdditionalTokensOptions, FirstWeekContainsDateOptions, LocalizedOptions, WeekOptions } from '../types'; /** * The {@link isMatch} function options. */ export interface IsMatchOptions - extends LocaleOptions, - WeekStartOptions, + extends LocalizedOptions<'options' | 'match' | 'formatLong'>, + WeekOptions, FirstWeekContainsDateOptions, AdditionalTokensOptions {} @@ -232,8 +232,8 @@ export interface IsMatchOptions * * The same difference is true for local and ISO week-numbering years (`Y` and `R`), * except local week-numbering years are dependent on `options.weekStartsOn` - * and `options.firstWeekContainsDate` (compare [setISOWeekYear]{@link https://date-fns.org/docs/setISOWeekYear} - * and [setWeekYear]{@link https://date-fns.org/docs/setWeekYear}). + * and `options.firstWeekContainsDate` (compare [setISOWeekYear](https://date-fns.org/docs/setISOWeekYear) + * and [setWeekYear](https://date-fns.org/docs/setWeekYear)). * * 5. These patterns are not in the Unicode Technical Standard #35: * - `i`: ISO day of week @@ -267,20 +267,22 @@ export interface IsMatchOptions * * If `formatString` matches with `dateString` but does not provides tokens, `referenceDate` will be returned. * + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). * - * - * @param dateString - the date string to verify - * @param formatString - the string of tokens - * @param options - an object with options. + * @param dateStr - The date string to verify + * @param format - The string of tokens + * @param options - An object with options. * see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md * see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md - * @returns is format string a match for date string? - * @throws {RangeError} `options.locale` must contain `match` property - * @throws {RangeError} use `yyyy` instead of `YYYY` for formatting years; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md - * @throws {RangeError} use `yy` instead of `YY` for formatting years; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md - * @throws {RangeError} use `d` instead of `D` for formatting days of the month; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md - * @throws {RangeError} use `dd` instead of `DD` for formatting days of the month; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md - * @throws {RangeError} format string contains an unescaped latin alphabet character + * + * @returns Is format string a match for date string? + * + * @throws `options.locale` must contain `match` property + * @throws use `yyyy` instead of `YYYY` for formatting years; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md + * @throws use `yy` instead of `YY` for formatting years; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md + * @throws use `d` instead of `D` for formatting days of the month; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md + * @throws use `dd` instead of `DD` for formatting days of the month; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md + * @throws format string contains an unescaped latin alphabet character * * @example * // Match 11 February 2014 from middle-endian format: @@ -295,6 +297,6 @@ export interface IsMatchOptions * }) * //=> true */ -export default function isMatch(dateString: string, formatString: string, options?: IsMatchOptions): boolean { - return isValid(parse(dateString, formatString, new Date(), options)); +export function isMatch(dateStr: string, formatStr: string, options?: IsMatchOptions): boolean { + return isValid(parse(dateStr, formatStr, new Date(), options)); } diff --git a/src/date-fns/isMonday/index.ts b/src/date-fns/isMonday/index.ts index 79d8658..412b23e 100644 --- a/src/date-fns/isMonday/index.ts +++ b/src/date-fns/isMonday/index.ts @@ -1,4 +1,4 @@ -import toDate from '../toDate/index'; +import { toDate } from '../toDate/index'; /** * @name isMonday @@ -8,14 +8,17 @@ import toDate from '../toDate/index'; * @description * Is the given date Monday? * - * @param date - the date to check - * @returns the date is Monday + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The date to check + * + * @returns The date is Monday * * @example * // Is 22 September 2014 Monday? * const result = isMonday(new Date(2014, 8, 22)) * //=> true */ -export default function isMonday(date: DateType | number): boolean { +export function isMonday(date: DateType | number | string): boolean { return toDate(date).getDay() === 1; } diff --git a/src/date-fns/isPast/index.ts b/src/date-fns/isPast/index.ts index 4b6902a..8b15c0e 100644 --- a/src/date-fns/isPast/index.ts +++ b/src/date-fns/isPast/index.ts @@ -1,4 +1,4 @@ -import toDate from '../toDate/index'; +import { toDate } from '../toDate/index'; /** * @name isPast @@ -9,17 +9,17 @@ import toDate from '../toDate/index'; * @description * Is the given date in the past? * - * > ⚠️ Please note that this function is not present in the FP submodule as - * > it uses `Date.now()` internally hence impure and can't be safely curried. + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). * - * @param date - the date to check - * @returns the date is in the past + * @param date - The date to check + * + * @returns The date is in the past * * @example * // If today is 6 October 2014, is 2 July 2014 in the past? * const result = isPast(new Date(2014, 6, 2)) * //=> true */ -export default function isPast(dirtyDate: DateType | number): boolean { - return toDate(dirtyDate).getTime() < Date.now(); +export function isPast(date: DateType | number | string): boolean { + return +toDate(date) < Date.now(); } diff --git a/src/date-fns/isSameDay/index.ts b/src/date-fns/isSameDay/index.ts index df61684..dc29b62 100644 --- a/src/date-fns/isSameDay/index.ts +++ b/src/date-fns/isSameDay/index.ts @@ -1,4 +1,4 @@ -import startOfDay from '../startOfDay/index'; +import { startOfDay } from '../startOfDay/index'; /** * @name isSameDay @@ -8,9 +8,12 @@ import startOfDay from '../startOfDay/index'; * @description * Are the given dates in the same day (and year and month)? * - * @param dateLeft - the first date to check - * @param dateRight - the second date to check - * @returns the dates are in the same day (and year and month) + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param dateLeft - The first date to check + * @param dateRight - The second date to check + + * @returns The dates are in the same day (and year and month) * * @example * // Are 4 September 06:00:00 and 4 September 18:00:00 in the same day? @@ -27,12 +30,12 @@ import startOfDay from '../startOfDay/index'; * const result = isSameDay(new Date(2014, 8, 4), new Date(2015, 8, 4)) * //=> false */ -export default function isSameDay( - dirtyDateLeft: DateType | number, - dirtyDateRight: DateType | number, +export function isSameDay( + dateLeft: DateType | number | string, + dateRight: DateType | number | string, ): boolean { - const dateLeftStartOfDay = startOfDay(dirtyDateLeft); - const dateRightStartOfDay = startOfDay(dirtyDateRight); + const dateLeftStartOfDay = startOfDay(dateLeft); + const dateRightStartOfDay = startOfDay(dateRight); - return dateLeftStartOfDay.getTime() === dateRightStartOfDay.getTime(); + return +dateLeftStartOfDay === +dateRightStartOfDay; } diff --git a/src/date-fns/isSameHour/index.ts b/src/date-fns/isSameHour/index.ts index b4e033d..4dac905 100644 --- a/src/date-fns/isSameHour/index.ts +++ b/src/date-fns/isSameHour/index.ts @@ -1,4 +1,4 @@ -import startOfHour from '../startOfHour/index'; +import { startOfHour } from '../startOfHour/index'; /** * @name isSameHour @@ -8,9 +8,12 @@ import startOfHour from '../startOfHour/index'; * @description * Are the given dates in the same hour (and same day)? * - * @param dateLeft - the first date to check - * @param dateRight - the second date to check - * @returns the dates are in the same hour (and same day) + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param dateLeft - The first date to check + * @param dateRight - The second date to check + * + * @returns The dates are in the same hour (and same day) * * @example * // Are 4 September 2014 06:00:00 and 4 September 06:30:00 in the same hour? @@ -22,12 +25,12 @@ import startOfHour from '../startOfHour/index'; * const result = isSameHour(new Date(2014, 8, 4, 6, 0), new Date(2014, 8, 5, 6, 0)) * //=> false */ -export default function isSameHour( - dirtyDateLeft: DateType | number, - dirtyDateRight: DateType | number, +export function isSameHour( + dateLeft: DateType | number | string, + dateRight: DateType | number | string, ): boolean { - const dateLeftStartOfHour = startOfHour(dirtyDateLeft); - const dateRightStartOfHour = startOfHour(dirtyDateRight); + const dateLeftStartOfHour = startOfHour(dateLeft); + const dateRightStartOfHour = startOfHour(dateRight); - return dateLeftStartOfHour.getTime() === dateRightStartOfHour.getTime(); + return +dateLeftStartOfHour === +dateRightStartOfHour; } diff --git a/src/date-fns/isSameISOWeek/index.ts b/src/date-fns/isSameISOWeek/index.ts index ddba14f..fe72458 100644 --- a/src/date-fns/isSameISOWeek/index.ts +++ b/src/date-fns/isSameISOWeek/index.ts @@ -1,4 +1,4 @@ -import isSameWeek from '../isSameWeek/index'; +import { isSameWeek } from '../isSameWeek/index'; /** * @name isSameISOWeek @@ -10,9 +10,12 @@ import isSameWeek from '../isSameWeek/index'; * * ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date * - * @param dateLeft - the first date to check - * @param dateRight - the second date to check - * @returns the dates are in the same ISO week (and year) + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param dateLeft - The first date to check + * @param dateRight - The second date to check + * + * @returns The dates are in the same ISO week (and year) * * @example * // Are 1 September 2014 and 7 September 2014 in the same ISO week? @@ -24,9 +27,9 @@ import isSameWeek from '../isSameWeek/index'; * const result = isSameISOWeek(new Date(2014, 8, 1), new Date(2015, 8, 1)) * //=> false */ -export default function isSameISOWeek( - dirtyDateLeft: DateType | number, - dirtyDateRight: DateType | number, +export function isSameISOWeek( + dateLeft: DateType | number | string, + dateRight: DateType | number | string, ): boolean { - return isSameWeek(dirtyDateLeft, dirtyDateRight, { weekStartsOn: 1 }); + return isSameWeek(dateLeft, dateRight, { weekStartsOn: 1 }); } diff --git a/src/date-fns/isSameISOWeekYear/index.ts b/src/date-fns/isSameISOWeekYear/index.ts index b497a8b..45bb436 100644 --- a/src/date-fns/isSameISOWeekYear/index.ts +++ b/src/date-fns/isSameISOWeekYear/index.ts @@ -1,4 +1,4 @@ -import startOfISOWeekYear from '../startOfISOWeekYear/index'; +import { startOfISOWeekYear } from '../startOfISOWeekYear/index'; /** * @name isSameISOWeekYear @@ -10,21 +10,24 @@ import startOfISOWeekYear from '../startOfISOWeekYear/index'; * * ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date * - * @param dateLeft - the first date to check - * @param dateRight - the second date to check - * @returns the dates are in the same ISO week-numbering year + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param dateLeft - The first date to check + * @param dateRight - The second date to check + * + * @returns The dates are in the same ISO week-numbering year * * @example * // Are 29 December 2003 and 2 January 2005 in the same ISO week-numbering year? * const result = isSameISOWeekYear(new Date(2003, 11, 29), new Date(2005, 0, 2)) * //=> true */ -export default function isSameISOWeekYear( - dirtyDateLeft: DateType | number, - dirtyDateRight: DateType | number, +export function isSameISOWeekYear( + dateLeft: DateType | number | string, + dateRight: DateType | number | string, ): boolean { - const dateLeftStartOfYear = startOfISOWeekYear(dirtyDateLeft); - const dateRightStartOfYear = startOfISOWeekYear(dirtyDateRight); + const dateLeftStartOfYear = startOfISOWeekYear(dateLeft); + const dateRightStartOfYear = startOfISOWeekYear(dateRight); - return dateLeftStartOfYear.getTime() === dateRightStartOfYear.getTime(); + return +dateLeftStartOfYear === +dateRightStartOfYear; } diff --git a/src/date-fns/isSameMinute/index.ts b/src/date-fns/isSameMinute/index.ts index 62c197c..3b4918a 100644 --- a/src/date-fns/isSameMinute/index.ts +++ b/src/date-fns/isSameMinute/index.ts @@ -1,4 +1,4 @@ -import startOfMinute from '../startOfMinute/index'; +import { startOfMinute } from '../startOfMinute/index'; /** * @name isSameMinute @@ -8,9 +8,12 @@ import startOfMinute from '../startOfMinute/index'; * @description * Are the given dates in the same minute (and hour and day)? * - * @param dateLeft - the first date to check - * @param dateRight - the second date to check - * @returns the dates are in the same minute (and hour and day) + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param dateLeft - The first date to check + * @param dateRight - The second date to check + * + * @returns The dates are in the same minute (and hour and day) * * @example * // Are 4 September 2014 06:30:00 and 4 September 2014 06:30:15 in the same minute? @@ -28,12 +31,12 @@ import startOfMinute from '../startOfMinute/index'; * ) * //=> false */ -export default function isSameMinute( - dirtyDateLeft: DateType | number, - dirtyDateRight: DateType | number, +export function isSameMinute( + dateLeft: DateType | number | string, + dateRight: DateType | number | string, ): boolean { - const dateLeftStartOfMinute = startOfMinute(dirtyDateLeft); - const dateRightStartOfMinute = startOfMinute(dirtyDateRight); + const dateLeftStartOfMinute = startOfMinute(dateLeft); + const dateRightStartOfMinute = startOfMinute(dateRight); - return dateLeftStartOfMinute.getTime() === dateRightStartOfMinute.getTime(); + return +dateLeftStartOfMinute === +dateRightStartOfMinute; } diff --git a/src/date-fns/isSameMonth/index.ts b/src/date-fns/isSameMonth/index.ts index 810a3e2..dc34de9 100644 --- a/src/date-fns/isSameMonth/index.ts +++ b/src/date-fns/isSameMonth/index.ts @@ -1,4 +1,4 @@ -import toDate from '../toDate/index'; +import { toDate } from '../toDate/index'; /** * @name isSameMonth @@ -8,9 +8,12 @@ import toDate from '../toDate/index'; * @description * Are the given dates in the same month (and year)? * - * @param dateLeft - the first date to check - * @param dateRight - the second date to check - * @returns the dates are in the same month (and year) + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param dateLeft - The first date to check + * @param dateRight - The second date to check + * + * @returns The dates are in the same month (and year) * * @example * // Are 2 September 2014 and 25 September 2014 in the same month? @@ -22,11 +25,11 @@ import toDate from '../toDate/index'; * const result = isSameMonth(new Date(2014, 8, 2), new Date(2015, 8, 25)) * //=> false */ -export default function isSameMonth( - dirtyDateLeft: DateType | number, - dirtyDateRight: DateType | number, +export function isSameMonth( + dateLeft: DateType | number | string, + dateRight: DateType | number | string, ): boolean { - const dateLeft = toDate(dirtyDateLeft); - const dateRight = toDate(dirtyDateRight); - return dateLeft.getFullYear() === dateRight.getFullYear() && dateLeft.getMonth() === dateRight.getMonth(); + const _dateLeft = toDate(dateLeft); + const _dateRight = toDate(dateRight); + return _dateLeft.getFullYear() === _dateRight.getFullYear() && _dateLeft.getMonth() === _dateRight.getMonth(); } diff --git a/src/date-fns/isSameQuarter/index.ts b/src/date-fns/isSameQuarter/index.ts index 3a64150..96ee162 100644 --- a/src/date-fns/isSameQuarter/index.ts +++ b/src/date-fns/isSameQuarter/index.ts @@ -1,4 +1,4 @@ -import startOfQuarter from '../startOfQuarter/index'; +import { startOfQuarter } from '../startOfQuarter/index'; /** * @name isSameQuarter @@ -8,9 +8,12 @@ import startOfQuarter from '../startOfQuarter/index'; * @description * Are the given dates in the same quarter (and year)? * - * @param dateLeft - the first date to check - * @param dateRight - the second date to check - * @returns the dates are in the same quarter (and year) + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param dateLeft - The first date to check + * @param dateRight - The second date to check + + * @returns The dates are in the same quarter (and year) * * @example * // Are 1 January 2014 and 8 March 2014 in the same quarter? @@ -22,12 +25,12 @@ import startOfQuarter from '../startOfQuarter/index'; * const result = isSameQuarter(new Date(2014, 0, 1), new Date(2015, 0, 1)) * //=> false */ -export default function isSameQuarter( - dirtyDateLeft: DateType | number, - dirtyDateRight: DateType | number, +export function isSameQuarter( + dateLeft: DateType | number | string, + dateRight: DateType | number | string, ): boolean { - const dateLeftStartOfQuarter = startOfQuarter(dirtyDateLeft); - const dateRightStartOfQuarter = startOfQuarter(dirtyDateRight); + const dateLeftStartOfQuarter = startOfQuarter(dateLeft); + const dateRightStartOfQuarter = startOfQuarter(dateRight); - return dateLeftStartOfQuarter.getTime() === dateRightStartOfQuarter.getTime(); + return +dateLeftStartOfQuarter === +dateRightStartOfQuarter; } diff --git a/src/date-fns/isSameSecond/index.ts b/src/date-fns/isSameSecond/index.ts index ef735a3..aa51e90 100644 --- a/src/date-fns/isSameSecond/index.ts +++ b/src/date-fns/isSameSecond/index.ts @@ -1,4 +1,4 @@ -import startOfSecond from '../startOfSecond/index'; +import { startOfSecond } from '../startOfSecond/index'; /** * @name isSameSecond @@ -8,9 +8,12 @@ import startOfSecond from '../startOfSecond/index'; * @description * Are the given dates in the same second (and hour and day)? * - * @param dateLeft - the first date to check - * @param dateRight - the second date to check - * @returns the dates are in the same second (and hour and day) + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param dateLeft - The first date to check + * @param dateRight - The second date to check + * + * @returns The dates are in the same second (and hour and day) * * @example * // Are 4 September 2014 06:30:15.000 and 4 September 2014 06:30.15.500 in the same second? @@ -36,12 +39,12 @@ import startOfSecond from '../startOfSecond/index'; * ) * //=> false */ -export default function isSameSecond( - dirtyDateLeft: DateType | number, - dirtyDateRight: DateType | number, +export function isSameSecond( + dateLeft: DateType | number | string, + dateRight: DateType | number | string, ): boolean { - const dateLeftStartOfSecond = startOfSecond(dirtyDateLeft); - const dateRightStartOfSecond = startOfSecond(dirtyDateRight); + const dateLeftStartOfSecond = startOfSecond(dateLeft); + const dateRightStartOfSecond = startOfSecond(dateRight); - return dateLeftStartOfSecond.getTime() === dateRightStartOfSecond.getTime(); + return +dateLeftStartOfSecond === +dateRightStartOfSecond; } diff --git a/src/date-fns/isSameWeek/index.ts b/src/date-fns/isSameWeek/index.ts index 14a5203..bbc274b 100644 --- a/src/date-fns/isSameWeek/index.ts +++ b/src/date-fns/isSameWeek/index.ts @@ -1,10 +1,10 @@ -import startOfWeek from '../startOfWeek/index'; -import type { LocaleOptions, WeekStartOptions } from '../types'; +import { startOfWeek } from '../startOfWeek/index'; +import type { LocalizedOptions, WeekOptions } from '../types'; /** * The {@link isSameWeek} function options. */ -export interface IsSameWeekOptions extends WeekStartOptions, LocaleOptions {} +export interface IsSameWeekOptions extends WeekOptions, LocalizedOptions<'options'> {} /** * @name isSameWeek @@ -14,10 +14,13 @@ export interface IsSameWeekOptions extends WeekStartOptions, LocaleOptions {} * @description * Are the given dates in the same week (and month and year)? * - * @param dateLeft - the first date to check - * @param dateRight - the second date to check - * @param options - an object with options. - * @returns the dates are in the same week (and month and year) + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param dateLeft - The first date to check + * @param dateRight - The second date to check + * @param options - An object with options + * + * @returns The dates are in the same week (and month and year) * * @example * // Are 31 August 2014 and 4 September 2014 in the same week? @@ -37,13 +40,13 @@ export interface IsSameWeekOptions extends WeekStartOptions, LocaleOptions {} * const result = isSameWeek(new Date(2014, 0, 1), new Date(2015, 0, 1)) * //=> false */ -export default function isSameWeek( - dirtyDateLeft: DateType | number, - dirtyDateRight: DateType | number, +export function isSameWeek( + dateLeft: DateType | number | string, + dateRight: DateType | number | string, options?: IsSameWeekOptions, ): boolean { - const dateLeftStartOfWeek = startOfWeek(dirtyDateLeft, options); - const dateRightStartOfWeek = startOfWeek(dirtyDateRight, options); + const dateLeftStartOfWeek = startOfWeek(dateLeft, options); + const dateRightStartOfWeek = startOfWeek(dateRight, options); - return dateLeftStartOfWeek.getTime() === dateRightStartOfWeek.getTime(); + return +dateLeftStartOfWeek === +dateRightStartOfWeek; } diff --git a/src/date-fns/isSameYear/index.ts b/src/date-fns/isSameYear/index.ts index f91b085..4ab76c0 100644 --- a/src/date-fns/isSameYear/index.ts +++ b/src/date-fns/isSameYear/index.ts @@ -1,4 +1,4 @@ -import toDate from '../toDate/index'; +import { toDate } from '../toDate/index'; /** * @name isSameYear @@ -8,20 +8,23 @@ import toDate from '../toDate/index'; * @description * Are the given dates in the same year? * - * @param dateLeft - the first date to check - * @param dateRight - the second date to check - * @returns the dates are in the same year + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param dateLeft - The first date to check + * @param dateRight - The second date to check + * + * @returns The dates are in the same year * * @example * // Are 2 September 2014 and 25 September 2014 in the same year? * const result = isSameYear(new Date(2014, 8, 2), new Date(2014, 8, 25)) * //=> true */ -export default function isSameYear( - dirtyDateLeft: DateType | number, - dirtyDateRight: DateType | number, +export function isSameYear( + dateLeft: DateType | number | string, + dateRight: DateType | number | string, ): boolean { - const dateLeft = toDate(dirtyDateLeft); - const dateRight = toDate(dirtyDateRight); - return dateLeft.getFullYear() === dateRight.getFullYear(); + const _dateLeft = toDate(dateLeft); + const _dateRight = toDate(dateRight); + return _dateLeft.getFullYear() === _dateRight.getFullYear(); } diff --git a/src/date-fns/isSaturday/index.ts b/src/date-fns/isSaturday/index.ts index 4c08611..12f7fa7 100644 --- a/src/date-fns/isSaturday/index.ts +++ b/src/date-fns/isSaturday/index.ts @@ -1,4 +1,4 @@ -import toDate from '../toDate/index'; +import { toDate } from '../toDate/index'; /** * @name isSaturday @@ -8,14 +8,17 @@ import toDate from '../toDate/index'; * @description * Is the given date Saturday? * - * @param date - the date to check - * @returns the date is Saturday + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The date to check + * + * @returns The date is Saturday * * @example * // Is 27 September 2014 Saturday? * const result = isSaturday(new Date(2014, 8, 27)) * //=> true */ -export default function isSaturday(dirtyDate: DateType | number): boolean { - return toDate(dirtyDate).getDay() === 6; +export function isSaturday(date: DateType | number | string): boolean { + return toDate(date).getDay() === 6; } diff --git a/src/date-fns/isSunday/index.ts b/src/date-fns/isSunday/index.ts index 9c261d1..c970862 100644 --- a/src/date-fns/isSunday/index.ts +++ b/src/date-fns/isSunday/index.ts @@ -1,4 +1,4 @@ -import toDate from '../toDate/index'; +import { toDate } from '../toDate/index'; /** * @name isSunday @@ -8,14 +8,17 @@ import toDate from '../toDate/index'; * @description * Is the given date Sunday? * - * @param date - the date to check - * @returns the date is Sunday + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The date to check + * + * @returns The date is Sunday * * @example * // Is 21 September 2014 Sunday? * const result = isSunday(new Date(2014, 8, 21)) * //=> true */ -export default function isSunday(dirtyDate: DateType | number): boolean { - return toDate(dirtyDate).getDay() === 0; +export function isSunday(date: DateType | number | string): boolean { + return toDate(date).getDay() === 0; } diff --git a/src/date-fns/isThisHour/index.ts b/src/date-fns/isThisHour/index.ts index a43841b..3f56a2e 100644 --- a/src/date-fns/isThisHour/index.ts +++ b/src/date-fns/isThisHour/index.ts @@ -1,4 +1,5 @@ -import isSameHour from '../isSameHour/index'; +import { constructNow } from '../constructNow/index'; +import { isSameHour } from '../isSameHour/index'; /** * @name isThisHour @@ -9,11 +10,11 @@ import isSameHour from '../isSameHour/index'; * @description * Is the given date in the same hour as the current date? * - * > ⚠️ Please note that this function is not present in the FP submodule as - * > it uses `Date.now()` internally hence impure and can't be safely curried. + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). * - * @param date - the date to check - * @returns the date is in this hour + * @param date - The date to check + * + * @returns The date is in this hour * * @example * // If now is 25 September 2014 18:30:15.500, @@ -21,6 +22,6 @@ import isSameHour from '../isSameHour/index'; * const result = isThisHour(new Date(2014, 8, 25, 18)) * //=> true */ -export default function isThisHour(dirtyDate: DateType | number): boolean { - return isSameHour(Date.now(), dirtyDate); +export function isThisHour(date: DateType | number | string): boolean { + return isSameHour(date, constructNow(date)); } diff --git a/src/date-fns/isThisISOWeek/index.ts b/src/date-fns/isThisISOWeek/index.ts index 924be6a..0a7427e 100644 --- a/src/date-fns/isThisISOWeek/index.ts +++ b/src/date-fns/isThisISOWeek/index.ts @@ -1,4 +1,5 @@ -import isSameISOWeek from '../isSameISOWeek/index'; +import { constructNow } from '../constructNow/index'; +import { isSameISOWeek } from '../isSameISOWeek/index'; /** * @name isThisISOWeek @@ -11,11 +12,11 @@ import isSameISOWeek from '../isSameISOWeek/index'; * * ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date * - * > ⚠️ Please note that this function is not present in the FP submodule as - * > it uses `Date.now()` internally hence impure and can't be safely curried. + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). * - * @param date - the date to check - * @returns the date is in this ISO week + * @param date - The date to check + * + * @returns The date is in this ISO week * * @example * // If today is 25 September 2014, is 22 September 2014 in this ISO week? @@ -23,6 +24,6 @@ import isSameISOWeek from '../isSameISOWeek/index'; * //=> true */ -export default function isThisISOWeek(dirtyDate: DateType | number): boolean { - return isSameISOWeek(dirtyDate, Date.now()); +export function isThisISOWeek(date: DateType | number | string): boolean { + return isSameISOWeek(date, constructNow(date)); } diff --git a/src/date-fns/isThisMinute/index.ts b/src/date-fns/isThisMinute/index.ts index 3939257..fec9448 100644 --- a/src/date-fns/isThisMinute/index.ts +++ b/src/date-fns/isThisMinute/index.ts @@ -1,4 +1,5 @@ -import isSameMinute from '../isSameMinute/index'; +import { constructNow } from '../constructNow/index'; +import { isSameMinute } from '../isSameMinute/index'; /** * @name isThisMinute @@ -9,11 +10,11 @@ import isSameMinute from '../isSameMinute/index'; * @description * Is the given date in the same minute as the current date? * - * > ⚠️ Please note that this function is not present in the FP submodule as - * > it uses `Date.now()` internally hence impure and can't be safely curried. + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). * - * @param date - the date to check - * @returns the date is in this minute + * @param date - The date to check + * + * @returns The date is in this minute * * @example * // If now is 25 September 2014 18:30:15.500, @@ -22,6 +23,6 @@ import isSameMinute from '../isSameMinute/index'; * //=> true */ -export default function isThisMinute(dirtyDate: DateType | number): boolean { - return isSameMinute(Date.now(), dirtyDate); +export function isThisMinute(date: DateType | number | string): boolean { + return isSameMinute(date, constructNow(date)); } diff --git a/src/date-fns/isThisMonth/index.ts b/src/date-fns/isThisMonth/index.ts index 31cc18f..10150c5 100644 --- a/src/date-fns/isThisMonth/index.ts +++ b/src/date-fns/isThisMonth/index.ts @@ -1,4 +1,5 @@ -import isSameMonth from '../isSameMonth/index'; +import { constructNow } from '../constructNow/index'; +import { isSameMonth } from '../isSameMonth/index'; /** * @name isThisMonth @@ -9,11 +10,11 @@ import isSameMonth from '../isSameMonth/index'; * @description * Is the given date in the same month as the current date? * - * > ⚠️ Please note that this function is not present in the FP submodule as - * > it uses `Date.now()` internally hence impure and can't be safely curried. + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). * - * @param date - the date to check - * @returns the date is in this month + * @param date - The date to check + * + * @returns The date is in this month * * @example * // If today is 25 September 2014, is 15 September 2014 in this month? @@ -21,6 +22,6 @@ import isSameMonth from '../isSameMonth/index'; * //=> true */ -export default function isThisMonth(dirtyDate: DateType | number): boolean { - return isSameMonth(Date.now(), dirtyDate); +export function isThisMonth(date: DateType | number | string): boolean { + return isSameMonth(date, constructNow(date)); } diff --git a/src/date-fns/isThisQuarter/index.ts b/src/date-fns/isThisQuarter/index.ts index a869da3..6fec7bc 100644 --- a/src/date-fns/isThisQuarter/index.ts +++ b/src/date-fns/isThisQuarter/index.ts @@ -1,4 +1,5 @@ -import isSameQuarter from '../isSameQuarter/index'; +import { constructNow } from '../constructNow/index'; +import { isSameQuarter } from '../isSameQuarter/index'; /** * @name isThisQuarter @@ -9,17 +10,17 @@ import isSameQuarter from '../isSameQuarter/index'; * @description * Is the given date in the same quarter as the current date? * - * > ⚠️ Please note that this function is not present in the FP submodule as - * > it uses `Date.now()` internally hence impure and can't be safely curried. + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). * - * @param date - the date to check - * @returns the date is in this quarter + * @param date - The date to check + * + * @returns The date is in this quarter * * @example * // If today is 25 September 2014, is 2 July 2014 in this quarter? * const result = isThisQuarter(new Date(2014, 6, 2)) * //=> true */ -export default function isThisQuarter(dirtyDate: DateType | number): boolean { - return isSameQuarter(Date.now(), dirtyDate); +export function isThisQuarter(date: DateType | number | string): boolean { + return isSameQuarter(date, constructNow(date)); } diff --git a/src/date-fns/isThisSecond/index.ts b/src/date-fns/isThisSecond/index.ts index 7b56c16..6073dd5 100644 --- a/src/date-fns/isThisSecond/index.ts +++ b/src/date-fns/isThisSecond/index.ts @@ -1,4 +1,5 @@ -import isSameSecond from '../isSameSecond/index'; +import { constructNow } from '../constructNow/index'; +import { isSameSecond } from '../isSameSecond/index'; /** * @name isThisSecond @@ -9,11 +10,11 @@ import isSameSecond from '../isSameSecond/index'; * @description * Is the given date in the same second as the current date? * - * > ⚠️ Please note that this function is not present in the FP submodule as - * > it uses `Date.now()` internally hence impure and can't be safely curried. + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). * - * @param date - the date to check - * @returns the date is in this second + * @param date - The date to check + * + * @returns The date is in this second * * @example * // If now is 25 September 2014 18:30:15.500, @@ -21,6 +22,6 @@ import isSameSecond from '../isSameSecond/index'; * const result = isThisSecond(new Date(2014, 8, 25, 18, 30, 15)) * //=> true */ -export default function isThisSecond(dirtyDate: DateType | number): boolean { - return isSameSecond(Date.now(), dirtyDate); +export function isThisSecond(date: DateType | number | string): boolean { + return isSameSecond(date, constructNow(date)); } diff --git a/src/date-fns/isThisWeek/index.ts b/src/date-fns/isThisWeek/index.ts index 192f842..7215b95 100644 --- a/src/date-fns/isThisWeek/index.ts +++ b/src/date-fns/isThisWeek/index.ts @@ -1,10 +1,11 @@ -import isSameWeek from '../isSameWeek/index'; -import type { LocaleOptions, WeekStartOptions } from '../types'; +import { constructNow } from '../constructNow/index'; +import { isSameWeek } from '../isSameWeek/index'; +import type { LocalizedOptions, WeekOptions } from '../types'; /** * The {@link isThisWeek} function options. */ -export interface IsThisWeekOptions extends WeekStartOptions, LocaleOptions {} +export interface IsThisWeekOptions extends WeekOptions, LocalizedOptions<'options'> {} /** * @name isThisWeek @@ -15,12 +16,12 @@ export interface IsThisWeekOptions extends WeekStartOptions, LocaleOptions {} * @description * Is the given date in the same week as the current date? * - * > ⚠️ Please note that this function is not present in the FP submodule as - * > it uses `Date.now()` internally hence impure and can't be safely curried. + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). * - * @param date - the date to check - * @param options - the object with options - * @returns the date is in this week + * @param date - The date to check + * @param options - The object with options + * + * @returns The date is in this week * * @example * // If today is 25 September 2014, is 21 September 2014 in this week? @@ -33,7 +34,9 @@ export interface IsThisWeekOptions extends WeekStartOptions, LocaleOptions {} * const result = isThisWeek(new Date(2014, 8, 21), { weekStartsOn: 1 }) * //=> false */ - -export default function is(dirtyDate: DateType | number, options?: IsThisWeekOptions): boolean { - return isSameWeek(dirtyDate, Date.now(), options); +export function isThisWeek( + date: DateType | number | string, + options?: IsThisWeekOptions, +): boolean { + return isSameWeek(date, constructNow(date), options); } diff --git a/src/date-fns/isThisYear/index.ts b/src/date-fns/isThisYear/index.ts index ee6a3d4..251ad8f 100644 --- a/src/date-fns/isThisYear/index.ts +++ b/src/date-fns/isThisYear/index.ts @@ -1,4 +1,5 @@ -import isSameYear from '../isSameYear/index'; +import { constructNow } from '../constructNow/index'; +import { isSameYear } from '../isSameYear/index'; /** * @name isThisYear @@ -9,17 +10,17 @@ import isSameYear from '../isSameYear/index'; * @description * Is the given date in the same year as the current date? * - * > ⚠️ Please note that this function is not present in the FP submodule as - * > it uses `Date.now()` internally hence impure and can't be safely curried. + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). * - * @param date - the date to check - * @returns the date is in this year + * @param date - The date to check + * + * @returns The date is in this year * * @example * // If today is 25 September 2014, is 2 July 2014 in this year? * const result = isThisYear(new Date(2014, 6, 2)) * //=> true */ -export default function isThisYear(dirtyDate: DateType | number): boolean { - return isSameYear(dirtyDate, Date.now()); +export function isThisYear(date: DateType | number | string): boolean { + return isSameYear(date, constructNow(date)); } diff --git a/src/date-fns/isThursday/index.ts b/src/date-fns/isThursday/index.ts index 73f0ffb..469e931 100644 --- a/src/date-fns/isThursday/index.ts +++ b/src/date-fns/isThursday/index.ts @@ -1,4 +1,4 @@ -import toDate from '../toDate/index'; +import { toDate } from '../toDate/index'; /** * @name isThursday @@ -8,14 +8,17 @@ import toDate from '../toDate/index'; * @description * Is the given date Thursday? * - * @param date - the date to check - * @returns the date is Thursday + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The date to check + * + * @returns The date is Thursday * * @example * // Is 25 September 2014 Thursday? * const result = isThursday(new Date(2014, 8, 25)) * //=> true */ -export default function isThursday(dirtyDate: DateType | number): boolean { - return toDate(dirtyDate).getDay() === 4; +export function isThursday(date: DateType | number | string): boolean { + return toDate(date).getDay() === 4; } diff --git a/src/date-fns/isToday/index.ts b/src/date-fns/isToday/index.ts index 0be0362..232bcda 100644 --- a/src/date-fns/isToday/index.ts +++ b/src/date-fns/isToday/index.ts @@ -1,4 +1,5 @@ -import isSameDay from '../isSameDay/index'; +import { constructNow } from '../constructNow/index'; +import { isSameDay } from '../isSameDay/index'; /** * @name isToday @@ -9,17 +10,17 @@ import isSameDay from '../isSameDay/index'; * @description * Is the given date today? * - * > ⚠️ Please note that this function is not present in the FP submodule as - * > it uses `Date.now()` internally hence impure and can't be safely curried. + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). * - * @param date - the date to check - * @returns the date is today + * @param date - The date to check + * + * @returns The date is today * * @example * // If today is 6 October 2014, is 6 October 14:00:00 today? * const result = isToday(new Date(2014, 9, 6, 14, 0)) * //=> true */ -export default function isToday(dirtyDate: DateType | number): boolean { - return isSameDay(dirtyDate, Date.now()); +export function isToday(date: DateType | number | string): boolean { + return isSameDay(date, constructNow(date)); } diff --git a/src/date-fns/isTomorrow/index.ts b/src/date-fns/isTomorrow/index.ts index 7a3cb82..d429019 100644 --- a/src/date-fns/isTomorrow/index.ts +++ b/src/date-fns/isTomorrow/index.ts @@ -1,5 +1,6 @@ -import addDays from '../addDays/index'; -import isSameDay from '../isSameDay/index'; +import { addDays } from '../addDays/index'; +import { constructNow } from '../constructNow/index'; +import { isSameDay } from '../isSameDay/index'; /** * @name isTomorrow @@ -10,17 +11,17 @@ import isSameDay from '../isSameDay/index'; * @description * Is the given date tomorrow? * - * > ⚠️ Please note that this function is not present in the FP submodule as - * > it uses `Date.now()` internally hence impure and can't be safely curried. + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). * - * @param date - the date to check - * @returns the date is tomorrow + * @param date - The date to check + * + * @returns The date is tomorrow * * @example * // If today is 6 October 2014, is 7 October 14:00:00 tomorrow? * const result = isTomorrow(new Date(2014, 9, 7, 14, 0)) * //=> true */ -export default function isTomorrow(dirtyDate: DateType | number): boolean { - return isSameDay(dirtyDate, addDays(Date.now(), 1)); +export function isTomorrow(date: DateType | number | string): boolean { + return isSameDay(date, addDays(constructNow(date), 1)); } diff --git a/src/date-fns/isTuesday/index.ts b/src/date-fns/isTuesday/index.ts index 4018987..01fbd3d 100644 --- a/src/date-fns/isTuesday/index.ts +++ b/src/date-fns/isTuesday/index.ts @@ -1,4 +1,4 @@ -import toDate from '../toDate/index'; +import { toDate } from '../toDate/index'; /** * @name isTuesday @@ -8,14 +8,17 @@ import toDate from '../toDate/index'; * @description * Is the given date Tuesday? * - * @param date - the date to check - * @returns the date is Tuesday + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The date to check + * + * @returns The date is Tuesday * * @example * // Is 23 September 2014 Tuesday? * const result = isTuesday(new Date(2014, 8, 23)) * //=> true */ -export default function isTuesday(dirtyDate: DateType | number): boolean { - return toDate(dirtyDate).getDay() === 2; +export function isTuesday(date: DateType | number | string): boolean { + return toDate(date).getDay() === 2; } diff --git a/src/date-fns/isValid/index.ts b/src/date-fns/isValid/index.ts index 114c554..d6d5fe3 100644 --- a/src/date-fns/isValid/index.ts +++ b/src/date-fns/isValid/index.ts @@ -1,5 +1,5 @@ -import isDate from '../isDate/index'; -import toDate from '../toDate/index'; +import { isDate } from '../isDate/index'; +import { toDate } from '../toDate/index'; /** * @name isValid @@ -8,13 +8,16 @@ import toDate from '../toDate/index'; * * @description * Returns false if argument is Invalid Date and true otherwise. - * Argument is converted to Date using `toDate`. See [toDate]{@link https://date-fns.org/docs/toDate} + * Argument is converted to Date using `toDate`. See [toDate](https://date-fns.org/docs/toDate) * Invalid Date is a Date, whose time value is NaN. * * Time value of Date: http://es5.github.io/#x15.9.1.1 * - * @param date - the date to check - * @returns the date is valid + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The date to check + * + * @returns The date is valid * * @example * // For the valid date: @@ -31,10 +34,10 @@ import toDate from '../toDate/index'; * const result = isValid(new Date('')) * //=> false */ -export default function isValid(dirtyDate: unknown): boolean { - if (!isDate(dirtyDate) && typeof dirtyDate !== 'number') { +export function isValid(date: unknown): boolean { + if (!isDate(date) && typeof date !== 'number') { return false; } - const date = toDate(dirtyDate); - return !isNaN(Number(date)); + const _date = toDate(date); + return !isNaN(Number(_date)); } diff --git a/src/date-fns/isWednesday/index.ts b/src/date-fns/isWednesday/index.ts index a354303..3e26dd5 100644 --- a/src/date-fns/isWednesday/index.ts +++ b/src/date-fns/isWednesday/index.ts @@ -1,4 +1,4 @@ -import toDate from '../toDate/index'; +import { toDate } from '../toDate/index'; /** * @name isWednesday @@ -8,14 +8,17 @@ import toDate from '../toDate/index'; * @description * Is the given date Wednesday? * - * @param date - the date to check - * @returns the date is Wednesday + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The date to check + * + * @returns The date is Wednesday * * @example * // Is 24 September 2014 Wednesday? * const result = isWednesday(new Date(2014, 8, 24)) * //=> true */ -export default function isWednesday(dirtyDate: DateType | number): boolean { - return toDate(dirtyDate).getDay() === 3; +export function isWednesday(date: DateType | number | string): boolean { + return toDate(date).getDay() === 3; } diff --git a/src/date-fns/isWeekend/index.ts b/src/date-fns/isWeekend/index.ts index 8b7af66..d69825e 100644 --- a/src/date-fns/isWeekend/index.ts +++ b/src/date-fns/isWeekend/index.ts @@ -1,4 +1,4 @@ -import toDate from '../toDate/index'; +import { toDate } from '../toDate/index'; /** * @name isWeekend @@ -8,16 +8,18 @@ import toDate from '../toDate/index'; * @description * Does the given date fall on a weekend? * - * @param date - the date to check - * @returns the date falls on a weekend + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The date to check + * + * @returns The date falls on a weekend * * @example * // Does 5 October 2014 fall on a weekend? * const result = isWeekend(new Date(2014, 9, 5)) * //=> true */ -export default function isWeekend(dirtyDate: DateType | number): boolean { - const date = toDate(dirtyDate); - const day = date.getDay(); +export function isWeekend(date: DateType | number | string): boolean { + const day = toDate(date).getDay(); return day === 0 || day === 6; } diff --git a/src/date-fns/isWithinInterval/index.ts b/src/date-fns/isWithinInterval/index.ts index 3c7a683..fbcab94 100644 --- a/src/date-fns/isWithinInterval/index.ts +++ b/src/date-fns/isWithinInterval/index.ts @@ -1,4 +1,4 @@ -import toDate from '../toDate/index'; +import { toDate } from '../toDate/index'; import type { Interval } from '../types'; /** @@ -9,11 +9,12 @@ import type { Interval } from '../types'; * @description * Is the given date within the interval? (Including start and end.) * - * @param date - the date to check - * @param interval - the interval to check - * @returns the date is within the interval - * @throws {RangeError} The start of an interval cannot be after its end - * @throws {RangeError} Date in interval cannot be `Invalid Date` + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The date to check + * @param interval - The interval to check + * + * @returns The date is within the interval * * @example * // For the date within the interval: @@ -33,24 +34,20 @@ import type { Interval } from '../types'; * * @example * // For date equal to interval start: - * isWithinInterval(date, { start, end: date }) // => true + * isWithinInterval(date, { start, end: date }) + * // => true * * @example * // For date equal to interval end: - * isWithinInterval(date, { start: date, end }) // => true + * isWithinInterval(date, { start: date, end }) + * // => true */ -export default function isWithinInterval( - dirtyDate: DateType | number, +export function isWithinInterval( + date: DateType | number | string, interval: Interval, ): boolean { - const time = toDate(dirtyDate).getTime(); - const startTime = toDate(interval.start).getTime(); - const endTime = toDate(interval.end).getTime(); - - // Throw an exception if start date is after end date or if any date is `Invalid Date` - if (!(startTime <= endTime)) { - throw new RangeError('Invalid interval'); - } + const time = +toDate(date); + const [startTime, endTime] = [+toDate(interval.start), +toDate(interval.end)].sort((a, b) => a - b); - return time >= startTime && time <= endTime; + return time >= startTime! && time <= endTime!; } diff --git a/src/date-fns/isYesterday/index.ts b/src/date-fns/isYesterday/index.ts index 0b83822..8d38018 100644 --- a/src/date-fns/isYesterday/index.ts +++ b/src/date-fns/isYesterday/index.ts @@ -1,5 +1,6 @@ -import isSameDay from '../isSameDay/index'; -import subDays from '../subDays/index'; +import { constructNow } from '../constructNow/index'; +import { isSameDay } from '../isSameDay/index'; +import { subDays } from '../subDays/index'; /** * @name isYesterday @@ -10,17 +11,17 @@ import subDays from '../subDays/index'; * @description * Is the given date yesterday? * - * > ⚠️ Please note that this function is not present in the FP submodule as - * > it uses `Date.now()` internally hence impure and can't be safely curried. + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). * - * @param date - the date to check - * @returns the date is yesterday + * @param date - The date to check + * + * @returns The date is yesterday * * @example * // If today is 6 October 2014, is 5 October 14:00:00 yesterday? * const result = isYesterday(new Date(2014, 9, 5, 14, 0)) * //=> true */ -export default function isYesterday(dirtyDate: DateType | number): boolean { - return isSameDay(dirtyDate, subDays(Date.now(), 1)); +export function isYesterday(date: DateType | number | string): boolean { + return isSameDay(date, subDays(constructNow(date), 1)); } diff --git a/src/date-fns/lastDayOfDecade/index.ts b/src/date-fns/lastDayOfDecade/index.ts index 69107ed..97dd635 100644 --- a/src/date-fns/lastDayOfDecade/index.ts +++ b/src/date-fns/lastDayOfDecade/index.ts @@ -1,4 +1,4 @@ -import toDate from '../toDate/index'; +import { toDate } from '../toDate/index'; /** * @name lastDayOfDecade @@ -8,19 +8,25 @@ import toDate from '../toDate/index'; * @description * Return the last day of a decade for the given date. * - * @param date - the original date - * @returns the last day of a decade + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The original date + * + * @returns The last day of a decade * * @example * // The last day of a decade for 21 December 2012 21:12:00: * const result = lastDayOfDecade(new Date(2012, 11, 21, 21, 12, 00)) * //=> Wed Dec 31 2019 00:00:00 */ -export default function lastDayOfDecade(dirtyDate: DateType | number): DateType { - const date = toDate(dirtyDate); - const year = date.getFullYear(); +export function lastDayOfDecade(date: DateType | number | string): DateType { + // TODO: Switch to more technical definition in of decades that start with 1 + // end with 0. I.e. 2001-2010 instead of current 2000-2009. It's a breaking + // change, so it can only be done in 4.0. + const _date = toDate(date); + const year = _date.getFullYear(); const decade = 9 + Math.floor(year / 10) * 10; - date.setFullYear(decade + 1, 0, 0); - date.setHours(0, 0, 0, 0); - return date; + _date.setFullYear(decade + 1, 0, 0); + _date.setHours(0, 0, 0, 0); + return _date; } diff --git a/src/date-fns/lastDayOfISOWeek/index.ts b/src/date-fns/lastDayOfISOWeek/index.ts index 8f50325..6519ff0 100644 --- a/src/date-fns/lastDayOfISOWeek/index.ts +++ b/src/date-fns/lastDayOfISOWeek/index.ts @@ -1,4 +1,4 @@ -import lastDayOfWeek from '../lastDayOfWeek/index'; +import { lastDayOfWeek } from '../lastDayOfWeek/index'; /** * @name lastDayOfISOWeek @@ -11,14 +11,17 @@ import lastDayOfWeek from '../lastDayOfWeek/index'; * * ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date * - * @param date - the original date - * @returns the last day of an ISO week + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The original date + * + * @returns The last day of an ISO week * * @example * // The last day of an ISO week for 2 September 2014 11:55:00: * const result = lastDayOfISOWeek(new Date(2014, 8, 2, 11, 55, 0)) * //=> Sun Sep 07 2014 00:00:00 */ -export default function lastDayOfISOWeek(dirtyDate: DateType | number): DateType { - return lastDayOfWeek(dirtyDate, { weekStartsOn: 1 }); +export function lastDayOfISOWeek(date: DateType | number | string): DateType { + return lastDayOfWeek(date, { weekStartsOn: 1 }); } diff --git a/src/date-fns/lastDayOfISOWeekYear/index.ts b/src/date-fns/lastDayOfISOWeekYear/index.ts index c3fcacb..b4691be 100644 --- a/src/date-fns/lastDayOfISOWeekYear/index.ts +++ b/src/date-fns/lastDayOfISOWeekYear/index.ts @@ -1,6 +1,6 @@ -import getISOWeekYear from '../getISOWeekYear/index'; -import startOfISOWeek from '../startOfISOWeek/index'; -import constructFrom from '../constructFrom/index'; +import { getISOWeekYear } from '../getISOWeekYear/index'; +import { startOfISOWeek } from '../startOfISOWeek/index'; +import { constructFrom } from '../constructFrom/index'; /** * @name lastDayOfISOWeekYear @@ -14,20 +14,23 @@ import constructFrom from '../constructFrom/index'; * * ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date * - * @param date - the original date - * @returns the end of an ISO week-numbering year + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The original date + * + * @returns The end of an ISO week-numbering year * * @example * // The last day of an ISO week-numbering year for 2 July 2005: * const result = lastDayOfISOWeekYear(new Date(2005, 6, 2)) * //=> Sun Jan 01 2006 00:00:00 */ -export default function lastDayOfISOWeekYear(dirtyDate: DateType | number): DateType { - const year = getISOWeekYear(dirtyDate); - const fourthOfJanuary = constructFrom(dirtyDate, 0); +export function lastDayOfISOWeekYear(date: DateType | number | string): DateType { + const year = getISOWeekYear(date); + const fourthOfJanuary = constructFrom(date, 0); fourthOfJanuary.setFullYear(year + 1, 0, 4); fourthOfJanuary.setHours(0, 0, 0, 0); - const date = startOfISOWeek(fourthOfJanuary); - date.setDate(date.getDate() - 1); - return date; + const _date = startOfISOWeek(fourthOfJanuary); + _date.setDate(_date.getDate() - 1); + return _date; } diff --git a/src/date-fns/lastDayOfMonth/index.ts b/src/date-fns/lastDayOfMonth/index.ts index d7eaa0b..11df24e 100644 --- a/src/date-fns/lastDayOfMonth/index.ts +++ b/src/date-fns/lastDayOfMonth/index.ts @@ -1,4 +1,4 @@ -import toDate from '../toDate/index'; +import { toDate } from '../toDate/index'; /** * @name lastDayOfMonth @@ -9,18 +9,21 @@ import toDate from '../toDate/index'; * Return the last day of a month for the given date. * The result will be in the local timezone. * - * @param date - the original date - * @returns the last day of a month + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The original date + * + * @returns The last day of a month * * @example * // The last day of a month for 2 September 2014 11:55:00: * const result = lastDayOfMonth(new Date(2014, 8, 2, 11, 55, 0)) * //=> Tue Sep 30 2014 00:00:00 */ -export default function lastDayOfMonth(dirtyDate: DateType | number): DateType { - const date = toDate(dirtyDate); - const month = date.getMonth(); - date.setFullYear(date.getFullYear(), month + 1, 0); - date.setHours(0, 0, 0, 0); - return date; +export function lastDayOfMonth(date: DateType | number | string): DateType { + const _date = toDate(date); + const month = _date.getMonth(); + _date.setFullYear(_date.getFullYear(), month + 1, 0); + _date.setHours(0, 0, 0, 0); + return _date; } diff --git a/src/date-fns/lastDayOfQuarter/index.ts b/src/date-fns/lastDayOfQuarter/index.ts index 6013455..23b12e5 100644 --- a/src/date-fns/lastDayOfQuarter/index.ts +++ b/src/date-fns/lastDayOfQuarter/index.ts @@ -1,4 +1,4 @@ -import toDate from '../toDate/index'; +import { toDate } from '../toDate/index'; /** * @name lastDayOfQuarter @@ -9,19 +9,22 @@ import toDate from '../toDate/index'; * Return the last day of a year quarter for the given date. * The result will be in the local timezone. * - * @param date - the original date - * @returns the last day of a quarter + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The original date + * + * @returns The last day of a quarter * * @example * // The last day of a quarter for 2 September 2014 11:55:00: * const result = lastDayOfQuarter(new Date(2014, 8, 2, 11, 55, 0)) * //=> Tue Sep 30 2014 00:00:00 */ -export default function lastDayOfQuarter(dirtyDate: DateType | number): DateType { - const date = toDate(dirtyDate); - const currentMonth = date.getMonth(); +export function lastDayOfQuarter(date: DateType | number | string): DateType { + const _date = toDate(date); + const currentMonth = _date.getMonth(); const month = currentMonth - (currentMonth % 3) + 3; - date.setMonth(month, 0); - date.setHours(0, 0, 0, 0); - return date; + _date.setMonth(month, 0); + _date.setHours(0, 0, 0, 0); + return _date; } diff --git a/src/date-fns/lastDayOfWeek/index.ts b/src/date-fns/lastDayOfWeek/index.ts index 0080f8b..f73a14c 100644 --- a/src/date-fns/lastDayOfWeek/index.ts +++ b/src/date-fns/lastDayOfWeek/index.ts @@ -1,11 +1,11 @@ -import toDate from '../toDate/index'; -import type { LocaleOptions, WeekStartOptions } from '../types'; +import { toDate } from '../toDate/index'; +import type { LocalizedOptions, WeekOptions } from '../types'; import { getDefaultOptions } from '../_lib/defaultOptions/index'; /** * The {@link lastDayOfWeek} function options. */ -export interface LastDayOfWeekOptions extends LocaleOptions, WeekStartOptions {} +export interface LastDayOfWeekOptions extends LocalizedOptions<'options'>, WeekOptions {} /** * @name lastDayOfWeek @@ -16,9 +16,12 @@ export interface LastDayOfWeekOptions extends LocaleOptions, WeekStartOptions {} * Return the last day of a week for the given date. * The result will be in the local timezone. * - * @param date - the original date - * @param options - an object with options. - * @returns the last day of a week + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The original date + * @param options - An object with options + * + * @returns The last day of a week * * @example * // The last day of a week for 2 September 2014 11:55:00: @@ -30,8 +33,8 @@ export interface LastDayOfWeekOptions extends LocaleOptions, WeekStartOptions {} * const result = lastDayOfWeek(new Date(2014, 8, 2, 11, 55, 0), { weekStartsOn: 1 }) * //=> Sun Sep 07 2014 00:00:00 */ -export default function lastDayOfWeek( - dirtyDate: DateType | number, +export function lastDayOfWeek( + date: DateType | number | string, options?: LastDayOfWeekOptions, ): DateType { const defaultOptions = getDefaultOptions(); @@ -42,11 +45,11 @@ export default function lastDayOfWeek( defaultOptions.locale?.options?.weekStartsOn ?? 0; - const date = toDate(dirtyDate); - const day = date.getDay(); + const _date = toDate(date); + const day = _date.getDay(); const diff = (day < weekStartsOn ? -7 : 0) + 6 - (day - weekStartsOn); - date.setHours(0, 0, 0, 0); - date.setDate(date.getDate() + diff); - return date; + _date.setHours(0, 0, 0, 0); + _date.setDate(_date.getDate() + diff); + return _date; } diff --git a/src/date-fns/lastDayOfYear/index.ts b/src/date-fns/lastDayOfYear/index.ts index bc3ca16..1b5f08d 100644 --- a/src/date-fns/lastDayOfYear/index.ts +++ b/src/date-fns/lastDayOfYear/index.ts @@ -1,4 +1,4 @@ -import toDate from '../toDate/index'; +import { toDate } from '../toDate/index'; /** * @name lastDayOfYear @@ -9,18 +9,21 @@ import toDate from '../toDate/index'; * Return the last day of a year for the given date. * The result will be in the local timezone. * - * @param date - the original date - * @returns the last day of a year + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The original date + * + * @returns The last day of a year * * @example * // The last day of a year for 2 September 2014 11:55:00: * const result = lastDayOfYear(new Date(2014, 8, 2, 11, 55, 00)) * //=> Wed Dec 31 2014 00:00:00 */ -export default function lastDayOfYear(dirtyDate: DateType | number): DateType { - const date = toDate(dirtyDate); - const year = date.getFullYear(); - date.setFullYear(year + 1, 0, 0); - date.setHours(0, 0, 0, 0); - return date; +export function lastDayOfYear(date: DateType | number | string): DateType { + const _date = toDate(date); + const year = _date.getFullYear(); + _date.setFullYear(year + 1, 0, 0); + _date.setHours(0, 0, 0, 0); + return _date; } diff --git a/src/date-fns/lightFormat/index.ts b/src/date-fns/lightFormat/index.ts index 8501095..cf81e0a 100644 --- a/src/date-fns/lightFormat/index.ts +++ b/src/date-fns/lightFormat/index.ts @@ -1,6 +1,10 @@ -import isValid from '../isValid/index'; -import toDate from '../toDate/index'; -import formatters from '../_lib/format/lightFormatters/index'; +import { isValid } from '../isValid/index'; +import { toDate } from '../toDate/index'; +import { lightFormatters } from '../_lib/format/lightFormatters/index'; + +// Rexports of internal for libraries to use. +// See: https://github.com/date-fns/date-fns/issues/3638#issuecomment-1877082874 +export { lightFormatters }; // This RegExp consists of three parts separated by `|`: // - (\w)\1* matches any sequences of the same letter @@ -17,6 +21,11 @@ const escapedStringRegExp = /^'([^]*?)'?$/; const doubleQuoteRegExp = /''/g; const unescapedLatinCharacterRegExp = /[a-zA-Z]/; +/** + * @private + */ +type Token = keyof typeof lightFormatters; + /** * @name lightFormat * @category Common Helpers @@ -62,22 +71,24 @@ const unescapedLatinCharacterRegExp = /[a-zA-Z]/; * | | SSS | 000, 001, ..., 999 | * | | SSSS | ... | * - * @param date - the original date - * @param format - the string of tokens - * @returns the formatted date string - * @throws {RangeError} format string contains an unescaped latin alphabet character + * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc). + * + * @param date - The original date + * @param format - The string of tokens + * + * @returns The formatted date string + * + * @throws `Invalid time value` if the date is invalid + * @throws format string contains an unescaped latin alphabet character * * @example * const result = lightFormat(new Date(2014, 1, 11), 'yyyy-MM-dd') * //=> '2014-02-11' */ +export function lightFormat(date: DateType | number | string, formatStr: string): string { + const _date = toDate(date); -type Token = keyof typeof formatters; - -export default function lightFormat(dirtyDate: DateType | number, formatStr: string): string { - const originalDate = toDate(dirtyDate); - - if (!isValid(originalDate)) { + if (!isValid(_date)) { throw new RangeError('Invalid time value'); } @@ -98,12 +109,12 @@ export default function lightFormat(dirtyDate: DateType | return cleanEscapedString(substring); } - const formatter = formatters[firstCharacter as Token]; + const formatter = lightFormatters[firstCharacter as Token]; if (formatter) { - return formatter(originalDate, substring); + return formatter(_date, substring); } - if (firstCharacter?.match(unescapedLatinCharacterRegExp)) { + if (firstCharacter!.match(unescapedLatinCharacterRegExp)) { throw new RangeError('Format string contains an unescaped latin alphabet character `' + firstCharacter + '`'); } @@ -114,12 +125,12 @@ export default function lightFormat(dirtyDate: DateType | return result; } -function cleanEscapedString(input: string): string { +function cleanEscapedString(input: string) { const matches = input.match(escapedStringRegExp); if (!matches) { return input; } - return matches[1]?.replace(doubleQuoteRegExp, "'") as string; + return matches[1]!.replace(doubleQuoteRegExp, "'"); } diff --git a/src/date-fns/locale/_lib/buildFormatLongFn/index.ts b/src/date-fns/locale/_lib/buildFormatLongFn/index.ts index eb93dcb..673cd5e 100644 --- a/src/date-fns/locale/_lib/buildFormatLongFn/index.ts +++ b/src/date-fns/locale/_lib/buildFormatLongFn/index.ts @@ -1,11 +1,13 @@ import type { FormatLongFn, FormatLongWidth } from '../../types'; export interface BuildFormatLongFnArgs { - formats: Partial<{ [format in FormatLongWidth]: string }> & { [format in DefaultMatchWidth]: string }; + formats: Partial<{ [format in FormatLongWidth]: string }> & { + [format in DefaultMatchWidth]: string; + }; defaultWidth: DefaultMatchWidth; } -export default function buildFormatLongFn( +export function buildFormatLongFn( args: BuildFormatLongFnArgs, ): FormatLongFn { return (options = {}) => { diff --git a/src/date-fns/locale/_lib/buildLocalizeFn/index.ts b/src/date-fns/locale/_lib/buildLocalizeFn/index.ts index 4127218..3a47576 100644 --- a/src/date-fns/locale/_lib/buildLocalizeFn/index.ts +++ b/src/date-fns/locale/_lib/buildLocalizeFn/index.ts @@ -1,13 +1,80 @@ -import type { Era, Quarter, Month, Day } from '../../../types'; -import type { LocaleDayPeriod, LocalePatternWidth, LocaleUnit, LocalizeFn, LocalizeUnitIndex } from '../../types'; +/* eslint-disable no-unused-vars */ -type LocalizeEraValues = readonly [string, string]; +import type { Day, Era, Month, Quarter } from '../../../types'; +import type { LocaleDayPeriod, LocaleUnitValue, LocaleWidth, LocalizeFn } from '../../types'; -type LocalizeQuarterValues = readonly [string, string, string, string]; +export type BuildLocalizeFnArgs< + Value extends LocaleUnitValue, + ArgCallback extends LocalizeFnArgCallback | undefined, +> = { + values: LocalizePeriodValuesMap; + defaultWidth: LocaleWidth; + formattingValues?: LocalizePeriodValuesMap; + defaultFormattingWidth?: LocaleWidth; +} & (ArgCallback extends undefined + ? { argumentCallback?: undefined } + : { argumentCallback: LocalizeFnArgCallback }); + +/** + * The localize function argument callback which allows to convert raw value to + * the actual type. + * + * @param value - The value to convert + * + * @returns The converted value + */ +export type LocalizeFnArgCallback = (value: Value) => LocalizeUnitIndex; + +/** + * The map of localized values for each width. + */ +export type LocalizePeriodValuesMap = { + [Pattern in LocaleWidth]?: LocalizeValues; +}; + +/** + * The index type of the locale unit value. It types conversion of units of + * values that don't start at 0 (i.e. quarters). + */ +export type LocalizeUnitIndex = Value extends LocaleUnitValue + ? keyof LocalizeValues + : number; + +/** + * Converts the unit value to the tuple of values. + */ +export type LocalizeValues = Value extends LocaleDayPeriod + ? Record + : Value extends Era + ? LocalizeEraValues + : Value extends Quarter + ? LocalizeQuarterValues + : Value extends Day + ? LocalizeDayValues + : Value extends Month + ? LocalizeMonthValues + : never; + +/** + * The tuple of localized era values. The first element represents BC, + * the second element represents AD. + */ +export type LocalizeEraValues = readonly [string, string]; + +/** + * The tuple of localized quarter values. The first element represents Q1. + */ +export type LocalizeQuarterValues = readonly [string, string, string, string]; -type LocalizeDayValues = readonly [string, string, string, string, string, string, string]; +/** + * The tuple of localized day values. The first element represents Sunday. + */ +export type LocalizeDayValues = readonly [string, string, string, string, string, string, string]; -type LocalizeMonthValues = readonly [ +/** + * The tuple of localized month values. The first element represents January. + */ +export type LocalizeMonthValues = readonly [ string, string, string, @@ -22,76 +89,25 @@ type LocalizeMonthValues = readonly [ string, ]; -export type LocalizeUnitValuesIndex> = Values extends Record< - LocaleDayPeriod, - string -> - ? string - : Values extends LocalizeEraValues - ? Era - : Values extends LocalizeQuarterValues - ? Quarter - : Values extends LocalizeDayValues - ? Day - : Values extends LocalizeMonthValues - ? Month - : never; - -export type LocalizeUnitValues = Unit extends LocaleDayPeriod - ? Record - : Unit extends Era - ? LocalizeEraValues - : Unit extends Quarter - ? LocalizeQuarterValues - : Unit extends Day - ? LocalizeDayValues - : Unit extends Month - ? LocalizeMonthValues - : never; - -export type LocalizePeriodValuesMap = { - [pattern in LocalePatternWidth]?: LocalizeUnitValues; -}; - -export type BuildLocalizeFnArgCallback = ( - value: Result, -) => LocalizeUnitIndex; - -export type BuildLocalizeFnArgs< - Result extends LocaleUnit, - ArgCallback extends BuildLocalizeFnArgCallback | undefined, -> = { - values: LocalizePeriodValuesMap; - defaultWidth: LocalePatternWidth; - formattingValues?: LocalizePeriodValuesMap; - defaultFormattingWidth?: LocalePatternWidth; -} & (ArgCallback extends undefined - ? { argumentCallback?: undefined } - : { argumentCallback: BuildLocalizeFnArgCallback }); - -export default function buildLocalizeFn< - Result extends LocaleUnit, - ArgCallback extends BuildLocalizeFnArgCallback | undefined, ->(args: BuildLocalizeFnArgs): LocalizeFn { - return (dirtyIndex, options) => { +export function buildLocalizeFn< + Value extends LocaleUnitValue, + ArgCallback extends LocalizeFnArgCallback | undefined, +>(args: BuildLocalizeFnArgs): LocalizeFn { + return (value, options) => { const context = options?.context ? String(options.context) : 'standalone'; - let valuesArray: LocalizeUnitValues; + let valuesArray: LocalizeValues; if (context === 'formatting' && args.formattingValues) { const defaultWidth = args.defaultFormattingWidth || args.defaultWidth; - const width = (options?.width ? String(options.width) : defaultWidth) as LocalePatternWidth; - valuesArray = (args.formattingValues[width] || args.formattingValues[defaultWidth]) as LocalizeUnitValues; + const width = (options?.width ? String(options.width) : defaultWidth) as LocaleWidth; + valuesArray = (args.formattingValues[width] || args.formattingValues[defaultWidth]) as LocalizeValues; } else { const defaultWidth = args.defaultWidth; - const width = (options?.width ? String(options.width) : args.defaultWidth) as LocalePatternWidth; - valuesArray = (args.values[width] || args.values[defaultWidth]) as LocalizeUnitValues; + const width = (options?.width ? String(options.width) : args.defaultWidth) as LocaleWidth; + valuesArray = (args.values[width] || args.values[defaultWidth]) as LocalizeValues; } - const index = ( - args.argumentCallback - ? args.argumentCallback(dirtyIndex as Result) - : (dirtyIndex as LocalizeUnitIndex as unknown) - ) as LocalizeUnitValuesIndex; - // @ts-ignore: For some reason TypeScript just don't want to match it, no matter how hard we try. I challenge you to try to remove it! + const index = (args.argumentCallback ? args.argumentCallback(value as Value) : value) as LocalizeUnitIndex; + // @ts-expect-error - For some reason TypeScript just don't want to match it, no matter how hard we try. I challenge you to try to remove it! return valuesArray[index]; }; } diff --git a/src/date-fns/locale/_lib/buildMatchFn/index.ts b/src/date-fns/locale/_lib/buildMatchFn/index.ts index 6bef197..2fa5dd6 100644 --- a/src/date-fns/locale/_lib/buildMatchFn/index.ts +++ b/src/date-fns/locale/_lib/buildMatchFn/index.ts @@ -1,10 +1,47 @@ -import type { BuildMatchFnArgs, LocaleDayPeriod, LocaleUnit, LocalePatternWidth, MatchFn } from '../../types'; +import type { Quarter, Era, Day, Month } from '../../../types'; +import type { LocaleUnitValue, LocaleWidth, LocaleDayPeriod, MatchFn, MatchValueCallback } from '../../types'; -export default function buildMatchFn< - Result extends LocaleUnit, - DefaultMatchWidth extends LocalePatternWidth, - DefaultParseWidth extends LocalePatternWidth, ->(args: BuildMatchFnArgs): MatchFn { +export interface BuildMatchFnArgs< + Result extends LocaleUnitValue, + DefaultMatchWidth extends LocaleWidth, + DefaultParseWidth extends LocaleWidth, +> { + matchPatterns: BuildMatchFnMatchPatterns; + defaultMatchWidth: DefaultMatchWidth; + parsePatterns: BuildMatchFnParsePatterns; + defaultParseWidth: DefaultParseWidth; + valueCallback?: MatchValueCallback; +} + +export type BuildMatchFnMatchPatterns = { + [Width in LocaleWidth]?: RegExp; +} & { + [Width in DefaultWidth]: RegExp; +}; + +export type BuildMatchFnParsePatterns = { + [Width in LocaleWidth]?: ParsePattern; +} & { + [Width in DefaultWidth]: ParsePattern; +}; + +export type ParsePattern = Value extends LocaleDayPeriod + ? Record + : Value extends Quarter + ? readonly [RegExp, RegExp, RegExp, RegExp] + : Value extends Era + ? readonly [RegExp, RegExp] + : Value extends Day + ? readonly [RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp] + : Value extends Month + ? readonly [RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp] + : never; + +export function buildMatchFn< + Value extends LocaleUnitValue, + DefaultMatchWidth extends LocaleWidth, + DefaultParseWidth extends LocaleWidth, +>(args: BuildMatchFnArgs): MatchFn { return (string, options = {}) => { const width = options.width; @@ -21,15 +58,19 @@ export default function buildMatchFn< const key = ( Array.isArray(parsePatterns) ? findIndex(parsePatterns, (pattern) => pattern.test(matchedString)) - : findKey(parsePatterns, (pattern: any) => pattern.test(matchedString)) - ) as Result extends LocaleDayPeriod ? string : number; + : // eslint-disable-next-line @typescript-eslint/no-explicit-any -- I challange you to fix the type + findKey(parsePatterns, (pattern: any) => pattern.test(matchedString)) + ) as Value extends LocaleDayPeriod ? string : number; - let value: Result; + let value: Value; - value = (args.valueCallback ? args.valueCallback(key) : key) as Result; - value = options.valueCallback ? options.valueCallback(value as any) : value; + value = (args.valueCallback ? args.valueCallback(key) : key) as Value; + value = options.valueCallback + ? // eslint-disable-next-line @typescript-eslint/no-explicit-any -- I challange you to fix the type + options.valueCallback(value as any) + : value; - const rest = string.slice((matchedString as string).length); + const rest = string.slice(matchedString.length); return { value, rest }; }; @@ -40,7 +81,7 @@ function findKey( predicate: (value: Value) => boolean, ): keyof Obj | undefined { for (const key in object) { - if (object.hasOwnProperty(key) && predicate(object[key] as Value)) { + if (Object.prototype.hasOwnProperty.call(object, key) && predicate(object[key]!)) { return key; } } @@ -49,7 +90,7 @@ function findKey( function findIndex(array: Item[], predicate: (item: Item) => boolean): number | undefined { for (let key = 0; key < array.length; key++) { - if (predicate(array[key] as Item)) { + if (predicate(array[key]!)) { return key; } } diff --git a/src/date-fns/locale/_lib/buildMatchPatternFn/index.ts b/src/date-fns/locale/_lib/buildMatchPatternFn/index.ts index 96a5a6a..9722692 100644 --- a/src/date-fns/locale/_lib/buildMatchPatternFn/index.ts +++ b/src/date-fns/locale/_lib/buildMatchPatternFn/index.ts @@ -6,7 +6,7 @@ export interface BuildMatchPatternFnArgs { valueCallback?: MatchValueCallback; } -export default function buildMatchPatternFn(args: BuildMatchPatternFnArgs): MatchFn { +export function buildMatchPatternFn(args: BuildMatchPatternFnArgs): MatchFn { return (string, options = {}) => { const matchResult = string.match(args.matchPattern); if (!matchResult) return null; @@ -14,10 +14,11 @@ export default function buildMatchPatternFn(args: BuildMatchPatternFnArg const parseResult = string.match(args.parsePattern); if (!parseResult) return null; - let value = (args.valueCallback ? args.valueCallback(parseResult[0] as string) : parseResult[0]) as Result; + let value = (args.valueCallback ? args.valueCallback(parseResult[0]) : parseResult[0]) as Result; + // eslint-disable-next-line @typescript-eslint/no-explicit-any -- I challange you to fix the type value = options.valueCallback ? options.valueCallback(value as any) : value; - const rest = string.slice((matchedString as string).length); + const rest = string.slice(matchedString.length); return { value, rest }; }; diff --git a/src/date-fns/locale/en-US/_lib/formatDistance/index.ts b/src/date-fns/locale/en-US/_lib/formatDistance/index.ts index f326151..f11b76a 100644 --- a/src/date-fns/locale/en-US/_lib/formatDistance/index.ts +++ b/src/date-fns/locale/en-US/_lib/formatDistance/index.ts @@ -86,7 +86,7 @@ const formatDistanceLocale: FormatDistanceLocale = { }, }; -const formatDistance: FormatDistanceFn = (token, count, options) => { +export const formatDistance: FormatDistanceFn = (token, count, options) => { let result; const tokenValue = formatDistanceLocale[token]; @@ -108,5 +108,3 @@ const formatDistance: FormatDistanceFn = (token, count, options) => { return result; }; - -export default formatDistance; diff --git a/src/date-fns/locale/en-US/_lib/formatLong/index.ts b/src/date-fns/locale/en-US/_lib/formatLong/index.ts index f4c7fa3..b078ffe 100644 --- a/src/date-fns/locale/en-US/_lib/formatLong/index.ts +++ b/src/date-fns/locale/en-US/_lib/formatLong/index.ts @@ -1,4 +1,4 @@ -import buildFormatLongFn from '../../../_lib/buildFormatLongFn/index'; +import { buildFormatLongFn } from '../../../_lib/buildFormatLongFn/index'; import type { FormatLong } from '../../../types'; const dateFormats = { @@ -22,7 +22,7 @@ const dateTimeFormats = { short: '{{date}}, {{time}}', }; -const formatLong: FormatLong = { +export const formatLong: FormatLong = { date: buildFormatLongFn({ formats: dateFormats, defaultWidth: 'full', @@ -38,5 +38,3 @@ const formatLong: FormatLong = { defaultWidth: 'full', }), }; - -export default formatLong; diff --git a/src/date-fns/locale/en-US/_lib/formatRelative/index.ts b/src/date-fns/locale/en-US/_lib/formatRelative/index.ts index 4e8b1e0..3276be2 100644 --- a/src/date-fns/locale/en-US/_lib/formatRelative/index.ts +++ b/src/date-fns/locale/en-US/_lib/formatRelative/index.ts @@ -9,6 +9,4 @@ const formatRelativeLocale = { other: 'P', }; -const formatRelative: FormatRelativeFn = (token, _date, _baseDate, _options) => formatRelativeLocale[token]; - -export default formatRelative; +export const formatRelative: FormatRelativeFn = (token, _date, _baseDate, _options) => formatRelativeLocale[token]; diff --git a/src/date-fns/locale/en-US/_lib/localize/index.ts b/src/date-fns/locale/en-US/_lib/localize/index.ts index a5f148b..a2aa27c 100644 --- a/src/date-fns/locale/en-US/_lib/localize/index.ts +++ b/src/date-fns/locale/en-US/_lib/localize/index.ts @@ -1,6 +1,5 @@ -import type { Quarter } from '../../../../types'; import type { Localize, LocalizeFn } from '../../../types'; -import buildLocalizeFn from '../../../_lib/buildLocalizeFn/index'; +import { buildLocalizeFn } from '../../../_lib/buildLocalizeFn/index'; const eraValues = { narrow: ['B', 'A'] as const, @@ -110,7 +109,7 @@ const formattingDayPeriodValues = { }, }; -const ordinalNumber: LocalizeFn = (dirtyNumber, _options) => { +const ordinalNumber: LocalizeFn = (dirtyNumber, _options) => { const number = Number(dirtyNumber); // If ordinal numbers depend on context, for example, @@ -134,7 +133,7 @@ const ordinalNumber: LocalizeFn = (dirtyNumber, _options) => return number + 'th'; }; -const localize: Localize = { +export const localize: Localize = { ordinalNumber, era: buildLocalizeFn({ @@ -145,7 +144,7 @@ const localize: Localize = { quarter: buildLocalizeFn({ values: quarterValues, defaultWidth: 'wide', - argumentCallback: (quarter) => (quarter - 1) as Quarter, + argumentCallback: (quarter) => quarter - 1, }), month: buildLocalizeFn({ @@ -165,5 +164,3 @@ const localize: Localize = { defaultFormattingWidth: 'wide', }), }; - -export default localize; diff --git a/src/date-fns/locale/en-US/_lib/match/index.ts b/src/date-fns/locale/en-US/_lib/match/index.ts index d1ce6f1..4449806 100644 --- a/src/date-fns/locale/en-US/_lib/match/index.ts +++ b/src/date-fns/locale/en-US/_lib/match/index.ts @@ -1,7 +1,7 @@ import type { Quarter } from '../../../../types'; import type { Match } from '../../../types'; -import buildMatchFn from '../../../_lib/buildMatchFn/index'; -import buildMatchPatternFn from '../../../_lib/buildMatchPatternFn/index'; +import { buildMatchFn } from '../../../_lib/buildMatchFn/index'; +import { buildMatchPatternFn } from '../../../_lib/buildMatchPatternFn/index'; const matchOrdinalNumberPattern = /^(\d+)(th|st|nd|rd)?/i; const parseOrdinalNumberPattern = /\d+/i; @@ -62,7 +62,7 @@ const parseDayPeriodPatterns = { }, }; -const match: Match = { +export const match: Match = { ordinalNumber: buildMatchPatternFn({ matchPattern: matchOrdinalNumberPattern, parsePattern: parseOrdinalNumberPattern, @@ -105,5 +105,3 @@ const match: Match = { defaultParseWidth: 'any', }), }; - -export default match; diff --git a/src/date-fns/locale/en-US/index.ts b/src/date-fns/locale/en-US/index.ts index ed95406..9b1b5ea 100644 --- a/src/date-fns/locale/en-US/index.ts +++ b/src/date-fns/locale/en-US/index.ts @@ -1,20 +1,19 @@ -import formatDistance from './_lib/formatDistance/index'; -import formatLong from './_lib/formatLong/index'; -import formatRelative from './_lib/formatRelative/index'; -import localize from './_lib/localize/index'; -import match from './_lib/match/index'; +import { formatDistance } from './_lib/formatDistance/index'; +import { formatLong } from './_lib/formatLong/index'; +import { formatRelative } from './_lib/formatRelative/index'; +import { localize } from './_lib/localize/index'; +import { match } from './_lib/match/index'; import type { Locale } from '../types'; /** - * @type {Locale} * @category Locales * @summary English locale (United States). * @language English * @iso-639-2 eng - * @author Sasha Koss [@kossnocorp]{@link https://github.com/kossnocorp} - * @author Lesha Koss [@leshakoss]{@link https://github.com/leshakoss} + * @author Sasha Koss [@kossnocorp](https://github.com/kossnocorp) + * @author Lesha Koss [@leshakoss](https://github.com/leshakoss) */ -const locale: Locale = { +export const enUS: Locale = { code: 'en-US', formatDistance: formatDistance, formatLong: formatLong, @@ -26,5 +25,3 @@ const locale: Locale = { firstWeekContainsDate: 1, }, }; - -export default locale; diff --git a/src/date-fns/locale/en-US/snapshot.md b/src/date-fns/locale/en-US/snapshot.md index c596e77..9aeb1da 100644 --- a/src/date-fns/locale/en-US/snapshot.md +++ b/src/date-fns/locale/en-US/snapshot.md @@ -22,28 +22,112 @@ | | | 2019-04-01T12:13:14.015Z | Q2 | 2019-04-01T00:00:00.000Z | | | qqqq | 2019-01-01T12:13:14.015Z | 1st quarter | 2019-01-01T00:00:00.000Z | | | | 2019-04-01T12:13:14.015Z | 2nd quarter | 2019-04-01T00:00:00.000Z | -| Month (formatting) | Mo | 2019-02-11T12:13:14.015Z | 2nd | 2019-02-01T00:00:00.000Z | +| Month (formatting) | Mo | 2019-01-11T12:13:14.015Z | 1st | 2019-01-01T00:00:00.000Z | +| | | 2019-02-11T12:13:14.015Z | 2nd | 2019-02-01T00:00:00.000Z | +| | | 2019-03-11T12:13:14.015Z | 3rd | 2019-03-01T00:00:00.000Z | +| | | 2019-04-10T12:13:14.015Z | 4th | 2019-04-01T00:00:00.000Z | +| | | 2019-05-10T12:13:14.015Z | 5th | 2019-05-01T00:00:00.000Z | +| | | 2019-06-10T12:13:14.015Z | 6th | 2019-06-01T00:00:00.000Z | | | | 2019-07-10T12:13:14.015Z | 7th | 2019-07-01T00:00:00.000Z | -| | MMM | 2019-02-11T12:13:14.015Z | Feb | 2019-02-01T00:00:00.000Z | +| | | 2019-08-10T12:13:14.015Z | 8th | 2019-08-01T00:00:00.000Z | +| | | 2019-09-10T12:13:14.015Z | 9th | 2019-09-01T00:00:00.000Z | +| | | 2019-10-10T12:13:14.015Z | 10th | 2019-10-01T00:00:00.000Z | +| | | 2019-11-10T12:13:14.015Z | 11th | 2019-11-01T00:00:00.000Z | +| | | 2019-12-10T12:13:14.015Z | 12th | 2019-12-01T00:00:00.000Z | +| | MMM | 2019-01-11T12:13:14.015Z | Jan | 2019-01-01T00:00:00.000Z | +| | | 2019-02-11T12:13:14.015Z | Feb | 2019-02-01T00:00:00.000Z | +| | | 2019-03-11T12:13:14.015Z | Mar | 2019-03-01T00:00:00.000Z | +| | | 2019-04-10T12:13:14.015Z | Apr | 2019-04-01T00:00:00.000Z | +| | | 2019-05-10T12:13:14.015Z | May | 2019-05-01T00:00:00.000Z | +| | | 2019-06-10T12:13:14.015Z | Jun | 2019-06-01T00:00:00.000Z | | | | 2019-07-10T12:13:14.015Z | Jul | 2019-07-01T00:00:00.000Z | -| | MMMM | 2019-02-11T12:13:14.015Z | February | 2019-02-01T00:00:00.000Z | +| | | 2019-08-10T12:13:14.015Z | Aug | 2019-08-01T00:00:00.000Z | +| | | 2019-09-10T12:13:14.015Z | Sep | 2019-09-01T00:00:00.000Z | +| | | 2019-10-10T12:13:14.015Z | Oct | 2019-10-01T00:00:00.000Z | +| | | 2019-11-10T12:13:14.015Z | Nov | 2019-11-01T00:00:00.000Z | +| | | 2019-12-10T12:13:14.015Z | Dec | 2019-12-01T00:00:00.000Z | +| | MMMM | 2019-01-11T12:13:14.015Z | January | 2019-01-01T00:00:00.000Z | +| | | 2019-02-11T12:13:14.015Z | February | 2019-02-01T00:00:00.000Z | +| | | 2019-03-11T12:13:14.015Z | March | 2019-03-01T00:00:00.000Z | +| | | 2019-04-10T12:13:14.015Z | April | 2019-04-01T00:00:00.000Z | +| | | 2019-05-10T12:13:14.015Z | May | 2019-05-01T00:00:00.000Z | +| | | 2019-06-10T12:13:14.015Z | June | 2019-06-01T00:00:00.000Z | | | | 2019-07-10T12:13:14.015Z | July | 2019-07-01T00:00:00.000Z | -| | MMMMM | 2019-02-11T12:13:14.015Z | F | 2019-02-01T00:00:00.000Z | +| | | 2019-08-10T12:13:14.015Z | August | 2019-08-01T00:00:00.000Z | +| | | 2019-09-10T12:13:14.015Z | September | 2019-09-01T00:00:00.000Z | +| | | 2019-10-10T12:13:14.015Z | October | 2019-10-01T00:00:00.000Z | +| | | 2019-11-10T12:13:14.015Z | November | 2019-11-01T00:00:00.000Z | +| | | 2019-12-10T12:13:14.015Z | December | 2019-12-01T00:00:00.000Z | +| | MMMMM | 2019-01-11T12:13:14.015Z | J | 2019-01-01T00:00:00.000Z | +| | | 2019-02-11T12:13:14.015Z | F | 2019-02-01T00:00:00.000Z | +| | | 2019-03-11T12:13:14.015Z | M | 2019-03-01T00:00:00.000Z | +| | | 2019-04-10T12:13:14.015Z | A | 2019-04-01T00:00:00.000Z | +| | | 2019-05-10T12:13:14.015Z | M | 2019-03-01T00:00:00.000Z | +| | | 2019-06-10T12:13:14.015Z | J | 2019-01-01T00:00:00.000Z | | | | 2019-07-10T12:13:14.015Z | J | 2019-01-01T00:00:00.000Z | -| Month (stand-alone) | Lo | 2019-02-11T12:13:14.015Z | 2nd | 2019-02-01T00:00:00.000Z | +| | | 2019-08-10T12:13:14.015Z | A | 2019-04-01T00:00:00.000Z | +| | | 2019-09-10T12:13:14.015Z | S | 2019-09-01T00:00:00.000Z | +| | | 2019-10-10T12:13:14.015Z | O | 2019-10-01T00:00:00.000Z | +| | | 2019-11-10T12:13:14.015Z | N | 2019-11-01T00:00:00.000Z | +| | | 2019-12-10T12:13:14.015Z | D | 2019-12-01T00:00:00.000Z | +| Month (stand-alone) | Lo | 2019-01-11T12:13:14.015Z | 1st | 2019-01-01T00:00:00.000Z | +| | | 2019-02-11T12:13:14.015Z | 2nd | 2019-02-01T00:00:00.000Z | +| | | 2019-03-11T12:13:14.015Z | 3rd | 2019-03-01T00:00:00.000Z | +| | | 2019-04-10T12:13:14.015Z | 4th | 2019-04-01T00:00:00.000Z | +| | | 2019-05-10T12:13:14.015Z | 5th | 2019-05-01T00:00:00.000Z | +| | | 2019-06-10T12:13:14.015Z | 6th | 2019-06-01T00:00:00.000Z | | | | 2019-07-10T12:13:14.015Z | 7th | 2019-07-01T00:00:00.000Z | -| | LLL | 2019-02-11T12:13:14.015Z | Feb | 2019-02-01T00:00:00.000Z | +| | | 2019-08-10T12:13:14.015Z | 8th | 2019-08-01T00:00:00.000Z | +| | | 2019-09-10T12:13:14.015Z | 9th | 2019-09-01T00:00:00.000Z | +| | | 2019-10-10T12:13:14.015Z | 10th | 2019-10-01T00:00:00.000Z | +| | | 2019-11-10T12:13:14.015Z | 11th | 2019-11-01T00:00:00.000Z | +| | | 2019-12-10T12:13:14.015Z | 12th | 2019-12-01T00:00:00.000Z | +| | LLL | 2019-01-11T12:13:14.015Z | Jan | 2019-01-01T00:00:00.000Z | +| | | 2019-02-11T12:13:14.015Z | Feb | 2019-02-01T00:00:00.000Z | +| | | 2019-03-11T12:13:14.015Z | Mar | 2019-03-01T00:00:00.000Z | +| | | 2019-04-10T12:13:14.015Z | Apr | 2019-04-01T00:00:00.000Z | +| | | 2019-05-10T12:13:14.015Z | May | 2019-05-01T00:00:00.000Z | +| | | 2019-06-10T12:13:14.015Z | Jun | 2019-06-01T00:00:00.000Z | | | | 2019-07-10T12:13:14.015Z | Jul | 2019-07-01T00:00:00.000Z | -| | LLLL | 2019-02-11T12:13:14.015Z | February | 2019-02-01T00:00:00.000Z | +| | | 2019-08-10T12:13:14.015Z | Aug | 2019-08-01T00:00:00.000Z | +| | | 2019-09-10T12:13:14.015Z | Sep | 2019-09-01T00:00:00.000Z | +| | | 2019-10-10T12:13:14.015Z | Oct | 2019-10-01T00:00:00.000Z | +| | | 2019-11-10T12:13:14.015Z | Nov | 2019-11-01T00:00:00.000Z | +| | | 2019-12-10T12:13:14.015Z | Dec | 2019-12-01T00:00:00.000Z | +| | LLLL | 2019-01-11T12:13:14.015Z | January | 2019-01-01T00:00:00.000Z | +| | | 2019-02-11T12:13:14.015Z | February | 2019-02-01T00:00:00.000Z | +| | | 2019-03-11T12:13:14.015Z | March | 2019-03-01T00:00:00.000Z | +| | | 2019-04-10T12:13:14.015Z | April | 2019-04-01T00:00:00.000Z | +| | | 2019-05-10T12:13:14.015Z | May | 2019-05-01T00:00:00.000Z | +| | | 2019-06-10T12:13:14.015Z | June | 2019-06-01T00:00:00.000Z | | | | 2019-07-10T12:13:14.015Z | July | 2019-07-01T00:00:00.000Z | -| | LLLLL | 2019-02-11T12:13:14.015Z | F | 2019-02-01T00:00:00.000Z | +| | | 2019-08-10T12:13:14.015Z | August | 2019-08-01T00:00:00.000Z | +| | | 2019-09-10T12:13:14.015Z | September | 2019-09-01T00:00:00.000Z | +| | | 2019-10-10T12:13:14.015Z | October | 2019-10-01T00:00:00.000Z | +| | | 2019-11-10T12:13:14.015Z | November | 2019-11-01T00:00:00.000Z | +| | | 2019-12-10T12:13:14.015Z | December | 2019-12-01T00:00:00.000Z | +| | LLLLL | 2019-01-11T12:13:14.015Z | J | 2019-01-01T00:00:00.000Z | +| | | 2019-02-11T12:13:14.015Z | F | 2019-02-01T00:00:00.000Z | +| | | 2019-03-11T12:13:14.015Z | M | 2019-03-01T00:00:00.000Z | +| | | 2019-04-10T12:13:14.015Z | A | 2019-04-01T00:00:00.000Z | +| | | 2019-05-10T12:13:14.015Z | M | 2019-03-01T00:00:00.000Z | +| | | 2019-06-10T12:13:14.015Z | J | 2019-01-01T00:00:00.000Z | | | | 2019-07-10T12:13:14.015Z | J | 2019-01-01T00:00:00.000Z | +| | | 2019-08-10T12:13:14.015Z | A | 2019-04-01T00:00:00.000Z | +| | | 2019-09-10T12:13:14.015Z | S | 2019-09-01T00:00:00.000Z | +| | | 2019-10-10T12:13:14.015Z | O | 2019-10-01T00:00:00.000Z | +| | | 2019-11-10T12:13:14.015Z | N | 2019-11-01T00:00:00.000Z | +| | | 2019-12-10T12:13:14.015Z | D | 2019-12-01T00:00:00.000Z | | Local week of year | wo | 2019-01-01T12:13:14.015Z | 1st | 2018-12-30T00:00:00.000Z | | | | 2019-12-01T12:13:14.015Z | 49th | 2019-12-01T00:00:00.000Z | | ISO week of year | Io | 2019-01-01T12:13:14.015Z | 1st | 2018-12-31T00:00:00.000Z | | | | 2019-12-01T12:13:14.015Z | 48th | 2019-11-25T00:00:00.000Z | -| Day of month | do | 2019-02-11T12:13:14.015Z | 11th | 2019-02-11T00:00:00.000Z | +| Day of month | do | 2019-02-01T12:13:14.015Z | 1st | 2019-02-01T00:00:00.000Z | +| | | 2019-02-11T12:13:14.015Z | 11th | 2019-02-11T00:00:00.000Z | | | | 2019-02-28T12:13:14.015Z | 28th | 2019-02-28T00:00:00.000Z | +| | do MMMM | 2019-02-01T12:13:14.015Z | 1st February | 2019-02-01T00:00:00.000Z | +| | | 2019-02-11T12:13:14.015Z | 11th February | 2019-02-11T00:00:00.000Z | +| | | 2019-02-28T12:13:14.015Z | 28th February | 2019-02-28T00:00:00.000Z | | Day of year | Do | 2019-02-11T12:13:14.015Z | 42nd | 2019-02-11T00:00:00.000Z | | | | 2019-12-31T12:13:14.015Z | 365th | 2019-12-31T00:00:00.000Z | | Day of week (formatting) | E | 2019-02-11T12:13:14.015Z | Mon | 2019-02-11T00:00:00.000Z | @@ -160,30 +244,150 @@ | | | 2019-04-01T12:55:14.015Z | 55th | 2019-04-01T12:55:00.000Z | | Second | so | 2019-01-01T12:13:01.015Z | 1st | 2019-01-01T12:13:01.000Z | | | | 2019-04-01T12:13:55.015Z | 55th | 2019-04-01T12:13:55.000Z | -| Long localized date | P | 1987-02-11T12:13:14.015Z | 02/11/1987 | 1987-02-11T00:00:00.000Z | +| Long localized date | P | 1987-01-11T12:13:14.015Z | 01/11/1987 | 1987-01-11T00:00:00.000Z | +| | | 1987-02-11T12:13:14.015Z | 02/11/1987 | 1987-02-11T00:00:00.000Z | +| | | 1987-03-11T12:13:14.015Z | 03/11/1987 | 1987-03-11T00:00:00.000Z | +| | | 1987-04-11T12:13:14.015Z | 04/11/1987 | 1987-04-11T00:00:00.000Z | | | | 1453-05-29T23:59:59.999Z | 05/29/1453 | 1453-05-29T00:00:00.000Z | -| | PP | 1987-02-11T12:13:14.015Z | Feb 11, 1987 | 1987-02-11T00:00:00.000Z | +| | | 1987-06-11T12:13:14.015Z | 06/11/1987 | 1987-06-11T00:00:00.000Z | +| | | 1987-07-11T12:13:14.015Z | 07/11/1987 | 1987-07-11T00:00:00.000Z | +| | | 1987-08-11T12:13:14.015Z | 08/11/1987 | 1987-08-11T00:00:00.000Z | +| | | 1987-09-11T12:13:14.015Z | 09/11/1987 | 1987-09-11T00:00:00.000Z | +| | | 1987-10-11T12:13:14.015Z | 10/11/1987 | 1987-10-11T00:00:00.000Z | +| | | 1987-11-11T12:13:14.015Z | 11/11/1987 | 1987-11-11T00:00:00.000Z | +| | | 1987-12-11T12:13:14.015Z | 12/11/1987 | 1987-12-11T00:00:00.000Z | +| | PP | 1987-01-11T12:13:14.015Z | Jan 11, 1987 | 1987-01-11T00:00:00.000Z | +| | | 1987-02-11T12:13:14.015Z | Feb 11, 1987 | 1987-02-11T00:00:00.000Z | +| | | 1987-03-11T12:13:14.015Z | Mar 11, 1987 | 1987-03-11T00:00:00.000Z | +| | | 1987-04-11T12:13:14.015Z | Apr 11, 1987 | 1987-04-11T00:00:00.000Z | | | | 1453-05-29T23:59:59.999Z | May 29, 1453 | 1453-05-29T00:00:00.000Z | -| | PPP | 1987-02-11T12:13:14.015Z | February 11th, 1987 | 1987-02-11T00:00:00.000Z | +| | | 1987-06-11T12:13:14.015Z | Jun 11, 1987 | 1987-06-11T00:00:00.000Z | +| | | 1987-07-11T12:13:14.015Z | Jul 11, 1987 | 1987-07-11T00:00:00.000Z | +| | | 1987-08-11T12:13:14.015Z | Aug 11, 1987 | 1987-08-11T00:00:00.000Z | +| | | 1987-09-11T12:13:14.015Z | Sep 11, 1987 | 1987-09-11T00:00:00.000Z | +| | | 1987-10-11T12:13:14.015Z | Oct 11, 1987 | 1987-10-11T00:00:00.000Z | +| | | 1987-11-11T12:13:14.015Z | Nov 11, 1987 | 1987-11-11T00:00:00.000Z | +| | | 1987-12-11T12:13:14.015Z | Dec 11, 1987 | 1987-12-11T00:00:00.000Z | +| | PPP | 1987-01-11T12:13:14.015Z | January 11th, 1987 | 1987-01-11T00:00:00.000Z | +| | | 1987-02-11T12:13:14.015Z | February 11th, 1987 | 1987-02-11T00:00:00.000Z | +| | | 1987-03-11T12:13:14.015Z | March 11th, 1987 | 1987-03-11T00:00:00.000Z | +| | | 1987-04-11T12:13:14.015Z | April 11th, 1987 | 1987-04-11T00:00:00.000Z | | | | 1453-05-29T23:59:59.999Z | May 29th, 1453 | 1453-05-29T00:00:00.000Z | -| | PPPP | 1987-02-11T12:13:14.015Z | Wednesday, February 11th, 1987 | 1987-02-11T00:00:00.000Z | +| | | 1987-06-11T12:13:14.015Z | June 11th, 1987 | 1987-06-11T00:00:00.000Z | +| | | 1987-07-11T12:13:14.015Z | July 11th, 1987 | 1987-07-11T00:00:00.000Z | +| | | 1987-08-11T12:13:14.015Z | August 11th, 1987 | 1987-08-11T00:00:00.000Z | +| | | 1987-09-11T12:13:14.015Z | September 11th, 1987 | 1987-09-11T00:00:00.000Z | +| | | 1987-10-11T12:13:14.015Z | October 11th, 1987 | 1987-10-11T00:00:00.000Z | +| | | 1987-11-11T12:13:14.015Z | November 11th, 1987 | 1987-11-11T00:00:00.000Z | +| | | 1987-12-11T12:13:14.015Z | December 11th, 1987 | 1987-12-11T00:00:00.000Z | +| | PPPP | 1987-01-11T12:13:14.015Z | Sunday, January 11th, 1987 | 1987-01-11T00:00:00.000Z | +| | | 1987-02-11T12:13:14.015Z | Wednesday, February 11th, 1987 | 1987-02-11T00:00:00.000Z | +| | | 1987-03-11T12:13:14.015Z | Wednesday, March 11th, 1987 | 1987-03-11T00:00:00.000Z | +| | | 1987-04-11T12:13:14.015Z | Saturday, April 11th, 1987 | 1987-04-11T00:00:00.000Z | | | | 1453-05-29T23:59:59.999Z | Sunday, May 29th, 1453 | 1453-05-29T00:00:00.000Z | -| Long localized time | p | 1987-02-11T12:13:14.015Z | 12:13 PM | 1987-02-11T12:13:00.000Z | +| | | 1987-06-11T12:13:14.015Z | Thursday, June 11th, 1987 | 1987-06-11T00:00:00.000Z | +| | | 1987-07-11T12:13:14.015Z | Saturday, July 11th, 1987 | 1987-07-11T00:00:00.000Z | +| | | 1987-08-11T12:13:14.015Z | Tuesday, August 11th, 1987 | 1987-08-11T00:00:00.000Z | +| | | 1987-09-11T12:13:14.015Z | Friday, September 11th, 1987 | 1987-09-11T00:00:00.000Z | +| | | 1987-10-11T12:13:14.015Z | Sunday, October 11th, 1987 | 1987-10-11T00:00:00.000Z | +| | | 1987-11-11T12:13:14.015Z | Wednesday, November 11th, 1987 | 1987-11-11T00:00:00.000Z | +| | | 1987-12-11T12:13:14.015Z | Friday, December 11th, 1987 | 1987-12-11T00:00:00.000Z | +| Long localized time | p | 1987-01-11T12:13:14.015Z | 12:13 PM | 1987-01-11T12:13:00.000Z | +| | | 1987-02-11T12:13:14.015Z | 12:13 PM | 1987-02-11T12:13:00.000Z | +| | | 1987-03-11T12:13:14.015Z | 12:13 PM | 1987-03-11T12:13:00.000Z | +| | | 1987-04-11T12:13:14.015Z | 12:13 PM | 1987-04-11T12:13:00.000Z | | | | 1453-05-29T23:59:59.999Z | 11:59 PM | 1453-05-29T23:59:00.000Z | -| | pp | 1987-02-11T12:13:14.015Z | 12:13:14 PM | 1987-02-11T12:13:14.000Z | +| | | 1987-06-11T12:13:14.015Z | 12:13 PM | 1987-06-11T12:13:00.000Z | +| | | 1987-07-11T12:13:14.015Z | 12:13 PM | 1987-07-11T12:13:00.000Z | +| | | 1987-08-11T12:13:14.015Z | 12:13 PM | 1987-08-11T12:13:00.000Z | +| | | 1987-09-11T12:13:14.015Z | 12:13 PM | 1987-09-11T12:13:00.000Z | +| | | 1987-10-11T12:13:14.015Z | 12:13 PM | 1987-10-11T12:13:00.000Z | +| | | 1987-11-11T12:13:14.015Z | 12:13 PM | 1987-11-11T12:13:00.000Z | +| | | 1987-12-11T12:13:14.015Z | 12:13 PM | 1987-12-11T12:13:00.000Z | +| | pp | 1987-01-11T12:13:14.015Z | 12:13:14 PM | 1987-01-11T12:13:14.000Z | +| | | 1987-02-11T12:13:14.015Z | 12:13:14 PM | 1987-02-11T12:13:14.000Z | +| | | 1987-03-11T12:13:14.015Z | 12:13:14 PM | 1987-03-11T12:13:14.000Z | +| | | 1987-04-11T12:13:14.015Z | 12:13:14 PM | 1987-04-11T12:13:14.000Z | | | | 1453-05-29T23:59:59.999Z | 11:59:59 PM | 1453-05-29T23:59:59.000Z | -| | ppp | 1987-02-11T12:13:14.015Z | 12:13:14 PM GMT+0 | Errored | +| | | 1987-06-11T12:13:14.015Z | 12:13:14 PM | 1987-06-11T12:13:14.000Z | +| | | 1987-07-11T12:13:14.015Z | 12:13:14 PM | 1987-07-11T12:13:14.000Z | +| | | 1987-08-11T12:13:14.015Z | 12:13:14 PM | 1987-08-11T12:13:14.000Z | +| | | 1987-09-11T12:13:14.015Z | 12:13:14 PM | 1987-09-11T12:13:14.000Z | +| | | 1987-10-11T12:13:14.015Z | 12:13:14 PM | 1987-10-11T12:13:14.000Z | +| | | 1987-11-11T12:13:14.015Z | 12:13:14 PM | 1987-11-11T12:13:14.000Z | +| | | 1987-12-11T12:13:14.015Z | 12:13:14 PM | 1987-12-11T12:13:14.000Z | +| | ppp | 1987-01-11T12:13:14.015Z | 12:13:14 PM GMT+0 | Errored | +| | | 1987-02-11T12:13:14.015Z | 12:13:14 PM GMT+0 | Errored | +| | | 1987-03-11T12:13:14.015Z | 12:13:14 PM GMT+0 | Errored | +| | | 1987-04-11T12:13:14.015Z | 12:13:14 PM GMT+0 | Errored | | | | 1453-05-29T23:59:59.999Z | 11:59:59 PM GMT+0 | Errored | -| | pppp | 1987-02-11T12:13:14.015Z | 12:13:14 PM GMT+00:00 | Errored | +| | | 1987-06-11T12:13:14.015Z | 12:13:14 PM GMT+0 | Errored | +| | | 1987-07-11T12:13:14.015Z | 12:13:14 PM GMT+0 | Errored | +| | | 1987-08-11T12:13:14.015Z | 12:13:14 PM GMT+0 | Errored | +| | | 1987-09-11T12:13:14.015Z | 12:13:14 PM GMT+0 | Errored | +| | | 1987-10-11T12:13:14.015Z | 12:13:14 PM GMT+0 | Errored | +| | | 1987-11-11T12:13:14.015Z | 12:13:14 PM GMT+0 | Errored | +| | | 1987-12-11T12:13:14.015Z | 12:13:14 PM GMT+0 | Errored | +| | pppp | 1987-01-11T12:13:14.015Z | 12:13:14 PM GMT+00:00 | Errored | +| | | 1987-02-11T12:13:14.015Z | 12:13:14 PM GMT+00:00 | Errored | +| | | 1987-03-11T12:13:14.015Z | 12:13:14 PM GMT+00:00 | Errored | +| | | 1987-04-11T12:13:14.015Z | 12:13:14 PM GMT+00:00 | Errored | | | | 1453-05-29T23:59:59.999Z | 11:59:59 PM GMT+00:00 | Errored | -| Combination of date and time | Pp | 1987-02-11T12:13:14.015Z | 02/11/1987, 12:13 PM | 1987-02-11T12:13:00.000Z | +| | | 1987-06-11T12:13:14.015Z | 12:13:14 PM GMT+00:00 | Errored | +| | | 1987-07-11T12:13:14.015Z | 12:13:14 PM GMT+00:00 | Errored | +| | | 1987-08-11T12:13:14.015Z | 12:13:14 PM GMT+00:00 | Errored | +| | | 1987-09-11T12:13:14.015Z | 12:13:14 PM GMT+00:00 | Errored | +| | | 1987-10-11T12:13:14.015Z | 12:13:14 PM GMT+00:00 | Errored | +| | | 1987-11-11T12:13:14.015Z | 12:13:14 PM GMT+00:00 | Errored | +| | | 1987-12-11T12:13:14.015Z | 12:13:14 PM GMT+00:00 | Errored | +| Combination of date and time | Pp | 1987-01-11T12:13:14.015Z | 01/11/1987, 12:13 PM | 1987-01-11T12:13:00.000Z | +| | | 1987-02-11T12:13:14.015Z | 02/11/1987, 12:13 PM | 1987-02-11T12:13:00.000Z | +| | | 1987-03-11T12:13:14.015Z | 03/11/1987, 12:13 PM | 1987-03-11T12:13:00.000Z | +| | | 1987-04-11T12:13:14.015Z | 04/11/1987, 12:13 PM | 1987-04-11T12:13:00.000Z | | | | 1453-05-29T23:59:59.999Z | 05/29/1453, 11:59 PM | 1453-05-29T23:59:00.000Z | -| | PPpp | 1987-02-11T12:13:14.015Z | Feb 11, 1987, 12:13:14 PM | 1987-02-11T12:13:14.000Z | +| | | 1987-06-11T12:13:14.015Z | 06/11/1987, 12:13 PM | 1987-06-11T12:13:00.000Z | +| | | 1987-07-11T12:13:14.015Z | 07/11/1987, 12:13 PM | 1987-07-11T12:13:00.000Z | +| | | 1987-08-11T12:13:14.015Z | 08/11/1987, 12:13 PM | 1987-08-11T12:13:00.000Z | +| | | 1987-09-11T12:13:14.015Z | 09/11/1987, 12:13 PM | 1987-09-11T12:13:00.000Z | +| | | 1987-10-11T12:13:14.015Z | 10/11/1987, 12:13 PM | 1987-10-11T12:13:00.000Z | +| | | 1987-11-11T12:13:14.015Z | 11/11/1987, 12:13 PM | 1987-11-11T12:13:00.000Z | +| | | 1987-12-11T12:13:14.015Z | 12/11/1987, 12:13 PM | 1987-12-11T12:13:00.000Z | +| | PPpp | 1987-01-11T12:13:14.015Z | Jan 11, 1987, 12:13:14 PM | 1987-01-11T12:13:14.000Z | +| | | 1987-02-11T12:13:14.015Z | Feb 11, 1987, 12:13:14 PM | 1987-02-11T12:13:14.000Z | +| | | 1987-03-11T12:13:14.015Z | Mar 11, 1987, 12:13:14 PM | 1987-03-11T12:13:14.000Z | +| | | 1987-04-11T12:13:14.015Z | Apr 11, 1987, 12:13:14 PM | 1987-04-11T12:13:14.000Z | | | | 1453-05-29T23:59:59.999Z | May 29, 1453, 11:59:59 PM | 1453-05-29T23:59:59.000Z | -| | PPPppp | 1987-02-11T12:13:14.015Z | February 11th, 1987 at 12:13:14 PM GMT+0 | Errored | +| | | 1987-06-11T12:13:14.015Z | Jun 11, 1987, 12:13:14 PM | 1987-06-11T12:13:14.000Z | +| | | 1987-07-11T12:13:14.015Z | Jul 11, 1987, 12:13:14 PM | 1987-07-11T12:13:14.000Z | +| | | 1987-08-11T12:13:14.015Z | Aug 11, 1987, 12:13:14 PM | 1987-08-11T12:13:14.000Z | +| | | 1987-09-11T12:13:14.015Z | Sep 11, 1987, 12:13:14 PM | 1987-09-11T12:13:14.000Z | +| | | 1987-10-11T12:13:14.015Z | Oct 11, 1987, 12:13:14 PM | 1987-10-11T12:13:14.000Z | +| | | 1987-11-11T12:13:14.015Z | Nov 11, 1987, 12:13:14 PM | 1987-11-11T12:13:14.000Z | +| | | 1987-12-11T12:13:14.015Z | Dec 11, 1987, 12:13:14 PM | 1987-12-11T12:13:14.000Z | +| | PPPppp | 1987-01-11T12:13:14.015Z | January 11th, 1987 at 12:13:14 PM GMT+0 | Errored | +| | | 1987-02-11T12:13:14.015Z | February 11th, 1987 at 12:13:14 PM GMT+0 | Errored | +| | | 1987-03-11T12:13:14.015Z | March 11th, 1987 at 12:13:14 PM GMT+0 | Errored | +| | | 1987-04-11T12:13:14.015Z | April 11th, 1987 at 12:13:14 PM GMT+0 | Errored | | | | 1453-05-29T23:59:59.999Z | May 29th, 1453 at 11:59:59 PM GMT+0 | Errored | -| | PPPPpppp | 1987-02-11T12:13:14.015Z | Wednesday, February 11th, 1987 at 12:13:14 PM GMT+00:00 | Errored | +| | | 1987-06-11T12:13:14.015Z | June 11th, 1987 at 12:13:14 PM GMT+0 | Errored | +| | | 1987-07-11T12:13:14.015Z | July 11th, 1987 at 12:13:14 PM GMT+0 | Errored | +| | | 1987-08-11T12:13:14.015Z | August 11th, 1987 at 12:13:14 PM GMT+0 | Errored | +| | | 1987-09-11T12:13:14.015Z | September 11th, 1987 at 12:13:14 PM GMT+0 | Errored | +| | | 1987-10-11T12:13:14.015Z | October 11th, 1987 at 12:13:14 PM GMT+0 | Errored | +| | | 1987-11-11T12:13:14.015Z | November 11th, 1987 at 12:13:14 PM GMT+0 | Errored | +| | | 1987-12-11T12:13:14.015Z | December 11th, 1987 at 12:13:14 PM GMT+0 | Errored | +| | PPPPpppp | 1987-01-11T12:13:14.015Z | Sunday, January 11th, 1987 at 12:13:14 PM GMT+00:00 | Errored | +| | | 1987-02-11T12:13:14.015Z | Wednesday, February 11th, 1987 at 12:13:14 PM GMT+00:00 | Errored | +| | | 1987-03-11T12:13:14.015Z | Wednesday, March 11th, 1987 at 12:13:14 PM GMT+00:00 | Errored | +| | | 1987-04-11T12:13:14.015Z | Saturday, April 11th, 1987 at 12:13:14 PM GMT+00:00 | Errored | | | | 1453-05-29T23:59:59.999Z | Sunday, May 29th, 1453 at 11:59:59 PM GMT+00:00 | Errored | +| | | 1987-06-11T12:13:14.015Z | Thursday, June 11th, 1987 at 12:13:14 PM GMT+00:00 | Errored | +| | | 1987-07-11T12:13:14.015Z | Saturday, July 11th, 1987 at 12:13:14 PM GMT+00:00 | Errored | +| | | 1987-08-11T12:13:14.015Z | Tuesday, August 11th, 1987 at 12:13:14 PM GMT+00:00 | Errored | +| | | 1987-09-11T12:13:14.015Z | Friday, September 11th, 1987 at 12:13:14 PM GMT+00:00 | Errored | +| | | 1987-10-11T12:13:14.015Z | Sunday, October 11th, 1987 at 12:13:14 PM GMT+00:00 | Errored | +| | | 1987-11-11T12:13:14.015Z | Wednesday, November 11th, 1987 at 12:13:14 PM GMT+00:00 | Errored | +| | | 1987-12-11T12:13:14.015Z | Friday, December 11th, 1987 at 12:13:14 PM GMT+00:00 | Errored | ## `formatDistance` diff --git a/src/date-fns/locale/index.ts b/src/date-fns/locale/index.ts index 6bd9135..3b7f9ee 100644 --- a/src/date-fns/locale/index.ts +++ b/src/date-fns/locale/index.ts @@ -1,3 +1,4 @@ // This file is generated automatically by `scripts/build/indices.ts`. Please, don't change it. -export { default as enUS } from './en-US/index'; +export * from './en-US/index'; +export type * from './types'; diff --git a/src/date-fns/locale/types.ts b/src/date-fns/locale/types.ts index df7c858..294cd00 100644 --- a/src/date-fns/locale/types.ts +++ b/src/date-fns/locale/types.ts @@ -1,23 +1,89 @@ /* eslint-disable no-unused-vars */ -import type { Day, Era, FirstWeekContainsDate, Month, Quarter, Unit } from '../types'; -import type { BuildLocalizeFnArgCallback, LocalizeUnitValues, LocalizeUnitValuesIndex } from './_lib/buildLocalizeFn'; +import type { Day, Era, FirstWeekContainsDateOptions, LocalizedOptions, Month, Quarter, WeekOptions } from '../types'; +/** + * The locale object with all functions and data needed to parse and format + * dates. This is what each locale implements and exports. + */ export interface Locale { + /** The locale code (ISO 639-1 + optional country code) */ code: string; + /** The function to format distance */ formatDistance: FormatDistanceFn; + /** The function to relative time */ formatRelative: FormatRelativeFn; + /** The object with functions used to localize various values */ localize: Localize; + /** The object with functions that return localized formats */ formatLong: FormatLong; + /** The object with functions used to match and parse various localized values */ match: Match; + /** An object with locale options */ options?: LocaleOptions; } -export interface LocaleOptions { - weekStartsOn?: Day; - firstWeekContainsDate?: FirstWeekContainsDate; +/** + * The locale options. + */ +export interface LocaleOptions extends WeekOptions, FirstWeekContainsDateOptions {} + +/// Format distance types + +/** + * The function that takes a token (i.e. halfAMinute) passed by `formatDistance` + * or `formatDistanceStrict` and payload, and returns localized distance. + * + * @param token - The token to localize + * @param count - The distance number + * @param options - The object with options + * + * @returns The localized distance in words + */ +export type FormatDistanceFn = (token: FormatDistanceToken, count: number, options?: FormatDistanceFnOptions) => string; + +/** + * The {@link FormatDistanceFn} function options. + */ +export interface FormatDistanceFnOptions { + /** Add "X ago"/"in X" in the locale language */ + addSuffix?: boolean; + /** The distance vector. -1 represents past and 1 future. Tells which suffix + * to use. */ + comparison?: -1 | 0 | 1; } +/** + * The function used inside the {@link FormatDistanceFn} function, implementing + * formatting for a particular token. + */ +export type FormatDistanceTokenFn = ( + /** The distance as number to format */ + count: number, + /** The object with options */ + options?: FormatDistanceFnOptions, +) => string; + +/** + * The tokens map to string templates used in the format distance function. + * It looks like this: + * + * const formatDistanceLocale: FormatDistanceLocale = { + * lessThanXSeconds: 'តិចជាង {{count}} វិនាទី', + * xSeconds: '{{count}} វិនាទី', + * // ... + * } + * + * @typeParam Template - The property value type. + */ +export type FormatDistanceLocale