Skip to content
klizhentas edited this page Sep 14, 2010 · 13 revisions

Sakura is a prototype & scripaculous based JS datetime parser/formatter and calendar library.

What does this library provide?

1. Date and time parser and formatter.

%m    Month as a decimal number [01,12].
%d    Day of the month as a decimal number [01,31].
%y    Year without century as a decimal number [00,99].
%Y    Year with century as a decimal number.
%H    Hour (24-hour clock) as a decimal number [00,23].
%P:   Hour:Minute AM/PM mode parser, accepts/folds format like 12:20AM 12:20PM
%p.   Hour:Minute am/pm mode parser, accepts/folds format like 12.20am 12.20pm
%M    Minute as a decimal number [00,59].
%S    Second as a decimal number [00,59].

Take a look at %P{delim}, actually {delim} can be any symbol you like, e.g. “%P?” will accept/fold expressions like “12?20 am”.

var formatter = new S.DateFormatter('%m-%d-%Y %p.');        
var date = formatter.from_string(' 03 - 16 - 2011 10.04 am');
var date_string = formatter.to_string(new Date());

2. Calendar with region selects, weeks starting from different days, etc.

 var calendar = new S.Calendar({
            inline: 'inline-parent',
            week_starts_from: S.Calendar.Sun,
            translate: S.Calendar.translate_en,
            region_select: true,
            region_select_grab_week: true,
            on_change: function(date){
                $('date-is').innerHTML = date.toString();
            },
            on_region_select: function(s,e){
                $('date-is').innerHTML = [s.toString(),'—',e.toString()].join(' ');
            }
        });

Watch demo/small.html for more code examples and demos, online demo is here: Sakura Demo.
The file tests/datetime.html is for unit tests (needs jsunit to work fine).
Please keep unit tests in touch with the codebase.

Clone this wiki locally