MCPcopy
hub / github.com/sequelize/sequelize / DATE

Class DATE

lib/data-types.js:425–476  ·  view source on GitHub ↗

* Date column with timezone, default is UTC

Source from the content-addressed store, hash-verified

423 * Date column with timezone, default is UTC
424 */
425class DATE extends ABSTRACT {
426 /**
427 * @param {string|number} [length] precision to allow storing milliseconds
428 */
429 constructor(length) {
430 super();
431 const options = typeof length === 'object' && length || { length };
432 this.options = options;
433 this._length = options.length || '';
434 }
435 toSql() {
436 return 'DATETIME';
437 }
438 validate(value) {
439 if (!Validator.isDate(String(value))) {
440 throw new sequelizeErrors.ValidationError(util.format('%j is not a valid date', value));
441 }
442 return true;
443 }
444 _sanitize(value, options) {
445 if ((!options || options && !options.raw) && !(value instanceof Date) && !!value) {
446 return new Date(value);
447 }
448 return value;
449 }
450 _isChanged(value, originalValue) {
451 if (originalValue && !!value &&
452 (value === originalValue ||
453 value instanceof Date && originalValue instanceof Date && value.getTime() === originalValue.getTime())) {
454 return false;
455 }
456 // not changed when set to same empty value
457 if (!originalValue && !value && originalValue === value) {
458 return false;
459 }
460 return true;
461 }
462 _applyTimezone(date, options) {
463 if (options.timezone) {
464 if (momentTz.tz.zone(options.timezone)) {
465 return momentTz(date).tz(options.timezone);
466 }
467 return date = moment(date).utcOffset(options.timezone);
468 }
469 return momentTz(date);
470 }
471 _stringify(date, options) {
472 date = this._applyTimezone(date, options);
473 // Z here means current timezone, _not_ UTC
474 return date.format('YYYY-MM-DD HH:mm:ss.SSS Z');
475 }
476}
477
478/**
479 * A date only column (no timestamp)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…