From e86bf13f78417a8c1fe3165ca8a4b50d4f5d520a Mon Sep 17 00:00:00 2001 From: Nissi Marcus Date: Fri, 10 Sep 2021 12:24:58 +0530 Subject: [PATCH] update in world_time The western time zones are showing wrong time as we are adding UTC. We have to subtract UTC for them. --- world_time_app/lib/services/world_time.dart | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/world_time_app/lib/services/world_time.dart b/world_time_app/lib/services/world_time.dart index fd1ec41..a282f8c 100644 --- a/world_time_app/lib/services/world_time.dart +++ b/world_time_app/lib/services/world_time.dart @@ -22,10 +22,11 @@ class WorldTime { // get properties from json String datetime = data['datetime']; String offset = data['utc_offset'].substring(1,3); + String offset_sign = data['utc_offset'].substring(0,1); // create DateTime object DateTime now = DateTime.parse(datetime); - now = now.add(Duration(hours: int.parse(offset))); + now = offset_sign == '+' ? now.add(Duration(hours: int.parse(offset))):now.subtract(Duration(hours: int.parse(offset))); // set the time property isDaytime = now.hour > 6 && now.hour < 20 ? true : false; @@ -38,4 +39,4 @@ class WorldTime { } -} \ No newline at end of file +}