diff --git a/src/decorator/attribute-types/date.spec.ts b/src/decorator/attribute-types/date.spec.ts index de57608..dc2ce24 100644 --- a/src/decorator/attribute-types/date.spec.ts +++ b/src/decorator/attribute-types/date.spec.ts @@ -44,11 +44,13 @@ describe('AttributeType/Date', () => { await new Promise((resolve) => setTimeout(resolve, 2000)) // save again + const updatedAtBeforeSave = record.updatedAt await record.save({ force: true }) // using force save so it saves, ignoring the fact there are no changes expect(record.updatedAt).to.be.a('date') expect(record.updatedAt).to.be.at.least(later) expect(record.updatedAt).to.be.at.within(later, new Date()) + expect(record.updatedAt).to.not.eq(updatedAtBeforeSave) expect(record.getAttributeDynamoValue('createdAt')).to.deep.eq({ S: record.createdAt.toISOString(), diff --git a/src/decorator/attribute-types/date.ts b/src/decorator/attribute-types/date.ts index aa63e64..072ac48 100644 --- a/src/decorator/attribute-types/date.ts +++ b/src/decorator/attribute-types/date.ts @@ -45,10 +45,6 @@ export class DateAttributeType extends AttributeType implements } toDynamo(dt: Value): AttributeValue { - if (this.metadata?.nowOnUpdate === true) { - dt = new Date() - } - if (this.metadata?.unixTimestamp === true || this.metadata?.millisecondTimestamp === true || this.metadata?.timeToLive === true) { return { N: this.parseDate(dt).toString(), @@ -114,7 +110,7 @@ export class DateAttributeType extends AttributeType implements // parse YYYY-MM-DD and ensure we create the Date object in UTC const b = dt.split('-').map((d) => parseInt(d, 10)) dt = new Date(Date.UTC(b[0], --b[1], b[2])) - // if timestamp, assume the value is a timestamp + // if configured as a timestamp, assume the value is a numeric string as a timestamp } else if (this.metadata?.unixTimestamp === true || this.metadata?.timeToLive === true) { dt = new Date(stringToNumber(dt) * 1000) } else if (this.metadata?.millisecondTimestamp === true) {