Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
81 changes: 39 additions & 42 deletions lib/atom-clock-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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')
Expand All @@ -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()
Expand All @@ -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'
})

Expand All @@ -152,7 +150,6 @@ export default class AtomClockView {
}
}


toggle() {
var style = this.element.style.display
this.element.style.display = style === 'none' ? '' : 'none'
Expand Down
17 changes: 12 additions & 5 deletions lib/atom-clock.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import AtomClockView from './atom-clock-view'

var mtz = require('moment-timezone')

export default {

config: {
Expand All @@ -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
}
},

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"atom": ">=1.0.0 <2.0.0"
},
"dependencies": {
"moment": "^2.18.x"
"moment-timezone": "^0.5.x"
},
"consumedServices": {
"status-bar": {
Expand Down
29 changes: 18 additions & 11 deletions spec/atom-clock-view-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -66,54 +67,60 @@ 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', () => {
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)
Expand All @@ -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)
Expand Down