Adds date type to ampersand-state using ISO 8601 locale serialized strings
Switch branches/tags
Nothing to show
Clone or download
Pull request Compare This branch is 4 commits behind cdaringe:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

Codeship Status for cdaringe/ampersand-state-mixin-datatype-iso-date


Adds ISO 8601 date functionality to ampersand state. This module stores dates explicity as full ISO 8601 strings with client locale TZ. This makes all timestamps lossless, vs using UTC ISO stamps or Unix time (epoch) values.

// same time, different formats
"2015-07-04T15:26:19-07:00" // good! lossless timestamp data, keeping client TZ. we use this
"2015-07-04T22:26:19.000Z" // poor! UTC normalized.  drops user TZ
1436048779 // poor! unix time, UTC normalized (maybe!*). drops user TZ

You may want to specify something like the following in your ampersand-states or ampersand-models:

var State = require('ampersand-state');
var DateState = State.extend(isoDateMixin, {
    props: {
        sometime: 'iso-date'


Using the example from above

var State = require('ampersand-state');
var funcMixin = require('ampersand-state-mixin-datatype-iso-date');
var DateState = State.extend(funcMixin, {
    props: {
        sometime: {
            type: 'iso-date',
            required: true

var model = new DateState({
    myTime: new Date()
model.myTime; //=> "2015-07-04T15:26:19-07:00"

model.myTime = "2015-07-04 16:30:20-07:00"; // no T is still ISO compliant. some DBs, like postgres, omit it by default
model.myTime; //=> "2015-07-04T16:30:20-07:00";

model.myTime = '10/10/2010'; // Using incomplete timestamps is deprecated in this module's moment.js dep, thus not recommended
model.myTime; //=> "2010-10-10T00:00:00-07:00" (caution!)