andrewplummer / Sugar

A Javascript library for working with native objects.
https://sugarjs.com/
MIT License
4.53k stars 306 forks source link

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

Open alFReD-NSH opened 7 years ago

alFReD-NSH commented 7 years ago

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(...));
andrewplummer commented 7 years ago

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.

alFReD-NSH commented 7 years ago

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. :)

andrewplummer commented 6 years ago

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