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

Date won't update on clockface

Programming my own paid clockfaces and everything works great except the date won't update.  Pretty much all of them get complaints from downloaders who say the date won't update unless they complete a watch reset.  I have the day/date/year separated to ease moving them around on the display.  They are displayed twice to simulate a drop shadow.  (Apologies, my code is far from perfect).  I've tried everything including updating when the screen is swiped, anytime the display turns on, and even getting rid of my FitFont integration to see if that affected it, but it still won't update.   My last try I got desperate and even tried to update my date function every 50 milliseconds...still no joy. 

Any ideas on how to make it update?

 

import clock from "clock";
import * as document from "document";
import { preferences } from "user-settings";
import * as util from "../common/utils";
import { FitFont } from 'fitfont';
import { battery } from "power";
import { HeartRateSensor } from "heart-rate";
import { display } from "display";
import { today } from 'user-activity';
import { me as appbit } from "appbit";
import { goals } from "user-activity";


// Update the clock every minute
clock.granularity = "minutes";

 

// Update the <text> element every tick with the current time
clock.ontick = (evt) => {
let today2 = evt.date;
let hours = today2.getHours();
today2.text = evt.date;
if (util.zeroPad(hours) < 12) {
ampmLabel.text = "AM";
} else {
ampmLabel.text = "PM";
}

if (preferences.clockDisplay === "12h") {
// 12h format
hours = hours % 12 || 12;
} else {
// 24h format
hours = util.zeroPad(hours);
ampmLabel.text = "";
}

let mins = util.zeroPad(today2.getMinutes());
const space = ' ';
myLabel.text = `${hours}:${mins}${ampmLabel.text}`;
myLabel2.text = `${hours}:${mins}${ampmLabel.text}`;
}

 

const myDay = new FitFont({id:'myDay', font:'TS_30'})
const days = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"];

let today2 = new Date();
let dayName = days[today2.getDay()];
//myDay.text = dayName;

 

const myMonth = new FitFont({id:'myMonth', font:'TS_30'})
const months = ["JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"];
let today2 = new Date();
let monthName = months[today2.getMonth()];
//myMonth.text = monthName;

 

const myDate = new FitFont({id:'myDate', font:'TS_40'})
const dates = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31"];
let today2 = new Date();
let dateName = dates[today2.getDate()];
//myDate.text = dateName;

const myYear = new FitFont({id:'myYear', font:'TS_20', halign:'middle'})
const myYear2 = new FitFont({id:'myYear2', font:'TS_20', halign:'middle'})
let today2 = new Date();
var year = [today2.getFullYear()];
myYear.text = `${year}`;
myYear2.text = `${year}`;

function refresh_myDate() {
const allDate = new FitFont({id:'allDate', font:'TS_30', halign:'middle'})
allDate.text = dayName+"_"+monthName+"_"+dateName;
const allDate = new FitFont({id:'allDate2', font:'TS_30', halign:'middle'})
allDate.text = dayName+"_"+monthName+"_"+dateName;
} setInterval(refresh_myDate, 50);

Best Answer
0 Votes
3 REPLIES 3

You don't seem to be initialising any variables to correspond to elements in your SVG view (eg, using getElementById).

Peter McLennan
Gondwana Software
Best Answer
0 Votes

I'm using FitFont for all of the text, so I haven't needed to call anything up from the SVG view.  Everything I have displays perfectly, it's just that the date doesn't change after midnight.

Best Answer
0 Votes

My approach is to keep track of the previous date (day of month) in a global variable, and check whether the value encountered in ontick is the same. If it isn't, I update the date display (and datePrevious variable).

Peter McLennan
Gondwana Software
Best Answer
0 Votes