{"record":{"id":"c845154b6040f47d","repo":"angular/angular.js","slug":"method-is-not-implemented-in-the-tzdate-mock","errorCode":null,"errorMessage":"Method '{}' is not implemented in the TzDate mock","messagePattern":"Method '(.+?)' is not implemented in the TzDate mock","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/ngMock/angular-mocks.js","lineNumber":878,"sourceCode":"            padNumberInMock(self.origDate.getUTCDate(), 2) + 'T' +\n            padNumberInMock(self.origDate.getUTCHours(), 2) + ':' +\n            padNumberInMock(self.origDate.getUTCMinutes(), 2) + ':' +\n            padNumberInMock(self.origDate.getUTCSeconds(), 2) + '.' +\n            padNumberInMock(self.origDate.getUTCMilliseconds(), 3) + 'Z';\n    };\n  }\n\n  //hide all methods not implemented in this mock that the Date prototype exposes\n  var unimplementedMethods = ['getUTCDay',\n      'getYear', 'setDate', 'setFullYear', 'setHours', 'setMilliseconds',\n      'setMinutes', 'setMonth', 'setSeconds', 'setTime', 'setUTCDate', 'setUTCFullYear',\n      'setUTCHours', 'setUTCMilliseconds', 'setUTCMinutes', 'setUTCMonth', 'setUTCSeconds',\n      'setYear', 'toDateString', 'toGMTString', 'toJSON', 'toLocaleFormat', 'toLocaleString',\n      'toLocaleTimeString', 'toSource', 'toString', 'toTimeString', 'toUTCString', 'valueOf'];\n\n  angular.forEach(unimplementedMethods, function(methodName) {\n    self[methodName] = function() {\n      throw new Error('Method \\'' + methodName + '\\' is not implemented in the TzDate mock');\n    };\n  });\n\n  return self;\n};\n\n//make \"tzDateInstance instanceof Date\" return true\nangular.mock.TzDate.prototype = Date.prototype;\n\n\n/**\n * @ngdoc service\n * @name $animate\n *\n * @description\n * Mock implementation of the {@link ng.$animate `$animate`} service. Exposes two additional methods\n * for testing animations.\n *","sourceCodeStart":860,"sourceCodeEnd":896,"githubUrl":"https://github.com/angular/angular.js/blob/d8f77817eb5c98dec5317bc3756d1ea1812bcfbe/src/ngMock/angular-mocks.js#L860-L896","documentation":"angular.mock.TzDate is a Date mock with a fixed timezone offset, intended only for testing timezone-dependent reading logic. It deliberately implements a small subset of Date (getTimezoneOffset, getDate, getHours, ...) and replaces every method in unimplementedMethods — mutators (setDate, setTime, ...), formatters (toString, toDateString, toISOString-adjacent, toLocaleString, ...) and toJSON/valueOf — with stubs that throw, because silently wrong results would be worse than a loud failure.","triggerScenarios":"Calling any listed method on a TzDate instance: tzDate.toString() (implicit string coercion), tzDate.setDate(n) or setHours(n) from a date-picker library, tzDate.toJSON() — which means JSON.stringify of an object holding a TzDate throws — or tzDate.valueOf() from arithmetic/comparison.","commonSituations":"Using TzDate as a drop-in general Date replacement in code under test; passing a model containing TzDate through JSON.stringify or $http request serialization; moment/lodash/date utilities calling valueOf()/set* methods; TzDate.prototype is even set to Date.prototype so instanceof Date passes, making the failure surprising.","solutions":["Restrict TzDate usage to code paths that only read the implemented getters (getTimezoneOffset, getDate, getDay, getHours, getMinutes, getMonth, getSeconds, getFullYear, getTime, getMilliseconds).","Convert to a real Date before general manipulation: var real = new Date(tzDate.getTime()); then call set*/toString/toJSON on that.","For richer timezone testing, use a real timezone library (moment-timezone) or set the runtime TZ environment instead of TzDate."],"exampleFix":"// before\nvar tz = new angular.mock.TzDate(-3, '2013-12-11T15:20:00Z');\nvar json = JSON.stringify({at: tz}); // throws: toJSON not implemented\n\n// after\nvar tz = new angular.mock.TzDate(-3, '2013-12-11T15:20:00Z');\nvar json = JSON.stringify({at: new Date(tz.getTime())}); // real Date serializes fine","handlingStrategy":"type-guard","validationCode":"// Convert to a real Date before any general Date manipulation\nvar date = (tzDate instanceof angular.mock.TzDate)\n  ? new Date(tzDate.getTime()) // getTime IS implemented\n  : tzDate;","typeGuard":"var TZ_DATE_UNIMPLEMENTED = ['getUTCDay','getYear','setDate','setFullYear','setHours',\n  'setMilliseconds','setMinutes','setMonth','setSeconds','setTime','setUTCDate',\n  'setUTCFullYear','setUTCHours','setUTCMilliseconds','setUTCMinutes','setUTCMonth',\n  'setUTCSeconds','setYear','toDateString','toGMTString','toJSON','toLocaleFormat',\n  'toLocaleString','toLocaleTimeString','toSource','toString','toTimeString',\n  'toUTCString','valueOf'];\n\nfunction isTzDateMethodSafe(methodName) {\n  return TZ_DATE_UNIMPLEMENTED.indexOf(methodName) === -1;\n}","tryCatchPattern":null,"preventionTips":["Use TzDate only for timezone-offset reading tests; convert with new Date(tzDate.getTime()) for everything else.","Never pass a TzDate through JSON.stringify (toJSON throws).","Remember TzDate passes instanceof Date, so instanceof is not a safety check."],"tags":["angular-mocks","date","timezone","not-implemented"],"backgroundTag":"mock-method-not-implemented","analyzedSha":"d8f77817eb5c98dec5317bc3756d1ea1812bcfbe","analyzedAt":"2026-08-21T20:36:31.651Z","schemaVersion":2},"datasetVersion":"2026-08-22T04:17:13.399Z"}