Sugar icon indicating copy to clipboard operation
Sugar copied to clipboard

Without opting-in into extended mode Date.create returns an ordinary non-extended date

Open alFReD-NSH opened this issue 7 years ago • 3 comments

The title says it all. Here's an example on how to reproduce it:

require('sugar').Date.create().format()

For now as a work around I'm wrapping create calls with Date:

const { Date } = require('sugar');
const myDate = Date(Date.create(...));

alFReD-NSH avatar Jul 31 '17 18:07 alFReD-NSH

This is expected behavior. The idea is that all methods on the Sugar.Date object are static methods that always return native objects, while it is required to either extend or use chainables with new Sugar.Date() for objects with extended functionality.

I realize that the signature Sugar.Date.create lends to the thinking that it would return a Sugar date as opposed to a normal one, and I also find it a bit annoying that it feels somewhat misleading. One idea I've had is to change the naming of create to parse.. Note also that this method is automatically when creating chainables so that you can do something like new Sugar.Date('tomorrow') instead of needing to do new Sugar.Date(Sugar.Date.create('tomorrow')).

I'm open to other suggestions here to help make this more intuitive if you have them.

andrewplummer avatar Jul 31 '17 23:07 andrewplummer

I think this is just a documentation issue, it makes sense. Not sure what can be added to the docs though. Feel free to close this. :)

alFReD-NSH avatar Aug 14 '17 15:08 alFReD-NSH

Going to revisit naming here for the next major verison... maybe there's a way to make this one more intuitive.

andrewplummer avatar Aug 06 '18 13:08 andrewplummer