Skip to content

Commit

Permalink
Fix a bug on daily reports
Browse files Browse the repository at this point in the history
  • Loading branch information
seratch committed Nov 3, 2023
1 parent 322f6fa commit d73eed8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
5 changes: 3 additions & 2 deletions functions/internals/reports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ export function generateDailyReport({
country,
language,
}: generateDailyReportArgs): DailyReport | undefined {
if (!entry.user_and_date) {
if (!entry.user_and_date && !lifelog?.user_and_date) {
return undefined;
}
const id = entry.user_and_date;
Expand Down Expand Up @@ -474,7 +474,8 @@ export function generateDailyReport({
if (overtimeWorkMinutes === undefined) overtimeWorkMinutes = 0;
overtimeWorkMinutes += workMinutes - 8 * 60;
}
const yyyymmdd = entry.user_and_date.split("-")[1];
const yyyymmdd =
(entry.user_and_date || lifelog!.user_and_date!).split("-")[1];
const date = toDateFormat(offset, yyyymmdd);

let projects: ProjectWork[] | undefined = undefined;
Expand Down
20 changes: 16 additions & 4 deletions functions/internals/views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -555,8 +555,11 @@ export async function mainViewBlocks({
];

const r = generateDailyReport({ entry, lifelog, offset, language, country });
if (isDebugMode) {
console.log(`### Generated daily report: ${JSON.stringify(r, null, 2)}`);
}

let report = " ";
const reportItems = [];
if (r && r.work_minutes + r.break_time_hours + r.time_off_minutes > 0) {
if (isDebugMode) {
console.log(
Expand Down Expand Up @@ -590,7 +593,6 @@ export async function mainViewBlocks({
hourDuration(r.time_off_hours, language),
minuteDuration(r.time_off_minutes, language),
].filter((e) => e).join(" ");
const reportItems = [];
if (workDuration) {
reportItems.push(
Emoji.Work + " *" + i18n(Label.Work, language) + ":* " + workDuration,
Expand Down Expand Up @@ -641,12 +643,22 @@ export async function mainViewBlocks({
);
}
}
report = reportItems.join("\n");
}
if (r && r.lifelogs && r.lifelogs.length > 0) {
reportItems.push("");
for (const log of r.lifelogs) {
reportItems.push(
"*" + Emoji.Lifelog + " " + log.what_to_do + "*: " +
hourDuration(log.spent_hours, language) + " " +
minuteDuration(log.spent_minutes, language),
);
}
}
const report = reportItems.join("\n");

topBlocks.push({
"type": "section",
"text": { "type": "mrkdwn", "text": report },
"text": { "type": "mrkdwn", "text": report + " " },
"accessory": {
"type": "button",
"action_id": ActionId.Refresh,
Expand Down

0 comments on commit d73eed8

Please sign in to comment.