nice
This commit is contained in:
@@ -15,14 +15,17 @@ class SyncedTimeModule extends InfoModule {
|
||||
}
|
||||
|
||||
Timer refreshTimer() => Timer.periodic(const Duration(seconds: 10), (timer) async {
|
||||
var res = await http.get(Uri.parse('http://worldtimeapi.org/api/timezone/Europe/London'));
|
||||
if (res.statusCode == 200) {
|
||||
var json = jsonDecode(res.body);
|
||||
DateTime time = DateTime.parse(json['datetime']);
|
||||
timeOffset = time.millisecondsSinceEpoch - DateTime.now().millisecondsSinceEpoch;
|
||||
lastUpdate = DateTime.now();
|
||||
print("Time offset: $timeOffset");
|
||||
} else {
|
||||
|
||||
try {
|
||||
var res = await http.get(Uri.parse('http://worldtimeapi.org/api/timezone/Europe/London'));
|
||||
if (res.statusCode == 200) {
|
||||
var json = jsonDecode(res.body);
|
||||
DateTime time = DateTime.parse(json['datetime']);
|
||||
timeOffset = time.millisecondsSinceEpoch - DateTime.now().millisecondsSinceEpoch;
|
||||
lastUpdate = DateTime.now();
|
||||
print("Time offset: $timeOffset");
|
||||
}
|
||||
} catch (e) {
|
||||
print("Failed to get time from worldtimeapi.org");
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user