README.md (2662B)
1 <!-- 2 3 @license Apache-2.0 4 5 Copyright (c) 2018 The Stdlib Authors. 6 7 Licensed under the Apache License, Version 2.0 (the "License"); 8 you may not use this file except in compliance with the License. 9 You may obtain a copy of the License at 10 11 http://www.apache.org/licenses/LICENSE-2.0 12 13 Unless required by applicable law or agreed to in writing, software 14 distributed under the License is distributed on an "AS IS" BASIS, 15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 See the License for the specific language governing permissions and 17 limitations under the License. 18 19 --> 20 21 # dayOfYear 22 23 > Determine the day of the year. 24 25 <section class="usage"> 26 27 ## Usage 28 29 ```javascript 30 var dayOfYear = require( '@stdlib/time/day-of-year' ); 31 ``` 32 33 #### dayOfYear( \[month\[, day, year]] ) 34 35 Returns the day of the year. 36 37 ```javascript 38 var num = dayOfYear(); 39 // returns <number> 40 ``` 41 42 By default, the function returns the day of the year for the current date (according to local time). To determine the day of the year for a particular day, provide `month`, `day`, and `year` arguments. 43 44 ```javascript 45 var num = dayOfYear( 12, 31, 2016 ); 46 // returns 366 47 48 num = dayOfYear( 12, 31, 2017 ); 49 // returns 365 50 ``` 51 52 A `month` may be either a month's integer value, three letter abbreviation, or full name (case insensitive). 53 54 ```javascript 55 var num = dayOfYear( 12, 31, 2016 ); 56 // returns 366 57 58 num = dayOfYear( 'dec', 31, 2016 ); 59 // returns 366 60 61 num = dayOfYear( 'december', 31, 2016 ); 62 // returns 366 63 ``` 64 65 The function also supports providing a [`Date`][date-object] object. 66 67 ```javascript 68 var num = dayOfYear( new Date() ); 69 // returns <number> 70 ``` 71 72 </section> 73 74 <!-- /.usage --> 75 76 <section class="examples"> 77 78 ## Examples 79 80 <!-- eslint no-undef: "error" --> 81 82 ```javascript 83 var dayOfYear = require( '@stdlib/time/day-of-year' ); 84 85 var v; 86 var i; 87 88 for ( i = 0; i < 2021; i++ ) { 89 v = dayOfYear( 'Dec', 31, i ); 90 console.log( 'In the year %d, December 31 is day number %d.', i, v ); 91 } 92 ``` 93 94 </section> 95 96 <!-- /.examples --> 97 98 * * * 99 100 <section class="cli"> 101 102 ## CLI 103 104 <section class="usage"> 105 106 ### Usage 107 108 ```text 109 Usage: day-of-year [options] [<month> <day> <year>] 110 111 Options: 112 113 -h, --help Print this message. 114 -V, --version Print the package version. 115 ``` 116 117 </section> 118 119 <!-- /.usage --> 120 121 <section class="examples"> 122 123 ### Examples 124 125 ```bash 126 $ day-of-year 127 <number> 128 ``` 129 130 For a specific date, 131 132 ```bash 133 $ day-of-year 12 31 2016 134 366 135 ``` 136 137 </section> 138 139 <!-- /.examples --> 140 141 </section> 142 143 <!-- /.cli --> 144 145 <section class="links"> 146 147 [date-object]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date 148 149 </section> 150 151 <!-- /.links -->