Skip to content

Commit

Permalink
hide alternate timezone when in that timezone, fix warmsound#174
Browse files Browse the repository at this point in the history
replaces the time text with `@` and hides city name
this allows the goal indicators to be drawn
  • Loading branch information
pfn committed Oct 15, 2020
1 parent 18ead97 commit 5e12bb7
Showing 1 changed file with 25 additions and 17 deletions.
42 changes: 25 additions & 17 deletions source/DataArea.mc
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class DataArea extends Ui.Drawable {
drawGoalIcon(dc, mGoalIconRightX, mRightGoalType, mRightGoalIsValid, Graphics.TEXT_JUSTIFY_RIGHT);

var city = App.getApp().getProperty("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 @@ -76,17 +77,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) {
Expand All @@ -111,11 +101,27 @@ 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);
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);
time = time[:hour] + ":" + time[:min] + time[:amPm];
shouldDrawGoalValues = false;
} else {
time = "@";
}
}

// Awaiting response to web request sent by BackgroundService.
Expand All @@ -132,7 +138,9 @@ 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

0 comments on commit 5e12bb7

Please sign in to comment.