Sugar
Sugar copied to clipboard
Without opting-in into extended mode Date.create returns an ordinary non-extended date
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(...));
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.
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. :)
Going to revisit naming here for the next major verison... maybe there's a way to make this one more intuitive.