Skip to content

Commit

Permalink
Added tests for time datatype, fixed bugs.
Browse files Browse the repository at this point in the history
  • Loading branch information
mde committed Jul 27, 2010
1 parent 9fa247d commit ca8abfa
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
27 changes: 26 additions & 1 deletion geddy-model/tests/datatypes.js
Expand Up @@ -12,7 +12,8 @@ global.ByTor = function () {
this.property('objectProp', 'object');
this.property('arrayProp', 'array');
this.property('dateProp', 'date');
this.property('datetimeProp', 'date');
this.property('datetimeProp', 'datetime');
this.property('timeProp', 'time');
};

geddy.model.registerModel('ByTor');
Expand Down Expand Up @@ -166,6 +167,30 @@ var testDatatypes = new function () {
}

};

this.testTime = function () {
var byTor;
var dates, dt, vals;
// Obj key is the input string, value is the list of values
// for the parse Date object's h/m/s/ms
dates = {
'21:12' : [21, 12, 0, 0]
, '1:11': [1, 11, 0, 0]
, '1:11:03': [1, 11, 3, 0]
, '1:11:03.999': [1, 11, 3, 999]
};
for (var p in dates) {
dt = p;
vals = dates[p];
byTor = ByTor.create({timeProp: dt});
assert.ok(byTor.valid());
assert.equal(byTor.timeProp.getHours(), vals[0]);
assert.equal(byTor.timeProp.getMinutes(), vals[1]);
assert.equal(byTor.timeProp.getSeconds(), vals[2]);
assert.equal(byTor.timeProp.getMilliseconds(), vals[3]);
}

};

}();

Expand Down
7 changes: 4 additions & 3 deletions geddy-util/lib/date.js
Expand Up @@ -23,7 +23,8 @@ geddy.util.date = new function () {

var _US_DATE_PAT = /^(\d{1,2})(?:\-|\/|\.)(\d{1,2})(?:\-|\/|\.)(\d{4})/;
var _DATETIME_PAT = /^(\d{4})(?:\-|\/|\.)(\d{1,2})(?:\-|\/|\.)(\d{1,2})(?:T| )?(\d{2})?(?::)?(\d{2})?(?::)?(\d{2})?(?:\.)?(\d+)?(Z|[+-]\d{4}|[+-]\d{2}:\d{2}|[+-]\d{2})?/;
var _TIME_PAT = /^(\d{2})?(?::)?(\d{2})?(?::)?(\d{2})?(?:\.)?(\d+)?$/;
// TODO Add am/pm parsing instead of dumb, 24-hour clock.
var _TIME_PAT = /^(\d{1,2})?(?::)?(\d{2})?(?::)?(\d{2})?(?:\.)?(\d+)?$/;

var _dateMethods = [
'FullYear'
Expand Down Expand Up @@ -625,9 +626,9 @@ geddy.util.date = new function () {

// Time-stored-in-Date hack?
if (!matches) {
val.match(_TIME_PAT);
matches = val.match(_TIME_PAT);
if (matches) {
reordered = [null, 0, 0, 0, matches[0], matches[1], matches[2], matches[3], null];
reordered = [matches[0], 0, 1, 0, matches[1], matches[2], matches[3], matches[4], null];
matches = reordered;
}
}
Expand Down

0 comments on commit ca8abfa

Please sign in to comment.