NOTE: this is not an injectable instance, just a globally available mock class of Date
.
Mock of the Date type which has its timezone specified via constructor arg.
The main purpose is to create Date-like instances with timezone fixed to the specified timezone offset, so that we can test code that depends on local timezone settings without dependency on the time zone settings of the machine where the code is running.
angular.mock.TzDate(offset, timestamp);
Param | Type | Details |
---|---|---|
offset | number | Offset of the desired timezone in hours (fractions will be honored) |
timestamp | number string | Timestamp representing the desired time in UTC |
!!!! WARNING !!!!! This is not a complete Date object so only methods that were implemented can be called safely. To make matters worse, TzDate instances inherit stuff from Date via a prototype.
We do our best to intercept calls to "unimplemented" methods, but since the list of methods is incomplete we might be missing some non-standard methods. This can result in errors like: "Date.prototype.foo called on incompatible Object".
var newYearInBratislava = new TzDate(-1, '2009-12-31T23:00:00Z'); newYearInBratislava.getTimezoneOffset() => -60; newYearInBratislava.getFullYear() => 2010; newYearInBratislava.getMonth() => 0; newYearInBratislava.getDate() => 1; newYearInBratislava.getHours() => 0; newYearInBratislava.getMinutes() => 0; newYearInBratislava.getSeconds() => 0;
© 2010–2017 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://code.angularjs.org/1.5.11/docs/api/ngMock/type/angular.mock.TzDate