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

hide alternate timezone when in that timezone, fix #174 #175

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
40 changes: 23 additions & 17 deletions source/DataArea.mc
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class DataArea extends Ui.Drawable {
drawGoalIcon(dc, mGoalIconRightX, mRightGoalType, mRightGoalIsValid, Graphics.TEXT_JUSTIFY_RIGHT);

var city = getPropertyValue("LocalTimeInCity");
var shouldDrawGoalValues = true;

// #78 Setting with value of empty string may cause corresponding property to be null.
if ((city != null) && (city.length() != 0)) {
Expand All @@ -88,17 +89,6 @@ class DataArea extends Ui.Drawable {
city = cityLocalTime["city"];
}

// Time zone 1 city.
dc.setColor(gMonoDarkColour, Gfx.COLOR_TRANSPARENT);
dc.drawText(
locX + (width / 2),
mRow1Y,
gNormalFont,
// Limit string length.
city.substring(0, 10),
Graphics.TEXT_JUSTIFY_CENTER | Graphics.TEXT_JUSTIFY_VCENTER
);

// Time zone 1 time.
var time;
if (cityLocalTime != null) {
Expand All @@ -123,11 +113,26 @@ class DataArea extends Ui.Drawable {
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) as FormattedTime;
time = time[:hour] + ":" + time[:min] + time[:amPm];
if (timeZoneGmtOffset.compare(localGmtOffset) != 0) {
// Time zone 1 city.
dc.setColor(gMonoDarkColour, Gfx.COLOR_TRANSPARENT);
dc.drawText(
locX + (width / 2),
mRow1Y,
gNormalFont,
// Limit string length.
city.substring(0, 10),
Graphics.TEXT_JUSTIFY_CENTER | Graphics.TEXT_JUSTIFY_VCENTER
);
// (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) as FormattedTime;
time = time[:hour] + ":" + time[:min] + time[:amPm];
shouldDrawGoalValues = false;
} else {
time = "";
}
}

// Awaiting response to web request sent by BackgroundService.
Expand All @@ -144,7 +149,8 @@ class DataArea extends Ui.Drawable {
Graphics.TEXT_JUSTIFY_CENTER | Graphics.TEXT_JUSTIFY_VCENTER
);

} else {
}
if (shouldDrawGoalValues) {
drawGoalValues(dc, locX, mLeftGoalCurrent, mLeftGoalMax, Graphics.TEXT_JUSTIFY_LEFT);
drawGoalValues(dc, locX + width, mRightGoalCurrent, mRightGoalMax, Graphics.TEXT_JUSTIFY_RIGHT);
}
Expand Down