summaryrefslogtreecommitdiff
path: root/internal/reports/timesheet.go
diff options
context:
space:
mode:
authorT <t@tjp.lol>2025-08-13 16:48:58 -0600
committerT <t@tjp.lol>2025-08-13 16:49:20 -0600
commit7d0d21ba8663ab7ff777a06f4b113337fa717ff3 (patch)
treef06d8691fd13bee6ebccfc17a08c599bd5710705 /internal/reports/timesheet.go
parent5c3554c7e49abe263faf54c61e435ba1d5202d27 (diff)
go module in git.tjp.lol
Diffstat (limited to 'internal/reports/timesheet.go')
-rw-r--r--internal/reports/timesheet.go67
1 files changed, 33 insertions, 34 deletions
diff --git a/internal/reports/timesheet.go b/internal/reports/timesheet.go
index a40d8ae..d9ad4b8 100644
--- a/internal/reports/timesheet.go
+++ b/internal/reports/timesheet.go
@@ -5,7 +5,7 @@ import (
"fmt"
"time"
- "punchcard/internal/queries"
+ "git.tjp.lol/punchcard/internal/queries"
)
type TimesheetData struct {
@@ -33,14 +33,14 @@ type TimesheetEntry struct {
}
type timesheetEntryData struct {
- TimeEntryID int64
- StartTime time.Time
- EndTime sql.NullTime
- Description sql.NullString
- ClientID int64
- ClientName string
- ProjectID sql.NullInt64
- ProjectName sql.NullString
+ TimeEntryID int64
+ StartTime time.Time
+ EndTime sql.NullTime
+ Description sql.NullString
+ ClientID int64
+ ClientName string
+ ProjectID sql.NullInt64
+ ProjectName sql.NullString
DurationSeconds int64
}
@@ -59,28 +59,28 @@ func GenerateTimesheetData(
case []queries.GetTimesheetDataByClientRow:
for _, entry := range e {
timeEntries = append(timeEntries, timesheetEntryData{
- TimeEntryID: entry.TimeEntryID,
- StartTime: entry.StartTime,
- EndTime: entry.EndTime,
- Description: entry.Description,
- ClientID: entry.ClientID,
- ClientName: entry.ClientName,
- ProjectID: entry.ProjectID,
- ProjectName: entry.ProjectName,
+ TimeEntryID: entry.TimeEntryID,
+ StartTime: entry.StartTime,
+ EndTime: entry.EndTime,
+ Description: entry.Description,
+ ClientID: entry.ClientID,
+ ClientName: entry.ClientName,
+ ProjectID: entry.ProjectID,
+ ProjectName: entry.ProjectName,
DurationSeconds: entry.DurationSeconds,
})
}
case []queries.GetTimesheetDataByProjectRow:
for _, entry := range e {
timeEntries = append(timeEntries, timesheetEntryData{
- TimeEntryID: entry.TimeEntryID,
- StartTime: entry.StartTime,
- EndTime: entry.EndTime,
- Description: entry.Description,
- ClientID: entry.ClientID,
- ClientName: entry.ClientName,
- ProjectID: sql.NullInt64{Int64: entry.ProjectID, Valid: true},
- ProjectName: sql.NullString{String: entry.ProjectName, Valid: true},
+ TimeEntryID: entry.TimeEntryID,
+ StartTime: entry.StartTime,
+ EndTime: entry.EndTime,
+ Description: entry.Description,
+ ClientID: entry.ClientID,
+ ClientName: entry.ClientName,
+ ProjectID: sql.NullInt64{Int64: entry.ProjectID, Valid: true},
+ ProjectName: sql.NullString{String: entry.ProjectName, Valid: true},
DurationSeconds: entry.DurationSeconds,
})
}
@@ -134,27 +134,27 @@ func convertToTimesheetEntries(entries []timesheetEntryData, loc *time.Location)
// Convert UTC times to specified timezone
localStartTime := entry.StartTime.In(loc)
localEndTime := entry.EndTime.Time.In(loc)
-
+
// Format date as YYYY-MM-DD
date := localStartTime.Format("2006-01-02")
-
+
// Format times as HH:MM
startTime := localStartTime.Format("15:04")
endTime := localEndTime.Format("15:04")
-
+
// Format duration as HH:MM
duration := formatDuration(entry.DurationSeconds)
-
+
// Calculate hours as decimal, rounded to nearest minute
- totalMinutes := (entry.DurationSeconds + 30) / 60 // Round to nearest minute
+ totalMinutes := (entry.DurationSeconds + 30) / 60 // Round to nearest minute
hours := float64(totalMinutes) / 60.0
-
+
// Get project name
projectName := ""
if entry.ProjectName.Valid {
projectName = entry.ProjectName.String
}
-
+
// Get description
description := ""
if entry.Description.Valid {
@@ -177,9 +177,8 @@ func convertToTimesheetEntries(entries []timesheetEntryData, loc *time.Location)
func formatDuration(seconds int64) string {
// Round to nearest minute
- totalMinutes := (seconds + 30) / 60 // Add 30 seconds for rounding
+ totalMinutes := (seconds + 30) / 60 // Add 30 seconds for rounding
hours := totalMinutes / 60
minutes := totalMinutes % 60
return fmt.Sprintf("%d:%02d", hours, minutes)
}
-