01-04-2019 12:27
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

01-04-2019 12:27
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Hi, all! I am building a Versa Clockface, I can put month, date and time on it, but still have problem with adding weekdate( Like Mon, Tue.....). Is there anyone can help me with this?Thanks!

01-05-2019 01:47
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

01-05-2019 01:47
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Hi sspyli,
you can use getDay():
let weekday = date_var.getDay(); if(weekday === 0) { console.log("Sun"); } else if(weekday === 1) { console.log("Mon"); } else if(weekday === 2) { console.log("Tue"); } else if(weekday === 3) { console.log("Wed"); } else if(weekday === 4) { console.log("Thu"); } else if(weekday === 5) { console.log("Fri"); } else if(weekday === 6) { console.log("Sat"); } else { console.log("Err"); }

01-05-2019 07:45
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

01-05-2019 07:45
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Thank you SO much!
I tried to use those, but I keep getting an error message which says "date_var is not defined weekday". How would I go about doing that?

01-05-2019 13:04 - edited 01-05-2019 13:05
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

01-05-2019 13:04 - edited 01-05-2019 13:05
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
date_var is simply the variable name nowo chose to use to make that code snippet (it's not a special keyword, or anything) - you will need to change that to whatever you currently call your date variable.

01-05-2019 14:21
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

01-05-2019 14:21
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Then I changed the name, shows "Expected a function", looks like still missing some code here.

01-05-2019 14:44
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

01-05-2019 14:44
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Post the code you're using - that's the only way we will be able to help more.

01-05-2019 14:46
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

01-05-2019 14:46
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
import clock from "clock";
import document from "document";
import { preferences } from "user-settings";
import * as util from "../common/utils";
import { today } from "user-activity";
import { display } from "display";
console.log((today.local.steps || 0) + " steps");
let txtSteps = document.getElementById("txtSteps");
function update() {
steps.text = today.adjusted.steps || 0 + " steps";
}
// Update the clock every minute
clock.granularity = "minutes";
// Get a handle on the <text> element
const myLabel = document.getElementById("myLabel");
const myweekday = document.getElementById("myWeekday");
const myMonth = document.getElementById("myMonth");
const myDay = document.getElementById("myDay");
const txtSeps = document.getElementById("txtSteps");
// inside the clock tick handler
txtSteps.text = today.adjusted.steps || 0 + " steps";
// Update the <text> element every tick with the current time
clock.ontick = (evt) => {
let today = evt.date;
let hours = today.getHours();
let monthnum = today.getMonth();
let day = today.getDate();
var month = new Array();
month[0] = "Jan";
month[1] = "Feb";
month[2] = "Mar";
month[3] = "Apr";
month[4] = "May";
month[5] = "Jun";
month[6] = "Jul";
month[7] = "Aug";
month[8] = "Sep";
month[9] = "Oct";
month[10] = "Nov";
month[11] = "Dec";
let monthname = month[monthnum];
let weekday = date1.getDay();
if(weekday === 0) {
console.log("Sun");
} else if(weekday === 1) {
console.log("Mon");
} else if(weekday === 2) {
console.log("Tue");
} else if(weekday === 3) {
console.log("Wed");
} else if(weekday === 4) {
console.log("Thu");
} else if(weekday === 5) {
console.log("Fri");
} else if(weekday === 6) {
console.log("Sat");
} else {
console.log("Err");
}
display.onchange = function() {
if (display.on) {
console.log("ON");
updateSteps();
}
}
if (preferences.clockDisplay === "12h") {
// 12h format
hours = hours % 12 || 12;
} else {
// 24h format
hours = util.zeroPad(hours);
}
let mins = util.zeroPad(today.getMinutes());
myLabel.text = `${hours}:${mins}`;
myMonth.text = `${monthname}`;
myDay.text = `${day}`;
myWeekday.text = `${weekday}`;
}

01-05-2019 14:53 - edited 01-05-2019 15:23
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

01-05-2019 14:53 - edited 01-05-2019 15:23
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Use the same setup as you use already for your month name.
Replace
let weekday = date1.getDay();
if(weekday === 0) {
console.log("Sun");
} else if(weekday === 1) {
console.log("Mon");
} else if(weekday === 2) {
console.log("Tue");
} else if(weekday === 3) {
console.log("Wed");
} else if(weekday === 4) {
console.log("Thu");
} else if(weekday === 5) {
console.log("Fri");
} else if(weekday === 6) {
console.log("Sat");
} else {
console.log("Err");
}
with
var day = new Array();
day[0] = "Mon";
day[1] = "Tue";
day[2] = "Wed";
day[3] = "Thu";
day[4] = "Fri";
day[5] = "Sat";
day[6] = "Sun";
let dayname = day[today.getDate];
then
myWeekday.text = `${weekday}`;
becomes
myWeekday.text = `${dayname}`;

01-05-2019 14:56
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


01-05-2019 14:56
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Where is date1 declared and initialised?
Gondwana Software

01-05-2019 14:58
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

01-05-2019 14:58
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
I just changed that one, have no clues to declare.

01-05-2019 15:04 - edited 01-05-2019 15:36
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

01-05-2019 15:04 - edited 01-05-2019 15:36
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
EDIT: Ignore. See my suggested fix above.

01-05-2019 15:12
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

01-05-2019 15:12
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Before I added the weekday code, the clock face I had built like this.

01-05-2019 15:28 - edited 01-05-2019 15:30
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

01-05-2019 15:28 - edited 01-05-2019 15:30
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
I've edited my answer above. Now that I can see your code, it's easier to replicate the monthname setup you're already using.
In your code above, you don't actually set a name for the day - you're logging the name to the console, but never actually retaining the name, so at best your weekday.text would be "0", "1", ... "6". In my code above, the name is actually set and used.
Note that for me the first day of the week is Monday, so I used that for value 0... If your week starts with Sunday, use that for value 0 (as nowo did in their example).

01-05-2019 16:08
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

01-05-2019 16:08
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
I replace all as you posted, but still shows my Weekday is not defined.

01-05-2019 16:25 - edited 01-05-2019 16:27
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

01-05-2019 16:25 - edited 01-05-2019 16:27
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Check your code:
const myweekday = document.getElementById("myWeekday");
^ note not a capitol W
but later on you call it with a capitol:
myWeekday.text = `${dayname}`;
I suspect that's all you're seeing just now.

01-05-2019 16:36
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

01-05-2019 16:36
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Thank you for that. Then I replaced the "const weekday" to "const Weekday". Then another issue came up, Unhandled TypeError, "can't set property "text"of null my Weekday.at the final line. And also did you see the clock face, all the weekday came out.

01-05-2019 16:58
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

01-05-2019 16:58
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
The clockface shows like this

01-05-2019 17:47
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

01-05-2019 17:47
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
This is from the original Fitbit sample. It has been working for me...
//Get the date in the proper order
function formatDate(date) { var monthNames = [ "Jan", "Feb", "Mar", "April", "May", "June", "July", "Aug", "Sep", "Oct", "Nov", "Dec" ]; var dayNames = [ "Sun", "Mon", "Tues", "Weds", "Thurs", "Fri", "Sat" ]; var day = date.getDate(); var monthIndex = date.getMonth(); var year = date.getFullYear(); var todayIndex = date.getDay(); return dayNames[todayIndex] + ', ' + day + ' ' + monthNames[monthIndex]; }

01-06-2019 08:39
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

01-06-2019 08:39
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Thank you! I will try it.

01-06-2019 10:48
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

01-06-2019 10:48
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
So I used the code you sent, then my clockface shows like this. Is there any thing I missed?

