Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions world_time_app/lib/services/world_time.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -38,4 +39,4 @@ class WorldTime {

}

}
}