1
0
Fork 0
forked from 0x2620/oxjs

better formatting of dates, especially around 0 AD

This commit is contained in:
rolux 2011-05-27 13:33:01 +02:00
commit 419985c835
3 changed files with 57 additions and 42 deletions

View file

@ -112,19 +112,13 @@ Ox.Calendar = function(options, self) {
- date: returns the start date of the index-th month
- name: returns a string representation of the index-th month
- value: returns the month index for a given date
Setting the date is verbose, but it's the only way to avoid years
like 50 to be coerced to 1950.
*/
self.units = [
{
id: 'millennium',
seconds: 365242.5 * 86400,
date: function(i) {
var date = new Date();
date.setUTCFullYear((i + 1) * 1000);
date.setUTCMonth(0);
date.setUTCDate(0);
return date;
return Ox.parseDate((i + 1) * 1000, true);
},
name: function(i) {
return i > -2
@ -139,11 +133,7 @@ Ox.Calendar = function(options, self) {
id: 'century',
seconds: 36524.25 * 86400,
date: function(i) {
var date = new Date();
date.setUTCFullYear((i + 19) * 100);
date.setUTCMonth(0);
date.setUTCDate(0);
return date;
return Ox.parseDate((i + 19) * 100, true);
},
name: function(i) {
return i > -20
@ -158,14 +148,12 @@ Ox.Calendar = function(options, self) {
id: 'decade',
seconds: 3652.425 * 86400,
date: function(i) {
var date = new Date();
date.setUTCFullYear((i + 197) * 10);
date.setUTCMonth(0);
date.setUTCDate(0);
return date;
return Ox.parseDate((i + 197) * 10, true);
},
name: function(i) {
return (i + 197) + '0s'
return i > -198
? (i + 197) + '0s'
: (-i - 198) + '0s BC';
},
value: function(date) {
return Math.floor(date.getUTCFullYear() / 10) - 197;
@ -175,14 +163,10 @@ Ox.Calendar = function(options, self) {
id: 'year',
seconds: 365.2425 * 86400,
date: function(i) {
var date = new Date();
date.setUTCFullYear(i + 1970);
date.setUTCMonth(0);
date.setUTCDate(0);
return date;
return Ox.parseDate(i + 1970, true);
},
name: function(i) {
return (i + 1970) + '';
return Ox.formatDate(Ox.parseDate(i + 1970, true), '%x', true);
},
value: function(date) {
return date.getUTCFullYear() - 1970;
@ -192,14 +176,14 @@ Ox.Calendar = function(options, self) {
id: 'month',
seconds: 365.2425 / 12 * 86400,
date: function(i) {
var date = new Date();
date.setUTCFullYear(Math.floor(i / 12) + 1970);
date.setUTCMonth(Ox.mod(i, 12));
date.setUTCDate(0); // fixme: WTF??
return date;
return Ox.parseDate(
(Math.floor(i / 12) + 1970) + '-' + (Ox.mod(i, 12) + 1), true
);
},
name: function(i) {
return Ox.SHORT_MONTHS[Ox.mod(i, 12)] + ' ' + Math.floor(i / 12 + 1970)
return Ox.formatDate(Ox.parseDate(
(Math.floor(i / 12 + 1970)) + '-' + (Ox.mod(i, 12) + 1), true
), '%b %x', true);
},
value: function(date) {
return (date.getUTCFullYear() - 1970) * 12 + date.getUTCMonth();
@ -212,7 +196,7 @@ Ox.Calendar = function(options, self) {
return new Date((i * 7 - 3) * 86400000);
},
name: function(i) {
return Ox.formatDate(new Date((i * 7 - 3) * 86400000), '%a, %b %e');
return Ox.formatDate(new Date((i * 7 - 3) * 86400000), '%a, %b %e', true);
},
value: function(date) {
return Math.floor((date / 86400000 + 4) / 7);
@ -225,7 +209,7 @@ Ox.Calendar = function(options, self) {
return new Date(i * 86400000);
},
name: function(i) {
return Ox.formatDate(new Date(i * 86400000), '%b %e, %Y', true);
return Ox.formatDate(new Date(i * 86400000), '%b %e, %x', true);
},
value: function(date) {
return Math.floor(date / 86400000);
@ -453,8 +437,8 @@ Ox.Calendar = function(options, self) {
function dragstart(event, e) {
//if ($(e.target).is(':not(.OxLine > .OxEvent)')) {
self.drag = {
x: e.clientX,
y: self.$container.$element[0].scrollTop
top: self.$container.$element[0].scrollTop,
x: e.clientX
};
//}
}
@ -473,7 +457,9 @@ Ox.Calendar = function(options, self) {
self.$scrollbar.css({
marginLeft: Math.round(marginLeft / scrollbarFactor) + 'px'
});
scrollTo(self.drag.y - e.clientDY);
scrollTo(self.drag.top - e.clientDY);
// fixme: after dragging too far in one direction,
// dragging in the opposite direction should work immediately
}
}
@ -961,6 +947,7 @@ Ox.Calendar = function(options, self) {
} else {
self.$container.$element[0].scrollTop = top;
}
Ox.print('scrollTo', top)
}
function selectEvent(id, $element) {