summaryrefslogtreecommitdiff
path: root/internal/reports/timesheet_test.go
diff options
context:
space:
mode:
authorT <t@tjp.lol>2025-08-22 15:52:06 -0600
committerT <t@tjp.lol>2025-08-28 22:02:13 -0600
commitadd7c1a8126733dd86282f443dc53127888c06af (patch)
tree7141166363b333a4c65e64785fdf4f5a08350a8d /internal/reports/timesheet_test.go
parent275cbc0b30121d3273f7fd428583e8c48ce7d017 (diff)
loads of testing
Diffstat (limited to 'internal/reports/timesheet_test.go')
-rw-r--r--internal/reports/timesheet_test.go200
1 files changed, 200 insertions, 0 deletions
diff --git a/internal/reports/timesheet_test.go b/internal/reports/timesheet_test.go
index ed35c86..591b90b 100644
--- a/internal/reports/timesheet_test.go
+++ b/internal/reports/timesheet_test.go
@@ -119,6 +119,110 @@ func TestGenerateTimesheetData(t *testing.T) {
entries: "invalid",
wantError: true,
},
+ {
+ name: "entries with Pacific timezone (UTC-8)",
+ entries: []queries.GetTimesheetDataByClientRow{
+ {
+ TimeEntryID: 5,
+ StartTime: mustParseTime("2025-07-15T08:00:00Z"), // 8 AM UTC = midnight PST
+ EndTime: sql.NullTime{Time: mustParseTime("2025-07-15T16:00:00Z"), Valid: true}, // 4 PM UTC = 8 AM PST
+ Description: sql.NullString{String: "Early morning work", Valid: true},
+ DurationSeconds: 28800, // 8 hours
+ },
+ },
+ clientID: 1,
+ clientName: "Test Client",
+ contractor: queries.Contractor{
+ Name: "Travis Parker",
+ Label: "Software Development",
+ Email: "travis@example.com",
+ },
+ dateRange: DateRange{
+ Start: mustParseTime("2025-07-01T00:00:00Z"),
+ End: mustParseTime("2025-07-31T23:59:59Z"),
+ },
+ timezone: mustLoadLocation("America/Los_Angeles"),
+ wantEntries: 1,
+ wantHours: 8.0,
+ },
+ {
+ name: "entries crossing date boundary in timezone",
+ entries: []queries.GetTimesheetDataByClientRow{
+ {
+ TimeEntryID: 6,
+ StartTime: mustParseTime("2025-07-15T23:30:00Z"), // 11:30 PM UTC = 4:30 PM PDT (July 15)
+ EndTime: sql.NullTime{Time: mustParseTime("2025-07-16T01:30:00Z"), Valid: true}, // 1:30 AM UTC = 6:30 PM PDT (July 15, same day in PDT)
+ Description: sql.NullString{String: "Late evening work", Valid: true},
+ DurationSeconds: 7200, // 2 hours
+ },
+ },
+ clientID: 1,
+ clientName: "Test Client",
+ contractor: queries.Contractor{
+ Name: "Travis Parker",
+ Label: "Software Development",
+ Email: "travis@example.com",
+ },
+ dateRange: DateRange{
+ Start: mustParseTime("2025-07-01T00:00:00Z"),
+ End: mustParseTime("2025-07-31T23:59:59Z"),
+ },
+ timezone: mustLoadLocation("America/Los_Angeles"),
+ wantEntries: 1,
+ wantHours: 2.0,
+ },
+ {
+ name: "entries with extreme positive timezone (UTC+14)",
+ entries: []queries.GetTimesheetDataByClientRow{
+ {
+ TimeEntryID: 7,
+ StartTime: mustParseTime("2025-07-15T10:00:00Z"), // 10 AM UTC = midnight+1day in UTC+14
+ EndTime: sql.NullTime{Time: mustParseTime("2025-07-15T12:00:00Z"), Valid: true}, // 12 PM UTC = 2 AM+1day in UTC+14
+ Description: sql.NullString{String: "Future timezone work", Valid: true},
+ DurationSeconds: 7200, // 2 hours
+ },
+ },
+ clientID: 1,
+ clientName: "Test Client",
+ contractor: queries.Contractor{
+ Name: "Travis Parker",
+ Label: "Software Development",
+ Email: "travis@example.com",
+ },
+ dateRange: DateRange{
+ Start: mustParseTime("2025-07-01T00:00:00Z"),
+ End: mustParseTime("2025-07-31T23:59:59Z"),
+ },
+ timezone: time.FixedZone("UTC+14", 14*3600),
+ wantEntries: 1,
+ wantHours: 2.0,
+ },
+ {
+ name: "entries with extreme negative timezone (UTC-12)",
+ entries: []queries.GetTimesheetDataByClientRow{
+ {
+ TimeEntryID: 8,
+ StartTime: mustParseTime("2025-07-15T12:00:00Z"), // 12 PM UTC = midnight in UTC-12
+ EndTime: sql.NullTime{Time: mustParseTime("2025-07-15T15:00:00Z"), Valid: true}, // 3 PM UTC = 3 AM in UTC-12
+ Description: sql.NullString{String: "Early timezone work", Valid: true},
+ DurationSeconds: 10800, // 3 hours
+ },
+ },
+ clientID: 1,
+ clientName: "Test Client",
+ contractor: queries.Contractor{
+ Name: "Travis Parker",
+ Label: "Software Development",
+ Email: "travis@example.com",
+ },
+ dateRange: DateRange{
+ Start: mustParseTime("2025-07-01T00:00:00Z"),
+ End: mustParseTime("2025-07-31T23:59:59Z"),
+ },
+ timezone: time.FixedZone("UTC-12", -12*3600),
+ wantEntries: 1,
+ wantHours: 3.0,
+ },
}
for _, tt := range tests {
@@ -250,6 +354,102 @@ func TestConvertToTimesheetEntries(t *testing.T) {
timezone: time.UTC,
want: []TimesheetEntry{}, // Should be empty
},
+ {
+ name: "entry crossing midnight boundary in Pacific timezone",
+ entries: []timesheetEntryData{
+ {
+ TimeEntryID: 4,
+ StartTime: mustParseTime("2025-07-15T23:00:00Z"), // 11 PM UTC = 4 PM PDT (July 15)
+ EndTime: sql.NullTime{Time: mustParseTime("2025-07-16T03:00:00Z"), Valid: true}, // 3 AM UTC = 8 PM PDT (July 15)
+ Description: sql.NullString{String: "Evening work", Valid: true},
+ DurationSeconds: 14400, // 4 hours
+ },
+ },
+ timezone: mustLoadLocation("America/Los_Angeles"),
+ want: []TimesheetEntry{
+ {
+ Date: "2025-07-15", // Should be July 15 in PDT despite UTC crossing midnight
+ StartTime: "16:00", // 4:00 PM PDT
+ EndTime: "20:00", // 8:00 PM PDT
+ Duration: "4:00",
+ Hours: 4.0,
+ ProjectName: "",
+ Description: "Evening work",
+ },
+ },
+ },
+ {
+ name: "entry in extreme timezone (UTC+14)",
+ entries: []timesheetEntryData{
+ {
+ TimeEntryID: 5,
+ StartTime: mustParseTime("2025-07-15T10:00:00Z"), // 10 AM UTC = midnight next day in UTC+14
+ EndTime: sql.NullTime{Time: mustParseTime("2025-07-15T13:00:00Z"), Valid: true}, // 1 PM UTC = 3 AM next day in UTC+14
+ Description: sql.NullString{String: "Future timezone work", Valid: true},
+ DurationSeconds: 10800, // 3 hours
+ },
+ },
+ timezone: time.FixedZone("UTC+14", 14*3600),
+ want: []TimesheetEntry{
+ {
+ Date: "2025-07-16", // Next day in UTC+14
+ StartTime: "00:00", // Midnight
+ EndTime: "03:00", // 3 AM
+ Duration: "3:00",
+ Hours: 3.0,
+ ProjectName: "",
+ Description: "Future timezone work",
+ },
+ },
+ },
+ {
+ name: "entry spanning DST transition (spring forward)",
+ entries: []timesheetEntryData{
+ {
+ TimeEntryID: 6,
+ StartTime: mustParseTime("2024-03-10T06:30:00Z"), // 1:30 AM EST, before DST
+ EndTime: sql.NullTime{Time: mustParseTime("2024-03-10T10:30:00Z"), Valid: true}, // 5:30 AM EST/6:30 AM EDT after DST
+ Description: sql.NullString{String: "DST transition work", Valid: true},
+ DurationSeconds: 14400, // 4 hours
+ },
+ },
+ timezone: mustLoadLocation("America/New_York"),
+ want: []TimesheetEntry{
+ {
+ Date: "2024-03-10",
+ StartTime: "01:30", // EST time before spring forward
+ EndTime: "06:30", // EDT time after spring forward (skips 2-3 AM)
+ Duration: "4:00", // Duration is still 4 hours
+ Hours: 4.0,
+ ProjectName: "",
+ Description: "DST transition work",
+ },
+ },
+ },
+ {
+ name: "rounding to nearest minute",
+ entries: []timesheetEntryData{
+ {
+ TimeEntryID: 7,
+ StartTime: mustParseTime("2025-07-10T14:00:00Z"),
+ EndTime: sql.NullTime{Time: mustParseTime("2025-07-10T15:01:29Z"), Valid: true}, // 1 hour 1 minute 29 seconds
+ Description: sql.NullString{String: "Rounding test", Valid: true},
+ DurationSeconds: 3689, // 1:01:29
+ },
+ },
+ timezone: time.UTC,
+ want: []TimesheetEntry{
+ {
+ Date: "2025-07-10",
+ StartTime: "14:00",
+ EndTime: "15:01",
+ Duration: "1:01", // Rounds down to 61 minutes
+ Hours: 1.0167, // (3689+30)/60 = 3719 seconds = 61.9833 minutes = 1.0331 hours rounded to nearest minute
+ ProjectName: "",
+ Description: "Rounding test",
+ },
+ },
+ },
}
for _, tt := range tests {