Browse Source

Enforce yyyy (instead of yy)

pull/2036/head
Thomas 2 years ago
parent
commit
eb88af42c3
  1. 12
      apps/client/src/app/services/import-activities.service.ts
  2. 2
      test/import/invalid-date-yy.csv

12
apps/client/src/app/services/import-activities.service.ts

@ -223,11 +223,17 @@ export class ImportActivitiesService {
for (const key of ImportActivitiesService.DATE_KEYS) { for (const key of ImportActivitiesService.DATE_KEYS) {
if (item[key]) { if (item[key]) {
if (isMatch(item[key], 'dd-MM-yyyy')) { if (isMatch(item[key], 'dd-MM-yyyy') && item[key].length === '10') {
// Check length to only match yyyy (and not yy)
date = parse(item[key], 'dd-MM-yyyy', new Date()).toISOString(); date = parse(item[key], 'dd-MM-yyyy', new Date()).toISOString();
} else if (isMatch(item[key], 'dd/MM/yyyy')) { } else if (
isMatch(item[key], 'dd/MM/yyyy') &&
item[key].length === '10'
) {
// Check length to only match yyyy (and not yy)
date = parse(item[key], 'dd/MM/yyyy', new Date()).toISOString(); date = parse(item[key], 'dd/MM/yyyy', new Date()).toISOString();
} else if (isMatch(item[key], 'yyyyMMdd')) { } else if (isMatch(item[key], 'yyyyMMdd') && item[key].length === '8') {
// Check length to only match yyyy (and not yy)
date = parse(item[key], 'yyyyMMdd', new Date()).toISOString(); date = parse(item[key], 'yyyyMMdd', new Date()).toISOString();
} else { } else {
try { try {

2
test/import/invalid-date-yy.csv

@ -0,0 +1,2 @@
Date,Code,Currency,Price,Quantity,Action,Fee
16/09/21,MSFT,USD,298.580,5,buy,19.00
1 Date Code Currency Price Quantity Action Fee
2 16/09/21 MSFT USD 298.580 5 buy 19.00
Loading…
Cancel
Save