Skip to content

Commit

Permalink
Restore isThisYear and adjust the building system
Browse files Browse the repository at this point in the history
  • Loading branch information
kossnocorp committed Jun 11, 2019
1 parent c00ef1d commit f0cdece
Show file tree
Hide file tree
Showing 10 changed files with 194 additions and 11 deletions.
33 changes: 22 additions & 11 deletions scripts/build/docs.js
Expand Up @@ -36,21 +36,32 @@ function generateDocsFromSource() {
'no-cache': true
})[0]
)
.map(doc => ({
type: 'jsdoc',
kind: 'function',
urlId: doc.name,
category: doc.category,
title: doc.name,
description: doc.summary,
content: doc
}))
.map(doc => {
const pureTag =
doc.customTags && doc.customTags.find(t => t.tag === 'pure')
const pure = (pureTag && pureTag.value) !== 'false'
return {
type: 'jsdoc',
kind: 'function',
urlId: doc.name,
category: doc.category,
title: doc.name,
description: doc.summary,
content: doc,
pure
}
})
.reduce(
(array, doc) =>
array
.concat(generateFnDoc(doc))
.concat(generateFPFnDoc(doc))
.concat(generateFPFnWithOptionsDoc(doc) || []),
.concat(
doc.pure
? [generateFPFnDoc(doc)].concat(
generateFPFnWithOptionsDoc(doc) || []
)
: []
),
[]
)

Expand Down
1 change: 1 addition & 0 deletions src/esm/index.js
Expand Up @@ -130,6 +130,7 @@ export { default as isSameWeek } from './isSameWeek/index.js'
export { default as isSameYear } from './isSameYear/index.js'
export { default as isSaturday } from './isSaturday/index.js'
export { default as isSunday } from './isSunday/index.js'
export { default as isThisYear } from './isThisYear/index.js'
export { default as isThursday } from './isThursday/index.js'
export { default as isTuesday } from './isTuesday/index.js'
export { default as isValid } from './isValid/index.js'
Expand Down
1 change: 1 addition & 0 deletions src/index.js
Expand Up @@ -103,6 +103,7 @@ module.exports = {
isSameYear: require('./isSameYear/index.js'),
isSaturday: require('./isSaturday/index.js'),
isSunday: require('./isSunday/index.js'),
isThisYear: require('./isThisYear/index.js'),
isThursday: require('./isThursday/index.js'),
isTuesday: require('./isTuesday/index.js'),
isValid: require('./isValid/index.js'),
Expand Down
2 changes: 2 additions & 0 deletions src/index.js.flow
Expand Up @@ -398,6 +398,8 @@ declare module.exports: {

isSunday: (date: Date | number) => boolean,

isThisYear: (date: string | number) => boolean,

isThursday: (date: Date | number) => boolean,

isTuesday: (date: Date | number) => boolean,
Expand Down
19 changes: 19 additions & 0 deletions src/isThisYear/benchmark.js
@@ -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()
}
}
)
4 changes: 4 additions & 0 deletions src/isThisYear/index.d.ts
@@ -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
33 changes: 33 additions & 0 deletions src/isThisYear/index.js
@@ -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)
}
38 changes: 38 additions & 0 deletions src/isThisYear/index.js.flow
@@ -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
36 changes: 36 additions & 0 deletions src/isThisYear/test.js
@@ -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)
})
})
38 changes: 38 additions & 0 deletions typings.d.ts
Expand Up @@ -559,6 +559,9 @@ declare module 'date-fns' {
function isSunday(date: Date | number): boolean
namespace isSunday {}

function isThisYear(date: string | number): boolean
namespace isThisYear {}

function isThursday(date: Date | number): boolean
namespace isThursday {}

Expand Down Expand Up @@ -1303,6 +1306,11 @@ declare module 'date-fns/isSunday' {
export default isSunday
}

declare module 'date-fns/isThisYear' {
import { isThisYear } from 'date-fns'
export default isThisYear
}

declare module 'date-fns/isThursday' {
import { isThursday } from 'date-fns'
export default isThursday
Expand Down Expand Up @@ -2088,6 +2096,11 @@ declare module 'date-fns/isSunday/index' {
export default isSunday
}

declare module 'date-fns/isThisYear/index' {
import { isThisYear } from 'date-fns'
export default isThisYear
}

declare module 'date-fns/isThursday/index' {
import { isThursday } from 'date-fns'
export default isThursday
Expand Down Expand Up @@ -2873,6 +2886,11 @@ declare module 'date-fns/isSunday/index.js' {
export default isSunday
}

declare module 'date-fns/isThisYear/index.js' {
import { isThisYear } from 'date-fns'
export default isThisYear
}

declare module 'date-fns/isThursday/index.js' {
import { isThursday } from 'date-fns'
export default isThursday
Expand Down Expand Up @@ -6988,6 +7006,9 @@ declare module 'date-fns/esm' {
function isSunday(date: Date | number): boolean
namespace isSunday {}

function isThisYear(date: string | number): boolean
namespace isThisYear {}

function isThursday(date: Date | number): boolean
namespace isThursday {}

Expand Down Expand Up @@ -7732,6 +7753,11 @@ declare module 'date-fns/esm/isSunday' {
export default isSunday
}

declare module 'date-fns/esm/isThisYear' {
import { isThisYear } from 'date-fns/esm'
export default isThisYear
}

declare module 'date-fns/esm/isThursday' {
import { isThursday } from 'date-fns/esm'
export default isThursday
Expand Down Expand Up @@ -8517,6 +8543,11 @@ declare module 'date-fns/esm/isSunday/index' {
export default isSunday
}

declare module 'date-fns/esm/isThisYear/index' {
import { isThisYear } from 'date-fns/esm'
export default isThisYear
}

declare module 'date-fns/esm/isThursday/index' {
import { isThursday } from 'date-fns/esm'
export default isThursday
Expand Down Expand Up @@ -9302,6 +9333,11 @@ declare module 'date-fns/esm/isSunday/index.js' {
export default isSunday
}

declare module 'date-fns/esm/isThisYear/index.js' {
import { isThisYear } from 'date-fns/esm'
export default isThisYear
}

declare module 'date-fns/esm/isThursday/index.js' {
import { isThursday } from 'date-fns/esm'
export default isThursday
Expand Down Expand Up @@ -15326,6 +15362,8 @@ interface dateFns {

isSunday(date: Date | number): boolean

isThisYear(date: string | number): boolean

isThursday(date: Date | number): boolean

isTuesday(date: Date | number): boolean
Expand Down

0 comments on commit f0cdece

Please sign in to comment.