Comparing version 1.2.0 to 1.3.0
@@ -43,3 +43,3 @@ // == BDS2 LICENSE == | ||
* @param {String} timestamp | ||
* @param {Number|String} offset mins ~from~ UTC | ||
* @param {Number} offset mins ~from~ UTC | ||
* | ||
@@ -76,2 +76,29 @@ * @return {Object} JavaScript Date yielding accurate UTC string from .toISOString() | ||
/* | ||
* Apply a timezone and a conversionOffset to a timezone-naive timestamp | ||
* | ||
* @param {String} timestamp | ||
* @param {String} timezone a valid timezone name as per moment-timezone | ||
* @param {Number} conversionOffset milliseconds ~from~ UTC | ||
* | ||
* @return {Object} JavaScript Date yielding accurate UTC string from .toISOString() | ||
*/ | ||
applyTimezoneAndConversionOffset: function(timestamp, timezone, conversionOffset) { | ||
this.checkTimezoneName(timezone); | ||
// NB: the result of this method will *not* yield the correct timezone offset from .getTimezoneOffset() | ||
// that is, the offset corresponding to the passed in timezone | ||
// because JavaScript Date doesn't do arbitrary timezones, only browser local | ||
if (timezone == null) { | ||
// some browsers assume no timezone offset means local time and others assume it means UTC | ||
// we explicitly make them all act like it is UTC | ||
return moment.utc(timestamp).toDate(); | ||
} else { | ||
if (timestamp instanceof Date) { | ||
return moment.tz(timestamp.toISOString().slice(0,-5), timezone) | ||
.subtract(conversionOffset, 'milliseconds').toDate(); | ||
} | ||
return moment.tz(timestamp, timezone) | ||
.subtract(conversionOffset, 'milliseconds').toDate(); | ||
} | ||
}, | ||
/* | ||
* Construct a Date from canonically-named time fields in the provided object | ||
@@ -131,2 +158,17 @@ * | ||
/* | ||
* Apply Tidepool timezoneOffset and conversionOffset to a JavaScript Date | ||
* | ||
* @param {Object} JavaScript Date formed from a deviceTime | ||
* @param {Number} timezoneOffset mins ~from~ UTC | ||
* @param {Number} conversionOffset milliseconds ~from~ UTC | ||
* | ||
* @return {Object} JavaScript Date yielding accurate UTC string from .toISOString() | ||
*/ | ||
findTimeFromDeviceTimeAndOffsets: function(dt, timezoneOffset, conversionOffset) { | ||
return moment.utc(dt) | ||
.subtract(timezoneOffset, 'minutes') | ||
.subtract(conversionOffset, 'milliseconds') | ||
.toDate(); | ||
}, | ||
/* | ||
* Get the floor for a date (see D3's time functions) | ||
@@ -133,0 +175,0 @@ * |
{ | ||
"name": "sundial", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "Tidepool's datetime wrapper", | ||
@@ -12,3 +12,3 @@ "keywords": [ | ||
"bugs": "https://github.com/tidepool-org/sundial/issues", | ||
"license": "BSD-2-clause", | ||
"license": "BSD-2-Clause", | ||
"author": { | ||
@@ -15,0 +15,0 @@ "name": "Eric Tschetter", |
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
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
29349
609