Closed gajus closed 5 years ago
As a quick workaround, I have used:
import parseInterval from 'postgres-interval';
import {
parse as parseIsoDuration,
toSeconds as durationToSeconds
} from 'iso8601-duration';
durationToSeconds(parseIsoDuration(parseInterval(value).toISOString()));
I'd be happy to review a PR!
You should be able to pass postgres-interval objects to moment.duration
. From there, you can do whatever you want with it.
I'd recommend against adding functionality like toSeconds
and instead point people in that direction.
After reading the original post a bit more carefully, I'm inclined to agree. We're not looking to build up a complete Interval
class here and returning standardized (8601) output should be good enough to interop with other tools to provide additional functionality.
I am doing a lot of
round(extract(epoch from intervalField))
.It would be handy if postgres-interval parser gave this as an option.