mirror of
https://github.com/jbranchaud/til
synced 2026-01-03 23:28:02 +00:00
Add New Dates Can Take Out Of Bounds Values as a javascript til
This commit is contained in:
@@ -10,7 +10,7 @@ smart people at [Hashrocket](http://hashrocket.com/).
|
|||||||
For a steady stream of TILs from a variety of rocketeers, checkout
|
For a steady stream of TILs from a variety of rocketeers, checkout
|
||||||
[til.hashrocket.com](https://til.hashrocket.com/).
|
[til.hashrocket.com](https://til.hashrocket.com/).
|
||||||
|
|
||||||
_617 TILs and counting..._
|
_618 TILs and counting..._
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -233,6 +233,7 @@ _617 TILs and counting..._
|
|||||||
- [Install The Latest Version Of Node With Nvm](javascript/install-the-latest-version-of-node-with-nvm.md)
|
- [Install The Latest Version Of Node With Nvm](javascript/install-the-latest-version-of-node-with-nvm.md)
|
||||||
- [ISO-8601 Formatted Dates Are Interpreted As UTC](javascript/iso-8601-formatted-dates-are-interpreted-as-utc.md)
|
- [ISO-8601 Formatted Dates Are Interpreted As UTC](javascript/iso-8601-formatted-dates-are-interpreted-as-utc.md)
|
||||||
- [Matching Multiple Values In A Switch Statement](javascript/matching-multiple-values-in-a-switch-statement.md)
|
- [Matching Multiple Values In A Switch Statement](javascript/matching-multiple-values-in-a-switch-statement.md)
|
||||||
|
- [New Dates Can Take Out Of Bounds Values](javascript/new-dates-can-take-out-of-bounds-values.md)
|
||||||
- [Numbers Are Empty](javascript/numbers-are-empty.md)
|
- [Numbers Are Empty](javascript/numbers-are-empty.md)
|
||||||
- [Object Initialization With Shorthand Property Names](javascript/object-initialization-with-shorthand-property-names.md)
|
- [Object Initialization With Shorthand Property Names](javascript/object-initialization-with-shorthand-property-names.md)
|
||||||
- [Random Cannot Be Seeded](javascript/random-cannot-be-seeded.md)
|
- [Random Cannot Be Seeded](javascript/random-cannot-be-seeded.md)
|
||||||
|
|||||||
36
javascript/new-dates-can-take-out-of-bounds-values.md
Normal file
36
javascript/new-dates-can-take-out-of-bounds-values.md
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
# New Dates Can Take Out Of Bounds Values
|
||||||
|
|
||||||
|
You can create a new date by feeding it arguments for _year_, _month_, and
|
||||||
|
_day_.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
> new Date(2017, 11, 31)
|
||||||
|
Sun Dec 31 2017 00:00:00 GMT-0600 (CST)
|
||||||
|
```
|
||||||
|
|
||||||
|
What happens if we push the _day_ value out of bounds?
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
> new Date(2017, 11, 32)
|
||||||
|
Mon Jan 01 2018 00:00:00 GMT-0600 (CST)
|
||||||
|
```
|
||||||
|
|
||||||
|
It rolls over to the next month.
|
||||||
|
|
||||||
|
Does the same happen when we push the _month_ value out of bounds?
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
> new Date(2017, 12, 31)
|
||||||
|
Wed Jan 31 2018 00:00:00 GMT-0600 (CST)
|
||||||
|
```
|
||||||
|
|
||||||
|
Yep.
|
||||||
|
|
||||||
|
What about negative values?
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
> new Date(2018, -1, 31)
|
||||||
|
Sun Dec 31 2017 00:00:00 GMT-0600 (CST)
|
||||||
|
```
|
||||||
|
|
||||||
|
It rolls the month, and consequently the year, back.
|
||||||
Reference in New Issue
Block a user