Sha256: 0e29b8f05274fa6ca38267a74614a87053c2a8e1310926aa5c0611c952a4b87f

Contents?: true

Size: 583 Bytes

Versions: 19

Compression:

Stored size: 583 Bytes

Contents

const mongoose = require('mongoose/browser');
const cql = require('cql-execution');

function DateTime(key, options) {
  mongoose.SchemaType.call(this, key, options, 'DateTime');
}
DateTime.prototype = Object.create(mongoose.SchemaType.prototype);

DateTime.prototype.cast = (dateTime) => {
  if (dateTime.isDateTime) {
    return dateTime;
  }

  if (!Date.parse(dateTime)) {
    throw new Error(`DateTime: ${dateTime} is not a valid DateTime`);
  }

  return cql.DateTime.fromJSDate(new Date(dateTime), 0);
};

mongoose.Schema.Types.DateTime = DateTime;
module.exports = DateTime;

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
cqm-models-4.2.0 app/assets/javascripts/basetypes/DateTime.js
cqm-models-3.1.2 app/assets/javascripts/basetypes/DateTime.js
cqm-models-4.1.1 app/assets/javascripts/basetypes/DateTime.js
cqm-models-4.1.0 app/assets/javascripts/basetypes/DateTime.js
cqm-models-4.0.2 app/assets/javascripts/basetypes/DateTime.js
cqm-models-4.0.1 app/assets/javascripts/basetypes/DateTime.js
cqm-models-4.0.0 app/assets/javascripts/basetypes/DateTime.js
cqm-models-3.1.1 app/assets/javascripts/basetypes/DateTime.js
cqm-models-3.1.0 app/assets/javascripts/basetypes/DateTime.js
cqm-models-3.0.6 app/assets/javascripts/basetypes/DateTime.js
cqm-models-3.0.5 app/assets/javascripts/basetypes/DateTime.js
cqm-models-3.0.4 app/assets/javascripts/basetypes/DateTime.js
cqm-models-3.0.3 app/assets/javascripts/basetypes/DateTime.js
cqm-models-3.0.2 app/assets/javascripts/basetypes/DateTime.js
cqm-models-3.0.1 app/assets/javascripts/basetypes/DateTime.js
cqm-models-2.0.1 app/assets/javascripts/basetypes/DateTime.js
cqm-models-3.0.0 app/assets/javascripts/basetypes/DateTime.js
cqm-models-2.0.0 app/assets/javascripts/basetypes/DateTime.js
cqm-models-1.1.1.0 app/assets/javascripts/basetypes/DateTime.js