Skip to content

Commit

Permalink
Add isSameOrAfter and isSameOrBefore
Browse files Browse the repository at this point in the history
  • Loading branch information
ichernev committed Jan 2, 2016
1 parent 8cf85ce commit cf9e6a1
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 0 deletions.
31 changes: 31 additions & 0 deletions docs/moment/05-query/04-is-same-or-before.md
@@ -0,0 +1,31 @@
---
title: Is Same or Before
version: 2.10.7
signature: |
moment().isSameOrBefore(Moment|String|Number|Date|Array);
moment().isSameOrBefore(Moment|String|Number|Date|Array, String);
---

Check if a moment is before or the same as another moment.

```javascript
moment('2010-10-20').isSameOrBefore('2010-10-21'); // true
moment('2010-10-20').isSameOrBefore('2010-10-20'); // true
moment('2010-10-20').isSameOrBefore('2010-10-19'); // false
```

If you want to limit the granularity to a unit other than milliseconds, pass the units as the second parameter.

As the second parameter determines the precision, and not just a single value to check, using day will check for year, month and day.

```javascript
moment('2010-10-20').isSameOrBefore('2009-12-31', 'year'); // false
moment('2010-10-20').isSameOrBefore('2010-12-31', 'year'); // true
moment('2010-10-20').isSameOrBefore('2011-01-01', 'year'); // true
```

Like `moment#isAfter` and `moment#isSame`, any of the units of time that are supported for `moment#startOf` are supported for `moment#isSameOrBefore`:

```
year month week day hour minute second
```
32 changes: 32 additions & 0 deletions docs/moment/05-query/05-is-same-or-after.md
@@ -0,0 +1,32 @@
---
title: Is Same Or After
version: 2.10.7
signature: |
moment().isSameOrAfter(Moment|String|Number|Date|Array);
moment().isSameOrAfter(Moment|String|Number|Date|Array, String);
---


Check if a moment is after or the same as another moment.

```javascript
moment('2010-10-20').isSameOrAfter('2010-10-19'); // true
moment('2010-10-20').isSameOrAfter('2010-10-20'); // true
moment('2010-10-20').isSameOrAfter('2010-10-21'); // false
```

If you want to limit the granularity to a unit other than milliseconds, pass the units as the second parameter.

As the second parameter determines the precision, and not just a single value to check, using day will check for year, month and day.

```javascript
moment('2010-10-20').isSameOrAfter('2011-12-31', 'year'); // false
moment('2010-10-20').isSameOrAfter('2010-01-01', 'year'); // true
moment('2010-10-20').isSameOrAfter('2009-12-31', 'year'); // true
```

Like `moment#isSame` and `moment#isBefore`, any of the units of time that are supported for `moment#startOf` are supported for `moment#isSameOrAfter`:

```
year month week day hour minute second
```
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit cf9e6a1

Please sign in to comment.