Coder Social home page Coder Social logo

Comments (14)

jadrake75 avatar jadrake75 commented on August 16, 2024 1

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

from date-utils.

joe-spanning avatar joe-spanning commented on August 16, 2024

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

from date-utils.

JerrySievert avatar JerrySievert commented on August 16, 2024

Check out cromag.js

from date-utils.

blmarket avatar blmarket commented on August 16, 2024

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.

from date-utils.

turbokuzmich avatar turbokuzmich commented on August 16, 2024

What about i18n? :)

from date-utils.

bebraw avatar bebraw commented on August 16, 2024

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

  • Instead of Date.validateDay etc. go for Date.validate. In this case the date atom is passed within an Object (ie {day: 4}). The function should check out the parameters and raise error/warning depending on Object contents.
  • Instead of d.addMilliseconds etc. go for Date.add. Same idea as above.
  • Instead of d.removeMilliseconds etc. go for Date.remove. Same idea as above.
  • Consider merging d.add and d.remove into a single method, d.offset. In this case the direction would be determined based on whether passed number is positive or negative. Ie. to remove a day you would do d.offset({day: -1}).

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.

from date-utils.

JerrySievert avatar JerrySievert commented on August 16, 2024

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.

from date-utils.

JerrySievert avatar JerrySievert commented on August 16, 2024

@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.

from date-utils.

jonstorer avatar jonstorer commented on August 16, 2024

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!

from date-utils.

sfeldkamp avatar sfeldkamp commented on August 16, 2024

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?

from date-utils.

JerrySievert avatar JerrySievert commented on August 16, 2024

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

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

from date-utils.

sfeldkamp avatar sfeldkamp commented on August 16, 2024

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.

from date-utils.

ORBAT avatar ORBAT commented on August 16, 2024

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:

  • the full name of a month could be MMMM, the abbreviated month name could be MMM, zero-padded month could be MM, and single or double digit month could be M
  • 24h hours could use H (with HH for zero-padded)
  • 12h hours could use h/hh
  • minutes could be m/mm instead of just the padded MI

etc.

from date-utils.

alexcoady avatar alexcoady commented on August 16, 2024

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.

from date-utils.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.