Skip to content

Instantly share code, notes, and snippets.

@vinicius73
Created January 2, 2018 18:32
Show Gist options
  • Save vinicius73/72888a496c2fb8e5d87b2cba041fbdf1 to your computer and use it in GitHub Desktop.
Save vinicius73/72888a496c2fb8e5d87b2cba041fbdf1 to your computer and use it in GitHub Desktop.
import moment from 'moment'
import { compose } from 'ramda'
const format = (dt, mask = 'YYYY-MM-DD') => moment.utc(dt).format(mask)
const preventFuture = dt => {
const date = moment.utc(dt)
const now = moment.utc()
return date.isAfter(now) ? now : date
}
const makeEndDate = compose(format, preventFuture)
const parseGraphqlPeriod = (start, end) => ({
start: format(start),
end: makeEndDate(end)
})
export { parseGraphqlPeriod, makeEndDate, format }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment