···11+MIT License
22+33+Copyright (c) 2019 Wojciech Maj
44+55+Permission is hereby granted, free of charge, to any person obtaining a copy
66+of this software and associated documentation files (the "Software"), to deal
77+in the Software without restriction, including without limitation the rights
88+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
99+copies of the Software, and to permit persons to whom the Software is
1010+furnished to do so, subject to the following conditions:
1111+1212+The above copyright notice and this permission notice shall be included in all
1313+copies or substantial portions of the Software.
1414+1515+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1616+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1717+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1818+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121+SOFTWARE.
···11+# Date-Utils
22+A collection of date-related utilities.
33+44+## tl;dr
55+* Install by executing `npm install @wojtekmaj/date-utils` or `yarn add @wojtekmaj/date-utils`.
66+* Import by adding `import * as dateUtils from '@wojtekmaj/date-utils`.
77+* Do stuff with it!
88+ ```js
99+ const now = new Date();
1010+ const beginOfCentury = getBeginOfCentury(now);
1111+ ```
1212+1313+## User guide
1414+1515+### General getters
1616+1717+#### `getYear()`
1818+1919+Gets year from a given date.
2020+2121+##### Sample usage
2222+2323+```js
2424+import { getYear } from '@wojtekmaj/date-utils';
2525+2626+getYear(new Date(2019, 0, 1); // 2019
2727+```
2828+2929+#### `getMonth()`
3030+3131+Gets month index from a given date. For example, returns 0 for January, 1 for February and so on.
3232+3333+##### Sample usage
3434+3535+```js
3636+import { getMonth } from '@wojtekmaj/date-utils';
3737+3838+getMonth(new Date(2019, 0, 1); // 0
3939+```
4040+4141+#### `getMonthHuman()`
4242+4343+Gets human-readable month number from a given date. For example, returns 1 for January, 2 for February and so on.
4444+4545+##### Sample usage
4646+4747+```js
4848+import { getMonth } from '@wojtekmaj/date-utils';
4949+5050+getMonth(new Date(2019, 0, 1); // 1
5151+```
5252+5353+#### `getDate()`
5454+5555+Gets day of the month from a given date.
5656+5757+##### Sample usage
5858+5959+```js
6060+import { getDate } from '@wojtekmaj/date-utils';
6161+6262+getDate(new Date(2019, 0, 15); // 15
6363+```
6464+6565+### Century-related getters
6666+6767+#### `getCenturyStart()`
6868+6969+Gets century start date from a given date.
7070+7171+##### Sample usage
7272+7373+```js
7474+import { getCenturyStart } from '@wojtekmaj/date-utils';
7575+7676+getCenturyStart(new Date(2019, 0, 1)); // new Date(2001, 0, 1)
7777+```
7878+7979+#### `getCenturyEnd()`
8080+8181+Gets century start date from a given date.
8282+8383+##### Sample usage
8484+8585+```js
8686+import { getCenturyEnd } from '@wojtekmaj/date-utils';
8787+8888+getCenturyEnd(new Date(2019, 0, 1)); // new Date(2100, 12, 31, 23, 59, 999)
8989+```
9090+9191+#### `getPreviousCenturyStart()`
9292+9393+Gets previous century start date from a given date.
9494+9595+##### Sample usage
9696+9797+```js
9898+import { getPreviousCenturyStart } from '@wojtekmaj/date-utils';
9999+100100+getPreviousCenturyStart(new Date(2019, 0, 1)); // new Date(1901, 0, 1)
101101+```
102102+103103+#### `getPreviousCenturyEnd()`
104104+105105+Gets century start date from a given date.
106106+107107+##### Sample usage
108108+109109+```js
110110+import { getPreviousCenturyEnd } from '@wojtekmaj/date-utils';
111111+112112+getPreviousCenturyEnd(new Date(2019, 0, 1)); // new Date(2000, 12, 31, 23, 59, 999)
113113+```
114114+115115+#### `getNextCenturyStart()`
116116+117117+Gets next century start date from a given date.
118118+119119+##### Sample usage
120120+121121+```js
122122+import { getNextCenturyStart } from '@wojtekmaj/date-utils';
123123+124124+getNextCenturyStart(new Date(2019, 0, 1)); // new Date(2101, 0, 1)
125125+```
126126+127127+#### `getNextCenturyEnd()`
128128+129129+Gets next century start date from a given date.
130130+131131+##### Sample usage
132132+133133+```js
134134+import { getNextCenturyEnd } from '@wojtekmaj/date-utils';
135135+136136+getNextCenturyEnd(new Date(2019, 0, 1)); // new Date(2200, 12, 31, 23, 59, 999)
137137+```
138138+139139+#### `getCenturyRange()`
140140+141141+Gets century range from a given date. Returns an array of values equal to the ones returned by `getCenturyStart()` and `getCenturyEnd()`.
142142+143143+##### Sample usage
144144+145145+```js
146146+import { getCenturyRange } from '@wojtekmaj/date-utils';
147147+148148+getCenturyRange(new Date(2019, 0, 1)); // [new Date(2001, 0, 1), new Date(2100, 12, 31, 23, 59, 999)
149149+```
150150+151151+### Decade-related getters
152152+153153+#### `getDecadeStart()`
154154+155155+Gets decade start date from a given date.
156156+157157+##### Sample usage
158158+159159+```js
160160+import { getDecadeStart } from '@wojtekmaj/date-utils';
161161+162162+getDecadeStart(new Date(2019, 0, 1)); // new Date(2011, 0, 1)
163163+```
164164+165165+#### `getDecadeEnd()`
166166+167167+Gets decade start date from a given date.
168168+169169+##### Sample usage
170170+171171+```js
172172+import { getDecadeEnd } from '@wojtekmaj/date-utils';
173173+174174+getDecadeEnd(new Date(2019, 0, 1)); // new Date(2020, 12, 31, 23, 59, 999)
175175+```
176176+177177+#### `getPreviousDecadeStart()`
178178+179179+Gets previous decade start date from a given date.
180180+181181+##### Sample usage
182182+183183+```js
184184+import { getPreviousDecadeStart } from '@wojtekmaj/date-utils';
185185+186186+getPreviousDecadeStart(new Date(2019, 0, 1)); // new Date(2001, 0, 1)
187187+```
188188+189189+#### `getPreviousDecadeEnd()`
190190+191191+Gets decade start date from a given date.
192192+193193+##### Sample usage
194194+195195+```js
196196+import { getPreviousDecadeEnd } from '@wojtekmaj/date-utils';
197197+198198+getPreviousDecadeEnd(new Date(2019, 0, 1)); // new Date(2010, 12, 31, 23, 59, 999)
199199+```
200200+201201+#### `getNextDecadeStart()`
202202+203203+Gets next decade start date from a given date.
204204+205205+##### Sample usage
206206+207207+```js
208208+import { getNextDecadeStart } from '@wojtekmaj/date-utils';
209209+210210+getNextDecadeStart(new Date(2019, 0, 1)); // new Date(2021, 0, 1)
211211+```
212212+213213+#### `getNextDecadeEnd()`
214214+215215+Gets next decade start date from a given date.
216216+217217+##### Sample usage
218218+219219+```js
220220+import { getNextDecadeEnd } from '@wojtekmaj/date-utils';
221221+222222+getNextDecadeEnd(new Date(2019, 0, 1)); // new Date(2030, 12, 31, 23, 59, 999)
223223+```
224224+225225+#### `getDecadeRange()`
226226+227227+Gets decade range from a given date. Returns an array of values equal to the ones returned by `getDecadeStart()` and `getDecadeEnd()`.
228228+229229+##### Sample usage
230230+231231+```js
232232+import { getDecadeRange } from '@wojtekmaj/date-utils';
233233+234234+getDecadeRange(new Date(2019, 0, 1)); // [new Date(2011, 0, 1), new Date(2020, 12, 31, 23, 59, 999)
235235+```
236236+237237+### Year-related getters
238238+239239+#### `getYearStart()`
240240+241241+Gets year start date from a given date.
242242+243243+##### Sample usage
244244+245245+```js
246246+import { getYearStart } from '@wojtekmaj/date-utils';
247247+248248+getYearStart(new Date(2019, 6, 1)); // new Date(2019, 0, 1)
249249+```
250250+251251+#### `getYearEnd()`
252252+253253+Gets year start date from a given date.
254254+255255+##### Sample usage
256256+257257+```js
258258+import { getYearEnd } from '@wojtekmaj/date-utils';
259259+260260+getYearEnd(new Date(2019, 6, 1)); // new Date(2019, 12, 31, 23, 59, 999)
261261+```
262262+263263+#### `getPreviousYearStart()`
264264+265265+Gets previous year start date from a given date.
266266+267267+##### Sample usage
268268+269269+```js
270270+import { getPreviousYearStart } from '@wojtekmaj/date-utils';
271271+272272+getPreviousYearStart(new Date(2019, 6, 1)); // new Date(2018, 0, 1)
273273+```
274274+275275+#### `getPreviousYearEnd()`
276276+277277+Gets year start date from a given date.
278278+279279+##### Sample usage
280280+281281+```js
282282+import { getPreviousYearEnd } from '@wojtekmaj/date-utils';
283283+284284+getPreviousYearEnd(new Date(2019, 6, 1)); // new Date(2018, 12, 31, 23, 59, 999)
285285+```
286286+287287+#### `getNextYearStart()`
288288+289289+Gets next year start date from a given date.
290290+291291+##### Sample usage
292292+293293+```js
294294+import { getNextYearStart } from '@wojtekmaj/date-utils';
295295+296296+getNextYearStart(new Date(2019, 6, 1)); // new Date(2020, 0, 1)
297297+```
298298+299299+#### `getNextYearEnd()`
300300+301301+Gets next year start date from a given date.
302302+303303+##### Sample usage
304304+305305+```js
306306+import { getNextYearEnd } from '@wojtekmaj/date-utils';
307307+308308+getNextYearEnd(new Date(2019, 6, 1)); // new Date(2020, 12, 31, 23, 59, 999)
309309+```
310310+311311+#### `getYearRange()`
312312+313313+Gets year range from a given date. Returns an array of values equal to the ones returned by `getYearStart()` and `getYearEnd()`.
314314+315315+##### Sample usage
316316+317317+```js
318318+import { getYearRange } from '@wojtekmaj/date-utils';
319319+320320+getYearRange(new Date(2019, 6, 1)); // [new Date(2019, 0, 1), new Date(2019, 12, 31, 23, 59, 999)
321321+```
322322+323323+### Month-related getters
324324+325325+#### `getMonthStart()`
326326+327327+Gets month start date from a given date.
328328+329329+##### Sample usage
330330+331331+```js
332332+import { getMonthStart } from '@wojtekmaj/date-utils';
333333+334334+getMonthStart(new Date(2019, 6, 15)); // new Date(2019, 6, 1)
335335+```
336336+337337+#### `getMonthEnd()`
338338+339339+Gets month start date from a given date.
340340+341341+##### Sample usage
342342+343343+```js
344344+import { getMonthEnd } from '@wojtekmaj/date-utils';
345345+346346+getMonthEnd(new Date(2019, 6, 15)); // new Date(2019, 6, 31, 23, 59, 999)
347347+```
348348+349349+#### `getPreviousMonthStart()`
350350+351351+Gets previous month start date from a given date.
352352+353353+##### Sample usage
354354+355355+```js
356356+import { getPreviousMonthStart } from '@wojtekmaj/date-utils';
357357+358358+getPreviousMonthStart(new Date(2019, 6, 15)); // new Date(2019, 5, 1)
359359+```
360360+361361+#### `getPreviousMonthEnd()`
362362+363363+Gets month start date from a given date.
364364+365365+##### Sample usage
366366+367367+```js
368368+import { getPreviousMonthEnd } from '@wojtekmaj/date-utils';
369369+370370+getPreviousMonthEnd(new Date(2019, 6, 15)) // new Date(2019, 5, 30, 23, 59, 999)
371371+```
372372+373373+#### `getNextMonthStart()`
374374+375375+Gets next month start date from a given date.
376376+377377+##### Sample usage
378378+379379+```js
380380+import { getNextMonthStart } from '@wojtekmaj/date-utils';
381381+382382+getNextMonthStart(new Date(2019, 6, 15)); // new Date(2019, 7, 1)
383383+```
384384+385385+#### `getNextMonthEnd()`
386386+387387+Gets next month start date from a given date.
388388+389389+##### Sample usage
390390+391391+```js
392392+import { getNextMonthEnd } from '@wojtekmaj/date-utils';
393393+394394+getNextMonthEnd(new Date(2019, 6, 15)); // new Date(2019, 7, 31, 23, 59, 999)
395395+```
396396+397397+#### `getMonthRange()`
398398+399399+Gets month range from a given date. Returns an array of values equal to the ones returned by `getMonthStart()` and `getMonthEnd()`.
400400+401401+##### Sample usage
402402+403403+```js
404404+import { getMonthRange } from '@wojtekmaj/date-utils';
405405+406406+getMonthRange(new Date(2019, 6, 15)); // [new Date(2019, 6, 1), new Date(2019, 6, 31, 23, 59, 999)
407407+```
408408+409409+## License
410410+411411+The MIT License.
412412+413413+## Author
414414+415415+<table>
416416+ <tr>
417417+ <td>
418418+ <img src="https://github.com/wojtekmaj.png?s=100" width="100">
419419+ </td>
420420+ <td>
421421+ Wojciech Maj<br />
422422+ <a href="mailto:kontakt@wojtekmaj.pl">kontakt@wojtekmaj.pl</a><br />
423423+ <a href="http://wojtekmaj.pl">http://wojtekmaj.pl</a>
424424+ </td>
425425+ </tr>
426426+</table>