Permalink
Browse files

added separator option for calendricalDate

for non us dates you may specify a string option called separator
(see example.html)
  • Loading branch information...
1 parent ff4d4d4 commit 8a996e81b6ceb8fab220a20cb321a8465e5cdda2 @panterch committed Jul 6, 2011
Showing with 31 additions and 11 deletions.
  1. +18 −1 example.html
  2. +13 −10 jquery.calendrical.js
View
@@ -143,6 +143,23 @@
</div>
<pre class="html"></pre>
</section>
+ <section>
+ <header>
+ <h2>Customized Date separator</h2>
+ </header>
+
+ <div class="demo">
+<input id="date_custom_separator" type="text" />
+<script>
+ $(function() {
+ $('#date_custom_separator').calendricalDate({
+ separator: '.'
+ });
+ });
+</script>
+ </div>
+ <pre class="html"></pre>
+ </section>
</div>
<script>
$(function() {
@@ -151,4 +168,4 @@
});
});
</script>
-</body>
+</body>
View
@@ -61,23 +61,25 @@
new Date(year, month + 1, 1);
}
- function formatDate(date, usa)
+ function formatDate(date, usa, separator)
{
+ separator = (separator || '/');
return (usa ?
- ((date.getMonth() + 1) + '/' + date.getDate()) :
- (date.getDate() + '/' + (date.getMonth() + 1))
- ) + '/' + date.getFullYear();
+ ((date.getMonth() + 1) + separator + date.getDate()) :
+ (date.getDate() + separator + (date.getMonth() + 1))
+ ) + separator + date.getFullYear();
}
- function parseDate(date, usa)
+ function parseDate(date, usa, separator)
{
if (usa) return new Date(date);
a = date.split(/[\.\-\/]/);
var day = a.shift();
var month = a.shift();
a.unshift(day);
a.unshift(month);
- return new Date(a.join('/'));
+ separator = (separator || '/');
+ return new Date(a.join(separator));
}
function formatTime(hour, minute, options)
@@ -347,7 +349,7 @@
});
element.after(div);
- var selected = parseDate(element.val(), options.usa);
+ var selected = parseDate(element.val(), options.usa, options.separator);
if (!selected.getFullYear()) selected = getToday();
renderCalendarPage(
@@ -357,12 +359,12 @@
selected: selected,
selectDate: function(date) {
within = false;
- element.val(formatDate(date, options.usa));
+ element.val(formatDate(date, options.usa, options.separator));
div.remove();
div = null;
if (options.endDate) {
var endDate = parseDate(
- options.endDate.val(), options.usa
+ options.endDate.val(), options.usa, options.separator
);
if (endDate >= selected) {
options.endDate.val(formatDate(
@@ -371,7 +373,8 @@
endDate.getTime() -
selected.getTime()
),
- options.usa
+ options.usa,
+ options.separator
));
}
}

0 comments on commit 8a996e8

Please sign in to comment.