diff options
| author | Igor Minar | 2012-03-27 08:05:07 -0700 |
|---|---|---|
| committer | Igor Minar | 2012-03-28 16:30:31 -0700 |
| commit | da9f4dfcf4f3d0c21821d8474ac0bb19a3c51415 (patch) | |
| tree | c70b8e9b3db5bd5a266ea7156ee7312c3cd80554 /src/ngMock/angular-mocks.js | |
| parent | ac4318a2fa5c6d306dbc19466246292a81767fca (diff) | |
| download | angular.js-da9f4dfcf4f3d0c21821d8474ac0bb19a3c51415.tar.bz2 | |
feat(TzDate): add support for toISOString method
Diffstat (limited to 'src/ngMock/angular-mocks.js')
| -rw-r--r-- | src/ngMock/angular-mocks.js | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/src/ngMock/angular-mocks.js b/src/ngMock/angular-mocks.js index f5dd6758..8c50c90e 100644 --- a/src/ngMock/angular-mocks.js +++ b/src/ngMock/angular-mocks.js @@ -397,6 +397,19 @@ angular.mock.$LogProvider = function() { return parseInt(str, 10); } + function padNumber(num, digits, trim) { + var neg = ''; + if (num < 0) { + neg = '-'; + num = -num; + } + num = '' + num; + while(num.length < digits) num = '0' + num; + if (trim) + num = num.substr(num.length - digits); + return neg + num; + } + /** * @ngdoc object @@ -523,12 +536,25 @@ angular.mock.$LogProvider = function() { return self.date.getDay(); }; + // provide this method only on browsers that already have it + if (self.toISOString) { + self.toISOString = function() { + return padNumber(self.origDate.getUTCFullYear(), 4) + '-' + + padNumber(self.origDate.getUTCMonth() + 1, 2) + '-' + + padNumber(self.origDate.getUTCDate(), 2) + 'T' + + padNumber(self.origDate.getUTCHours(), 2) + ':' + + padNumber(self.origDate.getUTCMinutes(), 2) + ':' + + padNumber(self.origDate.getUTCSeconds(), 2) + '.' + + padNumber(self.origDate.getUTCMilliseconds(), 3) + 'Z' + } + } + //hide all methods not implemented in this mock that the Date prototype exposes var unimplementedMethods = ['getMilliseconds', 'getUTCDay', 'getYear', 'setDate', 'setFullYear', 'setHours', 'setMilliseconds', 'setMinutes', 'setMonth', 'setSeconds', 'setTime', 'setUTCDate', 'setUTCFullYear', 'setUTCHours', 'setUTCMilliseconds', 'setUTCMinutes', 'setUTCMonth', 'setUTCSeconds', - 'setYear', 'toDateString', 'toJSON', 'toGMTString', 'toLocaleFormat', 'toLocaleString', + 'setYear', 'toDateString', 'toGMTString', 'toJSON', 'toLocaleFormat', 'toLocaleString', 'toLocaleTimeString', 'toSource', 'toString', 'toTimeString', 'toUTCString', 'valueOf']; angular.forEach(unimplementedMethods, function(methodName) { |
