Created
January 2, 2018 18:32
-
-
Save vinicius73/72888a496c2fb8e5d87b2cba041fbdf1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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