diff --git a/CHANGELOG.md b/CHANGELOG.md index 53502b2..3cc354f 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 0.2 +* Timezone selection added to the package. +* :white_check_mark: Timezone tests added +* :arrow_up: `moment-timezone` dependency added +* :arrow_down: `moment` dependency removed + ## 0.1.15 * UTC class added to clock items and tooltip, so that customization is possible when the UTC time is enabled diff --git a/lib/atom-clock-view.js b/lib/atom-clock-view.js index 7d3aa31..c3f7c68 100755 --- a/lib/atom-clock-view.js +++ b/lib/atom-clock-view.js @@ -21,42 +21,39 @@ export default class AtomClockView { this.setUTCClass(this.showUTC) this.startTicker() - this.subscriptions.add(atom.commands.add('atom-workspace', { - 'atom-clock:toggle': () => this.toggle(), - 'atom-clock:utc-mode': () => atom.config.set('atom-clock.showUTC', !this.showUTC) - })) - - this.subscriptions.add(atom.config.onDidChange('atom-clock.dateFormat', () => { - this.refreshTicker() - })) - - this.subscriptions.add(atom.config.onDidChange('atom-clock.showTooltip', () => { - this.setConfigValues() - this.setTooltip(this.showTooltip) - })) - - this.subscriptions.add(atom.config.onDidChange('atom-clock.tooltipDateFormat', () => { - this.refreshTicker() - })) - - this.subscriptions.add(atom.config.onDidChange('atom-clock.locale', () => { - this.refreshTicker() - })) - - this.subscriptions.add(atom.config.onDidChange('atom-clock.showUTC', () => { - this.refreshTicker() - this.setUTCClass(this.showUTC) - })) - - this.subscriptions.add(atom.config.onDidChange('atom-clock.refreshInterval', () => { - this.refreshTicker() - })) - - this.subscriptions.add(atom.config.onDidChange('atom-clock.showClockIcon', () => { - this.setConfigValues() - this.setIcon(this.showIcon) - })) - + this.subscriptions.add( + atom.commands.add('atom-workspace', { + 'atom-clock:toggle': () => this.toggle(), + 'atom-clock:utc-mode': () => atom.config.set('atom-clock.showUTC', !this.showUTC) + }), + atom.config.onDidChange('atom-clock.dateFormat', () => { + this.refreshTicker() + }), + atom.config.onDidChange('atom-clock.showTooltip', () => { + this.setConfigValues() + this.setTooltip(this.showTooltip) + }), + atom.config.onDidChange('atom-clock.tooltipDateFormat', () => { + this.refreshTicker() + }), + atom.config.onDidChange('atom-clock.locale', () => { + this.refreshTicker() + }), + atom.config.onDidChange('atom-clock.timezone', () => { + this.refreshTicker() + }), + atom.config.onDidChange('atom-clock.showUTC', () => { + this.refreshTicker() + this.setUTCClass(this.showUTC) + }), + atom.config.onDidChange('atom-clock.refreshInterval', () => { + this.refreshTicker() + }), + atom.config.onDidChange('atom-clock.showClockIcon', () => { + this.setConfigValues() + this.setIcon(this.showIcon) + }) + ) } drawElement() { @@ -83,6 +80,7 @@ export default class AtomClockView { this.showTooltip = atom.config.get('atom-clock.showTooltip') this.tooltipDateFormat = atom.config.get('atom-clock.tooltipDateFormat') this.locale = atom.config.get('atom-clock.locale') + this.timezone = atom.config.get('atom-clock.timezone') this.showUTC = atom.config.get('atom-clock.showUTC') this.refreshInterval = atom.config.get('atom-clock.refreshInterval') * 1000 this.showIcon = atom.config.get('atom-clock.showClockIcon') @@ -106,15 +104,15 @@ export default class AtomClockView { } setDate() { - this.date = this.getDate(this.locale, this.dateFormat) + this.date = this.getDate(this.locale, this.dateFormat, this.timezone) this.timeElement.textContent = this.date } - getDate(locale, format) { + getDate(locale, format, timezone) { if (!this.Moment) - this.Moment = require('moment') + this.Moment = require('moment-timezone') - var moment = this.Moment().locale(locale) + var moment = this.Moment().tz(timezone).locale(locale) if (this.showUTC) moment.utc() @@ -132,7 +130,7 @@ export default class AtomClockView { setTooltip(toSet) { if (this.tooltip === undefined) this.tooltip = atom.tooltips.add(this.element, { - title: () => this.getDate(this.locale, this.tooltipDateFormat), + title: () => this.getDate(this.locale, this.tooltipDateFormat, this.timezone), class: 'atom-clock-tooltip' }) @@ -152,7 +150,6 @@ export default class AtomClockView { } } - toggle() { var style = this.element.style.display this.element.style.display = style === 'none' ? '' : 'none' diff --git a/lib/atom-clock.js b/lib/atom-clock.js index 35325d1..16ef521 100755 --- a/lib/atom-clock.js +++ b/lib/atom-clock.js @@ -2,6 +2,8 @@ import AtomClockView from './atom-clock-view' +var mtz = require('moment-timezone') + export default { config: { @@ -17,37 +19,42 @@ export default { description: 'Specify the time locale. [Here](https://github.com/moment/moment/tree/master/locale) you can find all the available locales.', default: 'en', order: 2 + }, timezone: { + type: 'string', + default: mtz.tz.guess(), + enum: mtz.tz.names(), + order: 3 }, refreshInterval: { type: 'integer', title: 'Clock interval', description: 'Specify the refresh interval (in seconds) for the plugin to evaluate the date.', default: 60, minimum: 1, - order: 3 + order: 4 }, showTooltip: { type: 'boolean', title: 'Enable tooltip', description: 'Enables a customisable tooltip when you hover over the time.', default: false, - order: 4 + order: 5 }, tooltipDateFormat: { type: 'string', title: 'Tooltip time format', description: 'Specify the time format in the tooltip. [Here](http://momentjs.com/docs/#/displaying/format/) you can find all the available formats.', default: 'LLLL', - order: 5 + order: 6 }, showUTC: { type: 'boolean', title: 'Display UTC time', description: 'Use UTC to display the time instead of local time.', default: false, - order: 6 + order: 7 }, showClockIcon: { type: 'boolean', title: 'Icon clock', description: 'Show a clock icon next to the time in the status bar.', default: false, - order: 7 + order: 8 } }, diff --git a/package.json b/package.json index 24e02c1..ab3d8e2 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "atom": ">=1.0.0 <2.0.0" }, "dependencies": { - "moment": "^2.18.x" + "moment-timezone": "^0.5.x" }, "consumedServices": { "status-bar": { diff --git a/spec/atom-clock-view-spec.js b/spec/atom-clock-view-spec.js index 6b3dd3f..043fcf6 100644 --- a/spec/atom-clock-view-spec.js +++ b/spec/atom-clock-view-spec.js @@ -23,7 +23,8 @@ describe('Atom Clock', () => { beforeEach(() => { workspaceElement = atom.views.getView(atom.workspace) jasmine.attachToDOM(workspaceElement) - MockDate.set('1987-04-11 04:00', -300) + MockDate.set('1987-04-11 04:00:00 GMT', -60) + atom.config.set('atom-clock.timezone', 'Europe/Dublin') let statusBar let AtomClock @@ -66,46 +67,52 @@ describe('Atom Clock', () => { it('should show the time with the default format', () => { date = getDate(workspaceElement) - expect(date).toBe('4:00') + expect(date).toBe('5:00') }) it('should show the time in the tooltip with the default format', () => { date = getTooltipDate(workspaceElement) - expect(date.toLowerCase()).toBe('saturday, april 11, 1987 4:00 am') + expect(date.toLowerCase()).toBe('saturday, april 11, 1987 5:00 am') }) it('should change the format of displayed time', () => { atom.config.set('atom-clock.dateFormat', 'H:mm:ss') date = getDate(workspaceElement) - expect(date).toBe('4:00:00') + expect(date).toBe('5:00:00') atom.config.set('atom-clock.dateFormat', 'DD dddd YY H:mm') date = getDate(workspaceElement) - expect(date.toLowerCase()).toBe('11 saturday 87 4:00') + expect(date.toLowerCase()).toBe('11 saturday 87 5:00') }) it('should change the format of the displayed time in the tooltip', () => { atom.config.set('atom-clock.tooltipDateFormat', 'H:mm:ss') date = getTooltipDate(workspaceElement) - expect(date).toBe('4:00:00') + expect(date).toBe('5:00:00') atom.config.set('atom-clock.tooltipDateFormat', 'DD dddd YY H:mm') date = getTooltipDate(workspaceElement) - expect(date.toLowerCase()).toBe('11 saturday 87 4:00') + expect(date.toLowerCase()).toBe('11 saturday 87 5:00') }) it('should change the clock content according with the locale', () => { atom.config.set('atom-clock.dateFormat', 'DD dddd YY H:mm') atom.config.set('atom-clock.locale', 'it') date = getDate(workspaceElement) - expect(date.toLowerCase()).toBe('11 sabato 87 4:00') + expect(date.toLowerCase()).toBe('11 sabato 87 5:00') }) it('should change the clock content in the tooltip according with the locale', () => { atom.config.set('atom-clock.tooltipDateFormat', 'DD dddd YY H:mm') atom.config.set('atom-clock.locale', 'it') date = getTooltipDate(workspaceElement) - expect(date.toLowerCase()).toBe('11 sabato 87 4:00') + expect(date.toLowerCase()).toBe('11 sabato 87 5:00') + }) + + it('should change the clock content according with the timezone', () => { + atom.config.set('atom-clock.timezone', 'America/New_York') + date = getDate(workspaceElement) + expect(date.toLowerCase()).toBe('0:00') }) it('should change the whether UTC time is displayed', () => { @@ -113,7 +120,7 @@ describe('Atom Clock', () => { atom.config.set('atom-clock.showUTC', false) date = getDate(workspaceElement) - expect(date.toLowerCase()).toBe('+0500') + expect(date.toLowerCase()).toBe('+0100') atom.config.set('atom-clock.showUTC', true) date = getDate(workspaceElement) @@ -125,7 +132,7 @@ describe('Atom Clock', () => { atom.config.set('atom-clock.showUTC', false) date = getTooltipDate(workspaceElement) - expect(date.toLowerCase()).toBe('+0500') + expect(date.toLowerCase()).toBe('+0100') atom.config.set('atom-clock.showUTC', true) date = getTooltipDate(workspaceElement)