3
MochiKit.DateTime 1.3.1
5
See <http://mochikit.com/> for documentation, downloads, license, etc.
7
(c) 2005 Bob Ippolito. All rights Reserved.
11
if (typeof(dojo) != 'undefined') {
12
dojo.provide('MochiKit.DateTime');
15
if (typeof(MochiKit) == 'undefined') {
19
if (typeof(MochiKit.DateTime) == 'undefined') {
20
MochiKit.DateTime = {};
23
MochiKit.DateTime.NAME = "MochiKit.DateTime";
24
MochiKit.DateTime.VERSION = "1.3.1";
25
MochiKit.DateTime.__repr__ = function () {
26
return "[" + this.NAME + " " + this.VERSION + "]";
28
MochiKit.DateTime.toString = function () {
29
return this.__repr__();
32
MochiKit.DateTime.isoDate = function (str) {
34
if (typeof(str) != "string" || str.length === 0) {
37
var iso = str.split('-');
38
if (iso.length === 0) {
41
return new Date(iso[0], iso[1] - 1, iso[2]);
44
MochiKit.DateTime._isoRegexp = /(\d{4,})(?:-(\d{1,2})(?:-(\d{1,2})(?:[T ](\d{1,2}):(\d{1,2})(?::(\d{1,2})(?:\.(\d+))?)?(?:(Z)|([+-])(\d{1,2})(?::(\d{1,2}))?)?)?)?)?/;
46
MochiKit.DateTime.isoTimestamp = function (str) {
48
if (typeof(str) != "string" || str.length === 0) {
51
var res = str.match(MochiKit.DateTime._isoRegexp);
52
if (typeof(res) == "undefined" || res === null) {
55
var year, month, day, hour, min, sec, msec;
56
year = parseInt(res[1], 10);
57
if (typeof(res[2]) == "undefined" || res[2] === '') {
58
return new Date(year);
60
month = parseInt(res[2], 10) - 1;
61
day = parseInt(res[3], 10);
62
if (typeof(res[4]) == "undefined" || res[4] === '') {
63
return new Date(year, month, day);
65
hour = parseInt(res[4], 10);
66
min = parseInt(res[5], 10);
67
sec = (typeof(res[6]) != "undefined" && res[6] !== '') ? parseInt(res[6], 10) : 0;
68
if (typeof(res[7]) != "undefined" && res[7] !== '') {
69
msec = Math.round(1000.0 * parseFloat("0." + res[7]));
73
if ((typeof(res[8]) == "undefined" || res[8] === '') && (typeof(res[9]) == "undefined" || res[9] === '')) {
74
return new Date(year, month, day, hour, min, sec, msec);
77
if (typeof(res[9]) != "undefined" && res[9] !== '') {
78
ofs = parseInt(res[10], 10) * 3600000;
79
if (typeof(res[11]) != "undefined" && res[11] !== '') {
80
ofs += parseInt(res[11], 10) * 60000;
88
return new Date(Date.UTC(year, month, day, hour, min, sec, msec) - ofs);
91
MochiKit.DateTime.toISOTime = function (date, realISO/* = false */) {
92
if (typeof(date) == "undefined" || date === null) {
95
var hh = date.getHours();
96
var mm = date.getMinutes();
97
var ss = date.getSeconds();
99
((realISO && (hh < 10)) ? "0" + hh : hh),
100
((mm < 10) ? "0" + mm : mm),
101
((ss < 10) ? "0" + ss : ss)
103
return lst.join(":");
106
MochiKit.DateTime.toISOTimestamp = function (date, realISO/* = false*/) {
107
if (typeof(date) == "undefined" || date === null) {
110
var sep = realISO ? "T" : " ";
111
var foot = realISO ? "Z" : "";
113
date = new Date(date.getTime() + (date.getTimezoneOffset() * 60000));
115
return MochiKit.DateTime.toISODate(date) + sep + MochiKit.DateTime.toISOTime(date, realISO) + foot;
118
MochiKit.DateTime.toISODate = function (date) {
119
if (typeof(date) == "undefined" || date === null) {
122
var _padTwo = MochiKit.DateTime._padTwo;
125
_padTwo(date.getMonth() + 1),
126
_padTwo(date.getDate())
130
MochiKit.DateTime.americanDate = function (d) {
132
if (typeof(d) != "string" || d.length === 0) {
135
var a = d.split('/');
136
return new Date(a[2], a[0] - 1, a[1]);
139
MochiKit.DateTime._padTwo = function (n) {
140
return (n > 9) ? n : "0" + n;
143
MochiKit.DateTime.toPaddedAmericanDate = function (d) {
144
if (typeof(d) == "undefined" || d === null) {
147
var _padTwo = MochiKit.DateTime._padTwo;
149
_padTwo(d.getMonth() + 1),
150
_padTwo(d.getDate()),
155
MochiKit.DateTime.toAmericanDate = function (d) {
156
if (typeof(d) == "undefined" || d === null) {
159
return [d.getMonth() + 1, d.getDate(), d.getFullYear()].join('/');
162
MochiKit.DateTime.EXPORT = [
169
"toPaddedAmericanDate",
173
MochiKit.DateTime.EXPORT_OK = [];
174
MochiKit.DateTime.EXPORT_TAGS = {
175
":common": MochiKit.DateTime.EXPORT,
176
":all": MochiKit.DateTime.EXPORT
179
MochiKit.DateTime.__new__ = function () {
180
// MochiKit.Base.nameFunctions(this);
181
var base = this.NAME + ".";
182
for (var k in this) {
184
if (typeof(o) == 'function' && typeof(o.NAME) == 'undefined') {
194
MochiKit.DateTime.__new__();
196
if (typeof(MochiKit.Base) != "undefined") {
197
MochiKit.Base._exportSymbols(this, MochiKit.DateTime);
199
(function (globals, module) {
200
if ((typeof(JSAN) == 'undefined' && typeof(dojo) == 'undefined')
201
|| (typeof(MochiKit.__compat__) == 'boolean' && MochiKit.__compat__)) {
202
var all = module.EXPORT_TAGS[":all"];
203
for (var i = 0; i < all.length; i++) {
204
globals[all[i]] = module[all[i]];
207
})(this, MochiKit.DateTime);