5 ms·
A Javascript date library
- alexk 17y agoAnd a JS timezone library: http://js.fleegix.org/plugins/date/date http://js.fleegix.org/plugins/date/date
- unwind 17y agoNo support for fortnights?! I'm shocked at the omission of this critical unit of time, used throughout society.
- jdbeast00 17y agoin all seriousness, it did seem less intelligent than what i've seen (on RTM.com for example). next june returns June 4th? wtf?
- bdfh42 17y agowell today is the 4th. - which day in June 2010 would you pick as the default?
- jdbeast00 17y agoand i feel like an idiot. didn't realize that today was the 4th. i would imagine that June 1 would make more sense though...but thats pretty nit picky.
- jonp 17y agoI guess it's hard to give an answer to an ambiguous input that will please everyone. Personally I would have expected the 1st of the month. It seems unusual that "next June" and "last June" both pick the 4th of the month (today's date); but just "June" gives the 1st of the month. Also "next June" gives "Friday, June 04, 2010 12:00:00 AM" so it picks the day of the month based on today; but the time of day doesn't depend on the time now.
- fnid 17y agoIf you type in "next june 1" it'll give you what you are wanting.
- midnightmonster 17y agomy (available on the mailing list but not integrated) patch for the library gives you a callback into just that point in the process where the library has parsed out what it can but hasn't filled in defaults yet, so you can insert the assumptions that make sense for your application and not have to rely on the default ones.
- encoderer 17y agoThis is the test I use on all date libraries I come across. I don't know what the right answer is, I just want it to be logical: (pseudo) Date d = new Date('1/31/2009'); d.addOneMonth(); What is the value of d? 2/28/09? 3/2/09? 2/25/09? Writing a date library is not for the fainthearted.
- blasdel 17y agoIT SHOULD NOT PICK A DAY! It should return (2010, 6) -- with no precision implied beyond the input. This is a major personal hobby-horse of mine, and I don't know of a library that does all of what I want by default. The constructor for datetime in Python's standard library comes very close: datetime(year, month, day[, hour[, minute[, second[, microsecond[,tzinfo]]]]]) All of the time components have no implied precision beyond the input you've given -- "2009-06-04 3pm" is never implicitly upcast into "2009-06-04 15:00:00 UTC". This is awesome. Unfortunately the date object used internally does not allow for partial precision, so datetime doesn't expose it.
- sh1mmer 17y agoBritish society; living in the U.S. I find my American colleagues don't grok the fortnight.
- tdoggette 17y agoThat's very spiffy. I wonder how it compares to some of the smarter Perl date libraries?
- mtrimpe 17y agoI had the strangest bug with this library on Konfabulator a while ago where all Date.toString()'s returned an object instead of a string. Not really a useful thing to know but I wanted to post it anyhow.
- midnightmonster 17y agoI've used the library in a real project, and I'm on the mailing list. FYI, there doesn't seem to be much development activity going on, nor is it so perfect and complete that further development is unneeded. That's not to discourage anyone from using it, since it's the only JS lib I know that fills the same niche, just to let you know you may need to get your hands dirty. (I've got a patch waiting for integration but not enough attention available to test it for use cases that are not mine and really push it through. If you do have the interest and bandwidth to polish whatever improvements you make, you could probably help quite a bit.)
- mcxx 17y agoWhat parts did you miss?
- fnid 17y agoIt would be cool if it understood "Christmas" or other holidays. Also, things like, "two weeks after next wednesday at 1pm"
- midnightmonster 17y agoMy patch (which can be found discussed in the mailing list) provides a callback hook to modify the final result given the parsed details. I use it to modify assumptions: e.g., if you just type a year, for the final output, the library assumes the rest of the date should be jan 1, but if this field is the end of a date range, it should probably be dec 31 since "burglaries from 2001 to 2002" means the burglaries in 2001 and in 2002. I think it's an important function, and the original author agreed, but neither of us has had the time to test and time everything for all the relevant codepaths to make it into the library. Other posters have had other complaints about missing functionality--some struck me as reasonable, some not so much--but I haven't kept track.
- TravisLS 17y agoThere's another date formatting library if you're using Prototype, that I've used for a few things (although I have to say, I like the OP better). It was kind of hard to track down and doesn't seem to have any continuing support, but is used as part of this nice date picker: http://home.jongsma.org/software/js/datepicker http://home.jongsma.org/software/js/datepicker This is the .js file: http://home.jongsma.org/js/lib/prototype-date-extensions.js http://home.jongsma.org/js/lib/prototype-date-extensions.js
- discojesus 17y agoI went out on a javascript date once. Didn't get a callback. :( Hiohhhhhhhhhhhhhhhhhhhhhh!
- jpeterson 17y agoAye, it hurts the worst when you don't get closure.
- discojesus 17y agoand yet at the same time, they get offended if you try to check their readyState - you can't win!
- dkersten 17y agohaha. I miss read the title as "A javascript dating library" on first glance.
- callmeed 17y agoCurious if anyone has compared it to the Ruby chronic gem ...
- mildweed 17y agoPrevious related threads: http://news.ycombinator.com/item?id=84070 http://news.ycombinator.com/item?id=84070 http://news.ycombinator.com/item?id=630258 http://news.ycombinator.com/item?id=630258
- psyklic 17y ago"the day before last Saturday" doesn't work
- mhansen 17y agoThat interface... it's so fluent. I love javascript, for just the reason that it's possible to have beautiful interfaces like this. Date.today().add(3).days(); Be even better if it let you leave off the brackets like ruby, but oh well.
- rivo 17y agoMy first test was "6.2.2009" and it said "June 2, 2009" where I expected "Feb 6, 2009". So it'll be only usable for an American audience.