Skip to content

Instantly share code, notes, and snippets.

@francescozanoni
Last active May 16, 2018 07:54
Show Gist options
  • Save francescozanoni/26cde6cf80dceea9c3e9dbe378b4e4f1 to your computer and use it in GitHub Desktop.
Save francescozanoni/26cde6cf80dceea9c3e9dbe378b4e4f1 to your computer and use it in GitHub Desktop.

Code:

var year = new Date().getFullYear();
var months = ['01', '02', '03', '04', '05','06', '07', '08', '09', '10', '11', '12'];
var timezones = moment.tz.names();
var dates = months.map(function (month) {
    return year + '-'+ month +'-01';
});

var output = {};

for (var i = 0; i < timezones.length; i++) {
    var offsets = [];
    for (var j = 0; j < dates.length; j++) {
        var timezoneDateTime = moment.tz(dates[j], timezones[i]);
        if (timezoneDateTime.isDST() === true) {
            // continue;
        }
        offsets[offsets.length] = timezoneDateTime.format('Z');
    }
    offsets = offsets.filter(function (value, index, self) {
        return self.indexOf(value) === index;
    });
    output[timezones[i]] = offsets;
}

console.log(output);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment