[CLOCK] Issue #1273 : Allow clock to set timezone with autocomplete dropdown option.

This commit is contained in:
Dhrubomoy Das Gupta
2017-05-28 20:21:52 -04:00
parent 1bdc0497c7
commit 893e24ff98
11 changed files with 340 additions and 30 deletions

View File

@ -20,9 +20,14 @@
* at runtime from the About dialog for additional information.
*****************************************************************************/
define(
['moment'],
function (moment) {
define([
'moment',
'moment-timezone'
],
function (
moment,
momentTimezone
) {
/**
* Controller for views of a Clock domain object.
@ -37,10 +42,13 @@ define(
var lastTimestamp,
unlisten,
timeFormat,
zoneName,
self = this;
function update() {
var m = moment.utc(lastTimestamp);
var m = zoneName ?
moment.utc(lastTimestamp).tz(zoneName) : moment.utc(lastTimestamp);
self.zoneAbbr = zoneName ? m.zoneAbbr() : "UTC";
self.textValue = timeFormat && m.format(timeFormat);
self.ampmValue = m.format("A"); // Just the AM or PM part
}
@ -50,21 +58,23 @@ define(
update();
}
function updateFormat(clockFormat) {
function updateModel(model) {
var baseFormat;
if (model !== undefined) {
baseFormat = model.clockFormat[0];
if (clockFormat !== undefined) {
baseFormat = clockFormat[0];
self.use24 = clockFormat[1] === 'clock24';
self.use24 = model.clockFormat[1] === 'clock24';
timeFormat = self.use24 ?
baseFormat.replace('hh', "HH") : baseFormat;
update();
// If wrong timezone is provided, the UTC will be used
zoneName = momentTimezone.tz.names().includes(model.timezone) ?
model.timezone : "UTC";
}
update();
}
// Pull in the clock format from the domain object model
$scope.$watch('model.clockFormat', updateFormat);
// Pull in the model (clockFormat and timezone) from the domain object model
$scope.$watch('model', updateModel);
// Listen for clock ticks ... and stop listening on destroy
unlisten = tickerService.listen(tick);
@ -76,7 +86,7 @@ define(
* @returns {string}
*/
ClockController.prototype.zone = function () {
return "UTC";
return this.zoneAbbr;
};
/**