Tags
webcam vindaloo version vegan unix unicef trojan todo thinkpad textmate testing tagging syntax svn sugar subversion stubbing sphinx spam spaces solaris sitemap site sinatra shoulda sheet set security search schema_info SchemaInfo ruby rinari restaurant relationships refresh rdiff-backup ramaze railsconf08 railsconf07 rails protools production power placeboeffect pink floyd PIC perl overheat outbreak osx os x NYHS NYC nginx netbeans nested nanophotonics mysql music MPEG-4 mongrel model migration microvolunteer macbook mac logrotate logic log linux less leopard keynote JAX javascript java jacksonville imunizator highlighting hanna Handbrake haml hacks google geocoding genghistron gem gaming gabrielle's funny functional fun friends food fixes fixed firefox FF3 ferretThe Hacker said about 1 year ago permalink Comment? (0)
Tagged: rails javascript ruby sugar
Flexible date input and manipulation in javascript with date.js
date.js is a great little JavaScript library that can make your life a lot easier.
If your used to ruby’s date functions then date.js will make you feel right at home.
date.js can:
- Parse strings into dates.
- Add and Subtract time in days,hours,months or years.
- Easily return “x” “day of week” of “month”
- Boolean assertions for day, week, month, year.
- Turn you into a JavaScript ninja.
Note: Some of the syntactic goodies require ‘sugar.js’
Going into the future is no problem for date.js
Date.today().add(5).days(); Date.today().next().friday();Interested in this Friday? April of this year?
Date.friday(); Date.april();What about the first friday of april? No Sweat!
Date.april().first().friday();Assert any date properties you want.
Date.today().is().friday(); // returns true orfalseIt can parse just about anything you throw at it.
Date.parse(‘today’); Date.parse(‘tomorrow’); Date.parse(‘July 8’); Date.parse(‘July 8th, 2007’); Date.parse(‘July 8th, 2007, 10:30 PM’); // Even crazy! things like Date.parse(‘last april’); Date.parse(‘+2days’);There are also some fun number functions.
(8).days().fromNow(); (2).months().ago();For more reading, checkout: date.js examples