forked from cdaringe/ampersand-state-mixin-datatype-iso-date
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
33 lines (31 loc) · 929 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
'use strict';
var moment = require('moment');
module.exports = {
dataTypes : {
'iso-date' : {
set: function(newVal){
var newDate;
if (newVal._isAMomentObject) {
return {
val : newVal.format(),
type : 'iso-date'
};
}
newDate = moment(newVal);
return {
val : newDate.format(),
type : 'iso-date'
};
},
compare : function(currentVal, newVal, attributeName) {
if (!currentVal) {
return !newVal ? true : false;
}
if (newVal._isAMomentObject) {
return newVal.format() === currentVal;
}
return newVal === currentVal;
}
}
}
};