Feature/enforce yyyy instead of yy as date format in activities import (#2036)
* Enforce yyyy (instead of yy) * Update changelog
This commit is contained in:
parent
1809fc8a80
commit
97bcd8ff49
@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- Improved the routes of the tabs
|
- Improved the routes of the tabs
|
||||||
|
- Enforced a stricter date format in the activities import: `dd-MM-yyyy` instead of `dd-MM-yy`
|
||||||
- Updated the URL of the Ghostfolio Slack channel
|
- Updated the URL of the Ghostfolio Slack channel
|
||||||
- Removed the _Ghostfolio in Numbers_ section from the about page
|
- Removed the _Ghostfolio in Numbers_ section from the about page
|
||||||
|
|
||||||
|
@ -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
Normal file
2
test/import/invalid-date-yy.csv
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
Date,Code,Currency,Price,Quantity,Action,Fee
|
||||||
|
16/09/21,MSFT,USD,298.580,5,buy,19.00
|
|
Loading…
x
Reference in New Issue
Block a user