Advertisement
Guest User

Untitled

a guest
May 18th, 2025
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. wxNow = (Complications.getComplication(wxId)).value;
  2. if (wxNow == null && hasWx) {
  3. var tempTemp = Weather.getCurrentConditions();
  4. if (tempTemp != null) {
  5. wxNow = tempTemp.temperature;
  6. }
  7. if (wxNow != null) {
  8. // not sure why -99.0 is used as an indicator of an invalid value when null
  9. // would work just as well
  10. //
  11. // it just makes your code more complex tbh, as all
  12. // future code which handles wxNow will have to
  13. // look out for this special "magic number",
  14. // especially code which displays wxNow.
  15. // (unless it's intended to display -99.0 when
  16. // the temperature is unavailable)
  17. wxNow = -99.0;
  18. }
  19. }
  20.  
  21. // since it's possible for wxNow to be a Number,
  22. // ensure it's a Float. this not only solves the issue
  23. // with the following conversion to fahrenheit (although that
  24. // could've been easily solved by changing 9 to 9.0 or
  25. // 5 to 5.0), but it also ensures
  26. // whatever code handles/displays wxNow later will
  27. // always see a consistent type (Float rather than Number)
  28. wxNow = wxNow.toFloat();
  29.  
  30. if ((ForC != System.UNIT_METRIC) && (wxNow != -99.0)) {
  31. wxNow = (wxNow * 9 / 5 + 32);
  32. }
  33.  
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement