[edit]
Creating a Date Facet
If you have your date data in ISO 8601 format then you might want to be able to sort that data by year, month, hour of the day,etc.
This will create a facet to split the dates into Months of the year (from David Huynh). First, add this code after you include exhibit-api.js
<script>
var monthNames = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ];
Exhibit.Functions["month"] = {
f: function(args) {
var set = new Exhibit.Set();
args[0].forEachValue(function(v) {
var d = SimileAjax.DateTime.parseIso8601DateTime(v);
var m = d.getMonth();
set.add(monthNames[m]);
});
return new Exhibit.Expression._Collection(set, "text");
}
};
</script>
Then for the month facet, use this expression
ex:expression="month(.dateTime)"
So the complete facet would be:
<div ex:role="facet" ex:expression="month(.dateTime)" ex:facetLabel="Month of Year"></div>
To order the months in the usual month order use the setting name:
ex:fixedOrder
e.g.
<div ex:role="facet" ex:expression="month(.dateTime)" ex:fixedOrder="Jan;Feb;Mar;Apr;May;Jun;Jul;Aug;Sep;Oct;NOv;Dec" ex:facetLabel="Month of Year"></div>
[edit]
Hours Facet
An adaptation of the above to make an 'hour of the day' facet.
<script>
var hourNames = [ "00","01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23" ];
Exhibit.Functions["hour"] = {
f: function(args) {
var set = new Exhibit.Set();
args[0].forEachValue(function(v) {
var d = SimileAjax.DateTime.parseIso8601DateTime(v);
var m = d.getHours();
set.add(hourNames[m]);
});
return new Exhibit.Expression._Collection(set,"number");
}
};
</script>
and add this to the facet
ex:expression="month(.dateTime)"
A simple tutorial about using the javascript date object can be found at http://www.web-source.net/web_development/javascript_date.htm

