Closed davingreen closed 3 years ago
I resolved this by transforming the scheduledToSendAt to date from a string. Apparently, the data api driver causes an issue with TypeORM's automatic casting of date strings to dates (maybe?)
Anyway, I've got a workaround -- thanks!
Hello @davingreen,
Could you please confirm whether I have understood your workaround properly?
You had your initial property set up as Date type:
@Column({ nullable: true, type: 'timestamp' })
public scheduledToSendAt?: Date
You got the error and you changed it to a string type, thus fixing your problem:
@Column({ nullable: true, type: 'timestamp' })
public scheduledToSendAt?: string
I am asking because I am facing the exact same error, however, all date properties in my class are already strings like so:
@Column('date')
date1: string;
@Column({ type: 'timestamptz', nullable: true })
date2?: string;
And I am trying to save a record in the db like so:
const record = new Entity({
date1: new Date().toISOString(),
date2: new Date().toISOString(),
});
const errors = await validate(record);
if (errors.length > 0) {
console.log('Invalid record!');
} else {
console.log('Saving new record...');
await record.save();
}
of course without success because of the TypeError: date.getUTCFullYear is not a function
Thanks in advance! :)
Hi @tgechev,
Running latest updates, I was able to change the types back to Date. You can then use a JS Date object (instead of new Date().toISOString()
, just new Date()
.
I've found that the TypeError: date.getUTCFullYear is not a function
typically occurs when TypeORM is expecting a Date object, but receiving a string.
Hope that helps!
When trying to update:
using