Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/#162 UTC / GMT #201

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
35 changes: 19 additions & 16 deletions source/DataArea.mc
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,13 @@ class DataArea extends Ui.Drawable {
);

// Time zone 1 time.
var time;
if (cityLocalTime) {
var timeZoneGmtOffset = null;
var time = "...";
if (city.equals("UTC") || city.equals("GMT")) {

timeZoneGmtOffset = 0;

} else if (cityLocalTime) {

// Web request responded with server error e.g. unknown city.
if (cityLocalTime["error"] != null) {
Expand All @@ -98,29 +103,27 @@ class DataArea extends Ui.Drawable {

// Web request responded with time zone data for city.
} else {
var timeZoneGmtOffset;

// Use next GMT offset if it's now applicable (new data will be requested shortly).
if ((cityLocalTime["next"] != null) && (Time.now().value() >= cityLocalTime["next"]["when"])) {
timeZoneGmtOffset = cityLocalTime["next"]["gmtOffset"];
} else {
timeZoneGmtOffset = cityLocalTime["current"]["gmtOffset"];
}
timeZoneGmtOffset = new Time.Duration(timeZoneGmtOffset);

var localGmtOffset = Sys.getClockTime().timeZoneOffset;
localGmtOffset = new Time.Duration(localGmtOffset);

// (Local time) - (Local GMT offset) + (Time zone GMT offset)
time = Time.now().subtract(localGmtOffset).add(timeZoneGmtOffset);
time = Gregorian.info(time, Time.FORMAT_SHORT);
time = App.getApp().getFormattedTime(time.hour, time.min);
time = time[:hour] + ":" + time[:min] + time[:amPm];
}
}

// Awaiting response to web request sent by BackgroundService.
} else {
time = "...";
if (timeZoneGmtOffset != null) {
timeZoneGmtOffset = new Time.Duration(timeZoneGmtOffset);

var localGmtOffset = Sys.getClockTime().timeZoneOffset;
localGmtOffset = new Time.Duration(localGmtOffset);

// (Local time) - (Local GMT offset) + (Time zone GMT offset)
time = Time.now().subtract(localGmtOffset).add(timeZoneGmtOffset);
time = Gregorian.info(time, Time.FORMAT_SHORT);
time = App.getApp().getFormattedTime(time.hour, time.min);
time = time[:hour] + ":" + time[:min] + time[:amPm];
}

dc.setColor(gMonoLightColour, Gfx.COLOR_TRANSPARENT);
Expand Down
2 changes: 1 addition & 1 deletion source/DataFields.mc
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ class DataFields extends Ui.Drawable {
if (tomorrow) {
now = now.add(new Time.Duration(24 * 60 * 60));
}
var d = Gregorian.info(Time.now(), Time.FORMAT_SHORT);
var d = Gregorian.info(now, Time.FORMAT_SHORT);
var rad = Math.PI / 180.0d;
var deg = 180.0d / Math.PI;

Expand Down