mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-07-01 10:42:19 +08:00
fix: datetime parser of YYYYMMDD format (#5891)
* fix: parse number format in date only field * chore: test * chore: build
This commit is contained in:
parent
fbe63b1712
commit
fef379d9bf
@ -66,6 +66,14 @@ export class DatetimeInterface extends BaseInterface {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (typeof value === 'number') {
|
||||
const valueStr = value.toString();
|
||||
const dateOnlyMatch = /^(\d{4})[-/]?(\d{2})[-/]?(\d{2})$/.exec(valueStr);
|
||||
if (dateOnlyMatch) {
|
||||
value = valueStr;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof value === 'string') {
|
||||
const dateInfo = this.parseDateString(value);
|
||||
if (dateInfo) {
|
||||
|
@ -105,6 +105,7 @@ describe('xlsx importer', () => {
|
||||
[
|
||||
['test', 77383],
|
||||
['test2', '2021-10-18'],
|
||||
['test3', 20241112],
|
||||
],
|
||||
{ origin: 'A2' },
|
||||
);
|
||||
@ -121,6 +122,7 @@ describe('xlsx importer', () => {
|
||||
const users = (await User.repository.find()).map((user) => user.toJSON());
|
||||
expect(users[0]['dateOnly']).toBe('2111-11-12');
|
||||
expect(users[1]['dateOnly']).toBe('2021-10-18');
|
||||
expect(users[2]['dateOnly']).toBe('2024-11-12');
|
||||
});
|
||||
|
||||
it.skipIf(process.env['DB_DIALECT'] === 'sqlite')('should import with datetimeNoTz', async () => {
|
||||
@ -190,7 +192,15 @@ describe('xlsx importer', () => {
|
||||
|
||||
const worksheet = template.Sheets[template.SheetNames[0]];
|
||||
|
||||
XLSX.utils.sheet_add_aoa(worksheet, [['test', 77383]], { origin: 'A2' });
|
||||
XLSX.utils.sheet_add_aoa(
|
||||
worksheet,
|
||||
[
|
||||
['test', 77383],
|
||||
['test2', 20241112],
|
||||
['test3', '2024-11-12'],
|
||||
],
|
||||
{ origin: 'A2' },
|
||||
);
|
||||
|
||||
const importer = new XlsxImporter({
|
||||
collectionManager: app.mainDataSource.collectionManager,
|
||||
@ -203,6 +213,8 @@ describe('xlsx importer', () => {
|
||||
|
||||
const users = (await User.repository.find()).map((user) => user.toJSON());
|
||||
expect(moment(users[0]['unixTimestamp']).toISOString()).toEqual('2111-11-12T00:00:00.000Z');
|
||||
expect(moment(users[1]['unixTimestamp'])).toBeDefined();
|
||||
expect(moment(users[2]['unixTimestamp'])).toBeDefined();
|
||||
});
|
||||
|
||||
it('should import with datetimeTz', async () => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user