ampersand-state-mixin-datatype-iso-date

1.0.1 • Public • Published

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

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'
    }
});

usage

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!)

Package Sidebar

Install

npm i ampersand-state-mixin-datatype-iso-date

Weekly Downloads

1

Version

1.0.1

License

MIT

Last publish

Collaborators

  • cdaringe
  • waydotnet