• Jump To … +
    app.js Chronograph.js Crown.js DateIndicator.js DayIndicator.js DayNightIndicator.js Dial.js EquationOfTime.js Foudroyante.js MinuteRepeater.js MonthIndicator.js MoonPhase.js PowerReserve.js WeekIndicator.js YearIndicator.js
  • WeekIndicator.js

  • ¶

    Week Indicator Class @params settings: object @params parentWatch: Watch instance

    The Week Class will rotate an element to depict the current week of the year. By default, this class expects 52 weeks per year but an iso boolean can be passed to account for a 53rd week. The week indicator element can rotate either direction based on the invert boolean as well.

    class WeekIndicator {
        constructor(settings, parentWatch) {
            this.errorChecking(settings);
    
            this.element = document.getElementById(settings.id || settings);
            this.parent = parentWatch;
            this.iso = settings.iso || false;
            this.invert = settings.invert || false;
    
            this.week = 0;
            this.weekAmount = this.iso ? 53 : 52;
            this.increment = 360 / this.weekAmount;
    
            if (!this.parent.testing) this.init();
        }
    
        errorChecking(settings) {
            if (typeof settings === 'object') {
                if (!settings.id) throw new ReferenceError('The Week Indicator class requires that an ID of the element be provided.');
            } else if (typeof settings !== 'string') {
                throw new ReferenceError('The Week Indicator class expects either a settings object or a string containing the element\'s ID.');
            }
        }
    
        getWeekValue() {
            const rightNow = this.parent.rightNow;
            this.week = this.iso ? rightNow.isoWeek() - 1 : rightNow.week() - 1;
    
            this.rotateHands();
        }
    
        rotateHands() {
            let rotateVal = this.week * this.increment;
            if (this.invert) rotateVal *= -1;
    
            this.element.style.transform = `rotate(${rotateVal}deg)`;
        }
    
        init() {
            this.getWeekValue();
        }
    }
    
    module.exports = WeekIndicator;