* Date column with timezone, default is UTC
| 423 | * Date column with timezone, default is UTC |
| 424 | */ |
| 425 | class 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 | if (!moment.isMoment(date)) { |
| 473 | date = this._applyTimezone(date, options); |
| 474 | } |
| 475 | // Z here means current timezone, _not_ UTC |
| 476 | return date.format('YYYY-MM-DD HH:mm:ss.SSS Z'); |
| 477 | } |
| 478 | } |
| 479 | |
| 480 | /** |
| 481 | * A date only column (no timestamp) |
nothing calls this directly
no outgoing calls
no test coverage detected