New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@datatypes/moment

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@datatypes/moment - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

.babelrc

380

build/index.js
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _fromString = require('./fromString');
var _duration = require('@datatypes/duration');
Object.defineProperty(exports, 'default', {
enumerable: true,
get: function get() {
return _interopRequireDefault(_fromString).default;
}
});
var _duration2 = _interopRequireDefault(_duration);
var _Year = require('./Year');
var _addDurationToDate = require('./addDurationToDate');
Object.defineProperty(exports, 'Year', {
enumerable: true,
get: function get() {
return _Year.Year;
}
});
var _addDurationToDate2 = _interopRequireDefault(_addDurationToDate);
var _Month = require('./Month');
var _parseDateTime = require('./parseDateTime');
Object.defineProperty(exports, 'Month', {
enumerable: true,
get: function get() {
return _Month.Month;
}
});
var _parseDateTime2 = _interopRequireDefault(_parseDateTime);
var _Day = require('./Day');
var _serializeDateTime = require('./serializeDateTime');
Object.defineProperty(exports, 'Day', {
enumerable: true,
get: function get() {
return _Day.Day;
}
});
var _serializeDateTime2 = _interopRequireDefault(_serializeDateTime);
var _Hour = require('./Hour');
var _parseDate = require('./parseDate');
Object.defineProperty(exports, 'Hour', {
enumerable: true,
get: function get() {
return _Hour.Hour;
}
});
var _parseDate2 = _interopRequireDefault(_parseDate);
var _Minute = require('./Minute');
var _parseTime = require('./parseTime');
Object.defineProperty(exports, 'Minute', {
enumerable: true,
get: function get() {
return _Minute.Minute;
}
});
var _parseTime2 = _interopRequireDefault(_parseTime);
var _Second = require('./Second');
var _splitString = require('./splitString');
Object.defineProperty(exports, 'Second', {
enumerable: true,
get: function get() {
return _Second.Second;
}
});
var _splitString2 = _interopRequireDefault(_splitString);
var _Millisecond = require('./Millisecond');
var _precisionToDuration = require('./precisionToDuration');
Object.defineProperty(exports, 'Millisecond', {
enumerable: true,
get: function get() {
return _Millisecond.Millisecond;
}
});
var _precisionToDuration2 = _interopRequireDefault(_precisionToDuration);
var _startOf = require('./startOf');
var startOf = _interopRequireWildcard(_startOf);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Moment = function () {
function Moment(isoString) {
_classCallCheck(this, Moment);
if (!isoString) {
var startDate = new Date();
this._isoString = startDate.toISOString();
this._lowerLimit = startDate, this._upperLimit = (0, _addDurationToDate2.default)(startDate, new _duration2.default('P0.001S')), this._precision = 'millisecond';
} else {
this._isoString = isoString;
Object.assign(this, (0, _parseDateTime2.default)(isoString));
}
}
_createClass(Moment, [{
key: 'clone',
value: function clone() {
return new Moment(this.isoString);
}
// Years
}, {
key: 'setYears',
value: function setYears(years) {
this.years = years;
return this;
}
}, {
key: 'getYears',
value: function getYears() {
return this._years;
}
// Months
}, {
key: 'setMonths',
value: function setMonths(months) {
this.months = months;
return this;
}
}, {
key: 'getMonths',
value: function getMonths() {
return this._months;
}
// Days
}, {
key: 'setDays',
value: function setDays(days) {
this.days = days;
return this;
}
}, {
key: 'getDays',
value: function getDays() {
return this._days;
}
// Hours
}, {
key: 'setHours',
value: function setHours(hours) {
this.hours = hours;
return this;
}
}, {
key: 'getHours',
value: function getHours() {
return this._hours;
}
// Minutes
}, {
key: 'setMinutes',
value: function setMinutes(minutes) {
this.minutes = minutes;
return this;
}
}, {
key: 'getMinutes',
value: function getMinutes() {
return this._minutes;
}
// Seconds
}, {
key: 'setSeconds',
value: function setSeconds(seconds) {
this.seconds = seconds;
return this;
}
}, {
key: 'getSeconds',
value: function getSeconds() {
return this._seconds;
}
// Milliseconds
}, {
key: 'setMilliseconds',
value: function setMilliseconds(milliseconds) {
this.milliseconds = milliseconds;
return this;
}
}, {
key: 'getMilliseconds',
value: function getMilliseconds() {
return this._milliseconds;
}
}, {
key: 'startOfYear',
value: function startOfYear() {
startOf.year(this);return this;
}
}, {
key: 'startOfMonth',
value: function startOfMonth() {
startOf.month(this);return this;
}
}, {
key: 'startOfDay',
value: function startOfDay() {
startOf.day(this);return this;
}
}, {
key: 'startOfHour',
value: function startOfHour() {
startOf.hour(this);return this;
}
}, {
key: 'startOfMinute',
value: function startOfMinute() {
startOf.minute(this);return this;
}
}, {
key: 'startOfSecond',
value: function startOfSecond() {
startOf.second(this);return this;
}
}, {
key: 'toString',
value: function toString() {
return this.isoString;
}
}, {
key: 'toObject',
value: function toObject() {
var returnObject = {
type: this.type,
string: this.isoString,
precision: this.precision
};
if (this._lowerLimit) returnObject.lowerLimit = this._lowerLimit;
if (this._upperLimit) returnObject.upperLimit = this._upperLimit;
return returnObject;
}
}, {
key: 'toJSON',
value: function toJSON() {
return this.toObject();
}
}, {
key: 'years',
set: function set(years) {
this._years = years;
this._isoString = null;
this._dateString = null;
return this;
},
get: function get() {
return this._years;
}
}, {
key: 'months',
set: function set(months) {
this._months = months;
this._isoString = null;
this._dateString = null;
return this;
},
get: function get() {
return this._months;
}
}, {
key: 'days',
set: function set(days) {
this._days = days;
this._isoString = null;
this._dateString = null;
return this;
},
get: function get() {
return this._days;
}
}, {
key: 'hours',
set: function set(hours) {
hours = Number(hours);
this._hours = hours;
this._isoString = null;
this._timeString = null;
this._lowerLimit.setHours(hours);
this._upperLimit.setHours(hours);
},
get: function get() {
return this._hours;
}
}, {
key: 'minutes',
set: function set(minutes) {
this._minutes = minutes;
this._isoString = null;
this._timeString = null;
return this;
},
get: function get() {
return this._minutes;
}
}, {
key: 'seconds',
set: function set(seconds) {
this._seconds = seconds;
this._isoString = null;
this._timeString = null;
return this;
},
get: function get() {
return this._seconds;
}
}, {
key: 'milliseconds',
set: function set(milliseconds) {
this._milliseconds = milliseconds;
this._isoString = null;
this._timeString = null;
return this;
},
get: function get() {
return this._milliseconds;
}
}, {
key: 'precision',
get: function get() {
return this._precision;
},
set: function set(precision) {
this._precision = precision;
}
}, {
key: 'lowerLimit',
get: function get() {
return this._lowerLimit;
},
set: function set(lowerLimit) {
this._lowerLimit = lowerLimit;
}
}, {
key: 'upperLimit',
get: function get() {
return this._lowerLimit;
},
set: function set(upperLimit) {
this._upperLimit = upperLimit;
}
}, {
key: 'isoString',
get: function get() {
if (!this._isoString) {
this._isoString = (0, _serializeDateTime2.default)(this);
}
return this._isoString;
}
}]);
return Moment;
}();
exports.default = Moment;
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -8,2 +8,4 @@ 'use strict';

exports.default = function (precision) {
precision = precision.toLowerCase();
var map = {

@@ -10,0 +12,0 @@ millennium: new _duration2.default('P1000Y'),

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -13,3 +13,3 @@ Object.defineProperty(exports, "__esModule", {

function year(object) {
object.months = 1;
object.month = 1;
month(object);

@@ -19,3 +19,3 @@ }

function month(object) {
object.days = 1;
object.day = 1;
day(object);

@@ -25,3 +25,3 @@ }

function day(object) {
object.hours = 0;
object.hour = 0;
hour(object);

@@ -31,3 +31,3 @@ }

function hour(object) {
object.minutes = 0;
object.minute = 0;
minute(object);

@@ -37,3 +37,3 @@ }

function minute(object) {
object.seconds = 0;
object.second = 0;
second(object);

@@ -43,4 +43,3 @@ }

function second(object) {
object.milliseconds = 0;
object.precision = 'millisecond';
object.millisecond = 0;
}
{
"name": "@datatypes/moment",
"version": "0.1.0",
"version": "0.2.0",
"description": "ISO 8601 based time and date module",
"main": "build/index.js",
"main": "build/index",
"directories": {

@@ -11,3 +11,3 @@ "lib": "source",

"scripts": {
"build": "babel --quiet --presets es2015 source --out-dir build",
"build": "rm -r build && babel --quiet source --out-dir build",
"test": "npm run build && ava --fail-fast",

@@ -26,2 +26,5 @@ "prepublish": "npm test"

"babel-cli": "^6.6.5",
"babel-plugin-syntax-trailing-function-commas": "^6.5.0",
"babel-plugin-transform-builtin-extend": "^1.1.0",
"babel-polyfill": "^6.6.1",
"babel-preset-es2015": "^6.6.0",

@@ -28,0 +31,0 @@ "unexpected": "^10.4.0"

import runTest from 'ava'
import expect from 'unexpected'
import Moment from '../build/index.js'
import Minute from '../build/Minute'
import Day from '../build/Day'
import Millisecond from '../build/Millisecond'
runTest('set & get years', test => {
const moment = new Moment('2015-11-24T18:00')
moment.setYears(1995)
expect(moment.years, 'to equal', 1995)
moment.years = 1998
expect(moment.years, 'to equal', 1998)
runTest('set & get year', test => {
const moment = new Minute('2015-11-24T18:00')
moment.setYear(1995)
expect(moment.year, 'to equal', 1995)
moment.year = 1998
expect(moment.year, 'to equal', 1998)
})
runTest('set & get months', test => {
const moment = new Moment('2015-11-24T18:00')
moment.setMonths(9)
expect(moment.months, 'to equal', 9)
moment.months = 10
expect(moment.months, 'to equal', 10)
runTest('set & get month', test => {
const moment = new Minute('2015-11-24T18:00')
moment.setMonth(9)
expect(moment.month, 'to equal', 9)
moment.month = 10
expect(moment.month, 'to equal', 10)
})
runTest('set & get days', test => {
const moment = new Moment('2015-11-24T18:00')
moment.setDays(22)
expect(moment.days, 'to equal', 22)
moment.days = 23
expect(moment.days, 'to equal', 23)
runTest('set & get day', test => {
const moment = new Minute('2015-11-24T18:00')
moment.setDay(22)
expect(moment.day, 'to equal', 22)
moment.day = 23
expect(moment.day, 'to equal', 23)
})
runTest('set & get hours', test => {
const moment = new Moment('2015-11-24T18:00')
moment.setHours(12)
expect(moment.hours, 'to equal', 12)
moment.hours = 17
expect(moment.hours, 'to equal', 17)
runTest('set & get hour', test => {
const moment = new Minute('2015-11-24T18:00')
moment.setHour(12)
expect(moment.hour, 'to equal', 12)
moment.hour = 17
expect(moment.hour, 'to equal', 17)
})
runTest('set & get minutes', test => {
const moment = new Moment('2015-11-24T18:00')
moment.setMinutes(45)
expect(moment.minutes, 'to equal', 45)
moment.minutes = 50
expect(moment.minutes, 'to equal', 50)
runTest('set & get minute', test => {
const moment = new Minute('2015-11-24T18:00')
moment.setMinute(45)
expect(moment.minute, 'to equal', 45)
moment.minute = 50
expect(moment.minute, 'to equal', 50)
})
runTest('set & get seconds', test => {
const moment = new Moment('2015-11-24T18:00')
moment.setSeconds(45)
expect(moment.seconds, 'to equal', 45)
moment.seconds = 50
expect(moment.seconds, 'to equal', 50)
runTest('set & get second', test => {
const moment = new Millisecond('2015-11-24T18:00:00.000')
moment.setSecond(45)
expect(moment.second, 'to equal', 45)
moment.second = 50
expect(moment.second, 'to equal', 50)
})
runTest('set & get milliseconds', test => {
const moment = new Moment('2015-11-24T18:00')
moment.setMilliseconds(700)
expect(moment.milliseconds, 'to equal', 700)
moment.milliseconds = 800
expect(moment.milliseconds, 'to equal', 800)
runTest('set & get millisecond', test => {
const moment = new Millisecond('2015-11-24T18:00:00.000')
moment.setMillisecond(700)
expect(moment.millisecond, 'to equal', 700)
moment.millisecond = 800
expect(moment.millisecond, 'to equal', 800)
})
runTest('clone', test => {
const moment = new Moment('2015-11-24T12:00')
runTest.skip('clone', test => {
const moment = new Millisecond('2015-11-24T12:00:00.000')
const clone = moment.clone()
clone.setHours(18)
clone.setHour(18)
expect(moment.hours, 'to equal', 12)
expect(clone.hours, 'to equal', 18)
expect(moment.hour, 'to equal', 12)
expect(clone.hour, 'to equal', 18)
})
runTest('toJSON', test => {
const moment = new Moment('2015-11-24')
const day = new Day('2015-11-24')
expect(
JSON.stringify(moment),
JSON.stringify({day: day}),
'to equal',
'{' +
'"string":"2015-11-24",' +
'"precision":"day",' +
'"lowerLimit":"2015-11-24T00:00:00.000Z",' +
'"upperLimit":"2015-11-25T00:00:00.000Z"' +
'}'
'{"day":"2015-11-24"}'
)
})
runTest('toString', test => {
const moment = new Moment('2015-11-24')
expect(moment.toString(), 'to equal', '2015-11-24')
const day = new Day('2015-11-24')
expect('test ' + day, 'to equal', 'test 2015-11-24')
})
import runTest from 'ava'
import expect from 'unexpected'
import Moment from '../build/index'
import Millisecond from '../build/Millisecond'

@@ -23,3 +23,3 @@ const unitToIsoString = {

runTest('start of ' + unit, test => {
const moment = new Moment('2115-11-24T18:37:22.345')
const moment = new Millisecond('2115-11-24T18:37:22.345')
const functionName = 'startOf' +

@@ -26,0 +26,0 @@ unit.slice(0,1).toUpperCase() +

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