©
本文档使用 PHP中文网手册 发布
娉ㄦ剰: 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);
鍙傛暟 | 绫诲瀷 | 璇﹁堪 |
---|---|---|
offset | number |
Offset of the desired timezone in hours (fractions will be honored) |
timestamp | numberstring |
Timestamp representing the desired time in UTC |
!!!! 璀﹀憡 !!!!! 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;