forked from Stigmatoz/web-activity-time-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuseImportToCsv.ts
More file actions
35 lines (28 loc) · 946 Bytes
/
useImportToCsv.ts
File metadata and controls
35 lines (28 loc) · 946 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { DayTabs } from '../dto/tabListSummary';
import { useTabListByDays } from './useTabListByDays';
const CSV_HEADER = 'Date,WebSite,Time(sec),Sessions\r\n';
export async function useImportToCsvWithData(days: DayTabs[] | undefined): Promise<string> {
return getCsv(days);
}
export async function useImportToCsv(dateFrom: Date, dateTo: Date): Promise<string> {
const summary = await useTabListByDays(dateFrom, dateTo);
if (summary == null) return CSV_HEADER;
return getCsv(summary.days);
}
function getCsv(days: DayTabs[] | undefined) {
let str = CSV_HEADER;
if (days != undefined && days.length > 0) {
days.forEach(day => {
let newLine = '';
day.tabs.forEach(tab => {
newLine += day.day + ',';
newLine += tab.url + ',';
newLine += tab.summaryTime + ',';
newLine += tab.sessions;
newLine += '\r\n';
});
str += newLine + '\r\n';
});
}
return str;
}