Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

New Date() not at midnight (OS bug?)

It appears that the date doesn't change till 2am.

 

  • Is this because of daylight savings synchronization?
  • Is it because time zone is GMT +2?
  • Is it for goal matching?
  • Does it change when daylight savings is finished?
  • Is it a bug?

For most people the date changes at midnight, is there some other reason why the Fitbit OS works to a different standard?

Author | ch, passion for improvement.

Best Answer
0 Votes
9 REPLIES 9

Can you provide a bit more info? Which device and firmware version, and a small code snippet.

 

Thanks

Best Answer
0 Votes

Sense - 44.128.4.17

 

clock.granularity = "seconds";
clock.ontick = (evt) => {
  let today = evt.date;
  let hours = today.getHours();
  let mins = util.zeroPad(today.getMinutes());
  let secs = util.zeroPad(today.getSeconds());

  if (mins == 0 && secs == 0)

  {
    var newDay = new Date();
    console.log(hours +" " +newDay.toDateString());
  }
}

When hours = 2 the date changes.

Author | ch, passion for improvement.

Best Answer
0 Votes

Yeah, so in Javascript the Date object is UTC. 

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date

 

If you want the clock time, you should already have it in evt.date

Best Answer
0 Votes

Unfortunately its in the setInterval so the evt.date is not available as it won't have been updated.

What do you recommend as an alternative?.

Author | ch, passion for improvement.

Best Answer
0 Votes

Just did a test

let today = evt.date;

Console.log(today.toTimeString());

let myDay = new Date();

Console.log(myDay .toTimeString());

They print the same time. Why, if one is UTC and the other local.?

The .getTimezoneOffset() are also the same.

Author | ch, passion for improvement.

Best Answer
0 Votes

What it looks like is evt.date returns local date and hours and minutes, but new Date() returns UTC date and local hours and minutes.

Is that possible?

Author | ch, passion for improvement.

Best Answer
0 Votes

I don't think that `new Date()` has a time zone (except inasmuch as it's the number of milliseconds since 1 January 1970 UTC). It depends how you use it.

Peter McLennan
Gondwana Software
Best Answer
0 Votes

True, then it must be a bug with .getDate() [not sure now that evt.date does actually return local date, as opposed to utc date].

Odd that it seems ok in the test in the OS simulator.

Will investigate further in real conditions on a watch.

Author | ch, passion for improvement.

Best Answer
0 Votes

 

It seems toDateString returns a UTC date and toString local time, both using the same date field !!!

 

Its the same with evt.date and new Date()  in the simulator.

Author | ch, passion for improvement.

Best Answer