From 57cecb7feb1bbbd769844ecd56a72fb320ba098d Mon Sep 17 00:00:00 2001 From: Antonio Bevilacqua Date: Mon, 4 Sep 2017 11:06:25 +0100 Subject: [PATCH 1/3] timezone stub added --- CHANGELOG.md | 3 ++ lib/atom-clock-view.js | 82 ++++++++++++++++++------------------ lib/atom-clock.js | 17 +++++--- package.json | 2 +- spec/atom-clock-view-spec.js | 11 ++++- 5 files changed, 65 insertions(+), 50 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 53502b2..6aef12d 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 0.2 +* Timezone selection added to the package. + ## 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..e70bd46 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() { @@ -86,6 +83,8 @@ export default class AtomClockView { 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') + + this.timezone = atom.config.get('atom-clock.timezone') } startTicker() { @@ -106,15 +105,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 +131,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 +151,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..6aac223 100644 --- a/spec/atom-clock-view-spec.js +++ b/spec/atom-clock-view-spec.js @@ -24,6 +24,7 @@ describe('Atom Clock', () => { workspaceElement = atom.views.getView(atom.workspace) jasmine.attachToDOM(workspaceElement) MockDate.set('1987-04-11 04:00', -300) + atom.config.set('atom-clock.timezone', 'Europe/Dublin') let statusBar let AtomClock @@ -108,12 +109,18 @@ describe('Atom Clock', () => { expect(date.toLowerCase()).toBe('11 sabato 87 4: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('23:00') + }) + it('should change the whether UTC time is displayed', () => { atom.config.set('atom-clock.dateFormat', 'ZZ') 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) From bc1694af6d0fa3e20f92aade321d88dfef0c904d Mon Sep 17 00:00:00 2001 From: Antonio Bevilacqua Date: Mon, 4 Sep 2017 11:27:58 +0100 Subject: [PATCH 2/3] spec fixed on Europe/Rome timezone --- CHANGELOG.md | 4 ++++ spec/atom-clock-view-spec.js | 22 +++++++++++----------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6aef12d..b8395bc 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +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 diff --git a/spec/atom-clock-view-spec.js b/spec/atom-clock-view-spec.js index 6aac223..1e8b724 100644 --- a/spec/atom-clock-view-spec.js +++ b/spec/atom-clock-view-spec.js @@ -24,7 +24,7 @@ describe('Atom Clock', () => { workspaceElement = atom.views.getView(atom.workspace) jasmine.attachToDOM(workspaceElement) MockDate.set('1987-04-11 04:00', -300) - atom.config.set('atom-clock.timezone', 'Europe/Dublin') + atom.config.set('atom-clock.timezone', 'Europe/Rome') let statusBar let AtomClock @@ -67,46 +67,46 @@ 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', () => { @@ -120,7 +120,7 @@ describe('Atom Clock', () => { atom.config.set('atom-clock.showUTC', false) date = getDate(workspaceElement) - expect(date.toLowerCase()).toBe('+0100') + expect(date.toLowerCase()).toBe('+0200') atom.config.set('atom-clock.showUTC', true) date = getDate(workspaceElement) @@ -132,7 +132,7 @@ describe('Atom Clock', () => { atom.config.set('atom-clock.showUTC', false) date = getTooltipDate(workspaceElement) - expect(date.toLowerCase()).toBe('+0100') + expect(date.toLowerCase()).toBe('+0200') atom.config.set('atom-clock.showUTC', true) date = getTooltipDate(workspaceElement) From 2a4ff81d3596f6b55fbd030546c971cd63e55be7 Mon Sep 17 00:00:00 2001 From: Antonio Bevilacqua Date: Mon, 4 Sep 2017 12:57:37 +0100 Subject: [PATCH 3/3] changelog updated, test maybe fixed --- CHANGELOG.md | 1 - lib/atom-clock-view.js | 3 +-- spec/atom-clock-view-spec.js | 10 +++++----- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b8395bc..3cc354f 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,6 @@ * :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 e70bd46..c3f7c68 100755 --- a/lib/atom-clock-view.js +++ b/lib/atom-clock-view.js @@ -80,11 +80,10 @@ 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') - - this.timezone = atom.config.get('atom-clock.timezone') } startTicker() { diff --git a/spec/atom-clock-view-spec.js b/spec/atom-clock-view-spec.js index 1e8b724..043fcf6 100644 --- a/spec/atom-clock-view-spec.js +++ b/spec/atom-clock-view-spec.js @@ -23,8 +23,8 @@ describe('Atom Clock', () => { beforeEach(() => { workspaceElement = atom.views.getView(atom.workspace) jasmine.attachToDOM(workspaceElement) - MockDate.set('1987-04-11 04:00', -300) - atom.config.set('atom-clock.timezone', 'Europe/Rome') + MockDate.set('1987-04-11 04:00:00 GMT', -60) + atom.config.set('atom-clock.timezone', 'Europe/Dublin') let statusBar let AtomClock @@ -112,7 +112,7 @@ describe('Atom Clock', () => { 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('23:00') + expect(date.toLowerCase()).toBe('0:00') }) it('should change the whether UTC time is displayed', () => { @@ -120,7 +120,7 @@ describe('Atom Clock', () => { atom.config.set('atom-clock.showUTC', false) date = getDate(workspaceElement) - expect(date.toLowerCase()).toBe('+0200') + expect(date.toLowerCase()).toBe('+0100') atom.config.set('atom-clock.showUTC', true) date = getDate(workspaceElement) @@ -132,7 +132,7 @@ describe('Atom Clock', () => { atom.config.set('atom-clock.showUTC', false) date = getTooltipDate(workspaceElement) - expect(date.toLowerCase()).toBe('+0200') + expect(date.toLowerCase()).toBe('+0100') atom.config.set('atom-clock.showUTC', true) date = getTooltipDate(workspaceElement)