ampersand-state
Advanced tools
Comparing version 4.3.15 to 4.4.0
@@ -188,3 +188,3 @@ /*$AMPERSAND_VERSION*/ | ||
if (def.values && !_.contains(def.values, newVal)) { | ||
throw new TypeError('Property \'' + attr + '\' must be one of values: ' + def.values.join(', ')); | ||
throw new TypeError('Property \'' + attr + '\' must be one of values: ' + def.values.join(', ') + '. Tried to set ' + newVal); | ||
} | ||
@@ -589,6 +589,9 @@ | ||
try { | ||
newVal = new Date(parseInt(newVal, 10)); | ||
if (!_.isDate(newVal)) throw TypeError; | ||
newVal = newVal.valueOf(); | ||
if (_.isNaN(newVal)) throw TypeError; | ||
var dateVal = new Date(newVal).valueOf(); | ||
if (isNaN(dateVal)) { | ||
// If the newVal cant be parsed, then try parseInt first | ||
dateVal = new Date(parseInt(newVal, 10)).valueOf(); | ||
if (isNaN(dateVal)) throw TypeError; | ||
} | ||
newVal = dateVal; | ||
newType = 'date'; | ||
@@ -595,0 +598,0 @@ } catch (e) { |
{ | ||
"name": "ampersand-state", | ||
"description": "An observable, extensible state object with derived watchable properties.", | ||
"version": "4.3.15", | ||
"version": "4.4.0", | ||
"author": "Henrik Joreteg <henrik@andyet.net>", | ||
@@ -6,0 +6,0 @@ "browserify": { |
@@ -419,3 +419,3 @@ # ampersand-state | ||
var me = new Person({ personID: 123, name: 'Phil' }); | ||
var me = new Person({ personID: 123, name: 'Phil' },{ parse: true}); | ||
@@ -422,0 +422,0 @@ console.log(me.id) //=> 123 |
@@ -267,2 +267,5 @@ var tape = require('tape'); | ||
new Foo({today: '1397631169892'}); | ||
new Foo({today: '2014-11-13'}); | ||
new Foo({today: '2014-11-13T21:01Z'}); | ||
new Foo({today: '2014-11-13T21:01:28.752Z'}); | ||
}); | ||
@@ -1424,1 +1427,41 @@ t.throws(function () { | ||
}); | ||
test("#99 #101 - string dates can be parsed", function(t) { | ||
var Today = State.extend({ | ||
props: { | ||
today: 'date' | ||
} | ||
}); | ||
var isDate = function (obj) { return Object.prototype.toString.call(obj) === '[object Date]'; }; | ||
var isoString = '2014-04-16T06:52:49.892Z'; | ||
var date = new Date(isoString); | ||
var model = new Today(); | ||
model.today = 1397631169892; | ||
t.ok(isDate(model.today)); | ||
t.equal(model.today.valueOf(), date.valueOf(), 'date should accept an integer'); | ||
model.today = '1397631169892'; | ||
t.ok(isDate(model.today)); | ||
t.equal(model.today.valueOf(), date.valueOf(), 'date should accept a string which will be parsed to an integer'); | ||
model.today = isoString; | ||
t.ok(isDate(model.today)); | ||
t.equal(model.today.toJSON(), isoString, 'date should accept an iso string'); | ||
model.today = new Date(isoString); | ||
t.ok(isDate(model.today)); | ||
t.equal(model.today.toJSON(), isoString, 'date should accept a native date object'); | ||
model.today = '2014-11-13'; | ||
t.ok(isDate(model.today)); | ||
t.equal(model.today.toJSON(), '2014-11-13T00:00:00.000Z', 'date should accept YYYY-MM-DD'); | ||
model.today = '2014-11-13T21:01Z'; | ||
t.ok(isDate(model.today)); | ||
t.equal(model.today.toJSON(), '2014-11-13T21:01:00.000Z', 'date should accept YYYY-MM-DDTHH:MMZ'); | ||
t.end(); | ||
}); |
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
114608
2882