time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

README.md (3222B)


      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 # isLeapYear
     22 
     23 > Test if a value corresponds to a [leap year][leap-year] in the [Gregorian calendar][gregorian-calendar].
     24 
     25 A [leap year][leap-year] is defined as any year which is exactly divisible by `4`, except for years which are exactly divisible by `100` and not by `400`. In this definition, `100` corresponds to years marking a new century, and `400` corresponds to the length of the _leap cycle_.
     26 
     27 <section class="usage">
     28 
     29 ## Usage
     30 
     31 ```javascript
     32 var isLeapYear = require( '@stdlib/assert/is-leap-year' );
     33 ```
     34 
     35 #### isLeapYear( \[value] )
     36 
     37 Tests if a `value` corresponds to a [leap year][leap-year] in the [Gregorian calendar][gregorian-calendar].
     38 
     39 ```javascript
     40 var bool = isLeapYear();
     41 // returns <boolean>
     42 
     43 bool = isLeapYear( new Date() );
     44 // returns <boolean>
     45 
     46 bool = isLeapYear( 2000 );
     47 // returns true
     48 
     49 bool = isLeapYear( 2017 );
     50 // returns false
     51 ```
     52 
     53 </section>
     54 
     55 <!-- /.usage -->
     56 
     57 <section class="notes">
     58 
     59 ## Notes
     60 
     61 -   If not provided any `arguments`, the function returns a `boolean` indicating if the current year (according to local time) is a [leap year][leap-year].
     62 
     63 -   If provided a `value` which is neither an integer value nor a [`Date`][date-object], the function **always** returns `false`.
     64 
     65     ```javascript
     66     var bool = isLeapYear( '2016' );
     67     // returns false
     68 
     69     bool = isLeapYear( null );
     70     // returns false
     71     ```
     72 
     73 </section>
     74 
     75 <!-- /.notes -->
     76 
     77 <section class="examples">
     78 
     79 ## Examples
     80 
     81 <!-- eslint no-undef: "error" -->
     82 
     83 ```javascript
     84 var isLeapYear = require( '@stdlib/assert/is-leap-year' );
     85 
     86 var bool;
     87 var i;
     88 
     89 for ( i = 0; i < 2021; i++ ) {
     90     bool = isLeapYear( i );
     91     console.log( 'The year %d %s a leap year.', i, ( bool ) ? 'is' : 'is not' );
     92 }
     93 ```
     94 
     95 </section>
     96 
     97 <!-- /.examples -->
     98 
     99 * * *
    100 
    101 <section class="cli">
    102 
    103 ## CLI
    104 
    105 <section class="usage">
    106 
    107 ### Usage
    108 
    109 ```text
    110 Usage: is-leap-year [options] [<year>]
    111 
    112 Options:
    113 
    114   -h,    --help                Print this message.
    115   -V,    --version             Print the package version.
    116 ```
    117 
    118 </section>
    119 
    120 <!-- /.usage -->
    121 
    122 <section class="examples">
    123 
    124 ### Examples
    125 
    126 ```bash
    127 $ is-leap-year
    128 <boolean>
    129 
    130 $ is-leap-year 1993
    131 false
    132 ```
    133 
    134 To use as a [standard stream][standard-streams],
    135 
    136 ```bash
    137 $ echo -n 1992 | is-leap-year
    138 true
    139 ```
    140 
    141 </section>
    142 
    143 <!-- /.examples -->
    144 
    145 </section>
    146 
    147 <!-- /.cli -->
    148 
    149 <section class="links">
    150 
    151 [leap-year]: https://en.wikipedia.org/wiki/Leap_year
    152 
    153 [gregorian-calendar]: https://en.wikipedia.org/wiki/Gregorian_calendar
    154 
    155 [date-object]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date
    156 
    157 [standard-streams]: https://en.wikipedia.org/wiki/Standard_streams
    158 
    159 </section>
    160 
    161 <!-- /.links -->