I am writing a section on my angular app to select some timezones (i don't want to use a library, as I don't really need all the possible zones but just the basic ones) and so I found a list of zones and I have created this scope object:
$scope.timezones = [
{GMT: "-1200", label: "(GMT -12:00) Eniwetok, Kwajalein"},
{GMT: "-1100", label: "(GMT -11:00) Midway Island, Samoa"},
{GMT: "-1000", label: "(GMT -10:00) Hawaii"},
{GMT: "-0900", label: "(GMT -9:00) Alaska"},
{GMT: "-0800", label: "(GMT -8:00) Pacific Time (US & Canada)"},
{GMT: "-0700", label: "(GMT -7:00) Mountain Time (US & Canada)"},
{GMT: "-0600", label: "(GMT -6:00) Central Time (US & Canada), Mexico City"},
{GMT: "-0500", label: "(GMT -5:00) Eastern Time (US & Canada), Bogota, Lima"},
{GMT: "-0400", label: "(GMT -4:00) Atlantic Time (Canada), Caracas, La Paz"},
{GMT: "-0350", label: "(GMT -3:30) Newfoundland"},
{GMT: "-0300", label: "(GMT -3:00) Brazil, Buenos Aires, Georgetown"},
{GMT: "-0200", label: "(GMT -2:00) Mid-Atlantic"},
{GMT: "-0100", label: "(GMT -1:00 hour) Azores, Cape Verde Islands"},
{GMT: "0000", label: "(GMT) Western Europe Time, London, Lisbon, Casablanca"},
{GMT: "+0100", label: "(GMT +1:00 hour) Brussels, Copenhagen, Madrid, Paris"},
{GMT: "+0200", label: "(GMT +2:00) Kaliningrad, South Africa"},
{GMT: "+0300", label: "(GMT +3:00) Baghdad, Riyadh, Moscow, St. Petersburg"},
{GMT: "+0350", label: "(GMT +3:30) Tehran"},
{GMT: "+0400", label: "(GMT +4:00) Abu Dhabi, Muscat, Baku, Tbilisi"},
{GMT: "+0450", label: "(GMT +4:30) Kabul"},
{GMT: "+0500", label: "(GMT +5:00) Ekaterinburg, Islamabad, Karachi, Tashkent"},
{GMT: "+0550", label: "(GMT +5:30) Bombay, Calcutta, Madras, New Delhi"},
{GMT: "+0575", label: "(GMT +5:45) Kathmandu"},
{GMT: "+0600", label: "(GMT +6:00) Almaty, Dhaka, Colombo"},
{GMT: "+0700", label: "(GMT +7:00) Bangkok, Hanoi, Jakarta"},
{GMT: "+0800", label: "(GMT +8:00) Beijing, Perth, Singapore, Hong Kong"},
{GMT: "+0900", label: "(GMT +9:00) Tokyo, Seoul, Osaka, Sapporo, Yakutsk"},
{GMT: "+0950", label: "(GMT +9:30) Adelaide, Darwin"},
{GMT: "+1000", label: "(GMT +10:00) Eastern Australia, Guam, Vladivostok"},
{GMT: "+1100", label: "(GMT +11:00) Magadan, Solomon Islands, New Caledonia"},
{GMT: "+1200", label: "(GMT +12:00) Auckland, Wellington, Fiji, Kamchatka"}
]
then, using the date object I get back from an api call, I am stripping the relevant parts using momentjs.format()
.
The date object I am using for this example is the following:
var dateTime = "Tue Apr 25 2017 15:25:05 GMT+0100 (GMT Daylight Time)"
and then I create more scope variables like this:
$scope.Time = moment(dateTime).format("HH:mm")
$scope.Date = moment(dateTime).format("D/MM/YYYY")
$scope.Timezone = getTimezoneLabel(moment(dateTime).format("ZZ"))
getTimezoneLabel = function(timezone) {
var result;
result = null;
angular.forEach($scope.timezones, function(t) {
if (t.GMT === timezone) {
return result = t.label;
}
});
return result;
};
and the result on the page is pretty much all correct, apart from the timezone. The timezone that comes back is the following:
(GMT +1:00 hour) Brussels, Copenhagen, Madrid, Paris
but it's wrong! the correct one should be london, but the daylight saving times interferes with this.
So, my ideas where to get the value in brackets using moment.format({I couldn't find a right format for this}).
Is it even possible? do you have a better suggestion? thanks