My favorites | Sign in
Project Logo
          
Search
for
Updated Jan 25, 2008 by doug.sparling
Documentation  

jquery.datemaker.js - jQuery plugin to create Date objects

Introduction

jquery.datamaker.js provides an easy way to create Javascript Date objects using simple time interval indicators. Use datamaker to create Data objects to use with jQuery cookie plugin.

Time interval indicators are like those in Perl CGI::Cookie: '+1M,' '-10d,' etc., and Rails ActiveSupport-like time indicators: '3.days.ago.' A few named time indicators: 'midnight' and 'now.' Note that '3.days.ago' is a string, not a method on an integer.

Integrates with jQuery cookie plugin

$.cookie('cookie_name', 'cookie_value', { expires: $.datemaker('+1h') });

Details

Create a Date object using the given date format string.

Date formats (most like Perl CGI::Cookie) Date formats like Rails ActiveSupport::CoreExtension::Numeric::Time

Example

$.datemaker('+30s');                // 30 seconds from now
$.datemaker('+5m');                 // 5 minutes from now
$.datemaker('+1h');                 // 1 hour from now
$.datemaker('-1d');                 // 1 day ago
$.datemaker('+10d');                // 10 days from now
$.datemaker('+2M');                 // 2 months from now
$.datemaker('-6M');                 // 6 months ago
$.datemaker('+1y');                 // 1 year from now
$.datemaker('30.seconds.ago');      // 30 seconds ago
$.datemaker('30.seconds.from_now'); // 30 seconds from now
$.datemaker('5.minutes.ago');       // 5 minutes ago
$.datemaker('5.minutes.from_now');  // 5 minutes from now
$.datemaker('1.hour.ago');          // 1 hour ago
$.datemaker('1.hour.from_now');     // 1 hour from now
$.datemaker('10.days.ago');         // 10 days ago
$.datemaker('10.days.from_now');    // 10 days from now
$.datemaker('6.months.ago');        // 6 months ago
$.datemaker('6.months.from_now');   // 6 months from now
$.datemaker('1.year.ago');          // 1 year ago
$.datemaker('1.year.from_now');     // 1 year from now
$.datemaker('midnight');            // midnight
$.datemaker('now');                 // now

Example

Using with jQuery cookie plugin

$.cookie('cookie_name', 'cookie_value', { expires: $.datemaker('+1h') });

Comment by clucas82, Nov 17, 2008

Wed Nov 19 2008 00:00:00 GMT-0500 (Eastern Standard Time)


Sign in to add a comment
Hosted by Google Code