MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / fetchTime

Method fetchTime

contributed/modClock/main.js:821–851  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

819 }
820
821 fetchTime() {
822 if (this.rtc.valid)
823 this.setTime(this.rtc.seconds);
824
825 if (!this.connectionWasEstablished)
826 return;
827
828trace(`fetchTime\n`);
829 if (undefined !== this.upToDateTimer) {
830 Timer.schedule(this.upToDateTimer, 100, RESET_TIME_INTERVAL);
831 return;
832 }
833
834 this.upToDateTimer = Timer.set(id => {
835 let hosts = Object.assign([], ntpHosts);
836 let sntp = new SNTP({host: hosts.shift()}, function(message, value) {
837 switch (message) {
838 case 1: // success!
839 this.clock.setTime(value, 1);
840 this.clock.display.showTime(this.clock.currentStyle);
841 global.needsReboot = 0;
842 break;
843 case -1:
844 if (hosts.length)
845 return hosts.shift();
846 break;
847 }
848 });
849 sntp.clock = this;
850 }, 100, RESET_TIME_INTERVAL);
851 }
852
853/*
854 buttonPressed() {

Callers 4

connectedMethod · 0.95
tzMethod · 0.45
dstMethod · 0.45
configServerMethod · 0.45

Calls 4

setTimeMethod · 0.95
scheduleMethod · 0.80
showTimeMethod · 0.80
setMethod · 0.65

Tested by

no test coverage detected