Sha256: 46a1538dbc2340e4b78a9dbf9c6c3229e0e5a51dfe810cce36c0691f6dcd5e2d

Contents?: true

Size: 1.14 KB

Versions: 16

Compression:

Stored size: 1.14 KB

Contents

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

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

Interval.prototype.cast = (interval) => {
  if (interval.isInterval) {
    return interval;
  }
  const casted = new cql.Interval(interval.low, interval.high, interval.lowClosed, interval.highClosed);

  // Cast Low and High values to Quantities if it is a quantity
  if (casted.low && casted.low.unit && casted.low.value) {
    casted.low = new cql.Quantity(casted.low.value, casted.low.unit);
    if (casted.high && casted.high.unit && casted.high.value) {
      casted.high = new cql.Quantity(casted.high.value, casted.high.unit);
    }
    return casted;
  }

  // Cast to DateTime if it is a string representing a DateTime
  if (casted.low) {
    casted.low = DateTime.prototype.cast(casted.low);
  }

  if (casted.high) {
    casted.high = DateTime.prototype.cast(casted.high);
  }
  return casted;
};

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

Version data entries

16 entries across 16 versions & 1 rubygems

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