Closed ZigaStrgar closed 3 years ago
@tolu
Hey, thanks for the contribution! 🙏
I absolutely agree that this should be rectified.
I could imagine something like this, where we cover our backs for both cases of using any of the exports directly:
const defaultDuration = Object.freeze({
years: 0,
months: 0,
weeks: 0,
days: 0,
hours: 0,
minutes: 0,
seconds: 0
});
export const toSeconds = (duration, startDate) => {
duration = Object.assign({}, defaultDuration, duration)
// ...
}
export const end = (duration, startDate) => {
duration = Object.assign({}, defaultDuration, duration)
// ...
}
What do you think @ZigaStrgar?
@tolu You are welcome and I absolutely agree with your proposition and I've already made a commit to reflect that.
Motivation
Typescript declaration mentions that each of
Duration
s interface properties is optional but the case in the code it's not the same. Thus not allowing you to usetoSeconds
as a standalone function without all of the properties present in the object.Before change
After change
I know this library servers another purpose but as it already contains such functionality and it is exposed to the user, why not make it as simple as possible and require as small object as possible to calculate the value.