Comparing version 1.3.0 to 1.4.0
@@ -22,6 +22,4 @@ // == BDS2 LICENSE == | ||
'use strict'; | ||
var format = require('util').format; | ||
var timezones = require('./timezones'); | ||
var detectTimezone = require('./timezoneDetect'); | ||
var datetimeWrapper = function(moment) { | ||
@@ -256,10 +254,2 @@ var DEFAULT_DISPLAY_MASK = 'MMMM D [at] h:mm a'; | ||
/* | ||
* Try to detect current device's timezone | ||
* | ||
* @return {Object} a timezone object | ||
*/ | ||
getDeviceTimezone: function() { | ||
return detectTimezone(); | ||
}, | ||
/* | ||
* Get how many milliseconds you are into a day | ||
@@ -322,5 +312,78 @@ * | ||
* | ||
* @return {Array} a list of available timezone objects | ||
* @return {Object} a hash of arrays of timezone objects | ||
* in convenient categories for displaying in a searchable dropdown | ||
*/ | ||
getTimezones: function() { | ||
var tzNames = moment.tz.names(); | ||
var timezones = { | ||
// main timezones of the U.S. lower 48 | ||
bigFour: [], | ||
// remainder of U.S. timezones | ||
unitedStates: [], | ||
// the English-speaking world + Europe | ||
hoisted: [], | ||
// everywhere else | ||
theRest: [] | ||
}; | ||
var big4 = { | ||
'US/Eastern': true, | ||
'US/Central': true, | ||
'US/Mountain': true, | ||
'US/Pacific': true | ||
}; | ||
var newZealand = { | ||
'Pacific/Auckland': true, | ||
'Pacific/Chatham': true | ||
}; | ||
var now = new Date().valueOf(); | ||
for (var i = 0; i < tzNames.length; ++i) { | ||
var zone = moment.tz.zone(tzNames[i]); | ||
// we use the current epoch time to determine the current UTC | ||
// offset for each timezone (i.e., adjust for DST or not) | ||
// the offset is part of the `label` attribute | ||
var offsetInHours = moment.duration(zone.offset(now), 'minutes') | ||
.asMilliseconds()/(1000*60*60); | ||
// because moment signs offsets the opposite way from the ISO 8601 standard | ||
// the standard is negative for N. American timezones | ||
// but moment (and JavaScript in general) represent them as positive | ||
var offsetAsString = offsetInHours > 0 ? | ||
'-' + offsetInHours : '+' + Math.abs(offsetInHours); | ||
var timezone = { | ||
label: format('%s (UTC%s)', tzNames[i], offsetAsString), | ||
value: tzNames[i], | ||
offset: Number(offsetAsString) | ||
}; | ||
if (big4[tzNames[i]]) { | ||
timezones.bigFour.push(timezone); | ||
} | ||
else if (tzNames[i].search('US/') === 0) { | ||
timezones.unitedStates.push(timezone); | ||
} | ||
else if (tzNames[i].search('Canada/') === 0) { | ||
timezones.hoisted.push(timezone); | ||
} | ||
else if (tzNames[i].search('Europe/') === 0) { | ||
timezones.hoisted.push(timezone); | ||
} | ||
else if (tzNames[i].search('Australia/') === 0) { | ||
timezones.hoisted.push(timezone); | ||
} | ||
else if (newZealand[tzNames[i]]) { | ||
timezones.hoisted.push(timezone); | ||
} | ||
// reformat these a tiny bit so that 'New Zealand' is searchable | ||
else if (tzNames[i].search('NZ') === 0) { | ||
timezone.label = timezone.label.replace('NZ', 'New Zealand'); | ||
timezones.hoisted.push(timezone); | ||
} | ||
// there's a whole bunch of timezones listed as "Etc/GMT+1" | ||
// that clutter things up a lot... | ||
else if (tzNames[i].search('GMT') !== -1) {} | ||
else { | ||
timezones.theRest.push(timezone); | ||
} | ||
} | ||
return timezones; | ||
@@ -327,0 +390,0 @@ }, |
{ | ||
"name": "sundial", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"description": "Tidepool's datetime wrapper", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
5
22092
5
491