pd4d10 / moment

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Discussion] Features, API design... anything

pd4d10 opened this issue · comments

Dear Dart developers:

I started this project several months ago, aimed to build a Moment.js like library for Dart. Then I found that DateTime (Dart's std lib) is powerful enough to handle most of use cases, so this project is unmaintained since then.

Now I've noticed that this project is watched or stared by several people, and get its first PR (#1 ). So I open this issue to hear your thoughts. Any kind of discussion is appreciated.

Thanks!

just like in my PR :D just refactor your lib and return always DateTime and this lib will be nice with native DartTime lib :D

One of the features of moment.js that I appreciated was its parsing abilities. That seems lacking in the standard DateTime. Unless there's another solution I am missing, I've found that you can format a DateTime into a localized string easily but can't get it from a localized string back into a DateTime using the constructor. The underlying code wants the input string in a certain format while I'm wanting it to respect the locale.

I've used .startOf and .endOf in moment.js as well, though they are not as critical as the parsing (to me).

I've looked at the moment.js code to see how easily the parsing logic could be ported over to Dart, but I'm not quite ready yet to put in the time to tackle that. It is on my list unless a better solution is out there.

I created my own DateUtils class to handle parsing/formatting. Which is just a convenience wrapper for the intl.dart library. So I feel like there is an opportunity to extend some convenience that moment.js provides.

I'm happy to share my file for feedback and discussion.

Currently looking for a solution to moment's "Calendar Time" so there is that

commented

Although I also think parsing would be very useful, I haven't been able to find a nice solution for how moment handles relative time:

moment("20111031", "YYYYMMDD").fromNow(); // 7 years ago
moment("20120620", "YYYYMMDD").fromNow(); // 7 years ago
moment().startOf('day').fromNow();        // 12 hours ago
moment().endOf('day').fromNow();          // in 12 hours
moment().startOf('hour').fromNow();       // 31 minutes ago

There is a project called timeago which will handle relative past DateTimes, but it doesn't work for future DateTimes (just returns "now ago") which is fine given the scope of that project but I would rather use moment.