Skip to content

Instantly share code, notes, and snippets.

@vojd
Created October 2, 2012 11:12
Show Gist options
  • Save vojd/3818246 to your computer and use it in GitHub Desktop.
Save vojd/3818246 to your computer and use it in GitHub Desktop.
mobiscroll Formats date like [day date shortMonth] [hour] [minute]
/**
* Mobiscroll setup with swedish translation
* Formats date like [day date shortMonth] [hour] [minute]
*/
$(document).ready(function(){
(function ($) {
$.scroller.i18n.sv = $.extend($.scroller.i18n.sv, {
setText: 'Klar',
cancelText: 'Avbryt'
});
$.scroller.i18n.sv = $.extend($.scroller.i18n.sv || {}, {
dateFormat: 'yy-mm-dd',
dateOrder: 'ddmmyy',
dayText: 'Dag',
hourText: 'Timme',
minuteText: 'Minut',
monthNames : ['jan', 'feb', 'mar', 'apr', 'maj', 'jun', 'jul', 'aug', 'sep', 'okt', 'nov', 'dec'],
monthNamesShort : ['jan', 'feb', 'mar', 'apr', 'maj', 'jun', 'jul', 'aug', 'sep', 'okt', 'nov', 'dec'],
dayNames : ['Söndag', 'Måndag', 'Tisdag', 'Onsdag', 'Torsdag', 'Fredag', 'Lördag'],
dayNamesShort : ['sön', 'mån', 'tis', 'ons', 'tors', 'fre', 'lör'],
monthText: 'Månad',
secText: 'Sekund',
timeFormat: 'HH:ii',
timeWheels: 'HHii',
yearText: 'År'
});
$.scroller.i18n['en-US'] = $.scroller.i18n.sv;
})(jQuery);
$(function(){
var w = [{}],
startDate = new Date(2012,0,1);
endDate = new Date(2013,12,31);
datesettings = $.scroller.i18n.sv,
today = new Date(),
todaysDate = new Date(today.getFullYear(), today.getMonth(), today.getDate());
w[0].Date = {};
var i;
for (i = startDate.getTime(); i <= endDate.getTime(); i+= 1000 * 60 * 60 * 24) {
// compare dates to see if we're on today
var d = new Date(i),
a = $.scroller.formatDate('D d M', d),
b = $.scroller.formatDate('D d M', todaysDate);
if(a == b){
// todays date
dateDiv = '<span class="today">idag</span>';
}else{
dateDiv = $.scroller.formatDate(
"'<span class=\"grey\">'D'</span>' d M", d, datesettings
);
}
w[0].Date[$.scroller.formatDate('yy-mm-dd', d)] = dateDiv;
}
w[0].Hour = {};
for (i = 0; i < 24; i++){
var str = ''+i;
if(str.length < 2)
str = '0'+i;
w[0].Hour[i] = str === 0 ? 24 : str;
}
w[0].Minute = {};
for (i = 0; i < 60; i+=5){
var str = ''+i;
if(str.length < 2)
str = '0'+i;
w[0].Minute[i] = str;
}
$('#field-date').scroller({
width: 40,
theme: 'ios',
wheels: w,
display: 'modal',
mode: 'scroller',
rows: 3,
lang: 'sv',
formatResult: function(v) {
var d;
if (v) {
d = new Date(v[0]);
d.setHours(v[3] ? v[1] + 12 : v[1]);
console.log('v[2]', v[2]);
if(v[2] == undefined){
v[2] = "0";
}
d.setMinutes(v[2]);
}
else {
d = new Date();
}
//return $.scroller.formatDate('D dd M yyyy HH:ii', d, datesettings);
return $.scroller.formatDate('yyyy-mm-dd HH:ii', d, datesettings);
},
parseValue: function(v) {
var d = new Date();
if (v) {
d = $.scroller.parseDate('D dd M yyyy HH:ii', d, datesettings);
}
var h = d.getHours();
// for 12 hours AM/PM use this row
//var l = [$.scroller.formatDate('yy-mm-dd', d), h > 11 ? h - 12 : h, d.getMinutes(), h > 11 ? 1 : 0];
// for 24 hours
var l = [$.scroller.formatDate('yy-mm-dd', d), h > 23 ? h - 24 : h, d.getMinutes(), h > 23 ? 1 : 0];
console.log(l);
return l;
},
setValue: function(sc, fill, time, orig){
console.log('setValue');
console.log(sc, fill, time, orig);
},
onShow: function(inst){
$('<span class="dwb-text">Start och slut</span>').insertAfter($('div.dwbc .dwbw.dwb-c'));
}
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment