Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sundial

Package Overview
Dependencies
Maintainers
2
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sundial - npm Package Compare versions

Comparing version 1.2.0 to 1.3.0

44

lib/datetimeWrapper.js

@@ -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 @@ *

4

package.json
{
"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",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc