├── .eslintignore
├── .eslintrc.js
├── .github
├── ISSUE_TEMPLATE
│ ├── bug_report.md
│ └── feature_request.md
└── workflows
│ └── ci.yml
├── .gitignore
├── .idea
├── .gitignore
├── codeStyles
│ ├── Project.xml
│ └── codeStyleConfig.xml
├── easy-dates.iml
├── modules.xml
└── vcs.xml
├── .npmignore
├── .prettierignore
├── .prettierrc.json
├── LICENSE.md
├── README.md
├── docs
├── .gitignore
├── .prettierignore
├── README.md
├── babel.config.js
├── docs
│ ├── contributing
│ │ ├── _category_.json
│ │ ├── code-of-conduct.md
│ │ └── index.md
│ ├── functions
│ │ ├── _category_.json
│ │ ├── areIntervalsOverlapping.md
│ │ ├── closestTo.md
│ │ ├── dateNow.md
│ │ ├── dateNowISO.md
│ │ ├── dateNowUnix.md
│ │ ├── dateToMilliseconds.md
│ │ ├── dateToUnix.md
│ │ ├── daysFromNow.md
│ │ ├── daysToWeeks.md
│ │ ├── findEarliest.md
│ │ ├── findLatest.md
│ │ ├── getDaysInMonth.md
│ │ ├── getDuration.md
│ │ ├── getMonthIndex.md
│ │ ├── getMonthName.md
│ │ ├── getOverlappingDaysInIntervals.md
│ │ ├── getTodayName.md
│ │ ├── getTomorrow.md
│ │ ├── getYear.md
│ │ ├── hoursToMilliseconds.md
│ │ ├── hoursToMinutes.md
│ │ ├── index.md
│ │ ├── isAfter.md
│ │ ├── isBefore.md
│ │ ├── isDate.md
│ │ ├── isEqual.md
│ │ ├── isInFuture.md
│ │ ├── isInPast.md
│ │ ├── millisecondsToHours.md
│ │ ├── millisecondsToMinutes.md
│ │ ├── millisecondsToSeconds.md
│ │ ├── minutesToHours.md
│ │ ├── minutesToMilliseconds.md
│ │ ├── minutesToSeconds.md
│ │ ├── monthsToQuarters.md
│ │ ├── monthsToYears.md
│ │ ├── quartersToMonths.md
│ │ ├── quartersToYears.md
│ │ ├── secondsToHours.md
│ │ ├── secondsToMilliseconds.md
│ │ ├── secondsToMinutes.md
│ │ ├── unixToDate.md
│ │ ├── unixToDuration.md
│ │ ├── weeksToDays.md
│ │ ├── yearsToDays.md
│ │ ├── yearsToMonths.md
│ │ └── yearsToQuarters.md
│ ├── intro.md
│ └── introduction
│ │ ├── _category_.json
│ │ ├── faq.md
│ │ ├── index.md
│ │ ├── installation.md
│ │ ├── playground.md
│ │ └── usage.md
├── docusaurus.config.js
├── package-lock.json
├── package.json
├── sidebars.js
├── src
│ ├── components
│ │ ├── CallToAction
│ │ │ ├── CallToAction.jsx
│ │ │ └── CallToAction.module.css
│ │ ├── HomepageFeatures
│ │ │ ├── HomepageFeatures.jsx
│ │ │ └── HomepageFeatures.module.css
│ │ └── HomepageHero
│ │ │ ├── HomepageHero.jsx
│ │ │ └── HomepageHero.module.css
│ ├── css
│ │ └── custom.css
│ ├── pages
│ │ ├── index.js
│ │ └── index.module.css
│ └── theme
│ │ └── ReactLiveScope
│ │ └── index.js
└── static
│ ├── .nojekyll
│ └── img
│ ├── calendar-dark.svg
│ ├── calendar.png
│ ├── calendar.svg
│ ├── favicon.ico
│ ├── github.svg
│ └── tutorial
│ ├── docsVersionDropdown.png
│ └── localeDropdown.png
├── esbuild.js
├── package-lock.json
├── package.json
├── scripts
└── createNewFunctionFiles.js
└── src
├── areIntervalsOverlapping
├── areIntervalsOverlapping.js
└── areIntervalsOverlapping.test.js
├── closestTo
├── closestTo.js
└── closestTo.test.js
├── dateNow
├── dateNow.js
└── dateNow.test.js
├── dateNowIso
├── dateNowISO.js
└── dateNowIso.test.js
├── dateNowUnix
├── dateNowUnix.js
└── dateNowUnix.test.js
├── dateToMilliseconds
├── dateToMilliseconds.js
└── dateToMilliseconds.test.js
├── dateToUnix
├── dateToUnix.js
└── dateToUnix.test.js
├── daysFromNow
├── daysFromNow.js
└── daysFromNow.test.js
├── daysToWeeks
├── daysToWeeks.js
└── daysToWeeks.test.js
├── findEarliest
├── findEarliest.js
└── findEarliest.test.js
├── findLatest
├── findLatest.js
└── findLatest.test.js
├── getDaysInMonth
├── getDaysInMonth.js
└── getDaysInMonth.test.js
├── getDuration
├── getDuration.js
└── getDuration.test.js
├── getMonthIndex
├── getMonthIndex.js
└── getMonthIndex.test.js
├── getMonthName
├── getMonthName.js
└── getMonthName.test.js
├── getOverlappingDaysInIntervals
├── getOverlappingDaysInIntervals.js
└── getOverlappingDaysInIntervals.test.js
├── getTodayName
├── getTodayName.js
└── getTodayName.test.js
├── getTomorrow
├── getTomorrow.js
└── getTomorrow.test.js
├── getYear
├── getYear.js
└── getYear.test.js
├── hoursToMilliseconds
├── hoursToMilliseconds.js
└── hoursToMilliseconds.test.js
├── hoursToMinutes
├── hoursToMinutes.js
└── hoursToMinutes.test.js
├── index.js
├── isAfter
├── isAfter.js
└── isAfter.test.js
├── isBefore
├── isBefore.js
└── isBefore.test.js
├── isDate
├── isDate.js
└── isDate.test.js
├── isEqual
├── isEqual.js
└── isEqual.test.js
├── isInFuture
├── isInFuture.js
└── isInFuture.test.js
├── isInPast
├── isInPast.js
└── isInPast.test.js
├── millisecondsToHours
├── millisecondsToHours.js
└── millisecondsToHours.test.js
├── millisecondsToMinutes
├── millisecondsToMinutes.js
└── millisecondsToMinutes.test.js
├── millisecondsToSeconds
├── millisecondsToSeconds.js
└── millisecondsToSeconds.test.js
├── minutesToHours
├── minutesToHours.js
└── minutesToHours.test.js
├── minutesToMilliseconds
├── minutesToMilliseconds.js
└── minutesToMilliseconds.test.js
├── minutesToSeconds
├── minutesToSeconds.js
└── minutesToSeconds.test.js
├── monthsToQuarters
├── monthsToQuarters.js
└── monthsToQuarters.test.js
├── monthsToYears
├── monthsToYears.js
└── monthsToYears.test.js
├── quartersToMonths
├── quartersToMonths.js
└── quartersToMonths.test.js
├── quartersToYears
├── quartersToYears.js
└── quartersToYears.test.js
├── secondsToHours
├── secondsToHours.js
└── secondsToHours.test.js
├── secondsToMilliseconds
├── secondsToMilliseconds.js
└── secondsToMilliseconds.test.js
├── secondsToMinutes
├── secondsToMinutes.js
└── secondsToMinutes.test.js
├── unixToDate
├── unixToDate.js
└── unixToDate.test.js
├── unixToDuration
├── unixToDuration.js
└── unixToDuration.test.js
├── weeksToDays
├── weeksToDays.js
└── weeksToDays.test.js
├── yearsToDays
├── yearsToDays.js
└── yearsToDays.test.js
├── yearsToMonths
├── yearsToMonths.js
└── yearsToMonths.test.js
└── yearsToQuarters
├── yearsToQuarters.js
└── yearsToQuarters.test.js
/.eslintignore:
--------------------------------------------------------------------------------
1 | src/*/*.test.js
--------------------------------------------------------------------------------
/.eslintrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | "env": {
3 | "browser": true,
4 | "es2021": true
5 | },
6 | "extends": [
7 | "eslint:recommended",
8 | "prettier"
9 | ],
10 | "parserOptions": {
11 | "ecmaVersion": "latest",
12 | "sourceType": "module"
13 | },
14 | "rules": {
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Create a report to help us improve
4 | title: ''
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Describe the bug**
11 | A clear and concise description of what the bug is.
12 |
13 | **To Reproduce**
14 | Steps to reproduce the behavior:
15 | 1. Go to '...'
16 | 2. Click on '....'
17 | 3. Scroll down to '....'
18 | 4. See error
19 |
20 | **Expected behavior**
21 | A clear and concise description of what you expected to happen.
22 |
23 | **Screenshots**
24 | If applicable, add screenshots to help explain your problem.
25 |
26 | **Desktop (please complete the following information):**
27 | - OS: [e.g. iOS]
28 | - Browser [e.g. chrome, safari]
29 | - Version [e.g. 22]
30 |
31 | **Smartphone (please complete the following information):**
32 | - Device: [e.g. iPhone6]
33 | - OS: [e.g. iOS8.1]
34 | - Browser [e.g. stock browser, safari]
35 | - Version [e.g. 22]
36 |
37 | **Additional context**
38 | Add any other context about the problem here.
39 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature_request.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Feature request
3 | about: Suggest an idea for this project
4 | title: ''
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Is your feature request related to a problem? Please describe.**
11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12 |
13 | **Describe the solution you'd like**
14 | A clear and concise description of what you want to happen.
15 |
16 | **Describe alternatives you've considered**
17 | A clear and concise description of any alternative solutions or features you've considered.
18 |
19 | **Additional context**
20 | Add any other context or screenshots about the feature request here.
21 |
--------------------------------------------------------------------------------
/.github/workflows/ci.yml:
--------------------------------------------------------------------------------
1 | name: CI and Conditional Publish
2 |
3 | on:
4 | push:
5 | branches:
6 | - '**'
7 | pull_request:
8 |
9 | jobs:
10 | build-and-test:
11 | runs-on: ubuntu-latest
12 | strategy:
13 | matrix:
14 | node-version: [16.x]
15 | steps:
16 | - uses: actions/checkout@v2
17 | - name: Use Node.js ${{ matrix.node-version }}
18 | uses: actions/setup-node@v2
19 | with:
20 | node-version: ${{ matrix.node-version }}
21 | - run: npm ci
22 | - run: npm run test
23 |
24 | publish:
25 | needs: build-and-test
26 | runs-on: ubuntu-latest
27 | if: github.ref == 'refs/heads/main' && github.event_name == 'push'
28 | steps:
29 | - uses: actions/checkout@v2
30 | - name: Set up Node.js
31 | uses: actions/setup-node@v2
32 | with:
33 | node-version: '16'
34 | registry-url: 'https://registry.npmjs.org/'
35 | - name: Check if version changed
36 | id: check_version
37 | run: |
38 | PACKAGE_VERSION=$(node -p "require('./package.json').version")
39 | NPM_VERSION=$(npm view easy-dates version || echo '0.0.0')
40 | if [ "$PACKAGE_VERSION" != "$NPM_VERSION" ]; then
41 | echo "VERSION_CHANGED=true" >> $GITHUB_ENV
42 | fi
43 | - name: Install dependencies
44 | if: env.VERSION_CHANGED == 'true'
45 | run: npm ci
46 | - name: Publish to npm
47 | if: env.VERSION_CHANGED == 'true'
48 | run: npm publish
49 | env:
50 | NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
51 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | node_modules
3 | dist
4 | coverage
--------------------------------------------------------------------------------
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 | # Editor-based HTTP Client requests
5 | /httpRequests/
6 | # Datasource local storage ignored files
7 | /dataSources/
8 | /dataSources.local.xml
9 | # GitHub Copilot persisted chat sessions
10 | /copilot/chatSessions
11 |
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
--------------------------------------------------------------------------------
/.idea/codeStyles/codeStyleConfig.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/.idea/easy-dates.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | esbuild.js
2 | src/*/*.test.js
3 | coverage/
4 | .idea/
5 | node_modules/
6 | src/
7 | .eslintignore
8 | .eslintrc.js
9 | .prettierignore
10 | .prettierrc.json
11 | docs
12 | scripts
13 | .github/
--------------------------------------------------------------------------------
/.prettierignore:
--------------------------------------------------------------------------------
1 | build
2 | coverage
3 | dist
--------------------------------------------------------------------------------
/.prettierrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "trailingComma": "es5",
3 | "tabWidth": 2,
4 | "semi": true,
5 | "singleQuote": false
6 | }
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2022 sandypockets Zac A.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Easy Dates
2 | Easy dates is a lightweight, zero-dependency library for getting simple date information, easily.
3 |
4 | [](LICENSE.md)
5 | [](https://www.npmjs.com/package/easy-dates)
6 | [](https://www.npmjs.com/package/easy-dates)
7 | 
8 | [](https://packagephobia.com/result?p=easy-dates)
9 | [](https://www.buymeacoffee.com/sandypockets)
10 |
11 | ### Read the docs at [easy-dates.dev](https://easy-dates.dev)
12 |
13 | `easy-dates` was developed to solve a problem. Working with dates in JavaScript is a pain, and most libraries for working with them are massive, some even cresting 6mb. In most cases, that adds more to the bundle than can be justified. To fix it, `easy-dates` offers much of the same functionality as those other libraries, with a considerably smaller footprint.
14 |
15 | Check out the full list of what `easy-dates` can do in the [documentation](https://easy-dates.dev), and feel free to submit an issue if there is a particular function you'd like to see get added.
16 |
17 | > _New!_\
18 | > Looking for a Date Picker? Check out [easy-dates-picker](https://github.com/sandypockets/easy-dates-picker).
19 |
20 | ## Demo
21 | Check out a live demo of the latest `easy-dates` version on StackBlitz.
22 |
23 | [](https://stackblitz.com/edit/easy-dates-demo?file=src/App.js)
24 |
25 | ## Installation
26 | `easy-dates` can be installed with `yarn` or `npm`
27 | ```shell
28 | # with yarn
29 | yarn add easy-dates
30 | ```
31 |
32 | ```shell
33 | # with npm
34 | npm install easy-dates
35 | ```
36 |
37 | Or if you're working with a static HTML document, you can import it in script tags using a CDN.
38 |
39 | ### jsDeliver
40 | ```html
41 |
42 | ```
43 |
44 | ### UNPKG
45 | ```html
46 |
47 | ```
48 |
49 | ## Usage
50 | Check the docs at [easy-dates.dev](https://easy-dates.dev/docs/functions/) for the full list of functions and their specific usage.
51 |
52 | ```javascript
53 | import { dateNow } from 'easy-dates';
54 |
55 | dateNow('en-CA') // 2022-03-17, 11:50:09 p.m.
56 | ```
57 |
58 |
59 | ## Available functions
60 | Click on a function name below to view specific documentation for that function.
61 |
62 | - [`areIntervalsOverlapping()`](https://easy-dates.dev/docs/functions/areIntervalsOverlapping/)
63 | - [`closestTo()`](https://easy-dates.dev/docs/functions/closestTo)
64 | - [`dateNow()`](https://easy-dates.dev/docs/functions/dateNow)
65 | - [`dateNowISO()`](https://easy-dates.dev/docs/functions/dateNowISO)
66 | - [`dateNowUnix()`](https://easy-dates.dev/docs/functions/dateNowUnix)
67 | - [`dateToMilliseconds()`](https://easy-dates.dev/docs/functions/dateToMilliseconds)
68 | - [`dateToUnix()`](https://easy-dates.dev/docs/functions/dateToUnix)
69 | - [`daysFromNow()`](https://easy-dates.dev/docs/functions/daysFromNow)
70 | - [`daysToWeeks()`](https://easy-dates.dev/docs/functions/daysToWeeks)
71 | - [`findEarliest()`](https://easy-dates.dev/docs/functions/findEarliest)
72 | - [`findLatest()`](https://easy-dates.dev/docs/functions/findLatest)
73 | - [`getDaysInMonth()`](https://easy-dates.dev/docs/functions/getDaysInMonth)
74 | - [`getDuration()`](https://easy-dates.dev/docs/functions/getDuration)
75 | - [`getMonthIndex()`](https://easy-dates.dev/docs/functions/getMonthIndex)
76 | - [`getMonthName()`](https://easy-dates.dev/docs/functions/getMonthName)
77 | - [`getOverlappingDaysInIntervals()`](https://easy-dates.dev/docs/functions/getOverlappingDaysInIntervals)
78 | - [`getTodayName()`](https://easy-dates.dev/docs/functions/getTodayName)
79 | - [`getTomorrow()`](https://easy-dates.dev/docs/functions/getTomorrow)
80 | - [`getYear()`](https://easy-dates.dev/docs/functions/getYear)
81 | - [`hoursToMilliseconds()`](https://easy-dates.dev/docs/functions/hoursToMilliseconds)
82 | - [`hoursToMinutes()`](https://easy-dates.dev/docs/functions/hoursToMinutes)
83 | - [`isAfter()`](https://easy-dates.dev/docs/functions/isAfter)
84 | - [`isBefore()`](https://easy-dates.dev/docs/functions/isBefore)
85 | - [`isDate()`](https://easy-dates.dev/docs/functions/isDate)
86 | - [`isEqual()`](https://easy-dates.dev/docs/functions/isEqual)
87 | - [`isInFuture()`](https://easy-dates.dev/docs/functions/isInFuture)
88 | - [`isInPast()`](https://easy-dates.dev/docs/functions/isInPast)
89 | - [`millisecondsToSeconds()`](https://easy-dates.dev/docs/functions/millisecondsToSeconds)
90 | - [`millisecondsToMinutes()`](https://easy-dates.dev/docs/functions/millisecondsToMinutes)
91 | - [`MillisecondsToHours()`](https://easy-dates.dev/docs/functions/MillisecondsToHours)
92 | - [`minutesToSeconds()`](https://easy-dates.dev/docs/functions/minutesToSeconds)
93 | - [`minutesToHours()`](https://easy-dates.dev/docs/functions/minutesToHours)
94 | - [`minutesToMilliseconds()`](https://easy-dates.dev/docs/functions/minutesToMilliseconds)
95 | - [`monthsToQuarters()`](https://easy-dates.dev/docs/functions/monthsToQuarters)
96 | - [`monthsToYears()`](https://easy-dates.dev/docs/functions/monthsToYears)
97 | - [`quartersToYears()`](https://easy-dates.dev/docs/functions/quartersToYears)
98 | - [`quartersToMonths()`](https://easy-dates.dev/docs/functions/quartersToMonths)
99 | - [`secondsToMilliseconds()`](https://easy-dates.dev/docs/functions/secondsToMilliseconds)
100 | - [`secondsToMinutes()`](https://easy-dates.dev/docs/functions/secondsToMinutes)
101 | - [`secondsToHours()`](https://easy-dates.dev/docs/functions/secondsToHours)
102 | - [`unixToDate()`](https://easy-dates.dev/docs/functions/unixToDate)
103 | - [`unixToDuration()`](https://easy-dates.dev/docs/functions/unixToDuration)
104 | - [`weeksToDays()`](https://easy-dates.dev/docs/functions/weeksToDays)
105 | - [`yearsToDays()`](https://easy-dates.dev/docs/functions/yearsToDays)
106 | - [`yearsToMonths()`](https://easy-dates.dev/docs/functions/yearsToMonths)
107 | - [`yearsToQuarters()`](https://easy-dates.dev/docs/functions/yearsToQuarters)
108 |
109 |
110 | ### For more information about `easy-dates`, refer to the documentation website at [easy-dates.dev](https://easy-dates.dev)
111 |
--------------------------------------------------------------------------------
/docs/.gitignore:
--------------------------------------------------------------------------------
1 | # Dependencies
2 | /node_modules
3 |
4 | # Production
5 | /build
6 |
7 | # Generated files
8 | .docusaurus
9 | .cache-loader
10 |
11 | # Misc
12 | .DS_Store
13 | .env.local
14 | .env.development.local
15 | .env.test.local
16 | .env.production.local
17 |
18 | npm-debug.log*
19 | yarn-debug.log*
20 | yarn-error.log*
21 |
22 | blog
--------------------------------------------------------------------------------
/docs/.prettierignore:
--------------------------------------------------------------------------------
1 | .docusaurus
2 | docs
3 | node_modules
4 | static
5 | src/theme
6 |
--------------------------------------------------------------------------------
/docs/README.md:
--------------------------------------------------------------------------------
1 | # Website
2 |
3 | This website is built using [Docusaurus 2](https://docusaurus.io/), a modern static website generator.
4 |
5 | ### Installation
6 |
7 | ```
8 | $ yarn
9 | ```
10 |
11 | ### Local Development
12 |
13 | ```
14 | $ yarn start
15 | ```
16 |
17 | This command starts a local development server and opens up a browser window. Most changes are reflected live without having to restart the server.
18 |
19 | ### Build
20 |
21 | ```
22 | $ yarn build
23 | ```
24 |
25 | This command generates static content into the `build` directory and can be served using any static contents hosting service.
26 |
27 | ### Deployment
28 |
29 | Using SSH:
30 |
31 | ```
32 | $ USE_SSH=true yarn deploy
33 | ```
34 |
35 | Not using SSH:
36 |
37 | ```
38 | $ GIT_USER= yarn deploy
39 | ```
40 |
41 | If you are using GitHub pages for hosting, this command is a convenient way to build the website and push to the `gh-pages` branch.
42 |
--------------------------------------------------------------------------------
/docs/babel.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | presets: [require.resolve('@docusaurus/core/lib/babel/preset')],
3 | };
4 |
--------------------------------------------------------------------------------
/docs/docs/contributing/_category_.json:
--------------------------------------------------------------------------------
1 | {
2 | "label": "Contributing",
3 | "position": 4
4 | }
--------------------------------------------------------------------------------
/docs/docs/contributing/code-of-conduct.md:
--------------------------------------------------------------------------------
1 | # Code of Conduct
2 |
3 | ## Our Pledge
4 |
5 | In the interest of fostering an open and welcoming environment, we as
6 | contributors and maintainers pledge to making participation in our project and
7 | our community a harassment-free experience for everyone, regardless of age, body
8 | size, disability, ethnicity, gender identity and expression, level of experience,
9 | education, socio-economic status, nationality, personal appearance, race,
10 | religion, or sexual identity and orientation.
11 |
12 | ## Our Standards
13 |
14 | Examples of behavior that contributes to creating a positive environment
15 | include:
16 |
17 | * Using welcoming and inclusive language
18 | * Being respectful of differing viewpoints and experiences
19 | * Gracefully accepting constructive criticism
20 | * Focusing on what is best for the community
21 | * Showing empathy towards other community members
22 |
23 | Examples of unacceptable behavior by participants include:
24 |
25 | * The use of sexualized language or imagery and unwelcome sexual attention or
26 | advances
27 | * Trolling, insulting/derogatory comments, and personal or political attacks
28 | * Public or private harassment
29 | * Publishing others' private information, such as a physical or electronic
30 | address, without explicit permission
31 | * Other conduct which could reasonably be considered inappropriate in a
32 | professional setting
33 |
34 | ## Our Responsibilities
35 |
36 | Project maintainers are responsible for clarifying the standards of acceptable
37 | behavior and are expected to take appropriate and fair corrective action in
38 | response to any instances of unacceptable behavior.
39 |
40 | Project maintainers have the right and responsibility to remove, edit, or
41 | reject comments, commits, code, wiki edits, issues, and other contributions
42 | that are not aligned to this Code of Conduct, or to ban temporarily or
43 | permanently any contributor for other behaviors that they deem inappropriate,
44 | threatening, offensive, or harmful.
45 |
46 | ## Scope
47 |
48 | This Code of Conduct applies both within project spaces and in public spaces
49 | when an individual is representing the project or its community. Examples of
50 | representing a project or community include using an official project e-mail
51 | address, posting via an official social media account, or acting as an appointed
52 | representative at an online or offline event. Representation of a project may be
53 | further defined and clarified by project maintainers.
54 |
55 | ## Enforcement
56 |
57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be
58 | reported by contacting the project team at hello@sandypockets.dev. All
59 | complaints will be reviewed and investigated and will result in a response that
60 | is deemed necessary and appropriate to the circumstances. The project team is
61 | obligated to maintain confidentiality with regard to the reporter of an incident.
62 | Further details of specific enforcement policies may be posted separately.
63 |
64 | Project maintainers who do not follow or enforce the Code of Conduct in good
65 | faith may face temporary or permanent repercussions as determined by other
66 | members of the project's leadership.
67 |
68 | ## Attribution
69 |
70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72 |
73 | [homepage]: https://www.contributor-covenant.org
74 |
--------------------------------------------------------------------------------
/docs/docs/contributing/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | sidebar_position: 6
3 | sidebar_label: "Contributing"
4 | ---
5 |
6 | # Contributing to `easy-dates`
7 |
8 | First off, thanks for taking the time to contribute! :tada:
9 |
10 | The following is a set of guidelines for contributing to `easy-dates`. These are mostly guidelines, not rules. Use your best judgment, and feel free to propose changes to this document in a pull request.
11 |
12 | ## Code of Conduct
13 |
14 | This project and everyone participating in it is governed by the [Code of Conduct](code-of-conduct). By participating, you are expected to uphold this code. Please report unacceptable behavior to [hello@sandypockets.dev](mailto:hello@sandypockets.dev).
15 |
16 | ## How Can I Contribute?
17 |
18 | ### Reporting Bugs
19 |
20 | This section guides you through submitting a bug report. Following these guidelines helps maintainers and the community understand your report, reproduce the behavior, and find related reports.
21 |
22 | Before creating bug reports, please check [this list](#before-submitting-a-bug-report) as you might find out that you don't need to create one.
23 |
24 | When you are creating a bug report, please [include as many details as possible](#how-do-i-submit-a-good-bug-report). Fill out the required template, the information it asks for helps resolve issues faster.
25 |
26 | > **Note:** If you find a **Closed** issue that seems like it is the same thing that you're experiencing, open a new issue and include a link to the original issue in the body of your new one.
27 |
28 | #### Before Submitting A Bug Report
29 |
30 | * Check if you can reproduce the problem in the latest version of `easy-dates`. The current version is [](https://www.npmjs.com/package/easy-dates)
31 | * Check the existing open and closed issues, to be sure that the issue has not already been triaged or resolved.
32 |
33 | #### How Do I Submit A (Good) Bug Report?
34 |
35 | Bugs are tracked as [GitHub issues](https://guides.github.com/features/issues/). Create an issue, and provide the following information by filling in the questions in the issue template.
36 |
37 | * **Use a clear and descriptive title** for the issue to identify the problem.
38 | * **Describe the exact steps which reproduce the problem** in as many details as possible.
39 | * **Provide specific examples to demonstrate the steps**. Include links to files or GitHub projects, or copy/pasteable snippets, (or examples in StackBlitz or CodeSandbox), which you use in those examples. If you're providing snippets in the issue, use [Markdown code blocks](https://help.github.com/articles/markdown-basics/#multiple-lines).
40 | * **Describe the behavior you observed after following the steps** and point out what exactly is the problem with that behavior.
41 | * **Explain which behavior you expected to see instead and why.**
42 | * **Include screenshots and animated GIFs** which show you following the described steps and clearly demonstrate the problem.
43 |
44 | ### Suggesting Enhancements
45 | When you are creating an enhancement suggestion, please include as many details as possible, including the steps that you imagine you would take if the feature you're requesting existed.
46 |
47 | #### Before Submitting An Enhancement Suggestion
48 |
49 | * **Perform a cursory search** to see if the enhancement has already been suggested. If it has, add a comment to the existing issue instead of opening a new one. Enhancement suggestions are tracked as [GitHub issues](https://guides.github.com/features/issues/). Create an issue in the repository and provide the following information:
50 | * **Use a clear and descriptive title** for the issue to identify the suggestion.
51 | * **Provide a step-by-step description of the suggested enhancement** in as many details as possible.
52 | * **Provide specific examples to demonstrate the steps**. Include copy/pasteable snippets which you use in those examples, as [Markdown code blocks](https://help.github.com/articles/markdown-basics/#multiple-lines).
53 | * **Describe the current behavior** and **explain which behavior you expected to see instead** and why.
54 |
55 | ### Pull Requests
56 |
57 | The maintainers must be satisfied prior to having your pull request reviewed, and the reviewer(s) may ask you to complete additional design work, tests, or other changes before your pull request can be ultimately accepted.
58 |
59 | ## Styleguides
60 |
61 | ### Git Commit Messages
62 |
63 | * Use the present tense ("Add feature" not "Added feature")
64 | * Use the imperative mood ("Move cursor to..." not "Moves cursor to...")
65 | * Limit the first line to 72 characters or less
66 |
67 | ### JavaScript Styleguide
68 |
69 | All JavaScript code is linted with [Prettier](https://prettier.io/).
70 |
71 | * Prefer the object spread operator (`{...anotherObj}`) to `Object.assign()`
72 | * Inline `export`s with expressions whenever possible
73 |
74 | ## Automating the development process
75 | If you're writing new functions for the library, then you can use a the `createNewFunctionFiles` script to generate a new function file and test file. To run the script, run the following command, replacing `myNewFunctionName` with the actual name of the function you're creating:
76 |
77 | ```shell
78 | yarn new myNewFunctionName
79 | ```
80 |
81 | This will generate a new directory with a new function file and test file.
82 |
83 | ```shell
84 | src/myNewFunctionName/myNewFunctionName.js
85 | src/myNewFunctionName/myNewFunctionName.test.js
86 | ```
87 |
88 | It will also generate an export statement in the `src/index.js` file, and create a new documentation entry in the `docs/myNewFunctionName.md` file.
89 |
90 | ### Testing your new function
91 | When your function code and tests are written, run `yarn test`. This will lint your code, run the build script, then run your tests. If you have any errors, you can fix them and re-run the tests by once again running `yarn test`. Once all test are passing, submit your pull request.
--------------------------------------------------------------------------------
/docs/docs/functions/_category_.json:
--------------------------------------------------------------------------------
1 | {
2 | "label": "Functions",
3 | "position": 2
4 | }
--------------------------------------------------------------------------------
/docs/docs/functions/areIntervalsOverlapping.md:
--------------------------------------------------------------------------------
1 | ---
2 | sidebar_label: areIntervalsOverlapping()
3 | ---
4 |
5 | # `areIntervalsOverlapping()`
6 | Returns a boolean representing whether two date ranges have any overlap.
7 |
8 | ## Usage
9 | ```javascript
10 | import { areIntervalsOverlapping } from 'easy-dates';
11 |
12 | areIntervalsOverlapping(rangeOne, rangeTwo);
13 | ```
14 |
15 | ## Prop types
16 | The function accepts two arrays. Each array should contain two dates, forming a range.
17 |
18 |
19 | | prop | type | required | default |
20 | |------------|---------|----------|-----------|
21 | | `rangeOne` | `Array` | yes | `null` |
22 | | `rangeTwo` | `Array` | yes | `null` |
23 |
24 | :::info
25 | _Within_ each array (i.e. `rangeOne`), the first date must be before the second date.
26 |
27 | #### Example
28 | ```javascript
29 | const today = new Date(Date.now());
30 | const tomorrow = new Date(Date.now() + oneDay);
31 |
32 | // The earlier date must be first
33 | const rangeOne = [today, tomorrow]; // Do this
34 | const rangeTwo = [tomorrow, today]; // Don't do this
35 |
36 | // If the arrays above are in the correct order, then the order of arguments doesn't matter
37 | areIntervalsOverlapping(rangeOne, rangeTwo) // Do this
38 | areIntervalsOverlapping(rangeTwo, rangeOne) // or do this
39 | ```
40 | :::
41 |
42 | ## Examples
43 | ```javascript
44 | const oneDay = 24 * 60 * 60 * 1000;
45 | const today = new Date(Date.now());
46 | const tomorrow = new Date(Date.now() + oneDay);
47 | const nextWeek = new Date(Date.now() + oneDay * 7);
48 |
49 | const rangeOne = [today, nextWeek];
50 | const rangeTwo = [tomorrow, nextWeek];
51 |
52 | areIntervalsOverlapping(rangeOne, rangeTwo) // true
53 | ```
54 |
55 | ```javascript
56 | const oneDay = 24 * 60 * 60 * 1000;
57 | const today = new Date(Date.now());
58 | const nextWeek = new Date(Date.now() + oneDay * 7);
59 |
60 | const rangeOne = [today, nextWeek];
61 |
62 | const twoWeeks = new Date(Date.now() + oneDay * 14);
63 | const threeWeeks = new Date(Date.now() + oneDay * 21);
64 |
65 | const rangeThree = [twoWeeks, threeWeeks]
66 |
67 | areIntervalsOverlapping(rangeOne, rangeThree) // false
68 | ```
--------------------------------------------------------------------------------
/docs/docs/functions/closestTo.md:
--------------------------------------------------------------------------------
1 | ---
2 | sidebar_label: "closestTo()"
3 | ---
4 |
5 | # `closestTo()`
6 | Given an array of dates, `closestTo()` returns an object containing data of the `compareDate` closest to the `controlDate`.
7 |
8 | ## Usage
9 | ```javascript
10 | import { closestTo } from 'easy-dates';
11 |
12 | closestTo(controlDate, compareDate)
13 | ```
14 |
15 | The expected output is an `object` with the following properties:
16 |
17 | - **`difference`**: the time in _milliseconds_ between the `controlDate` and the date closest in time from the `compareDate` argument.
18 | - **`closest`**: the date object of the closest date from the `compareDate`.
19 | - **`closestIndex`**: the index of the closest date in the `compareDate` array.
20 |
21 | ## Prop types
22 |
23 | | prop | type | required | default |
24 | |---------------|---------|----------|---------|
25 | | `controlDate` | `date` | yes | `null` |
26 | | `compareDate` | `array` | yes | `null` |
27 |
28 | ## Examples
29 | ```javascript title='Compare multiple dates'
30 | const twentyFourHours = 86400000;
31 | const today = new Date(Date.now());
32 | const tomorrow = new Date(Date.now() + twentyFourHours);
33 | const dayAfterTomorrow = new Date(Date.now() + twentyFourHours * 2);
34 | const weekAfterTomorrow = new Date(Date.now() + twentyFourHours * 7);
35 |
36 | const argumentsArray = [tomorrow, dayAfterTomorrow, weekAfterTomorrow];
37 |
38 | closestTo(today, argumentsArray) // { difference: 85400000, closest: Sat Mar 19 2022 20:26:34 GMT-0400 (Eastern Daylight Time), closestIndex: 0 }
39 | ```
40 |
41 | ```javascript title='Compare a single date'
42 | const twentyFourHours = 86400000;
43 |
44 | const today = new Date(Date.now());
45 | const tomorrow = new Date(Date.now() + twentyFourHours);
46 |
47 | closestTo(today, [tomorrow]) // { difference: 85400000, closest: Sat Mar 19 2022 20:26:34 GMT-0400 (Eastern Daylight Time), closestIndex: 0 }
48 | ```
49 |
50 | :::info Comparing a single date?
51 | Don't forget that the `compareDate` must be an array.
52 | :::
--------------------------------------------------------------------------------
/docs/docs/functions/dateNow.md:
--------------------------------------------------------------------------------
1 | ---
2 | sidebar_label: 'dateNow()'
3 | ---
4 |
5 | # `dateNow()`
6 | The `dateNow()` function returns the current date in a specified locale.
7 |
8 | ### Usage
9 | ```javascript
10 | import { dateNow } from 'easy-dates';
11 |
12 | dateNow(locale)
13 | ```
14 |
15 | ### Prop types
16 | If a locale argument is not provided when calling the function, then the locale defaults to Canadian English.
17 |
18 | | prop | type | required | default |
19 | |----------|----------|----------|-----------|
20 | | `locale` | `string` | no | `'en-CA'` |
21 |
22 | ### Examples
23 | For more examples of which locales can be used, refer to the [MDN Documentation: Using locales](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString#using_locales).
24 |
25 | ```javascript title='Canadian English'
26 | dateNow('en-CA') // 2022-03-20, 11:07:04 p.m.
27 | ```
28 |
29 | ```javascript title='US English'
30 | dateNow('en-US') // 3/20/2022, 11:07:04 PM
31 | ```
32 |
33 | ```javascript title='UK English'
34 | dateNow('en-UK') // 20/03/2022, 23:06:39
35 | ```
36 |
37 | ```javascript title='Arabic'
38 | dateNow('ar-EG') // '٢٠/٣/٢٠٢٢, ١١:٠٨:٠١ م'
39 | ```
40 |
41 |
--------------------------------------------------------------------------------
/docs/docs/functions/dateNowISO.md:
--------------------------------------------------------------------------------
1 | ---
2 | sidebar_label: dateNowISO()
3 | ---
4 |
5 | # `dateNowISO()`
6 | Returns the current date as an [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) string.
7 |
8 | :::tip
9 | ISO is an international standard for date and time representation.
10 | :::
11 |
12 | ## Usage
13 | ```javascript
14 | import { dateNowISO } from 'easy-dates';
15 |
16 | dateNowISO();
17 | ```
18 |
19 | ## Prop types
20 | This function does not take any props.
21 |
22 | ## Examples
23 | ```javascript
24 | dateNowISO() // "2022-04-02T15:43:01.539Z"
25 | ```
26 |
--------------------------------------------------------------------------------
/docs/docs/functions/dateNowUnix.md:
--------------------------------------------------------------------------------
1 | ---
2 | sidebar_label: dateNowUnix()
3 | ---
4 |
5 | # `dateNowUnix()`
6 | Returns a number representing the current date and time in Unix time (seconds).
7 |
8 | :::tip
9 | If you need the current date in milliseconds (JavaScript timestamp), then use [`secondsToMilliseconds()`](/docs/functions/secondsToMilliseconds) on the result of `dateNowUnix()`.
10 | :::
11 |
12 | ## Usage
13 | ```javascript
14 | import { dateNowUnix } from 'easy-dates';
15 |
16 | dateNowUnix();
17 | ```
18 |
19 | ## Prop types
20 | This function does not take any props.
21 |
22 | ## Examples
23 | ```javascript
24 | dateNowUnix() // 1648871014
25 | ```
--------------------------------------------------------------------------------
/docs/docs/functions/dateToMilliseconds.md:
--------------------------------------------------------------------------------
1 | ---
2 | sidebar_label: dateToMilliseconds()
3 | ---
4 |
5 | # `dateToMilliseconds()`
6 | Returns the number of milliseconds (JavaScript timestamp) representing a given date.
7 |
8 | ## Usage
9 | ```javascript
10 | import { dateToMilliseconds } from 'easy-dates';
11 |
12 | dateToMilliseconds(date)
13 | ```
14 |
15 | ## Prop types
16 | | prop | type | required | default |
17 | |--------|--------|----------|-----------|
18 | | `date` | `date` | yes | `null` |
19 |
20 | ## Examples
21 | ```javascript
22 | dateToMilliseconds(new Date("2022-01-01")) // 1640995200000
23 | ```
24 |
25 | ```javascript
26 | dateToMilliseconds("2022-01-01") // Error
27 | ```
28 |
--------------------------------------------------------------------------------
/docs/docs/functions/dateToUnix.md:
--------------------------------------------------------------------------------
1 | ---
2 | sidebar_label: "dateToUnix()"
3 | ---
4 |
5 | # `dateToUnix()`
6 | Returns a Unix timestamp from a given date object, string, or milliseconds timestamp.
7 |
8 | ### Usage
9 | ```javascript
10 | import { dateToUnix } from 'easy-dates';
11 |
12 | const dateObject = new Date(Date.now()) // Sat Mar 19 2022 23:46:03 GMT-0400 (Eastern Daylight Time)
13 | const millisecondsDateStamp = new Date(Date.now()).getTime(); // 1647747963147
14 |
15 | dateToUnix(dateObject) // 1647747963
16 | dateToUnix(millisecondsDateStamp) // 1647747963
17 | ```
18 |
19 | ### Prop types
20 |
21 | | prop | type | required | default |
22 | |--------|-------|----------|----------|
23 | | `date` | `any` | yes | `null` |
24 |
25 |
26 | :::info Using a `string` prop?
27 |
28 | _Does this work to convert a locale date string back to a date or timestamp too?_ It does. But you should try to avoid it. Here's an example.
29 |
30 | ```javascript title="locale string"
31 | const localeDateString = new Date(millisecondsDateStamp).toLocaleString('en-CA') // '2022-03-19, 11:46:03 p.m.'
32 |
33 | dateToUnix(localeDateString) // 1647734940
34 | ```
35 |
36 | As you can see, the first two conversions (a date object or milliseconds timestamp) are exact, however converting a locale date string back into a date object or timestamp is not.
37 |
38 | Similar behaviour can be observed when casting an `object` as a `string`.
39 |
40 | ```javascript title="date object as string"
41 | const someDateObject = new Date(Date.now()) // Sun Mar 20 2022 23:21:10 GMT-0400 (Eastern Daylight Time)
42 |
43 | dateToUnix("Sun Mar 20 2022 23:21:10 GMT-0400 (Eastern Daylight Time)") // 1647919810
44 | ```
45 |
46 | ### When are strings ok to use?
47 | When the value of the string is a number.
48 |
49 | ```javascript
50 | const someTimeNumber = new Date(Date.now()).getTime();
51 |
52 | dateToUnix("1647833600771") // 1647833600
53 | ```
54 | :::
55 |
56 |
--------------------------------------------------------------------------------
/docs/docs/functions/daysFromNow.md:
--------------------------------------------------------------------------------
1 | ---
2 | sidebar_label: "daysFromNow()"
3 | ---
4 |
5 | # `daysFromNow()`
6 | Returns a localized date that is a specified number of days away.
7 |
8 | ## Usage
9 | ```javascript
10 | import { daysFromNow } from 'easy-dates';
11 |
12 | daysFromNow(multiplier, locale)
13 | ```
14 |
15 | ## Prop types
16 | | prop | type | required | default |
17 | |--------------|----------|----------|-----------|
18 | | `multiplier` | `number` | yes | `null` |
19 | | `locale` | `string` | no | `'en-CA'` |
20 |
21 | ## Examples
22 | ```javascript title='one day from now - defaults to Canadian English'
23 | daysFromNow(1) // Tue Mar 22 2022 00:08:07 GMT-0400 (Eastern Daylight Time)
24 | ```
25 |
26 | ```javascript title='one day from now - United Kingdom Enlighs'
27 | daysFromNow(1, 'en-UK') // '22/03/2022, 00:08:57'
28 | ```
29 |
30 | ```javascript title='42 days from now - United States English'
31 | daysFromNow(42, 'en-US') // '5/2/2022, 12:09:45 AM'
32 | ```
--------------------------------------------------------------------------------
/docs/docs/functions/daysToWeeks.md:
--------------------------------------------------------------------------------
1 | ---
2 | sidebar_label: daysToWeeks()
3 | ---
4 |
5 | # `daysToWeeks()`
6 | Returns the number of weeks equal to the given number of days.
7 |
8 | ## Usage
9 | ```javascript
10 | import { daysToWeeks } from 'easy-dates';
11 |
12 | daysToWeeks(days);
13 | ```
14 |
15 | ## Prop types
16 |
17 | | prop | type | required | default |
18 | |--------|----------|----------|----------|
19 | | `days` | `number` | yes | `null` |
20 |
21 | ## Examples
22 | ```javascript
23 | daysToWeeks(7); // 1
24 | ```
25 |
26 | ```javascript
27 | daysToWeeks(14); // 2
28 | ```
29 |
30 | ```javascript
31 | daysToWeeks(365); // 52.142857142857146
32 | ```
--------------------------------------------------------------------------------
/docs/docs/functions/findEarliest.md:
--------------------------------------------------------------------------------
1 | ---
2 | sidebar_label: "findEarliest()"
3 | ---
4 |
5 | # `findEarliest()`
6 | Returns the earliest date from an array of dates, in milliseconds.
7 |
8 | ## Usage
9 | ```javascript
10 | import { findEarliest } from 'easy-dates';
11 |
12 | findEarliest(array)
13 | ```
14 |
15 | ## Prop types
16 | Takes an array of dates, or array of dates as milliseconds.
17 |
18 | | props | type | required | default |
19 | |---------|-------|----------|---------|
20 | | `array` | Array | yes | n/a |
21 |
22 | ## Examples
23 |
24 | ```javascript title="returning milliseconds"
25 | const today = new Date();
26 | const tomorrow = new Date(today.getTime() + 86400000);
27 | findEarliest([today, tomorrow]) // returns today's date in milliseconds
28 | ```
29 |
30 | ```javascript title="convert milliseconds to date"
31 | const today = new Date();
32 | const tomorrow = new Date(today.getTime() + 86400000);
33 | const latestDate = findEarliest([today, tomorrow]) // 1648513095866
34 | new Date(latestDate) // Sun Mar 27 2022 20:18:22 GMT-0400 (Eastern Daylight Time)
35 | ```
--------------------------------------------------------------------------------
/docs/docs/functions/findLatest.md:
--------------------------------------------------------------------------------
1 | ---
2 | sidebar_label: "findLatest()"
3 | ---
4 |
5 | # `findLatest()`
6 | Returns the latest date from an array of dates, in milliseconds.
7 |
8 | ## Usage
9 | ```javascript
10 | import { findLatest } from 'easy-dates';
11 |
12 | findLatest(array)
13 | ```
14 |
15 | ## Prop types
16 | Takes an array of dates, or array of dates as milliseconds.
17 |
18 | | props | type | required | default |
19 | |---------|-------|----------|---------|
20 | | `array` | Array | yes | n/a |
21 |
22 | ## Examples
23 | ```javascript title="returning milliseconds"
24 | const today = new Date();
25 | const tomorrow = new Date(today.getTime() + 86400000);
26 | findLatest([today, tomorrow]) // 1580291200000
27 | ```
28 |
29 | ```javascript title="convert milliseconds to date"
30 | const today = new Date();
31 | const tomorrow = new Date(today.getTime() + 86400000);
32 | const latestDate = findLatest([today, tomorrow])
33 | new Date(latestDate) // Mon Mar 28 2022 20:17:22 GMT-0400 (Eastern Daylight Time)
34 | ```
--------------------------------------------------------------------------------
/docs/docs/functions/getDaysInMonth.md:
--------------------------------------------------------------------------------
1 | ---
2 | sidebar_label: "getDaysInMonth()"
3 | ---
4 |
5 | # `getDaysInMonth()`
6 | Returns the number of days in a given month. Note that month indexes start at 0. If no arguments are provided, it returns data about the current month.
7 |
8 | ## Usage
9 | ```javascript
10 | import { getDaysInMonth } from 'easy-dates';
11 |
12 | getDaysInMonth(month, year)
13 | ```
14 |
15 | ## Prop types
16 | The `month` can be a number, representing the index of the month, or can be the name of the month.
17 |
18 | | prop | type | required | default |
19 | |-----------|------------------|----------|---------------|
20 | | `year` | number | no | current year |
21 | | `month ` | string or number | no | current month |
22 |
23 | ## Examples
24 | ```javascript title='using two number arguments'
25 | getDaysInMonth(1, 2022) // 28
26 | ```
27 |
28 | ```javascript title='using a string for the month'
29 | getDaysInMonth("feb", 2022) // 28
30 | ```
31 |
32 | ```javascript title='when no args are used, the current month (Feb) is returned'
33 | getDaysInMonth() // 28
34 | ```
--------------------------------------------------------------------------------
/docs/docs/functions/getDuration.md:
--------------------------------------------------------------------------------
1 | ---
2 | sidebar_label: "getDuration()"
3 | ---
4 |
5 | # `getDuration()`
6 | Returns a number representing the amount of time between two dates. Since Unix timestamps are in seconds, this function technically returns a Unix timestamp when the `measure` is set to `seconds`.
7 |
8 | ## Usage
9 | ```javascript
10 | import { getDuration } from 'easy-dates';
11 |
12 | getDuration(firstDate, secondDate, measure)
13 | ```
14 |
15 | ## Prop types
16 | | prop | type | required | default |
17 | |--------------|--------|----------|---------|
18 | | `firstDate` | any | yes | null |
19 | | `secondDate` | any | yes | null |
20 | | `measure` | string | yes | days |
21 |
22 | ## Examples
23 | ```javascript
24 | const oneDay = 86400000;
25 | const today = new Date(Date.now());
26 | const tomorrow = new Date(Date.now() + oneDay);
27 |
28 | getDuration(today, tomorrow, 'seconds') // 86400
29 | getDuration(today, tomorrow, 'minutes') // 1440
30 | getDuration(today, tomorrow, 'hours') // 24
31 | getDuration(today, tomorrow, 'days') // 1
32 | getDuration(today, tomorrow, 'weeks') // 0.14246575342465753
33 | getDuration(today, tomorrow, 'months') // 0.03287671232876713
34 | getDuration(today, tomorrow, 'years') // 0.0027397260273972603
35 | ```
--------------------------------------------------------------------------------
/docs/docs/functions/getMonthIndex.md:
--------------------------------------------------------------------------------
1 | ---
2 | sidebar_label: "getMonthIndex()"
3 | ---
4 |
5 | # `getMonthIndex()`
6 | Returns the index of the current month. Note that month indexes start at 0.
7 |
8 | ## Usage
9 | ```javascript
10 | import { getMonthIndex } from 'easy-dates';
11 |
12 | getMonthIndex(monthName)
13 | ```
14 |
15 | ## Prop types
16 | | prop | type | required | default |
17 | |-------------|--------|----------|---------|
18 | | `monthName` | string | no | current |
19 |
20 | ## Examples
21 | ```javascript title="get the current month (March)"
22 | getMonthIndex() // 2
23 | // or
24 | getMonthIndex('current') // 2
25 | ```
26 |
27 | ```javascript title="get a specific month by name"
28 | getMonthIndex('April') // 3
29 | // or
30 | getMonthIndex('april') // 3
31 | ```
32 |
33 | ```javascript title="get a specific month by short name"
34 | getMonthIndex('Apr') // 3
35 | // or
36 | getMonthIndex('apr') // 3
37 | ```
--------------------------------------------------------------------------------
/docs/docs/functions/getMonthName.md:
--------------------------------------------------------------------------------
1 | ---
2 | sidebar_label: getMonthName()
3 | ---
4 |
5 | # `getMonthName()`
6 | Returns the name of the month, for the given month number, in a given locale. The default locale is English.
7 |
8 | :::info
9 | ### Supported locales
10 | At this time, this function supports:
11 |
12 | - English (en)
13 | - French (fr)
14 | :::
15 |
16 | ## Usage
17 | ```javascript
18 | import { getMonthName } from 'easy-dates';
19 |
20 | getMonthName(local, index, short);
21 | ```
22 |
23 | ## Prop types
24 | | prop | type | required | default |
25 | |----------|-----------|----------|-----------------|
26 | | `locale` | `String` | no | `en` |
27 | | `index` | `Number` | no | `current month` |
28 | | `short` | `Boolean` | no | `false` |
29 |
30 | ## Examples
31 | ```javascript
32 | getMonthName("en", 0); // "January"
33 | getMonthName("en", 1); // "February"
34 |
35 | getMonthName("fr", 0); // "Janvier"
36 | getMonthName("fr", 1); // "Février"
37 | ```
38 |
39 | ```javascript title="with short parameter true"
40 | getMonthName("en", 0, true); // "Jan"
41 | getMonthName("en", 1, true); // "Feb"
42 |
43 | getMonthName("fr", 0, true); // "Jan"
44 | getMonthName("fr", 1, true); // "Fév"
45 | ```
46 |
47 | ```javascript title="returns current month when no index is provided"
48 | getMonthName(); // "April"
49 | ```
--------------------------------------------------------------------------------
/docs/docs/functions/getOverlappingDaysInIntervals.md:
--------------------------------------------------------------------------------
1 | ---
2 | sidebar_label: getOverlappingDaysInIntervals()
3 | ---
4 |
5 | # `getOverlappingDaysInIntervals()`
6 | Returns an array of dates representing the days that overlap between two date ranges.
7 |
8 | :::tip
9 | This function returns an array of `Date` objects. If you need something like seconds (Unix timestamp) or milliseconds (JavaScript timestamp), then you can use the [`dateToUnix()`](dateToUnix) or [`dateToMilliseconds()`](dateToMilliseconds) functions.
10 | :::
11 |
12 | ## Usage
13 | ```javascript
14 | import { getOverlappingDaysInIntervals } from 'easy-dates';
15 |
16 | getOverlappingDaysInIntervals(rangeOne, rangeTwo);
17 | ```
18 |
19 | ## Prop types
20 | | prop | type | required | default |
21 | |------------|---------|----------|-----------|
22 | | `rangeOne` | `array` | yes | `null` |
23 | | `rangeTwo` | `array` | yes | `null` |
24 |
25 | ## Examples
26 | ```javascript
27 | getOverlappingDaysInIntervals(
28 | [new Date(2022, 0, 1), new Date(2022, 0, 10)],
29 | [new Date(2022, 0, 2), new Date(2022, 0, 11)]
30 | )
31 |
32 | // Result
33 | // [
34 | // new Date(2022, 0, 2),
35 | // new Date(2022, 0, 3),
36 | // new Date(2022, 0, 4),
37 | // new Date(2022, 0, 5),
38 | // new Date(2022, 0, 6),
39 | // new Date(2022, 0, 7),
40 | // new Date(2022, 0, 8),
41 | // new Date(2022, 0, 9),
42 | // new Date(2022, 0, 10)
43 | // ]
44 | ```
45 |
46 | ```javascript
47 | getOverlappingDaysInIntervals(
48 | ["2022, 0, 1", "2022, 0, 10"],
49 | [new Date(2022, 0, 2), new Date(2022, 0, 11)]
50 | ) // Error
51 | ```
52 |
--------------------------------------------------------------------------------
/docs/docs/functions/getTodayName.md:
--------------------------------------------------------------------------------
1 | ---
2 | sidebar_label: "getTodayName()"
3 | ---
4 |
5 | # `getTodayName()`
6 | Returns the name of today's day.
7 |
8 | ## Usage
9 | ```javascript
10 | import { getTodayName } from 'easy-dates';
11 |
12 | getTodayName() // Friday
13 | ```
14 |
15 | ## Prop types
16 | This function does not take in any props.
17 |
18 | | prop | type | required | default |
19 | |------|------|----------|---------|
20 | | n/a | n/a | n/a | n/a |
--------------------------------------------------------------------------------
/docs/docs/functions/getTomorrow.md:
--------------------------------------------------------------------------------
1 | ---
2 | sidebar_label: "getTomorrow()"
3 | ---
4 |
5 | # `getTomorrow()`
6 | Returns tomorrow's date as a JavaScript date object.
7 |
8 | ## Usage
9 | ```javascript
10 | import { getTomorrow } from 'easy-dates';
11 |
12 | getTomorrow(locale)
13 | ```
14 |
15 | ## Prop types
16 | | prop | type | required | default |
17 | |----------|--------|----------|-----------|
18 | | `locale` | string | no | `'en-CA'` |
19 |
20 | ## Examples
21 | ```javascript title="providing a locale"
22 | getTomorrow('en-CA') // 2022-03-19, 4:00:29 p.m.
23 | ```
24 |
25 | ```javascript title="default 'en-CA' locale"
26 | getTomorrow() // 2022-03-19, 4:00:29 p.m.
27 | ```
--------------------------------------------------------------------------------
/docs/docs/functions/getYear.md:
--------------------------------------------------------------------------------
1 | ---
2 | sidebar_label: "getYear()"
3 | ---
4 |
5 | # `getYear()`
6 | Returns the current year. This function does not accept any arguments.
7 |
8 | ## Usage
9 | ```javascript
10 | import { getYear } from 'easy-dates';
11 |
12 | getYear()
13 | ```
14 |
15 | ## Prop types
16 | This function does not take arguments.
17 |
18 | | props | type | required | default |
19 | |-------|------|----------|---------|
20 | | n/a | n/a | n/a | n/a |
21 |
22 | ## Examples
23 | ```javascript
24 | getYear() // 2022
25 | ```
--------------------------------------------------------------------------------
/docs/docs/functions/hoursToMilliseconds.md:
--------------------------------------------------------------------------------
1 | ---
2 | sidebar_label: 'hoursToMilliseconds()'
3 | ---
4 |
5 | # `hoursToMilliseconds()`
6 | Returns the number of milliseconds in the specified number of hours.
7 |
8 | ### Usage
9 | ```javascript
10 | import { hoursToMilliseconds } from 'easy-dates';
11 |
12 | hoursToMilliseconds(hours)
13 | ```
14 |
15 | ### Prop types
16 |
17 | | prop | type | required | default |
18 | |---------|----------|----------|---------|
19 | | `hours` | `number` | yes | n/a |
20 |
21 | ### Examples
22 | ```javascript
23 | hoursToMilliseconds(1) // 3600000
24 | ```
25 |
26 | ```javascript
27 | hoursToMilliseconds(2) // 7200000
28 | ```
29 |
30 |
--------------------------------------------------------------------------------
/docs/docs/functions/hoursToMinutes.md:
--------------------------------------------------------------------------------
1 | ---
2 | sidebar_label: 'hoursToMinutes()'
3 | ---
4 |
5 | # `hoursToMinutes()`
6 | Returns the number of minutes in the specified number of hours.
7 |
8 | ### Usage
9 | ```javascript
10 | import { hoursToMinutes } from 'easy-dates';
11 |
12 | hoursToMinutes(hours)
13 | ```
14 |
15 | ### Prop types
16 |
17 | | prop | type | required | default |
18 | |---------|----------|----------|---------|
19 | | `hours` | `number` | yes | n/a |
20 |
21 | ### Examples
22 | ```javascript
23 | hoursToMinutes(1) // 60
24 | ```
25 |
26 | ```javascript
27 | hoursToMinutes(2) // 120
28 | ```
29 |
30 |
--------------------------------------------------------------------------------
/docs/docs/functions/index.md:
--------------------------------------------------------------------------------
1 | # Functions
2 | The entire `easy-dates` package is just a collection of functions. You'll find an explanation of how to use each function, and make the most of `easy-dates` in this section.
3 |
4 | ### Developer experience matters
5 | If a function behaves differently than you would expect it to, or you wish `easy-dates` could do something that it currently can't, please do [open an issue on GitHub](https://github.com/sandypockets/easy-dates/issues).
--------------------------------------------------------------------------------
/docs/docs/functions/isAfter.md:
--------------------------------------------------------------------------------
1 | ---
2 | sidebar_label: isAfter()
3 | ---
4 |
5 | # `isAfter()`
6 | Returns a boolean, `true` if the first date is after the second date.
7 |
8 | ## Usage
9 | ```javascript
10 | import { isAfter } from 'easy-dates'
11 |
12 | isAfter(date, dateToCompare)
13 | ```
14 |
15 | ## Prop types
16 | | prop | type | required | description |
17 | |-----------------|--------|----------|--------------------------|
18 | | `date` | `date` | yes | The date to compare |
19 | | `dateToCompare` | `date` | yes | The date to compare with |
20 |
21 | ## Examples
22 | ```javascript
23 | isAfter(new Date('2022-01-01'), new Date('2022-01-02')) // true
24 | ```
25 |
26 | ```javascript
27 | isAfter(new Date('2022-01-01'), new Date('2022-01-01')) // false
28 | ```
29 |
30 | ```javascript
31 | isAfter(new Date('2022-01-02'), new Date('2022-01-01')) // false
32 | ```
33 |
34 | ```javascript
35 | const today = new Date();
36 | const tomorrow = new Date(today.getTime() + 24 * 60 * 60 * 1000);
37 | isAfter(tomorrow.toString(), today) // error
38 | ```
--------------------------------------------------------------------------------
/docs/docs/functions/isBefore.md:
--------------------------------------------------------------------------------
1 | ---
2 | sidebar_label: isBefore()
3 | ---
4 |
5 | # `isBefore()`
6 | Returns a boolean, `false` if the first date is after the second date.
7 |
8 | ## Usage
9 | ```javascript
10 | import { isBefore } from 'easy-dates'
11 |
12 | isBefore(date, dateToCompare)
13 | ```
14 |
15 | ## Prop types
16 | | prop | type | required | default |
17 | |-----------------|--------|----------|---------|
18 | | `date` | `date` | yes | n/a |
19 | | `dateToCompare` | `date` | yes | n/a |
20 |
21 | ## Examples
22 | ```javascript
23 | isBefore(new Date('2022-01-01'), new Date('2022-01-02')) // false
24 | ```
25 |
26 | ```javascript
27 | isBefore(new Date('2022-01-01'), new Date('2022-01-01')) // true
28 | ```
29 |
30 | ```javascript
31 | isBefore(new Date('2022-01-02'), new Date('2022-01-01')) // true
32 | ```
33 |
34 | ```javascript
35 | const today = new Date();
36 | const tomorrow = new Date(today.getTime() + 24 * 60 * 60 * 1000);
37 | isBefore(tomorrow.toString(), today) // error when given the wrong type
38 | ```
--------------------------------------------------------------------------------
/docs/docs/functions/isDate.md:
--------------------------------------------------------------------------------
1 | ---
2 | sidebar_label: isDate()
3 | ---
4 |
5 | # `isDate()`
6 | Returns a boolean, `false` if the first date is after the second date.
7 |
8 | ## Usage
9 | ```javascript
10 | import { isDate } from 'easy-dates'
11 |
12 | isDate(date)
13 | ```
14 |
15 | ## Prop types
16 | | prop | type | required | default |
17 | |-----------------|--------|----------|---------|
18 | | `date` | `date` | yes | n/a |
19 |
20 | ## Examples
21 | ```javascript
22 | isDate(new Date('2022-01-01')) // true
23 | ```
24 |
25 | ```javascript
26 | isDate(`${new Date('2022-01-01')}`) // false
27 | ```
28 |
29 | ```javascript
30 | isDate('2022-01-02') // false
31 | ```
--------------------------------------------------------------------------------
/docs/docs/functions/isEqual.md:
--------------------------------------------------------------------------------
1 | ---
2 | sidebar_label: isEqual()
3 | ---
4 |
5 | # `isEqual`
6 | Returns a boolean, `false` if the first date is after the second date.
7 |
8 | ## Usage
9 | ```javascript
10 | import { isEqual } from 'easy-dates'
11 |
12 | isEqual(date, dateToCompare)
13 | ```
14 |
15 | ## Prop types
16 | | prop | type | required | default |
17 | |-----------------|--------|----------|---------|
18 | | `date` | `date` | yes | n/a |
19 | | `dateToCompare` | `date` | yes | n/a |
20 |
21 | ## Examples
22 | ```javascript
23 | isEqual(new Date('2022-01-01'), new Date('2022-01-01')) // true
24 | ```
25 |
26 | ```javascript
27 | isEqual(new Date(Date.now()), new Date(Date.now())) // true
28 | ```
29 |
30 | ```javascript
31 | isEqual(new Date('2022-01-01'), new Date('2022-01-02')) // false
32 | ```
33 |
34 | ```javascript
35 | isEqual(new Date('2022-01-01')) // false
36 | ```
37 |
38 | ```javascript
39 | isEqual('2022-01-02') // false
40 | ```
--------------------------------------------------------------------------------
/docs/docs/functions/isInFuture.md:
--------------------------------------------------------------------------------
1 | ---
2 | sidebar_label: isInFuture()
3 | ---
4 |
5 | # `isInFuture`
6 | Returns a boolean, `true` if the given date is in the future.
7 |
8 | ## Usage
9 | ```javascript
10 | import { isInFuture } from 'easy-dates'
11 |
12 | isInFuture(date)
13 | ```
14 |
15 | ## Prop types
16 | Throws an error when given a type other than `Date`.
17 |
18 | | prop | type | required | default |
19 | |-----------------|--------|----------|---------|
20 | | `date` | `date` | yes | n/a |
21 |
22 | ## Examples
23 | ```javascript
24 | isInFuture(new Date('2022-01-01')) // false
25 | ```
26 |
27 | ```javascript
28 | isInFuture(new Date('2030-01-01')) // true
29 | ```
30 |
31 | ```javascript
32 | isInFuture('2022-01-02') // throws an error
33 | ```
34 |
35 |
--------------------------------------------------------------------------------
/docs/docs/functions/isInPast.md:
--------------------------------------------------------------------------------
1 | ---
2 | sidebar_label: isInPast()
3 | ---
4 |
5 | # `isInPast`
6 | Returns a boolean, `true` if the given date is in the past.
7 |
8 | ## Usage
9 | ```javascript
10 | import { isInPast } from 'easy-dates'
11 |
12 | isInPast(date)
13 | ```
14 |
15 | ## Prop types
16 | Throws an error when given a type other than `Date`.
17 |
18 | | prop | type | required | default |
19 | |-----------------|--------|----------|---------|
20 | | `date` | `date` | yes | n/a |
21 |
22 | ## Examples
23 | ```javascript
24 | isInPast(new Date('2022-01-01')) // true
25 | ```
26 |
27 | ```javascript
28 | isInPast(new Date('2030-01-01')) // false
29 | ```
30 |
31 | ```javascript
32 | isInPast('2022-01-02') // throws an error
33 | ```
34 |
35 |
--------------------------------------------------------------------------------
/docs/docs/functions/millisecondsToHours.md:
--------------------------------------------------------------------------------
1 | ---
2 | sidebar_label: 'millisecondsToHours()'
3 | ---
4 |
5 | # `millisecondsToHours()`
6 | Returns the number of hours from a given number of milliseconds.
7 |
8 | ### Usage
9 | ```javascript
10 | import { millisecondsToHours } from 'easy-dates';
11 |
12 | millisecondsToHours(milliseconds);
13 | ```
14 |
15 | ### Prop types
16 |
17 | | prop | type | required | default |
18 | |----------------|----------|----------|---------|
19 | | `milliseconds` | `number` | yes | n/a |
20 |
21 | ### Examples
22 | ```javascript
23 | millisecondsToHours(3600000) // 1
24 | ```
25 |
26 | ```javascript
27 | millisecondsToHours(7200000) // 2
28 | ```
29 |
30 |
--------------------------------------------------------------------------------
/docs/docs/functions/millisecondsToMinutes.md:
--------------------------------------------------------------------------------
1 | ---
2 | sidebar_label: 'millisecondsToMinutes()'
3 | ---
4 |
5 | # `millisecondsToMinutes()`
6 | Returns the number of minutes from a given number of milliseconds.
7 |
8 | ### Usage
9 | ```javascript
10 | import { millisecondsToMinutes } from 'easy-dates';
11 |
12 | millisecondsToMinutes(milliseconds);
13 | ```
14 |
15 | ### Prop types
16 |
17 | | prop | type | required | default |
18 | |----------------|----------|----------|---------|
19 | | `milliseconds` | `number` | yes | n/a |
20 |
21 | ### Examples
22 | ```javascript
23 | millisecondsToMinutes(3600000) // 60
24 | ```
25 |
26 | ```javascript
27 | millisecondsToMinutes(7200000) // 120
28 | ```
29 |
30 |
--------------------------------------------------------------------------------
/docs/docs/functions/millisecondsToSeconds.md:
--------------------------------------------------------------------------------
1 | ---
2 | sidebar_label: millisecondsToSeconds()
3 | ---
4 |
5 | # `millisecondsToSeconds()`
6 | Returns the number of seconds equal to the given number of milliseconds.
7 |
8 | ## Usage
9 | ```javascript
10 | import { millisecondsToSeconds } from 'easy-dates';
11 |
12 | millisecondsToSeconds(milliseconds);
13 | ```
14 |
15 | ## Prop types
16 |
17 | | prop | type | required | default |
18 | |----------------|----------|----------|----------|
19 | | `milliseconds` | `number` | yes | `null` |
20 |
21 | ## Examples
22 | ```javascript
23 | millisecondsToSeconds(1000); // 1
24 | ```
25 |
26 | ```javascript
27 | millisecondsToSeconds(60000); // 60
28 | ```
29 |
30 | ```javascript
31 | millisecondsToSeconds('60000'); // Error
32 | ```
--------------------------------------------------------------------------------
/docs/docs/functions/minutesToHours.md:
--------------------------------------------------------------------------------
1 | ---
2 | sidebar_label: minutesToHours()
3 | ---
4 |
5 | # `minutesToHours()`
6 | Returns the number of hours from a given number of minutes.
7 |
8 | ## Usage
9 | ```javascript
10 | import { minutesToHours } from 'easy-dates';
11 |
12 | minutesToHours(minutes)
13 | ```
14 |
15 | ## Prop types
16 |
17 | | prop | type | required | default |
18 | |-----------|----------|----------|----------|
19 | | `minutes` | `number` | yes | `null` |
20 |
21 | ## Examples
22 | ```javascript
23 | minutesToHours(30); // 0.5
24 | ```
25 |
26 | ```javascript
27 | minutesToHours(60); // 1
28 | ```
29 |
30 | ```javascript
31 | minutesToHours("some string"); // throw error
32 | ```
--------------------------------------------------------------------------------
/docs/docs/functions/minutesToMilliseconds.md:
--------------------------------------------------------------------------------
1 | ---
2 | sidebar_label: minutesToMilliseconds()
3 | ---
4 |
5 | # `minutesToMilliseconds()`
6 | Returns the number of years equal to the given number of months.
7 |
8 | ## Usage
9 | ```javascript
10 | import { minutesToMilliseconds } from 'easy-dates';
11 |
12 | minutesToMilliseconds(minutes);
13 | ```
14 |
15 | ## Prop types
16 |
17 | | prop | type | required | default |
18 | |-----------|----------|----------|----------|
19 | | `minutes` | `number` | yes | `null` |
20 |
21 | ## Examples
22 | ```javascript
23 | minutesToMilliseconds(1); // 60000
24 | ```
25 |
26 | ```javascript
27 | minutesToMilliseconds(0.5); // 30000
28 | ```
--------------------------------------------------------------------------------
/docs/docs/functions/minutesToSeconds.md:
--------------------------------------------------------------------------------
1 | ---
2 | sidebar_label: minutesToSeconds()
3 | ---
4 |
5 | # `minutesToSeconds()`
6 | Returns the number of seconds equal to the given number of minutes.
7 |
8 | ## Usage
9 | ```javascript
10 | import { minutesToSeconds } from 'easy-dates';
11 |
12 | minutesToSeconds(minutes);
13 | ```
14 |
15 | ## Prop types
16 |
17 | | prop | type | required | default |
18 | |-----------|----------|----------|----------|
19 | | `minutes` | `number` | yes | `null` |
20 |
21 | ## Examples
22 | ```javascript
23 | minutesToSeconds(1); // 60
24 | ```
25 |
26 | ```javascript
27 | minutesToSeconds(60); // 3600
28 | ```
29 |
30 | ```javascript
31 | minutesToSeconds('1'); // Error
32 | ```
--------------------------------------------------------------------------------
/docs/docs/functions/monthsToQuarters.md:
--------------------------------------------------------------------------------
1 | ---
2 | sidebar_label: monthsToQuarters()
3 | ---
4 |
5 | # `monthsToQuarters()`
6 | Returns the number of quarters equal to the given number of months. There are 3 months in a quarter.
7 |
8 | ## Usage
9 | ```javascript
10 | import { monthsToQuarters } from 'easy-dates';
11 |
12 | monthsToQuarters(months);
13 | ```
14 |
15 | ## Prop types
16 |
17 | | prop | type | required | default |
18 | |----------|----------|----------|----------|
19 | | `months` | `number` | yes | `null` |
20 |
21 | ## Examples
22 | ```javascript
23 | monthsToQuarters(3); // 1
24 | ```
25 |
26 | ```javascript
27 | monthsToQuarters(12); // 4
28 | ```
29 |
30 | ```javascript
31 | monthsToQuarters('3'); // Error
32 | ```
--------------------------------------------------------------------------------
/docs/docs/functions/monthsToYears.md:
--------------------------------------------------------------------------------
1 | ---
2 | sidebar_label: monthsToYears()
3 | ---
4 |
5 | # `monthsToYears()`
6 | Returns the number of years equal to the given number of months.
7 |
8 | ## Usage
9 | ```javascript
10 | import { monthsToYears } from 'easy-dates';
11 |
12 | monthsToYears(months);
13 | ```
14 |
15 | ## Prop types
16 |
17 | | prop | type | required | default |
18 | |----------|----------|----------|----------|
19 | | `months` | `number` | yes | `null` |
20 |
21 | ## Examples
22 | ```javascript
23 | monthsToYears(12); // 1
24 | ```
25 |
26 | ```javascript
27 | monthsToYears(6); // 0.5
28 | ```
29 |
30 | ```javascript
31 | monthsToYears(24); // 2
32 | ```
--------------------------------------------------------------------------------
/docs/docs/functions/quartersToMonths.md:
--------------------------------------------------------------------------------
1 | ---
2 | sidebar_label: quartersToMonths()
3 | ---
4 |
5 | # `quartersToMonths()`
6 | Returns the number of months equal to the given number of quarters. There are 3 months in a quarter.
7 |
8 | ## Usage
9 | ```javascript
10 | import { quartersToMonths } from 'easy-dates';
11 |
12 | quartersToMonths(quarters);
13 | ```
14 |
15 | ## Prop types
16 |
17 | | prop | type | required | default |
18 | |------------|----------|----------|----------|
19 | | `quarters` | `number` | yes | `null` |
20 |
21 | ## Examples
22 | ```javascript
23 | quartersToMonths(1); // 3
24 | ```
25 |
26 | ```javascript
27 | quartersToMonths(4); // 12
28 | ```
29 |
30 | ```javascript
31 | quartersToMonths('12'); // Error
32 | ```
--------------------------------------------------------------------------------
/docs/docs/functions/quartersToYears.md:
--------------------------------------------------------------------------------
1 | ---
2 | sidebar_label: quartersToYears()
3 | ---
4 |
5 | # `quartersToYears()`
6 | Returns the number of years equal to the given number of quarters. There are 3 months in a quarter.
7 |
8 | ## Usage
9 | ```javascript
10 | import { quartersToYears } from 'easy-dates';
11 |
12 | quartersToYears(quarters);
13 | ```
14 |
15 | ## Prop types
16 |
17 | | prop | type | required | default |
18 | |------------|----------|----------|----------|
19 | | `quarters` | `number` | yes | `null` |
20 |
21 | ## Examples
22 | ```javascript
23 | quartersToYears(4); // 1
24 | ```
25 |
26 | ```javascript
27 | quartersToYears(2); // 0.5
28 | ```
29 |
30 | ```javascript
31 | quartersToYears('6'); // Error
32 | ```
--------------------------------------------------------------------------------
/docs/docs/functions/secondsToHours.md:
--------------------------------------------------------------------------------
1 | ---
2 | sidebar_label: secondsToHours()
3 | ---
4 |
5 | # `secondsToHours()`
6 | Returns the number of hours equal to the given number of seconds. There are 3600 seconds in an hour.
7 |
8 | ## Usage
9 | ```javascript
10 | import { secondsToHours } from 'easy-dates';
11 |
12 | secondsToHours(seconds);
13 | ```
14 |
15 | ## Prop types
16 |
17 | | prop | type | required | default |
18 | |-----------|----------|----------|----------|
19 | | `seconds` | `number` | yes | `null` |
20 |
21 | ## Examples
22 | ```javascript
23 | secondsToHours(3600); // 1
24 | ```
25 |
26 | ```javascript
27 | secondsToHours(1800); // 0.5
28 | ```
29 |
30 | ```javascript
31 | secondsToHours('60'); // Error
32 | ```
--------------------------------------------------------------------------------
/docs/docs/functions/secondsToMilliseconds.md:
--------------------------------------------------------------------------------
1 | ---
2 | sidebar_label: secondsToMilliseconds()
3 | ---
4 |
5 | # `secondsToMilliseconds()`
6 | Returns the number of milliseconds equal to the given number of seconds.
7 |
8 | ## Usage
9 | ```javascript
10 | import { secondsToMilliseconds } from 'easy-dates';
11 |
12 | secondsToMilliseconds(seconds);
13 | ```
14 |
15 | ## Prop types
16 |
17 | | prop | type | required | default |
18 | |-----------|----------|----------|----------|
19 | | `seconds` | `number` | yes | `null` |
20 |
21 | ## Examples
22 | ```javascript
23 | secondsToMilliseconds(1); // 1000
24 | ```
25 |
26 | ```javascript
27 | secondsToMilliseconds(60); // 60000
28 | ```
29 |
30 | ```javascript
31 | secondsToMilliseconds('60'); // Error
32 | ```
--------------------------------------------------------------------------------
/docs/docs/functions/secondsToMinutes.md:
--------------------------------------------------------------------------------
1 | ---
2 | sidebar_label: secondsToMinutes()
3 | ---
4 |
5 | # `secondsToMinutes()`
6 | Returns the number of minutes equal to the given number of seconds.
7 |
8 | ## Usage
9 | ```javascript
10 | import { secondsToMinutes } from 'easy-dates';
11 |
12 | secondsToMinutes(seconds);
13 | ```
14 |
15 | ## Prop types
16 |
17 | | prop | type | required | default |
18 | |-----------|----------|----------|----------|
19 | | `seconds` | `number` | yes | `null` |
20 |
21 | ## Examples
22 | ```javascript
23 | secondsToMinutes(60); // 1
24 | ```
25 |
26 | ```javascript
27 | secondsToMinutes(3600); // 60
28 | ```
29 |
30 | ```javascript
31 | secondsToMinutes('2'); // Error
32 | ```
--------------------------------------------------------------------------------
/docs/docs/functions/unixToDate.md:
--------------------------------------------------------------------------------
1 | ---
2 | sidebar_label: 'unixToDate()'
3 | ---
4 |
5 | # `unixToDate()`
6 | Returns a JavaScript Date object when given a Unix timestamp. Optionally include a locale to have the data object returned in a particular locale.
7 |
8 | ## Usage
9 | ```javascript
10 | import { unixToDate } from 'easy-dates'
11 |
12 | unixToDate(unixTimeStamp, locale)
13 | ```
14 |
15 | ## Prop types
16 |
17 | | prop | type | required | default |
18 | |-----------------|----------|----------|---------|
19 | | `unixTimeStamp` | `number` | yes | `null` |
20 | | `locale` | `string` | no | `null` |
21 |
22 | ## Examples
23 | ```javascript title="returns an object"
24 | unixToDate(1648078332) // Wed Mar 23 2022 19:32:12 GMT-0400 (Eastern Daylight Time)
25 | ```
26 |
27 | ```javascript title="returns a string"
28 | unixToDate(1648078332, 'en-CA') // 2022-03-23, 7:32:12 p.m.
29 | ```
30 |
--------------------------------------------------------------------------------
/docs/docs/functions/unixToDuration.md:
--------------------------------------------------------------------------------
1 | ---
2 | sidebar_label: "unixToDuration()"
3 | ---
4 |
5 | # `unixToDuration()`
6 | Takes in a Unix timestamp, and a measurement type (i.e. minutes), and returns the amount, or duration, in said type.
7 |
8 | ## Usage
9 | ```javascript
10 | import { unixToDuration } from 'easy-dates';
11 |
12 | getDuration(unixTimestamp, measure)
13 | ```
14 |
15 | ## Prop types
16 | | prop | type | required | default |
17 | |-----------------|--------|----------|---------|
18 | | `unixTimestamp` | number | yes | null |
19 | | `measure` | string | yes | days |
20 |
21 | ## Examples
22 | ```javascript
23 | const firstDate = new Date("December 17, 1995 03:24:00");
24 | const secondDate = new Date("December 17, 2000 03:24:00");
25 |
26 | // Gets difference between 1995 and 2000 as a Unix timestamp
27 | const durationAsUnixTimestamp = getDuration(firstDate, secondDate, "seconds");
28 |
29 | // Convert the Unix timestamp from seconds into years
30 | unixToDuration(durationAsUnixTimestamp, "years") // 5.019230769230769
31 | ```
32 |
33 | ```javascript title="years since January 1st, 1970"
34 | const dateNow = new Date(Date.now())
35 | unixToDuration(dateNow, "years") // 52
36 | ```
--------------------------------------------------------------------------------
/docs/docs/functions/weeksToDays.md:
--------------------------------------------------------------------------------
1 | ---
2 | sidebar_label: weeksToDays()
3 | ---
4 |
5 | # `weeksToDays()`
6 | Returns the number of days equal to the given number of weeks.
7 |
8 | ## Usage
9 | ```javascript
10 | import { weeksToDays } from 'easy-dates';
11 |
12 | weeksToDays(weeks);
13 | ```
14 |
15 | ## Prop types
16 |
17 | | prop | type | required | default |
18 | |---------|----------|----------|----------|
19 | | `weeks` | `number` | yes | `null` |
20 |
21 | ## Examples
22 | ```javascript
23 | weeksToDays(1); // 7
24 | ```
25 |
26 | ```javascript
27 | weeksToDays(52); // 364
28 | ```
29 |
30 | ```javascript
31 | weeksToDays('2'); // Error
32 | ```
--------------------------------------------------------------------------------
/docs/docs/functions/yearsToDays.md:
--------------------------------------------------------------------------------
1 | ---
2 | sidebar_label: yearsToDays()
3 | ---
4 |
5 | # `yearsToDays()`
6 | Returns the number of days equal to the given number of years.
7 |
8 | ## Usage
9 | ```javascript
10 | import { yearsToDays } from 'easy-dates';
11 |
12 | yearsToDays(years);
13 | ```
14 |
15 | ## Prop types
16 |
17 | | prop | type | required | default |
18 | |---------|----------|----------|----------|
19 | | `years` | `number` | yes | `null` |
20 |
21 | ## Examples
22 | ```javascript
23 | yearsToDays(1); // 365
24 | ```
25 |
26 | ```javascript
27 | yearsToDays(3); // 1095
28 | ```
29 |
30 | ```javascript
31 | yearsToDays('3'); // Error
32 | ```
--------------------------------------------------------------------------------
/docs/docs/functions/yearsToMonths.md:
--------------------------------------------------------------------------------
1 | ---
2 | sidebar_label: yearsToMonths()
3 | ---
4 |
5 | # `yearsToMonths()`
6 | Returns the number of months equal to the given number of years.
7 |
8 | ## Usage
9 | ```javascript
10 | import { yearsToMonths } from 'easy-dates';
11 |
12 | yearsToMonths(years);
13 | ```
14 |
15 | ## Prop types
16 |
17 | | prop | type | required | default |
18 | |---------|----------|----------|----------|
19 | | `years` | `number` | yes | `null` |
20 |
21 | ## Examples
22 | ```javascript
23 | yearsToMonths(1); // 12
24 | ```
25 |
26 | ```javascript
27 | yearsToMonths(2.5); // 30
28 | ```
29 |
30 | ```javascript
31 | yearsToMonths('1'); // Error
32 | ```
--------------------------------------------------------------------------------
/docs/docs/functions/yearsToQuarters.md:
--------------------------------------------------------------------------------
1 | ---
2 | sidebar_label: yearsToQuarters()
3 | ---
4 |
5 | # `yearsToQuarters()`
6 | Returns the number of quarters equal to the given number of years.
7 |
8 | ## Usage
9 | ```javascript
10 | import { yearsToQuarters } from 'easy-dates';
11 |
12 | yearsToQuarters(years);
13 | ```
14 |
15 | ## Prop types
16 |
17 | | prop | type | required | default |
18 | |---------|----------|----------|----------|
19 | | `years` | `number` | yes | `null` |
20 |
21 | ## Examples
22 | ```javascript
23 | yearsToQuarters(1); // 4
24 | ```
25 |
26 | ```javascript
27 | yearsToQuarters(0.5); // 2
28 | ```
29 |
30 | ```javascript
31 | yearsToQuarters('1'); // Error
32 | ```
--------------------------------------------------------------------------------
/docs/docs/intro.md:
--------------------------------------------------------------------------------
1 | ---
2 | sidebar_position: 1
3 | ---
4 |
5 | # Welcome
6 |
7 | :::caution
8 | `easy-dates` is currently under heavy development, working towards a 1.0.0 release. Until then, it's possible (though I'll do my best to avoid it!) that there could be some breaking changes. For that reason, it is not recommended to use `easy-dates` in production _yet_.
9 | :::
10 |
11 | Thanks for checking out `easy-dates`!
12 |
13 | If you've never used `easy-dates` before, then have a look at the [Getting started](introduction) section. It covers everything from adding the package to using it in a project. Otherwise, if you know what you're looking for, then take a look through the [Functions](functions) tab for full docs on everything.
--------------------------------------------------------------------------------
/docs/docs/introduction/_category_.json:
--------------------------------------------------------------------------------
1 | {
2 | "label": "Getting started",
3 | "position": 1
4 | }
5 |
--------------------------------------------------------------------------------
/docs/docs/introduction/faq.md:
--------------------------------------------------------------------------------
1 | ---
2 | sidebar_position: 5
3 | sidebar_label: "FAQ"
4 | ---
5 |
6 | # Frequently Asked Questions
7 |
8 | ## Does `easy-dates` work with JavaScript modules?
9 | Yes. Import it like you would any other package. View the [React.js demo on StackBlitz](https://stackblitz.com/edit/easy-dates-demo?file=src/App.js) for a live example.
10 |
11 | ## Does `easy-dates` work with CommonJS?
12 | Yes. Require it like you would any other package. View the [Node.js demo on StackBlitz](https://stackblitz.com/edit/easy-dates-nodejs?file=index.js) for a live example.
13 |
14 | ## This function isn't behaving as I expected. What can I do?
15 | Open an issue on GitHub [here](https://github.com/sandypockets/easy-dates/issues).
16 |
17 | ## How can I contribute to `easy-dates`?
18 | Please read the [guide on contributing](../contributing), and submit an issue or pull request.
19 |
20 | ## Is `easy-dates` tested?
21 | Yes. `easy-dates` uses Jest for testing, and maintains +95% statement, and 100% functions test coverage at all times.
22 |
23 | ## Does `easy-dates` use TypeScript?
24 | No. `easy-dates` uses JavaScript.
25 |
26 | ## Does `easy-dates` have any dependencies?
27 | No, the library is zero-dependency, and intended to be as small as possible.
--------------------------------------------------------------------------------
/docs/docs/introduction/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | sidebar_position: 1
3 | ---
4 |
5 | # Getting started
6 | `easy-dates` is a tiny, zero-dependency library intended to make working with JavaScript dates easier.
7 |
8 | It helps you ship compact code, that behaves consistently, and removes challenges like mixing up the millisecond clock that JavaScript uses with the seconds-based clock of Unix.
9 |
10 | Most importantly, `easy-dates` lets you focus on what you're building, instead of fiddling around with dates.
--------------------------------------------------------------------------------
/docs/docs/introduction/installation.md:
--------------------------------------------------------------------------------
1 | ---
2 | sidebar_position: 2
3 | ---
4 |
5 | # Installation
6 | The `easy-dates` package is available via package managers, or CDNs.
7 |
8 | ## Package managers
9 | `easy-dates` is available via Yarn on NPM.
10 |
11 | ### Yarn
12 | ```shell
13 | yarn add easy-dates
14 | ```
15 |
16 | ### NPM
17 | ```shell
18 | npm install easy-dates
19 | ```
20 |
21 | ## CDN
22 | Prefer to get your code from a script tag? No problem. Below are the latest versions of our CDN links on jsDeliver or UNPKG.
23 |
24 | ### jsDeliver
25 | ```html
26 |
27 | ```
28 |
29 | ### UNPKG
30 | ```html
31 |
32 | ```
--------------------------------------------------------------------------------
/docs/docs/introduction/playground.md:
--------------------------------------------------------------------------------
1 | ---
2 | sidebar_position: 4
3 | ---
4 |
5 | # Playground
6 | Need to play around with `easy-dates` in a live environment before deciding if it's the right fit? No problem.
7 |
8 | Whether you're looking for examples using `require` with CommonJS, `import` statements with ESM, or script tags in an HTML document, we've got a live demo ready to go.
9 |
10 | ## React.js
11 | This demo uses an `import` statement, Ecma Script Modules
12 |
13 | [](https://stackblitz.com/edit/easy-dates-demo?file=src/App.js)
14 |
15 | ## Node.js
16 | This demo uses a `require` statement, CommonJS
17 |
18 | [](https://stackblitz.com/edit/easy-dates-nodejs?file=index.js)
19 |
20 | ## HTML and Vanilla JS
21 | This demo uses a `