Skip to content

Commit

Permalink
Merge pull request #189 from vsimakhin/feature/import-date-auto-format
Browse files Browse the repository at this point in the history
add date autoformat for import
  • Loading branch information
vsimakhin authored Jan 27, 2024
2 parents 35d619a + 8902d97 commit 47d429d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## [Unreleased]

- New: Add autoformat for the date field, so it can convert `D/MM/YYYY`, `DD/MM/YYYY` and `D/M/YYYY` to the full `DD/MM/YYYY` format.
- Fix: Allow full HH:MM format for flight time, so even 02:15 is valid (previosly it allowed 2:15 only without leading 0)
- Fix: If the name field in the AirportDB listing is too long, the listing was displayed outside the popup. Fixed.

Expand Down
15 changes: 14 additions & 1 deletion cmd/web/templates/import-js.partials.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,26 @@ wlbImport = function () {
return time;
}

function convertToDDMMYYYY(dateString) {
// Split the input date string
const parts = dateString.split('/');

// Extract day, month, and year from the split parts
const day = parts[0].padStart(2, '0'); // Pad with leading zero if needed
const month = parts[1].padStart(2, '0'); // Pad with leading zero if needed
const year = parts[2];

// Return the formatted date
return `${day}/${month}/${year}`;
}

// preview data for import table
function previewImport() {
table_data = [];

for (var i = 1; i < csv_import.data.length-1; i++) {
var item = {
date: getMappedValue("date", csv_import.data[i]).replace(/[.]/g, '/'),
date: convertToDDMMYYYY(getMappedValue("date", csv_import.data[i]).replace(/[.]/g, '/')),
departure_place: getMappedValue("departure_place", csv_import.data[i]),
departure_time: autoTimeRecog(getMappedValue("departure_time", csv_import.data[i])),
arrival_place: getMappedValue("arrival_place", csv_import.data[i]),
Expand Down

0 comments on commit 47d429d

Please sign in to comment.