Skip to content

Commit 560b8ad

Browse files
committed
Changed the way Date is initialized
1 parent f0fcbfb commit 560b8ad

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

dist/analogclock.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,16 @@ class AnalogClock extends HTMLElement {
3030
function drawClock() {
3131
getConfig();
3232
var now = new Date();
33-
var options = '';
33+
//var options = { timeZone: 'Europe/London', minute: 'numeric' },
3434
if (config.timezone) { options = { timeZone: timezone } };
35-
var timestring = now.toLocaleString('sv-SE', options);
36-
now = new Date(timestring);
37-
if (demo) now = new Date('2021-01-10 10:08:20');
35+
var year = now.toLocaleString('sv-SE', { year: 'numeric', timeZone: timezone });
36+
var month = now.toLocaleString('sv-SE', { month: 'numeric', timeZone: timezone });
37+
var day = now.toLocaleString('sv-SE', { day: 'numeric', timeZone: timezone });
38+
var hour = now.toLocaleString('sv-SE', { hour: 'numeric', timeZone: timezone });
39+
var minute = now.toLocaleString('sv-SE', { minute: 'numeric', timeZone: timezone });
40+
var second = now.toLocaleString('sv-SE', { second: 'numeric', timeZone: timezone });
41+
now = new Date(year, month, day, hour, minute, second);
42+
if (demo) now = new Date(2021, 0, 10, 10, 8, 20);
3843
drawFace(ctx, radius, color_Background);
3944
drawTicks(ctx, radius, color_Ticks);
4045
if (!hide_FaceDigits) { drawFaceDigits(ctx, radius, color_FaceDigits) };
@@ -43,12 +48,12 @@ class AnalogClock extends HTMLElement {
4348
if (!hide_WeekNumber) { drawWeeknumber(ctx, now, locale, radius, color_Text) };
4449
if (!hide_DigitalTime) { drawTime(ctx, now, locale, radius, color_DigitalTime, timezone) };
4550
var options = { hour: '2-digit', hour12: false };
46-
var hour = now.toLocaleTimeString("sv-SE", options);
51+
hour = now.toLocaleTimeString("sv-SE", options);
4752
options = { minute: '2-digit', hour12: false };
48-
var min = now.toLocaleTimeString("sv-SE", options);
53+
minute = now.toLocaleTimeString("sv-SE", options);
4954
// drawHandX(ctx, ang, length, width, color, style) ang in degrees
50-
drawHand(ctx, (Number(hour) + Number(min) / 60) * 30, radius * 0.5, radius / 20, color_HourHand, style_HourHand);
51-
drawHand(ctx, (Number(min) + now.getSeconds() / 60) * 6, radius * 0.8, radius / 20, color_MinuteHand, style_MinuteHand);
55+
drawHand(ctx, (Number(hour) + Number(minute) / 60) * 30, radius * 0.5, radius / 20, color_HourHand, style_HourHand);
56+
drawHand(ctx, (Number(minute) + now.getSeconds() / 60) * 6, radius * 0.8, radius / 20, color_MinuteHand, style_MinuteHand);
5257
if (!hide_SecondHand) { drawHand(ctx, (now.getSeconds()) * 6, radius * 0.8, 0, color_SecondHand, style_SecondHand) };
5358
}
5459

0 commit comments

Comments
 (0)