Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restore isThisYear and adjust the building system
- Loading branch information
1 parent
c00ef1d
commit f0cdece
Showing
10 changed files
with
194 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// @flow | ||
/* eslint-env mocha */ | ||
/* global suite, benchmark */ | ||
|
||
import isThisYear from '.' | ||
|
||
suite( | ||
'isThisYear', | ||
() => { | ||
benchmark('date-fns', function() { | ||
return isThisYear(this.date) | ||
}) | ||
}, | ||
{ | ||
setup: function() { | ||
this.date = new Date() | ||
} | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it. | ||
|
||
import { isThisYear } from 'date-fns' | ||
export default isThisYear |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import isSameYear from '../isSameYear/index.js' | ||
|
||
/** | ||
* @name isThisYear | ||
* @category Year Helpers | ||
* @summary Is the given date in the same year as the current date? | ||
* @pure false | ||
* | ||
* @description | ||
* Is the given date in the same year as the current date? | ||
* | ||
* > ⚠️ Please note that this function is not present in the FP submodule as | ||
* > it uses `Date.now()` internally hence impure and can't be safely curried. | ||
* | ||
* @param {String|Number} date - the date to check | ||
* @returns {Boolean} the date is in this year | ||
* @throws {TypeError} 1 argument required | ||
* | ||
* @example | ||
* // If today is 25 September 2014, is 2 July 2014 in this year? | ||
* var result = isThisYear(new Date(2014, 6, 2)) | ||
* //=> true | ||
*/ | ||
|
||
export default function isThisYear(dirtyDate) { | ||
if (arguments.length < 1) { | ||
throw new TypeError( | ||
'1 argument required, but only ' + arguments.length + ' present' | ||
) | ||
} | ||
|
||
return isSameYear(Date.now(), dirtyDate) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// @flow | ||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it. | ||
|
||
type Interval = { | ||
start: Date | number, | ||
end: Date | number | ||
} | ||
|
||
type Locale = { | ||
formatDistance: Function, | ||
formatRelative: Function, | ||
localize: { | ||
ordinalNumber: Function, | ||
era: Function, | ||
quarter: Function, | ||
month: Function, | ||
day: Function, | ||
dayPeriod: Function | ||
}, | ||
formatLong: Object, | ||
date: Function, | ||
time: Function, | ||
dateTime: Function, | ||
match: { | ||
ordinalNumber: Function, | ||
era: Function, | ||
quarter: Function, | ||
month: Function, | ||
day: Function, | ||
dayPeriod: Function | ||
}, | ||
options?: { | ||
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6, | ||
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | ||
} | ||
} | ||
|
||
declare module.exports: (date: string | number) => boolean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// @flow | ||
/* eslint-env mocha */ | ||
|
||
import assert from 'assert' | ||
import sinon from 'sinon' | ||
import isThisYear from '.' | ||
|
||
describe('isThisYear', () => { | ||
let clock | ||
beforeEach(() => { | ||
clock = sinon.useFakeTimers(new Date(2014, 8 /* Sep */, 25).getTime()) | ||
}) | ||
|
||
afterEach(() => { | ||
clock.restore() | ||
}) | ||
|
||
it('returns true if the given date and the current date have the same year', () => { | ||
var date = new Date(2014, 6 /* Jul */, 2) | ||
assert(isThisYear(date) === true) | ||
}) | ||
|
||
it('returns false if the given date and the current date have different years', () => { | ||
var date = new Date(2015, 6 /* Jul */, 2) | ||
assert(isThisYear(date) === false) | ||
}) | ||
|
||
it('accepts a timestamp', () => { | ||
var date = new Date(2014, 6 /* Jul */, 2).getTime() | ||
assert(isThisYear(date) === true) | ||
}) | ||
|
||
it('throws TypeError exception if passed less than 1 argument', function() { | ||
assert.throws(isThisYear.bind(null), TypeError) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters