Gregorian.info() versus System.getClockTime(): Is there a preferred way?

Assuming I would like to have a watch face app on my Fenix 3 that shows the time as well as date. I can see three ways to accomplish that:

  1. Use Toybox.Time.Gregorian.info(Toybox.Time.now(), ...) for time as well as date
  2. Use Toybox.Time.Gregorian.info(Toybox.Time.now(), ...) only for the date and Toybox.System.getClockTime() for time
  3. Use Toybox.Time.Gregorian.info(Toybox.Time.today(), ...) for the date and Toybox.System.getClockTime() for time

Is there any preferred solution? Are there any differences in required resources (CPU, RAM)?

  • I use 1 if I want both time data and time and Sys.getClockTime() if I only need the time (getting the current seconds in a 1hz WF for example)

    2 and 3 would be two calls, where you only need one.

  • That's true, but the number of function calls doesn't usually say anything about computational effort. Maybe there's not much difference. I just wondered why they provided the Gregorian.info(Toybox.Time.today(), ...) version and whether it is more efficient than the call with now().

  • If you look at the API doc, Time.today() returns a Moment representing the beginning of the current day, while Time.now() returns a Moment representing the current time

  • If you can get all the data you need from a single call to Gregorian.info, you should do that.

    The work of getting a broken-down time (hour/minute/second) has to be done for each of System.getClockTime() and Gregorian.info(). At the very least there is unnecessary duplication of work there, and duplication of work is waste.

    In the worst case (I have no evidence that this is the case), given that you're making two calls you could *theoretically* get different results. If you wrote this code:

    var clockTime = System.getClockTime();
    var gregorianInfo = Gregorian.info(Time.now(), ...);

    the first line could return 23:59:59.999, and the second line could return 2019-06-09T00:00:00.001 (one is just before midnight, and the other is just after, but for different days). I don't believe this is possible in ConnectIQ, but why would you even chance it given that making the two calls is guaranteed to be less efficient than just one of them?