Skip to content

Commit

Permalink
format feeling's date field to not show time
Browse files Browse the repository at this point in the history
  • Loading branch information
vinaybadgujar102 committed Nov 30, 2024
1 parent 519270d commit f83822f
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/utils/ExportStrategies/CsvExportStrategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,23 @@ export class CsvExportStrategy implements ExportStrategy {
try {
const goalsArray = await db.goalsCollection.toArray();
const feelingsArray = await db.feelingsCollection.toArray();

// Format dates only show YYYY-MM-DD
const formattedFeelingsArray = feelingsArray.map((feeling) => ({
...feeling,
date: new Date(feeling.date).toISOString().slice(0, 10),
}));

console.log(formattedFeelingsArray[0].date);

const goalsCollectionKeys = db.goalsCollection.schema.indexes;
const goalsKeys = goalsCollectionKeys.map((key) => key.name);

const feelingsCollectionKeys = db.feelingsCollection.schema.indexes;
const feelingsKeys = feelingsCollectionKeys.map((key) => key.name);

const goalsCsvContent = convertJSONToCSV(goalsArray, goalsKeys);
const feelingsCsvContent = convertJSONToCSV(feelingsArray, feelingsKeys);
const feelingsCsvContent = convertJSONToCSV(formattedFeelingsArray, feelingsKeys);

const goalsBlob = new Blob([goalsCsvContent], { type: "text/csv;charset=utf-8;" });
const feelingsBlob = new Blob([feelingsCsvContent], { type: "text/csv;charset=utf-8;" });
Expand Down

0 comments on commit f83822f

Please sign in to comment.