add %x option (show BC/AD if year < 1000) to formatDate, and use on mousemove

This commit is contained in:
rolux 2011-05-26 19:20:55 +02:00
parent f0052d3e3c
commit bd0f1e1ae3
2 changed files with 10 additions and 4 deletions

View file

@ -701,7 +701,7 @@ Ox.Calendar = function(options, self) {
title = '<span class="OxBright">' + event.name + '</span><br/>' + title = '<span class="OxBright">' + event.name + '</span><br/>' +
event.rangeText + '<br>' + event.durationText; event.rangeText + '<br>' + event.durationText;
} else { } else {
title = Ox.formatDate(getMouseDate(e), '%a, %b %e, %Y, %H:%M:%S', true); title = Ox.formatDate(getMouseDate(e), '%a, %b %e, %x, %H:%M:%S', true);
} }
self.$tooltip.options({ self.$tooltip.options({
title: title title: title

View file

@ -2114,7 +2114,7 @@ Ox.formatDate <f> Formats a date according to a format string
See See
<a href="http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/strftime.3.html">strftime</a> <a href="http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/strftime.3.html">strftime</a>
and <a href="http://en.wikipedia.org/wiki/ISO_8601">ISO 8601</a>. and <a href="http://en.wikipedia.org/wiki/ISO_8601">ISO 8601</a>.
'%Q' (quarter) and '%X' (year with 'BC'/'AD') are non-standard '%Q' (quarter) and '%X'/'%x' (year with 'BC'/'AD') are non-standard
<script> <script>
Ox.test.date = new Date('2005-01-02 00:03:04'); Ox.test.date = new Date('2005-01-02 00:03:04');
</script> </script>
@ -2190,6 +2190,8 @@ Ox.formatDate <f> Formats a date according to a format string
'0' '0'
> Ox.formatDate(Ox.test.date, '%X') // Full year with BC or AD > Ox.formatDate(Ox.test.date, '%X') // Full year with BC or AD
'2005 AD' '2005 AD'
> Ox.formatDate(Ox.test.date, '%x') // Full year with BC or AD if year < 1000
'2005'
> Ox.formatDate(Ox.test.date, '%Y') // Full year > Ox.formatDate(Ox.test.date, '%Y') // Full year
'2005' '2005'
> Ox.formatDate(Ox.test.date, '%y') // Abbreviated year > Ox.formatDate(Ox.test.date, '%y') // Abbreviated year
@ -2247,8 +2249,12 @@ Ox.formatDate = function(date, str, utc) {
}], }],
['w', function(d) {return Ox.getDay(d, utc);}], ['w', function(d) {return Ox.getDay(d, utc);}],
['X', function(d) { ['X', function(d) {
var y = Ox.getFullYear(d, utc); var y = Ox.getFullYear(d, utc);
return Math.abs(y) + ' ' + Ox.BCAD[y < 0 ? 0 : 1]; return Math.abs(y) + ' ' + Ox.BCAD[y < 0 ? 0 : 1];
}],
['x', function(d) {
var y = Ox.getFullYear(d, utc);
return Math.abs(y) + (y < 1000 ? ' ' + Ox.BCAD[y < 0 ? 0 : 1] : '');
}], }],
['Y', function(d) {return Ox.getFullYear(d, utc);}], ['Y', function(d) {return Ox.getFullYear(d, utc);}],
['y', function(d) {return Ox.getFullYear(d, utc).toString().substr(-2);}], ['y', function(d) {return Ox.getFullYear(d, utc).toString().substr(-2);}],