We live in UTC+1:00 Timezone.
In Summer (lfrom Mar 27 to Okt 30) comes additional hour to this ("Summertime").
The Simulator taks care of summer or wintertime and get local time correct. On Device the getting of a time from the other timearea become 1 hour defference, which is wrong:
- If now is summer and I want to get correct Gregorian representation of a epoch from winter, it diffs 1 hour from correct time
- If now is winter and I want to get correct Gregorian representation of a epoch from summer, it diffs 1 hour from correct time
Consider the following Code based on Unix Epochs:
function test_time(dc as G.Dc) { var location = new Position.Location({ :latitude => 51.338248, :longitude => 12.362537, :format => :degrees, }); var text = ""; // var m = Time.Gregorian.moment({ :year => 2015, :month => 10, :day => 15, :hour => 14, :minute => 0, :second => 0 }); // var i = Time.Gregorian.info(m, Time.FORMAT_MEDIUM); // var s = Lang.format("$1$ $2$ $3$ $4$:$5$:$6$", [i.month, i.day, i.year, i.hour.format("%02d"), i.min.format("%02d"), i.sec.format("%02d")]); // Sys.println(s); // m = Time.Gregorian.moment({ :year => 2015, :month => 11, :day => 15, :hour => 14, :minute => 0, :second => 0 }); // i = Time.Gregorian.info(m, Time.FORMAT_MEDIUM); // Sys.println(Lang.format("$1$ $2$ $3$ $4$:$5$:$6$", [i.month, i.day, i.year, i.hour.format("%02d"), i.min.format("%02d"), i.sec.format("%02d")])); // Sys.println(""); Sys.println("\n *************** test_time *****************"); Sys.println("summer=1667023200"); Sys.println(" should GMT: Sat Oct 29 2022 06:00:00 GMT+0000"); Sys.println(" should loc: Sat Oct 29 2022 08:00:00 GMT+0200 (Mitteleuropäische Sommerzeit)"); var m = new Time.Moment(1667023200); var i = Time.Gregorian.utcInfo(m, Time.FORMAT_SHORT); var s = Lang.format("utc: $1$ $2$ $3$ $4$:$5$:$6$", [i.month, i.day, i.year, i.hour.format("%02d"), i.min.format("%02d"), i.sec.format("%02d")]); text += s; Sys.println(s); i = Time.Gregorian.info(m, Time.FORMAT_SHORT); s = Lang.format("inf: $1$ $2$ $3$ $4$:$5$:$6$", [i.month, i.day, i.year, i.hour.format("%02d"), i.min.format("%02d"), i.sec.format("%02d")]); text += "\n" + s; Sys.println(s); text += "\n"; Sys.println(""); Sys.println("winter=1667113200"); Sys.println(" should GMT: Sun Oct 30 2022 07:00:00 GMT+0000"); Sys.println(" should loc: Sun Oct 30 2022 08:00:00 GMT+0100 (Mitteleuropäische Normalzeit)"); m = new Time.Moment(1667113200); i = Time.Gregorian.utcInfo(m, Time.FORMAT_SHORT); s = Lang.format("utc: $1$ $2$ $3$ $4$:$5$:$6$", [i.month, i.day, i.year, i.hour.format("%02d"), i.min.format("%02d"), i.sec.format("%02d")]); text += "\n" + s; Sys.println(s); i = Time.Gregorian.info(m, Time.FORMAT_SHORT); s = Lang.format("inf: $1$ $2$ $3$ $4$:$5$:$6$", [i.month, i.day, i.year, i.hour.format("%02d"), i.min.format("%02d"), i.sec.format("%02d")]); text += "\n" + s; Sys.println(s); var myTextArea = new WatchUi.TextArea({ :text=>text, :color=>Graphics.COLOR_BLACK, :font=>[Graphics.FONT_MEDIUM, Graphics.FONT_XTINY, Graphics.FONT_XTINY], :locX =>WatchUi.LAYOUT_HALIGN_CENTER, :locY=>WatchUi.LAYOUT_VALIGN_CENTER, :width=>220, :height=>200 }); myTextArea.draw(dc); }
on Log it prints:
Info: Okt 29 ist the last day of summertime (UTC+2:00), Okt 30 ist the first day with wintertime (UTC+1:00)
*************** test_time ***************** summer=1667023200 should GMT: Sat Oct 29 2022 06:00:00 GMT+0000 should loc: Sat Oct 29 2022 08:00:00 GMT+0200 (Mitteleuropäische Sommerzeit) utc: 10 29 2022 06:00:00 inf: 10 29 2022 08:00:00 winter=1667113200 should GMT: Sun Oct 30 2022 07:00:00 GMT+0000 should loc: Sun Oct 30 2022 08:00:00 GMT+0100 (Mitteleuropäische Normalzeit) utc: 10 30 2022 07:00:00 inf: 10 30 2022 08:00:00
Here the Screenshot of Simulator and real Device:
It is so that the simulator takes into account the correct time zone offset of the given time:
- in summer 2 hours are added (UTC+2:00)
- in winter 1 hour is added (UTC+1:00)
But the same call on the clock ALWAYS takes into account the CURRENT timezone offset at runtime of the program.
I can correct this manually in the codee, but this leads to a wrong display in the simulator and works only for Central European Time. The problem cannot be solved satisfactorily for mic. Since my watchface represents the course of the sun and additionally the shortest and longest day, it is always displayed incorrectly, since times must always be calculated from the other time (summer and winter).
This then looks like this:
The simulator calculates (we are NOW in summer time UTC+2:00) the sunrises and sunsets for winter (blue line with UTC+1:00) correctly.
The real device calculates the times in coming winter with the TODAY SHIFT (UTC+2:00) and therefore wrong.
How can I solve the Probelem? To me it looks like a bug in the API.