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 0.1.6 to 0.2.0

132

lib/datetimeWrapper.js

@@ -21,6 +21,3 @@ // == BDS2 LICENSE ==

var datetimeWrapper = function(givenMoment) {
var usedMoment = givenMoment;
var datetimeWrapper = function(moment) {
var DEFAULT_DISPLAY_MASK = 'MMMM D [at] h:mm a';

@@ -30,10 +27,33 @@

/*
* Get a UTC based string that represents `now`
* Format the given timestamp for display
*
* @ return {String} an ISO8601-formatted timestamp with the offset from UTC specified
* @ param {String} utc timestamp
* @ param {String} mask [mask='MMMM D [at] h:mm a'] the date format mask to apply
*
* @ return {String} the formatted date
*/
utcDateString: function() {
return usedMoment().format();
formatForDisplay: function(timestamp,mask) {
mask = mask || DEFAULT_DISPLAY_MASK;
return moment(timestamp).format(mask);
},
/*
* Format the given timestamp for storage
*
* @ param {String} timestamp
* @ param {Number} offset mins from UTC
*
* @ return {String} an ISO8601-formatted timestamp
*/
formatForStorage: function(timestamp, zone) {
return moment(timestamp).zone(zone).format();
},
/*
* Try to detect current device's timezone
*
* @ return {Object} a timezone object
*/
getDeviceTimezone: function() {
return detectTimezone();
},
/*
* Get the offset from the given date

@@ -43,4 +63,4 @@ *

*/
getOffsetFromTime: function(timestamp) {
return usedMoment.parseZone(timestamp).zone();
getOffset: function() {
return moment().zone();
},

@@ -52,16 +72,12 @@ /*

*/
getOffset: function() {
return usedMoment().zone();
getOffsetFromTime: function(timestamp) {
return moment.parseZone(timestamp).zone();
},
/*
* Format the given timestamp for display
* Get all timezone objects
*
* @ param {String} utc timestamp
* @ param {String} mask [mask='MMMM D [at] h:mm a'] the date format mask to apply
*
* @ return {String} the formatted date
* @ return {Array} a list of available timezone objects
*/
formatForDisplay: function(timestamp,mask) {
mask = mask || DEFAULT_DISPLAY_MASK;
return usedMoment(timestamp).format(mask);
getTimezones: function() {
return timezones;
},

@@ -76,3 +92,3 @@ /*

isValidDate: function(timestamp) {
var m = usedMoment(timestamp);
var m = moment(timestamp);
// Be careful, if `value` is empty, `m` can be null

@@ -82,50 +98,64 @@ return m && m.isValid();

/*
* How long ago is this date from now
* Get an instance of moment that is used
*
* @ param {String} timestamp
* @ param {String} period years, months, weeks, days, hours, minutes, and seconds
*
* @ return {Number}
* @ return {Object} an instance of moment
*/
timeAgo: function(timestamp,period) {
if(period){
var today = usedMoment();
return today.diff(timestamp, period);
}
return null;
momentInstance: function() {
return moment;
},
/*
* Format the given timestamp for storage
* Parses a string using the provided format into a moment of the provided timezone
*
* @ param {String} timestamp
* @ param {Number} offset mins from UTC
*
* @ return {String} an ISO8601-formatted timestamp
* @param ts the timestamp string to parse
* @param format the format to parse the string with
* @param timezone a valid timezone specifier as per moment-timezone
* @return {Object} a moment datetime object
*/
formatForStorage: function(timestamp, zone) {
return usedMoment(timestamp).zone(zone).format();
parse: function(ts, timezone) {
if (timezone == null) {
return moment.utc(ts);
} else {
return moment.tz(ts, timezone);
}
},
/*
* Get all timezone objects
* Parses a string using the provided format into a moment of the provided timezone
*
* @ return {Array} a list of available timezone objects
* @param ts the timestamp string to parse
* @param format the format to parse the string with
* @param timezone a valid timezone specifier as per moment-timezone
* @return {Object} a moment datetime object
*/
getTimezones: function() {
return timezones;
parseFormat: function(ts, format, timezone) {
if (timezone == null) {
return moment.utc(ts, format);
} else {
return moment.tz(ts, format, timezone);
}
},
/*
* Try to detect current device's timezone
* How long ago is this date from now
*
* @ return {Object} a timezone object
* @ param {String} timestamp
* @ param {String} period years, months, weeks, days, hours, minutes, and seconds
*
* @ return {Number}
*/
getDeviceTimezone: function() {
return detectTimezone();
timeAgo: function(timestamp,period) {
if(period){
var today = moment();
return today.diff(timestamp, period);
}
return null;
},
/*
* Get an instance of moment that is used
* Get a UTC based string that represents `now`
*
* @ return {Object} an instance of moment
* @ return {String} an ISO8601-formatted timestamp with the offset from UTC specified
*/
momentInstance: function() {
return usedMoment;
utcDateString: function() {
return moment().format();
}

@@ -132,0 +162,0 @@ };

{
"name": "sundial",
"version": "0.1.6",
"version": "0.2.0",
"description": "Tidepool's datetime wrapper",

@@ -34,3 +34,4 @@ "keywords": [

"dependencies": {
"moment": "2.8.1"
"moment": "2.8.3",
"moment-timezone": "0.2.2"
},

@@ -37,0 +38,0 @@ "devDependencies": {

@@ -18,4 +18,4 @@ // == BSD2 LICENSE ==

var moment = require('moment');
var moment = require('moment-timezone');
module.exports = require('./lib/datetimeWrapper.js')(moment);
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