@@ -45,16 +45,15 @@ function FakeDate() {
4545 }
4646}
4747
48- FakeDate . now =
49- function ( this : unknown ) {
48+ FakeDate . now = function ( this : unknown ) {
5049 const fakeAsyncTestZoneSpec = Zone . current . get ( 'FakeAsyncTestZoneSpec' ) ;
5150 if ( fakeAsyncTestZoneSpec ) {
52- return fakeAsyncTestZoneSpec . getCurrentRealTime ( ) + fakeAsyncTestZoneSpec . getCurrentTime ( ) ;
51+ return fakeAsyncTestZoneSpec . getFakeSystemTime ( ) ;
5352 }
5453 return OriginalDate . now . apply ( this , arguments ) ;
55- }
54+ } ;
5655
57- FakeDate . UTC = OriginalDate . UTC ;
56+ FakeDate . UTC = OriginalDate . UTC ;
5857FakeDate . parse = OriginalDate . parse ;
5958
6059// keep a reference for zone patched timer function
@@ -72,24 +71,24 @@ class Scheduler {
7271 // Scheduler queue with the tuple of end time and callback function - sorted by end time.
7372 private _schedulerQueue : ScheduledFunction [ ] = [ ] ;
7473 // Current simulated time in millis.
75- private _currentTime : number = 0 ;
76- // Current real time in millis.
77- private _currentRealTime : number = OriginalDate . now ( ) ;
74+ private _currentTickTime : number = 0 ;
75+ // Current fake system base time in millis.
76+ private _currentFakeBaseSystemTime : number = OriginalDate . now ( ) ;
7877 // track requeuePeriodicTimer
7978 private _currentTickRequeuePeriodicEntries : any [ ] = [ ] ;
8079
8180 constructor ( ) { }
8281
83- getCurrentTime ( ) {
84- return this . _currentTime ;
82+ getCurrentTickTime ( ) {
83+ return this . _currentTickTime ;
8584 }
8685
87- getCurrentRealTime ( ) {
88- return this . _currentRealTime ;
86+ getFakeSystemTime ( ) {
87+ return this . _currentFakeBaseSystemTime + this . _currentTickTime ;
8988 }
9089
91- setCurrentRealTime ( realTime : number ) {
92- this . _currentRealTime = realTime ;
90+ setFakeBaseSystemTime ( fakeBaseSystemTime : number ) {
91+ this . _currentFakeBaseSystemTime = fakeBaseSystemTime ;
9392 }
9493
9594 getRealSystemTime ( ) {
@@ -114,7 +113,7 @@ class Scheduler {
114113 ...options
115114 } ;
116115 let currentId = options . id ! < 0 ? Scheduler . nextId ++ : options . id ! ;
117- let endTime = this . _currentTime + delay ;
116+ let endTime = this . _currentTickTime + delay ;
118117
119118 // Insert so that scheduler queue remains sorted by end time.
120119 let newEntry : ScheduledFunction = {
@@ -165,15 +164,15 @@ class Scheduler {
165164 }
166165 // Find the last task currently queued in the scheduler queue and tick
167166 // till that time.
168- const startTime = this . _currentTime ;
167+ const startTime = this . _currentTickTime ;
169168 const targetTask = this . _schedulerQueue [ step - 1 ] ;
170169 this . tick ( targetTask . endTime - startTime , doTick , tickOptions ) ;
171170 }
172171
173172 tick ( millis : number = 0 , doTick ?: ( elapsed : number ) => void , tickOptions ?: {
174173 processNewMacroTasksSynchronously : boolean
175174 } ) : void {
176- let finalTime = this . _currentTime + millis ;
175+ let finalTime = this . _currentTickTime + millis ;
177176 let lastCurrentTime = 0 ;
178177 tickOptions = Object . assign ( { processNewMacroTasksSynchronously : true } , tickOptions ) ;
179178 // we need to copy the schedulerQueue so nested timeout
@@ -202,13 +201,13 @@ class Scheduler {
202201 this . _schedulerQueue . splice ( idx , 1 ) ;
203202 }
204203 }
205- lastCurrentTime = this . _currentTime ;
206- this . _currentTime = current . endTime ;
204+ lastCurrentTime = this . _currentTickTime ;
205+ this . _currentTickTime = current . endTime ;
207206 if ( doTick ) {
208- doTick ( this . _currentTime - lastCurrentTime ) ;
207+ doTick ( this . _currentTickTime - lastCurrentTime ) ;
209208 }
210209 let retval = current . func . apply (
211- global , current . isRequestAnimationFrame ? [ this . _currentTime ] : current . args ) ;
210+ global , current . isRequestAnimationFrame ? [ this . _currentTickTime ] : current . args ) ;
212211 if ( ! retval ) {
213212 // Uncaught exception in the current scheduled function. Stop processing the queue.
214213 break ;
@@ -230,10 +229,10 @@ class Scheduler {
230229 }
231230 }
232231 }
233- lastCurrentTime = this . _currentTime ;
234- this . _currentTime = finalTime ;
232+ lastCurrentTime = this . _currentTickTime ;
233+ this . _currentTickTime = finalTime ;
235234 if ( doTick ) {
236- doTick ( this . _currentTime - lastCurrentTime ) ;
235+ doTick ( this . _currentTickTime - lastCurrentTime ) ;
237236 }
238237 }
239238
@@ -243,10 +242,10 @@ class Scheduler {
243242 }
244243 // Find the last task currently queued in the scheduler queue and tick
245244 // till that time.
246- const startTime = this . _currentTime ;
245+ const startTime = this . _currentTickTime ;
247246 const lastTask = this . _schedulerQueue [ this . _schedulerQueue . length - 1 ] ;
248247 this . tick ( lastTask . endTime - startTime , doTick , { processNewMacroTasksSynchronously : false } ) ;
249- return this . _currentTime - startTime ;
248+ return this . _currentTickTime - startTime ;
250249 }
251250
252251 flush ( limit = 20 , flushPeriodic = false , doTick ?: ( elapsed : number ) => void ) : number {
@@ -263,14 +262,14 @@ class Scheduler {
263262 }
264263 // Find the last task currently queued in the scheduler queue and tick
265264 // till that time.
266- const startTime = this . _currentTime ;
265+ const startTime = this . _currentTickTime ;
267266 const lastTask = this . _schedulerQueue [ this . _schedulerQueue . length - 1 ] ;
268267 this . tick ( lastTask . endTime - startTime , doTick ) ;
269- return this . _currentTime - startTime ;
268+ return this . _currentTickTime - startTime ;
270269 }
271270
272271 private flushNonPeriodic ( limit : number , doTick ?: ( elapsed : number ) => void ) : number {
273- const startTime = this . _currentTime ;
272+ const startTime = this . _currentTickTime ;
274273 let lastCurrentTime = 0 ;
275274 let count = 0 ;
276275 while ( this . _schedulerQueue . length > 0 ) {
@@ -289,19 +288,19 @@ class Scheduler {
289288 }
290289
291290 const current = this . _schedulerQueue . shift ( ) ! ;
292- lastCurrentTime = this . _currentTime ;
293- this . _currentTime = current . endTime ;
291+ lastCurrentTime = this . _currentTickTime ;
292+ this . _currentTickTime = current . endTime ;
294293 if ( doTick ) {
295294 // Update any secondary schedulers like Jasmine mock Date.
296- doTick ( this . _currentTime - lastCurrentTime ) ;
295+ doTick ( this . _currentTickTime - lastCurrentTime ) ;
297296 }
298297 const retval = current . func . apply ( global , current . args ) ;
299298 if ( ! retval ) {
300299 // Uncaught exception in the current scheduled function. Stop processing the queue.
301300 break ;
302301 }
303302 }
304- return this . _currentTime - startTime ;
303+ return this . _currentTickTime - startTime ;
305304 }
306305}
307306
@@ -426,16 +425,16 @@ class FakeAsyncTestZoneSpec implements ZoneSpec {
426425 throw error ;
427426 }
428427
429- getCurrentTime ( ) {
430- return this . _scheduler . getCurrentTime ( ) ;
428+ getCurrentTickTime ( ) {
429+ return this . _scheduler . getCurrentTickTime ( ) ;
431430 }
432431
433- getCurrentRealTime ( ) {
434- return this . _scheduler . getCurrentRealTime ( ) ;
432+ getFakeSystemTime ( ) {
433+ return this . _scheduler . getFakeSystemTime ( ) ;
435434 }
436435
437- setCurrentRealTime ( realTime : number ) {
438- this . _scheduler . setCurrentRealTime ( realTime ) ;
436+ setFakeBaseSystemTime ( realTime : number ) {
437+ this . _scheduler . setFakeBaseSystemTime ( realTime ) ;
439438 }
440439
441440 getRealSystemTime ( ) {
0 commit comments