JerrySievert / date-utils

Date Pollyfills for Node.js and Browser
https://jerrysievert.github.io/date-utils/
MIT License
373 stars 60 forks source link

Version 2 Feature Discussion #37

Open JerrySievert opened 11 years ago

JerrySievert commented 11 years ago

Let's talk about possible features and changes for version 2!

joe-spanning commented 11 years ago

I would be nice if there was a version that does not alter the default Date object prototype.

JerrySievert commented 11 years ago

Check out cromag.js

blmarket commented 10 years ago

I want crop feature. sometimes I need to set milisecond, second, minute field to zero. I'd like to see that feature in date-utils.

turbokuzmich commented 10 years ago

What about i18n? :)

bebraw commented 10 years ago

Just to continue on #36 and compacting the API, I would propose the following:

Doing this would remove 20-21 functions/methods from the API depending whether you go with offset.

Maybe there are other ways to compact but these seem the most obvious.

JerrySievert commented 10 years ago

i like the idea of compacting the api - want to finish documenting everything so there is fresh knowledge, and a good tag for 1.x.

jadrake75 commented 10 years ago

It would be nice if the toFormat( ) series of functions took symbols for timezones such as Z etc. So we can generate string dates that have an offset of -05:00 for example

JerrySievert commented 10 years ago

@jadrake75 if you can expand that into a set of rules, it would help a lot - at that point we can talk about a complete ruleset and set up boundaries.

jonstorer commented 10 years ago

I would love chainable ruby/rails like dates (I know this is js, but bare with me). I would love to be able to code:

7.days().from_now()
14.minutes().ago()

I realize that we're not going to extend the Number object, but something like.

Date.integer(7).days().from_now().at_beginning_of_day() // hh:mm:ss.ms / 00:00:00.000
Date.integer(7).days().from_now().at_end_of_day() // hh:mm:ss.ms / 23:59:99.999
Date.i(14).minutes.ago()
Date.i(15).days().since(Date.i(1).week().ago())
Date.between(new Date("1/1/2014"), new Date("12/11/2014")).days()

would be amazing!

sfeldkamp commented 9 years ago

I would like to see a static method added as a proxy to calling the constructor. This would ease testing by providing a method that can be easily mocked. Perhaps... Date.now()? We already have Date.today() so this would be very similar.

I may be missing something with testing as I'm just getting started, however I can't figure out how to mock a constructor using Jest.

In fact I think I will fork and add this. Would you consider a pull request to add it?

JerrySievert commented 9 years ago

i'm curious what this would add, since it would be a synonym to new Date().

as an aside, Date.now() is already taken :)

sfeldkamp commented 9 years ago

It is indeed. I've given it some more thought and I don't think it would help me with testing anyway since date-utils extends the global Date object. As far as I know Jest doesn't have a way to mock objects/methods unless they can be loaded with require(). Sorry for the spurious suggestion.

The library is very nice, thank you for providing it.

ORBAT commented 9 years ago

to(UTC)Format's formatting patterns could be more like what other languages use for specifying date formats; the current patterns are a tad surprising at times (like having HH24 for 24h padded time, but HH for 12h padded, and no way of having unpadded 24h hours). Java's patterns are, surprisingly enough, easy to use and follow. With patterns akin to Java's, the more letters you have in the pattern the longer the output you get (either more padding or abbreviated/long forms of words), and patterns use both lower and upper case.

Some examples:

etc.

alexcoady commented 9 years ago

An ordinal suffix for the day of month, like 2nd, 6th, etc would be incredibly useful. Like the S flag in PHP's date format function.