1: Calculating "n"
Code: Select all
let n = Math.ceil(((e.utc - new Date(e.year, 0, 1).getTime()) / 864e5 + new Date(e.year, 0, 1).getDay() + 1) / 7);
e.utc: Assuming this is the current date in UTC.
new Date(e.year, 0, 1).getTime(): The timestamp in milliseconds for January 1st of the year specified by e.year.
864e5: This is the number of milliseconds in one day (86400000 milliseconds).
new Date(e.year, 0, 1).getDay(): The day of the week for January 1st (0 is Sunday, 1 is Monday, and so on).
This part of the code calculates the number of days from the beginning of the year to e.utc, adds the day of the week for January 1st, and then divides by 7 to find the number of weeks. Math.ceil is used to round up to the nearest whole number.
2: Padding n with Leading Zeros (if necessary)
Code: Select all
if (L) {
n = n.toString().padStart(v.length, "0");
}
If L is true, the value of n is converted to a string and padded with leading zeros to match the length of v.length.
(But where does the value of L come from? How is it obtained? I'm not sure because from the attached script it doesn't seem like it's been mentioned yet.)
3: Setting Widget Properties
Code: Select all
for (let e = 0; e < v.length; e++) {
if (v.length - n.length < e && L === false) {
v[e].setProperty(hmUI.prop.VISIBLE, false);
} else {
v[e].setProperty(hmUI.prop.VISIBLE, true);
v[e].setProperty(hmUI.prop.SRC, N[n.toString().charAt(e)]);
}
}
Iterates over each element in v (assuming v is an array of widgets).
If the condition v.length - n.length < e is met and L is false, the widget is set to not be visible (VISIBLE is false).
Otherwise, the widget is set to be visible (VISIBLE is true) and its source image (SRC) is set using the character from n at position e.
4: Creating Widgets
Code: Select all
for (let e = 0; e < v.length; e++) {
v[e] = hmUI.createWidget(hmUI.widget.IMG, {x: 257 + e * 25, y: 378, w: 25, h: 37, enable: false, show_level: hmUI.show_level.ONLY_NORMAL});
}
E = hmUI.createWidget(hmUI.widget.IMG, {x: 157, y: 379, w: 94, h: 37, src: "0120.png", enable: false, show_level: hmUI.show_level.ONLY_NORMAL});
Iterates to create widgets for each element in v and sets their position and size.
Creates another widget E with specified position, size, and image source.
Summary
Calculates the week number of the year based on the given date and time.
Pads the value n with leading zeros if necessary.
Sets the visibility and image source of widgets based on the calculated value.
Creates the necessary widgets in the user interface.