Add a difference method to SC.DateTime #845

Closed
wants to merge 3 commits into
from

Projects

None yet

3 participants

Member

This method allow to compute the number of weeks, days, hours, minutes,
or seconds between two dates.

Nicolas BADIA Add a difference method to SC.DateTime
This method allow to compute the number of weeks, days, hours, minutes,
or seconds between two dates.
2f02e5f

+1! This would have been extremely useful on a couple of projects I worked on when a total newbie.

This code would throw an error if null values are passed in. Thoughts on some gatekeeping code? Opens up a (smallish) can of worms, might not be worth it.

Owner

I can make this method throw an error if a or b are null, but in this case, I should also do it for the compare and compareDate methods.

Not sure to understand what you mean about gatekeeping code :(

You got it - gatekeeping code is fancy words for code that quits the function early if all the ducks aren't in a row. My instinct is to return null when the arguments don't make sense (i.e. a or b is SC.none()) but I bet it would be easier for developers to debug if it threw a well-described error. Thoughts?

nicolasbadia added some commits Oct 24, 2012
@nicolasbadia nicolasbadia Throw errors is the passed parameters are invalid
As suggest by dcporter an error is now throw for the methods: compare,
compareDate and difference if the parameters are incorrect.
8322790
@nicolasbadia nicolasbadia The result should be rounded 52e0153
Owner

Cool!

Rebased directly onto master. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment