summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
Diffstat (limited to 'internal')
-rw-r--r--internal/database/queries.sql18
-rw-r--r--internal/queries/queries.sql.go26
-rw-r--r--internal/tui/app.go4
-rw-r--r--internal/tui/history_box.go2
-rw-r--r--internal/tui/modal.go10
-rw-r--r--internal/tui/shared.go6
6 files changed, 24 insertions, 42 deletions
diff --git a/internal/database/queries.sql b/internal/database/queries.sql
index 8eda5f4..969119a 100644
--- a/internal/database/queries.sql
+++ b/internal/database/queries.sql
@@ -25,11 +25,7 @@ values (
@description,
@client_id,
@project_id,
- coalesce(
- @billable_rate,
- (select p.billable_rate from project p where p.id = @project_id),
- (select c.billable_rate from client c where c.id = @client_id)
- )
+ @billable_rate
)
returning *;
@@ -127,16 +123,12 @@ values (
@description,
@client_id,
@project_id,
- coalesce(
- @billable_rate,
- (select p.billable_rate from project p where p.id = @project_id),
- (select c.billable_rate from client c where c.id = @client_id)
- )
+ @billable_rate
)
returning *;
-- name: GetInvoiceDataByClient :many
-select
+select
te.id as time_entry_id,
te.start_time,
te.end_time,
@@ -321,8 +313,8 @@ where id = (
-- name: EditTimeEntry :exec
update time_entry
set
- start_time = @start_time,
- end_time = @end_time,
+ start_time = datetime(@start_time),
+ end_time = datetime(@end_time),
description = @description,
client_id = @client_id,
project_id = @project_id,
diff --git a/internal/queries/queries.sql.go b/internal/queries/queries.sql.go
index fb7f390..35d90ea 100644
--- a/internal/queries/queries.sql.go
+++ b/internal/queries/queries.sql.go
@@ -128,11 +128,7 @@ values (
?1,
?2,
?3,
- coalesce(
- ?4,
- (select p.billable_rate from project p where p.id = ?3),
- (select c.billable_rate from client c where c.id = ?2)
- )
+ ?4
)
returning id, start_time, end_time, description, client_id, project_id, billable_rate
`
@@ -141,7 +137,7 @@ type CreateTimeEntryParams struct {
Description sql.NullString
ClientID int64
ProjectID sql.NullInt64
- BillableRate interface{}
+ BillableRate sql.NullInt64
}
func (q *Queries) CreateTimeEntry(ctx context.Context, arg CreateTimeEntryParams) (TimeEntry, error) {
@@ -172,11 +168,7 @@ values (
?3,
?4,
?5,
- coalesce(
- ?6,
- (select p.billable_rate from project p where p.id = ?5),
- (select c.billable_rate from client c where c.id = ?4)
- )
+ ?6
)
returning id, start_time, end_time, description, client_id, project_id, billable_rate
`
@@ -187,7 +179,7 @@ type CreateTimeEntryWithTimesParams struct {
Description sql.NullString
ClientID int64
ProjectID sql.NullInt64
- BillableRate interface{}
+ BillableRate sql.NullInt64
}
func (q *Queries) CreateTimeEntryWithTimes(ctx context.Context, arg CreateTimeEntryWithTimesParams) (TimeEntry, error) {
@@ -215,8 +207,8 @@ func (q *Queries) CreateTimeEntryWithTimes(ctx context.Context, arg CreateTimeEn
const editTimeEntry = `-- name: EditTimeEntry :exec
update time_entry
set
- start_time = ?1,
- end_time = ?2,
+ start_time = datetime(?1),
+ end_time = datetime(?2),
description = ?3,
client_id = ?4,
project_id = ?5,
@@ -225,8 +217,8 @@ where id = ?7
`
type EditTimeEntryParams struct {
- StartTime time.Time
- EndTime sql.NullTime
+ StartTime interface{}
+ EndTime interface{}
Description sql.NullString
ClientID int64
ProjectID sql.NullInt64
@@ -404,7 +396,7 @@ func (q *Queries) GetHighestInvoiceNumber(ctx context.Context, arg GetHighestInv
}
const getInvoiceDataByClient = `-- name: GetInvoiceDataByClient :many
-select
+select
te.id as time_entry_id,
te.start_time,
te.end_time,
diff --git a/internal/tui/app.go b/internal/tui/app.go
index 0caf571..6765cd1 100644
--- a/internal/tui/app.go
+++ b/internal/tui/app.go
@@ -203,9 +203,9 @@ func (m *AppModel) openEntryEditor() {
f.fields[0].Focus()
entry := m.historyBox.selectedEntry()
- f.fields[0].SetValue(entry.StartTime.Format(time.DateTime))
+ f.fields[0].SetValue(entry.StartTime.Local().Format(time.DateTime))
if entry.EndTime.Valid {
- f.fields[1].SetValue(entry.EndTime.Time.Format(time.DateTime))
+ f.fields[1].SetValue(entry.EndTime.Time.Local().Format(time.DateTime))
}
for _, client := range m.projectsBox.clients {
if client.ID == entry.ClientID {
diff --git a/internal/tui/history_box.go b/internal/tui/history_box.go
index 00b39f3..d2f71f9 100644
--- a/internal/tui/history_box.go
+++ b/internal/tui/history_box.go
@@ -247,7 +247,7 @@ func (m HistoryBoxModel) renderSummaryView(timer TimerBoxModel) string {
var activeKey HistorySummaryKey
if timer.timerInfo.IsActive {
activeKey = HistorySummaryKey{
- Date: dateOnly(timer.timerInfo.StartTime),
+ Date: dateOnly(timer.timerInfo.StartTime.Local()),
ClientID: timer.timerInfo.ClientID,
}
if timer.timerInfo.ProjectID != nil {
diff --git a/internal/tui/modal.go b/internal/tui/modal.go
index 167b659..9a72336 100644
--- a/internal/tui/modal.go
+++ b/internal/tui/modal.go
@@ -92,7 +92,7 @@ func (m ModalBoxModel) Render() string {
func (m ModalBoxModel) RenderFormModal(title string) string {
return fmt.Sprintf(
- "%s\n\n%s\n\n%s Delete %s Cancel",
+ "%s\n\n%s\n\n%s Submit %s Cancel",
modalTitleStyle.Render(title),
m.form.View(),
boldStyle.Render("[Enter]"),
@@ -231,22 +231,22 @@ func (m *ModalBoxModel) validateAndParseEntryForm(am AppModel) (queries.EditTime
entry, _ := am.queries.GetTimeEntryById(context.Background(), params.EntryID)
startTimeStr := m.form.fields[0].Value()
- startTime, err := time.Parse(time.DateTime, startTimeStr)
+ startTime, err := time.ParseInLocation(time.DateTime, startTimeStr, time.Local)
if err != nil {
m.form.fields[0].Err = fmt.Errorf("invalid start time format")
hasErrors = true
} else {
- params.StartTime = startTime
+ params.StartTime = startTime.UTC().Format(time.DateTime)
}
endTimeStr := m.form.fields[1].Value()
if endTimeStr != "" {
- endTime, err := time.Parse(time.DateTime, endTimeStr)
+ endTime, err := time.ParseInLocation(time.DateTime, endTimeStr, time.Local)
if err != nil {
m.form.fields[1].Err = fmt.Errorf("invalid end time format")
hasErrors = true
} else {
- params.EndTime = sql.NullTime{Time: endTime, Valid: true}
+ params.EndTime = endTime.UTC().Format(time.DateTime)
}
} else if entry.EndTime.Valid {
m.form.fields[1].Err = fmt.Errorf("can not re-open an entry")
diff --git a/internal/tui/shared.go b/internal/tui/shared.go
index 0b0a8c2..e0ee9a0 100644
--- a/internal/tui/shared.go
+++ b/internal/tui/shared.go
@@ -132,9 +132,7 @@ func RenderTopBar(m AppModel) string {
week += activeTime
}
- right := fmt.Sprintf("Today: %s | Week: %s",
- FormatDuration(today),
- FormatDuration(week))
+ right := fmt.Sprintf("Today: %s | Week: %s", FormatDuration(today), FormatDuration(week))
// Use lipgloss to create left and right aligned content
leftStyle := lipgloss.NewStyle().Align(lipgloss.Left)
@@ -237,7 +235,7 @@ func getAppData(
return
}
- now := time.Now()
+ now := time.Now().UTC()
todayY, todayM, todayD := now.Date()
lastMon := mostRecentMonday(now)
inDay := true