-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
54 lines (48 loc) · 1.11 KB
/
index.js
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
/**
* current-day-number <https://github.com/datetime/current-day-number>
*
* Copyright (c) 2014-2015 Charlike Mike Reagent, contributors.
* Released under the MIT license.
*/
'use strict';
var daySeconds = require('day-seconds');
/**
* Get day number of the current date/year or given valid `Date` string format
*
* **Example:**
*
* ```js
* var currentDayNumber = require('current-day-number');
*
* // june 27, 2014
* currentDayNumber();
* //=> 177
*
* currentDayNumber('');
* //=> 177
*
* currentDayNumber('August 07, 2015');
* //=> 218
*
* currentDayNumber('August 07, 2016');
* //=> 219, cuz' year is leap
*
* currentDayNumber('02/16/2015');
* //=> 47
* ```
*
* @name currentDayNumber
* @param {String} `[date]` every valid Date-ish string format
* @return {Number}
* @api public
*/
module.exports = function currentDayNumber(date) {
var instance = new Date();
if (typeof date === 'string' && date.length) {
instance = new Date(date);
}
var now = instance.getTime();
var start = instance.setMonth(0,0);
var diff = now - start;
return (diff / daySeconds(false)) | 0;
};