Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

33
LINES

< > BotCompany Repo | #1015620 // timeJumpDetector (notices wake-up from suspend/hibernate mode)

JavaX fragment (include)

1  
static long timeJumpDetector_lastTimeJump; // in sys time
2  
static long timeJumpDetector_lastTimeJumpLength;
3  
sbool timeJumpDetector_verbose;
4  
static L timeJumpDetector_onTimeJump = synchroList();
5  
static int timeJumpDetector_minJump = 5000;
6  
7  
static void timeJumpDetector() {
8  
  doEvery(1000, new Runnable {
9  
    long diff = now()-sysNow();
10  
    long lastSysNow = sysNow();
11  
    
12  
    public void run() {
13  
      long sysNow = sysNow();
14  
      long newDiff = now()-sysNow;
15  
      long d = newDiff-diff;
16  
      if (timeJumpDetector_verbose)
17  
        print("timeJumpDetector: sysNow=" + sysNow + ", diff=" + newDiff);
18  
      if (abs(d) <= timeJumpDetector_minJump && /*isWindows() &&*/ sysNow-lastSysNow >= 10000)
19  
        d = sysNow-lastSysNow-10000;
20  
      if (abs(d) > timeJumpDetector_minJump) {
21  
        diff = now()-sysNow();
22  
        timeJumpDetector_lastTimeJump = sysNow();
23  
        timeJumpDetector_lastTimeJumpLength = d;
24  
        printAndProgramLog(ymd_hms() + ": Time jump occurred! (" + formatDouble(toSeconds(d), 1) + " seconds)");
25  
        if (nempty(timeJumpDetector_onTimeJump)) thread {
26  
          pcallFAll(concurrentlyIterateList(timeJumpDetector_onTimeJump));
27  
        }
28  
      }
29  
      diff = newDiff;
30  
      lastSysNow = sysNow;
31  
    }
32  
  });
33  
}

Author comment

Began life as a copy of #1015617

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1015620
Snippet name: timeJumpDetector (notices wake-up from suspend/hibernate mode)
Eternal ID of this version: #1015620/20
Text MD5: 16d4cdfc3f6537e917feb56c7289ef80
Author: stefan
Category: javax / os
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-11-12 16:29:35
Source code size: 1267 bytes / 33 lines
Pitched / IR pitched: No / No
Views / Downloads: 470 / 559
Version history: 19 change(s)
Referenced in: [show references]